I need to asset an action called by a mock component.
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);
}
}
Maybe I need to restructure the code, but confused on that. Could you please advise?