jeudi 7 juillet 2016

Exception of invocation on the mock was 0 times, but I can see performed invocations correctly

Here's my simplified version of unit test

var service = Fixture.Freeze<IService>();
var outerService = Fixture.Create<OuterService>();

var testObject = Fixture.Create<TestObject>();

outerService.Notify(testObject);
Mock.Get(service).Verify(s => s.SendNotification(It.IsAny<String>(), It.IsAny<TestObject>(), null), Times.Once);

Note that:

outerService.Notify(testObject)

internally calls

IService.SendNotification(string testObject.Name, testObject, extraObject = null)


The above will cause the test to fail, complaining that:

Expected invocation 1 time,but was 0 times: 
s => s.SendNotification(It.IsAny<String>(), It.IsAny<TestObject>(), null)
No setups configured.

Performed invocations:
IService.SendNotification("testObject", UnitTest.TestObject, null)

I don't understand, the performed invocation looks exactly like the expected invocation, what is going on here?

Aucun commentaire:

Enregistrer un commentaire