11

如果您有房产:

public class Fred
{
   public string UserName
   {
     set
     {
        userName=value;
     }
   }
}

你如何使用 Rhino Mocks 来检查

fred= new Fred();
fred.UserName="Jim";

叫做。

Expect.Call(mockFred.UserName).SetPropertyWithArgument("Jim");

不编译。

4

2 回答 2

27
public interface IFred
{
    string UserName { set; }
}

[Test]
public void TestMethod1()
{
    IFred fred = MockRepository.GenerateMock<IFred>();
    fred.UserName = "Jim";
    fred.AssertWasCalled(x => x.UserName = "Jim");
}
于 2009-02-08T20:26:37.310 回答
4

您应该能够对属性集进行全部验证

[TestClass]
public class FredTests
{
    [TestMethod]
    public void TestFred()
    {
        var mocker = new MockRepository();
        var fredMock = mocker.DynamicMock<IFred>();

        fredMock.UserName = "Name";
        // the last call is actually to the set method of username
        LastCall.IgnoreArguments(); 
        mocker.ReplayAll();

        fredMock.UserName = "Some Test that does this.";
        mocker.VerifyAll();
    }

}

public interface IFred
{
    string UserName { set; }
}
于 2009-02-08T20:20:02.707 回答