【发布时间】:2011-06-20 14:46:10
【问题描述】:
我需要资产一个由模拟组件调用的操作。
public interface IDispatcher
{
void Invoke(Action action);
}
public interface IDialogService
{
void Prompt(string message);
}
public class MyClass
{
private readonly IDispatcher dispatcher;
private readonly IDialogservice dialogService;
public MyClass(IDispatcher dispatcher, IDialogService dialogService)
{
this.dispatcher = dispatcher;
this.dialogService = dialogService;
}
public void PromptOnUiThread(string message)
{
dispatcher.Invoke(()=>dialogService.Prompt(message));
}
}
..and in my test..
[TestFixture]
public class Test
{
private IDispatcher mockDispatcher;
private IDialogService mockDialogService;
[Setup]
public void Setup()
{
mockDispatcher = MockRepository.GenerateMock<IDispatcher>();
mockDialogService = MockRepository.GenerateMock<IDialogService>();
}
[Test]
public void Mytest()
{
var sut = CreateSut();
sut.Prompt("message");
//Need to assert that mockdispatcher.Invoke was called
//Need to assert that mockDialogService.Prompt("message") was called.
}
public MyClass CreateSut()
{
return new MyClass(mockDipatcher,mockDialogService);
}
}
也许我需要重组代码,但对此感到困惑。可以请教吗?
【问题讨论】:
标签: c# tdd rhino-mocks