To make fun of the Names property in the following example ...
Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string> GetNames(IView view) { return view.Names; } }
NUnit Mock Solution for Property
using NUnit.Mocks;
In NUnit, a property name can be mocked with get_PropertyName to mock get accessor and set_PropertyName to mock a set accessory using the mock Expect * (..) library:
List names = new List {"Test", "Test1"}; DynamicMock mockView = new DynamicMock(typeof(IView)); mockView.ExpectAndReturn("get_Names", names); IView view = (IView)mockView.MockInstance; Assert.AreEqual(names, presenter.GetNames(view));
Therefore, in our specific code example above, the .Names property is mocked as get_Names or set_Names .
Etc.
This blog post provides additional information, given that NUnit seems to provide mock methods only for target methods:
I began to think about it and realized that setters are simply perceived as special named methods under covers
John k
source share