【问题标题】:How can I set a value of a property without setter on a stub?如何在存根上没有设置器的情况下设置属性的值?
【发布时间】:2011-11-30 00:09:27
【问题描述】:

我可以设置由 Rhino.Mocks 创建的存根的无 setter 属性的返回值吗?

例如:

public interface IMyMachine { string myProperty { get; } }

...

IMyMachine m = MockRepository.GenerateMock<IMyMachine>();

// implement in a way so that m.myProperty will return "Ahoj!"
if (m.myProperty == "Ahoj!")
 //do something

【问题讨论】:

    标签: c# .net unit-testing rhino-mocks stub


    【解决方案1】:
    m.Expect(x => x.myProperty).Return("abc");
    

    或者如果您使用存根:

    var m = MockRepository.GenerateStub<IMyMachine>();
    m.Stub(x => x.myProperty).Return("abc");
    

    【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2011-05-01
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    相关资源
    最近更新 更多