【发布时间】:2013-06-17 12:21:08
【问题描述】:
我有一个服务类,它在执行操作之前创建一个新的具体 PropertyClass。我正在尝试测试 DoSomething() 是否已运行。 是否可以创建螺柱并将返回的属性值控制为模拟对象?
public class ServiceClass
{
public PropertyClass Property {set; get;}
public void Action()
{
Property = new PropertyClass();
Property.DoSomething();
}
}
[Test] // This test does not work.
public class Action_Test
{
var service = new ServiceClass();
var mockPropertyClass = MockRepository.GenerateMock<IPropertyClass>();
service.Property.Stub(x=> new PropertyClass()).Return(mockPropertyClass);
service.Action();
service.Property.AssertWasCalled(x => x.DoSomething());
}
【问题讨论】:
标签: c# unit-testing rhino-mocks