title: NUnit Attribute to simulate condition-based Assert.Inconclusive with custom message text
body: <p>I have some tests that depend on a certain thing being true (access to the internet, as it happens, but that isn't important and I don't want to discuss the details of the condition).</p>
  
  <p>I can very easily write a static helper method which will test the (parameterless) condition and call <code>Assert.Inconclusive("Explanatory Message")</code> if it's <code>true</code>/<code>false</code>. And then call that at the start of each <code>Test</code> which has this requirement.</p>
  
  <p>But I'd like to do this as an <code>Attribute</code>, if possible.</p>
  
  <p><hr>
  <strong>How, in detail, do I achieve that, in NUnit?</strong></p>
  
  <hr>
  
  <h1><em>What I've tried so far:</em></h1>
  
  <p>There's an <a href="https://github.com/nunit/docs/wiki/IApplyToTest-Interface" rel="nofollow noreferrer"><code>IApplyToTest</code> interface</a>, exposed by NUnit, which I can make my Attribute implement, and will allow me to hook into the TestRunner, but I can't get it to do what I want :(</p>
  
  <p>That interface gives me access to an <code>NUnit.Framework.Internal.Test</code> object.</p>
  
  <p>If I call:</p>
  
  <blockquote>
    <p><code>test.RunState = RunState.NotRunnable;</code></p>
  </blockquote>
  
  <p>then I get something equivalent to <code>Assert.Fail("")</code>.</p>
  
  <p>Similarly <code>RunState.Skipped</code> or <code>RunState.Ignored</code> give me the equivalent of <code>Assert.Ignore("")</code>.</p>
  
  <p>But none of these are setting a message on the Test, and there's no <code>test.Message = "foo";</code> or equivalent (that I can see).</p>
  
  <p>There's a <code>test.MakeInvalid("Foo")</code> which <em>does</em> set a message, but that's equivalent to <code>Assert.Fail("Foo")</code>.</p>
  
  <p>I found something that looked promising:</p>
  
  <pre><code>var result = test.MakeTestResult();
  result.SetResult(ResultState.Inconclusive, "Custom Message text");
  </code></pre>
  
  <p>But that doesn't seem to <em>do</em> anything; the Test just Passes :( I looked for a <code>test.SetAsCurrentResult(result)</code> method in case I need to "attach" that result object back to the test? But nothing doing.</p>
  
  <p>It feels like this is supposed to be possible, but I can't quite figure out how to make it all play together.
  <hr>
  If anyone can even show me how to get to <code>Skipped</code> + <code>Custom Message displayed</code>, then I'd probably take that!</p>