I\'m trying to find the best way to uncouple messageboxes from my logic so I can properly unittest it. Now I was wondering if it would be enough if I just made a seperate he
Yes, it is right way. But instead of static class, you should implement IDialogService
and inject it into classes that should display dialogs:
public interface IDialogService
{
void ShowMessageBox(...);
...
}
public class SomeClass
{
private IDialogService dialogService;
public SomeClass(IDialogService dialogService)
{
this.dialogService = dialogService;
}
public void SomeLogic()
{
...
if (ok)
{
this.dialogService.ShowMessageBox("SUCCESS", ...);
}
else
{
this.dialogService.ShowMessageBox("SHIT HAPPENS...", ...);
}
}
}
During testing the SomeClass
you should inject mock object of the IDialogService
instead of real one.
If you need to test more UI logic, consider to use MVVM pattern.