Rhino Mocks - 当属性没有 Get 时验证属性集

发布于 2024-07-13 18:20:19 字数 363 浏览 9 评论 0原文

如果您有一个属性:

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

如何使用 Rhino Mocks 来检查该

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

属性是否被调用。

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

不编译。

If you have a property:

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

how do you use Rhino Mocks to check that

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

is called.

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

does not compile.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临走之时 2024-07-20 18:20:19
public interface IFred
{
    string UserName { set; }
}

[Test]
public void TestMethod1()
{
    IFred fred = MockRepository.GenerateMock<IFred>();
    fred.UserName = "Jim";
    fred.AssertWasCalled(x => x.UserName = "Jim");
}
public interface IFred
{
    string UserName { set; }
}

[Test]
public void TestMethod1()
{
    IFred fred = MockRepository.GenerateMock<IFred>();
    fred.UserName = "Jim";
    fred.AssertWasCalled(x => x.UserName = "Jim");
}
少女七分熟 2024-07-20 18:20:19

您应该能够对属性集进行所有验证

[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; }
}

You should just be able to do a verify all on the property set

[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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文