I am currently using the Moq library for unit testing. Moq gives me the ability to register callbacks before and after method invocation on a mocked object like so:
Mock<IMyClass> mock = new Mock<IMyClass>();
mock.Setup(o => o.MyMethod())
.Callback(() => Console.WriteLine("BEFORE!"))
.Returns(true)
.Callback(() => Console.WriteLine("AFTER!"));
However, if MyMethod does not return a value (i.e. it has a void return type), then I can only setup a single Callback like so:
mock.Setup(o => o.MyMethod())
.Callback(() => Console.WriteLine("BEFORE!"));
As noted in the code, this callback happens BEFORE the method is invoked. There don't seem to be any other options for specifying a second callback for after the method is invoked.
Is this possible? There doesn't seem to be anything in the documentation about it. Am I missing something?
Aucun commentaire:
Enregistrer un commentaire