title: How can I Fail a WebTest?
body: <p>I'm using Microsoft WebTest and want to be able to do something similar to NUnit's <code>Assert.Fail()</code>. The best i have come up with is to <code>throw new webTestException()</code> but this shows in the test results as an <code>Error</code> rather than a <code>Failure</code>. </p>
  
  <p>Other than reflecting on the <code>WebTest</code> to set a private member variable to indicate the failure, is there something I've missed?</p>
  
  <p>EDIT: I have also used the <code>Assert.Fail()</code> method, but this still shows up as an error rather than a failure when used from within WebTest, and the <code>Outcome</code> property is read-only (has no public setter).</p>
  
  <p>EDIT: well now I'm really stumped. I used reflection to set the <code>Outcome</code> property to Failed but the test <em>still</em> passes!</p>
  
  <p>Here's the code that sets the Oucome to failed:</p>
  
  <pre><code>public static class WebTestExtensions
  {
      public static void Fail(this WebTest test)
      {
          var method = test.GetType().GetMethod("set_Outcome", BindingFlags.NonPublic | BindingFlags.Instance);
          method.Invoke(test, new object[] {Outcome.Fail});
      }
  }
  </code></pre>
  
  <p>and here's the code that I'm trying to fail:</p>
  
  <pre><code>    public override IEnumerator&lt;WebTestRequest&gt; GetRequestEnumerator()
      {
          this.Fail();
          yield return new WebTestRequest("http://google.com");
      }
  </code></pre>
  
  <p><code>Outcome</code> is getting set to <code>Oucome.Fail</code> but apparently the WebTest framework doesn't really use this to determine test pass/fail results.</p>