Given 2 interfaces having one function in common
public interface I1 { void Foo(string p);};
public interface I2 { void Foo(string p);};
We create a mock of both interfaces using moq
Mock<I1> menuServiceMock = new Mock<I1>();
menuServiceMock.As<I2>();
The problem is that when you call Foo on I2
(menuServiceMock.Object as I2).Foo("foo"); // in real code, we have a handle on I2
You cannot verify it with:
menuServiceMock.Verify(x => x.Foo("foo"), Times.Once());
…because only calls to I1::Foo are counted.
How can we overcome that (apart from reversing I1 and I2 in mock construction)?
I think you need to do this: