You can easily check a method being called with Moq using the following code:
[TestFixture]
public class UnitTest1
{
[Test]
public void TestMethod1()
{
// Create a mock of your interface and make the methods verifiable.
var mock = new Mock<ISomeDependency>();
mock.Setup(m => m.DoSomething())
.Verifiable();
// Setup your class which you expect to be calling the verifiable method
var classToTest = new SomeClass(mock.Object);
classToTest.DoWork();
// Verify the method is called
mock.Verify(m => m.DoSomething());
}
}
public class SomeClass
{
private readonly ISomeDependency _someDependency;
public SomeClass(ISomeDependency someDependency)
{
_someDependency = someDependency;
}
public void DoWork()
{
_someDependency.DoSomething();
}
}
public interface ISomeDependency
{
void DoSomething();
}
public class SomeDependency : ISomeDependency
{
public void DoSomething()
{
}
}
Basicly all you are looking for is the Verifiable in the Arrange part of ur unit test, and the Verify in the Assert part.