Starting to use the DynamicMock feature of NUnit.Mocks. I had a class with a property getter that I wanted to use it with. The code consistently failed. Grabbed the NUnit source and looked at the covering unit test for DynamicMock. Guess what, no covering test for a Property to show me how to do it! I started thinking about it and realized that Property getters and setters are just treated as speciallly named methods under the covers and started playing around. Finally came up with the following that works:
8 namespace DynamicMockTest
9 {
10 [TestFixture]
11 public class Class1
12 {
13
14 [Test]
15 public void Test1()
16 {
17 DynamicMock mock = new DynamicMock(typeof(IMockTest));
18 mock.ExpectAndReturn("get_Domain", "AMSWORLD");
19
20 Assert.AreEqual("AMSWORLD", ((IMockTest)mock.MockInstance).Domain);
21 }
22
23 }
24
25
26 public interface IMockTest
27 {
28 string Domain { get; }
29 }
30 }
The trick is to precede the property name with get_ or set_