Today , I will cover a very simple topic, which can be useful in cases we want to mock different interfaces on our expected mock object. Our target interface is simple and it looks like:
Our target interface has an IDisposable implemented. Now, generally if we implement it in a class , we have to implement the whole of it [which is quite logical] and that should not wait for any extra calls or constructs. Considering that, when we are creating our target mock it should also implement all the dependent interfaces for us as well.
Therefore, as we are creating our mock using Mock.Create<IFoo> like that follows, it also implements the dependencies for us :
Then, as we are interested only in IDisposable calls, we just need to do the following:
Finally, we proceed with our existing mock code. Considering the current context, I will check if the dispose method has invoked our mock code successfully.
Further, we assert our expectation as follows:
Hopefully that will help a bit and stay tuned.