I am having a class "Example" with a property "data" which has a private setter and I would like to mock that data property
Public class Example { public string data {get; private set;}}
I would like to mock the data property using NSubstitute. Could someone help me how to do it.
NSubstitute can only mock abstract
or virtual
methods on concrete classes. If you can modify the underlying code to use an interface , then you could mock the interface:
public class Example : IExample { public string data { get; private set; } }
public interface IExample { string data { get; } }
[TestMethod]
public void One()
{
var fakeExample = NSubstitute.Substitute.For<IExample>();
fakeExample.data.Returns("FooBar");
Assert.AreEqual("FooBar", fakeExample.data);
}