I am a little confused by your ModelView and ViewModel conditions. With MVVM, there is only a model, view, and presentation model.
This article talks about abstracting the message box so that you can run unit tests without blocking the build server while it waits for user interaction.
The implementation uses the Func
delegate, but you can do it just as easily using the interface. An approach then would be to create your own enumerations, and then convert them to implement the MessageBox interface.
eg.
public enum ConfirmationResult { Yes, No, Cancel ..etc } public enum ConfirmationType { YesNo, OkCancel ..etc } public interface IConfirmation { ConfirmationResult ShowConfirmation(string message, ConfirmationType confirmationType) } public class MessageBoxConfirmation : IConfirmation { ConfirmationResult ShowConfirmation(string message, ConfirmationType confirmationType) {
Then your view models perceive IConfirmation as a dependency (for example, in their constructor), and in unit tests you can drown out the IConfirmation interface to always return a specific result from the ShowConfirmation method.
You can also overload the ShowConfirmation method to provide options for images, window titles, etc.
source share