title: MVVM design: Blocking MessageBox in ViewModel
body: <p>This question refers to a WPF application based on PRISM 5.0 and the MVVM pattern.</p>
  
  <p>Sometimes when users make decisions, that could have unwanted or negative consequences, it is very common to ask the user, if he really wants to go on and proceed. </p>
  
  <p><strong>For example:</strong> 
  One common way, is to ask the user with a messagebox, if he really wants to delete data, that can not be restored after deletion.</p>
  
  <p><strong>The problem is:</strong> 
  If I call the MessageBox inside the ViewModel, the ViewModel becomes <strong><em>untestable</em></strong> from the outside.</p>
  
  <pre><code>//BAD!
  public class ViewModel
  {
      public Boolean Delete()
      {
          //Blocking and therefore untestable in automatic UnitTests
          MsgBoxResult result = MsgBox.Show("Do you really want to delete?"); 
  
          if (result == yes) {//Do stuff that deletes data here;}
  
      }
  }
  </code></pre>
  
  <p>One possibility would be, to ask the question in a different private method, that calls the public method</p>
  
  <pre><code>//BETTER, BUT OK?
  public class ViewModel
  {
      private void OnDeleteAction
      {
          MsgBoxResult result = MsgBox.Show("Do you really want to delete?"); 
          if (result == yes) {Delete();}
      }
  
      public Boolean Delete()
      {
          //Testable from the outside again, because no blocking question
  
          //Do stuff that deletes data here
      }
  </code></pre>
  
  <p><strong>My question:</strong> Is is this a good way or is there a more elegant way to ask the user inside a ViewModel? Can you give me a hint or link, what is the best for PRISM 5.0?</p>
  
  <p>I know, that a rule of thumb is, not to use any UI elements in the ViewModel, but I see no alternative to a blocking MessageBox or something else, that blocks the process, before proceeding.</p>
  
  <p>Thank you any hints!</p>