I am trying the following in my Unit Test:
var sut = new MyClass(dependentOne.Object, dependentTwo.Object);
Action act = () => sut.DoSomething();
// Assert
dependentOne.Verify(m => m.MethodOne(), Times.Once);
dependentTwo.Verify(m => m.MethodTwo(), Times.Once);
act.Should().NotThrow<Exception>();
Looks like the two methods of MethodOne()
and MethodTwo()
that will get called within DoSomething() are not called at all, but if I directly call without Action, the methods are called.
sut.DoSomething();
Although I haven't fleshed out the definition for the methods and initialization, but the above code snippet should be enough to explain the situation. So, shouldn't Action act = () => sut.DoSomething();
actually call the methods so Verify will work as expected?