title: NSubstitute - Received for async - “call is not awaited”warning
body: <p>I am trying to verify that an asynchronous method was called with the correct parameters. However, I get the warning:</p>
  
  <p>"Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call". This warning appears on the line of code underneath the <code>//Assert</code> comment (below).</p>
  
  <p>My test using <strong>NSubstitute</strong> is as follows:</p>
  
  <pre><code>[Test]
  public async Task SimpleTests()
  {
    //Arrange
    var request = CreateUpdateItemRequest();
  
    databaseHelperSub.ExecuteProcAsync(Arg.Any&lt;DatabaseParams&gt;()).Returns(Task.FromResult((object)null));
  
    //Act      
    await underTest.ExecuteAsync(request);
  
    //Assert
    databaseHelperSub.Received().ExecuteProcAsync(Arg.Is&lt;DatabaseParams&gt;(
      p =&gt; p.StoredProcName == StoredProcedureName
           &amp;&amp; p.Parameters[0].ParameterName == "Param1"
           &amp;&amp; p.Parameters[0].Value.ToString() == "Value1"
           &amp;&amp; p.Parameters[1].ParameterName == "Param2"
           &amp;&amp; p.Parameters[1].Value.ToString() == "Value2"));
  }
  </code></pre>
  
  <p>The unit under test method <code>underTest.ExecuteAsync(request)</code> calls <code>ExecuteProcedureAsync</code> and performs the await:</p>
  
  <pre><code>var ds = await DatabaseHelper.ExecuteProcAsync(dbParams);
  </code></pre>
  
  <p>Due to the fact that with NSubstitute, the Received() is required after the execution of the unit under test. Whereas in RhinoMocks, you can <strong>expect</strong> for a call to occur before the unit under test is executed. RhinoMocks can return the Task.FromResult() whereas NSubstitute cannot.</p>
  
  <p>The RhinoMocks equivalent that works is this:</p>
  
  <pre><code>[Test]
          public async Task SimpleTest()
          {
              // Arrange
              var request = new UpdateItemRequest();
  
              databaseHelperMock.Expect(m =&gt; m.ExecuteProcAsync(Arg&lt;DatabaseParams&gt;.Matches(
                  p =&gt;   p.StoredProcName == StoredProcedureName
                      &amp;&amp; p.Parameters[0].ParameterName == "Param1"
                      &amp;&amp; p.Parameters[0].Value.ToString() == "Value1"
                      &amp;&amp; p.Parameters[1].ParameterName == "Param2"
                      &amp;&amp; p.Parameters[1].Value.ToString() == "Value2
                  ))).Return(Task.FromResult&lt;object&gt;(null));
  
              // Act
              await underTest.ExecuteAsync(request);
  
          }
  </code></pre>
  
  <p>I have seen that there is a workaround where you can add an extension method to remove the issue:</p>
  
  <pre><code>  public static class TestHelper
    {
      public static void IgnoreAwait(this Task task)
      {
  
      }
    }
  </code></pre>
  
  <p>Meaning my test line for <strong>NSubstitute</strong> can be executed as follows and the warning goes away:</p>
  
  <pre><code>databaseHelperSub.Received().ExecuteProcAsync(Arg.Is&lt;DatabaseParams&gt;(
          p =&gt; p.StoredProcName == StoredProcedureName
               &amp;&amp; p.Parameters[0].ParameterName == "Param1"
               &amp;&amp; p.Parameters[0].Value.ToString() == "Value1"
               &amp;&amp; p.Parameters[1].ParameterName == "Param2"
               &amp;&amp; p.Parameters[1].Value.ToString() == "Value2")).IgnoreAwait();
      }
  </code></pre>
  
  <p>However, I assumed there must be a better solution out there for this?</p>