title: Test Environment.Exit() in C#
body: <p>Is there in C# some kind of equivalent of <a href="http://stefanbirkner.github.io/system-rules/#ExpectedSystemExit" rel="noreferrer"><code>ExpectedSystemExit</code></a> in Java? I have an exit in my code and would really like to be able to test it. The only thing I found in C# is a not really nice <a href="https://stackoverflow.com/questions/1121655/vs2008-unit-tests-assert-method-exits/1121693#1121693">workaround</a>.</p>
  
  <p><strong>Example Code</strong></p>
  
  <pre><code>public void CheckRights()
  {
      if(!service.UserHasRights())
      {
           Environment.Exit(1);
      }
  }
  </code></pre>
  
  <p><strong>Test Code</strong></p>
  
  <pre><code>[TestMethod]
  public void TestCheckRightsWithoutRights()
  {
      MyService service = ...
      service.UserHasRights().Returns(false);
  
      ???
  }
  </code></pre>
  
  <p>I am using the VS framework for testing (+ NSubstitute for mocking) but it is not a problem to switch to nunit or whatever for this test. </p>