James Burani
James Burani

Reputation: 179

Moq, Visual Studio Unit Testing - Tests keep skipping a method in a mocked service

I'm testing a GET action method that calls a public method in a service that has been mocked.

The test fails. When I placed a break-point in the service method, I found that it gets skipped during execution of the test. How do I ensure that the service method doesn't get skipped?

I'm using Visual Studio Unit Testing Tools, Moq, Castle Windsor

Upvotes: 0

Views: 865

Answers (1)

absolutegoose
absolutegoose

Reputation: 11

As @sir-rufo stated in the comments, it is not sufficient to just mock the class, you have to define the behaviour of the methods within that class. For instance:

var mock = new Mock<IFoo>();
mock.Setup(foo => foo.DoSomething("ping")).Returns(true);

You can find more examples on Moq github.

Upvotes: 1

Related Questions