Telerik® JustMock™ by Progress

When a mock is created by using Mock.Create all dependencies are also implemented. Thus, if you are interested in a specific interface implementation you can use the as operator and call the interface members.


Consider the following interface:

C# Copy imageCopy
public interface IFoo : IDisposable
    void Do();

The IFoo interface has IDisposable implemented. When you are interested only in IDisposable calls you need to perform a conversion from the created mock to IDisposable.

C# Copy imageCopy
// Arrange
var foo = Mock.Create<IFoo>();
var iDisposable = foo as IDisposable;

Finally, check whether the dispose method invokes our mock code successfully.

C# Copy imageCopy
bool called = false;

Mock.Arrange(() => iDisposable.Dispose()).DoInstead(() => called = true);

// Act

// Assert

Mock.Assert(() => iDisposable.Dispose(), Occurs.Once());

See Also

Other Resources