我需要资产一个模拟组件调用的动作.
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 …Run Code Online (Sandbox Code Playgroud)