Reputation: 5619
I am new to NSubstitute and 30 minutes in I can't find how to mock class level fields / variables.
In MOQ I would do this:
public class PlanControllerTest
{
Mock<IDataAccessTemplate> _template = new Mock<IDataAccessTemplate>();
[TestMethod]
public void BadDataResponse()
{
Mock<ISomethingElse> other = new Mock<ISomethingElse>();
}
}
However refactoring to NSubstitute I use:
public class PlanControllerTest
{
???? _template = Substitute.For<IDataAccessTemplate>();
[TestMethod]
public void BadDataResponse()
{
var other = new Substitute.For<ISomethingElse>();
}
}
It is that class level declaration that I can't figure out. I've been through the basic tutorial here:
http://nsubstitute.github.io/help/creating-a-substitute/
and the closest I find via Google is:
How to set value to a local variable of a class using NSubstitute in TestProject?
Surely this is not the first time this has been asked??
Upvotes: 2
Views: 684
Reputation: 3694
See the NSubstitute code. The implementation of For <T> will return T. So using IDataAccessTemplate should compile.
Upvotes: 1