If you call MessageBox.Show()
from a service that can be replaced with a mock when testing, you're fine.
After all, what you do not want is a message box popping up when running your view models unit tests...
Example:
public interface IMessageBoxService
{
ClickedButten ShowMessageBox( string message, Buttons buttons );
}
internal class SomeViewModel
{
public SomeViewModel( IMessageBoxService messageBoxService )
{
_messageBoxService = messageBoxService;
}
public void SomeMethodThatNeedsAMessageBox()
{
var theClickedButton = _messageBoxService.ShowMessageBox( "Click me!", Buttons.Ok | Buttons.Cancel );
// react to the click...
}
}
internal class SystemMessageBoxService : IMessageBoxService
{
public ClickedButten ShowMessageBox( string message, Buttons buttons )
{
// adapt parameters...
MessageBox.Show(...);
// adapt result...
}
}
internal class XceedMessageBoxService : IMessageBoxService
{
public ClickedButten ShowMessageBox( string message, Buttons buttons )
{
// adapt parameters...
Xceed.ShowMessageBox(...);
// adapt result...
}
}
Now just bind the service that you want to use (could even be decided at runtime), and inject a mock when testing.