title: How to test my ASP.NET Core 2.2 Web API GET IActionResult that returns Ok(object)?
body: <p>In my Web API I have a simple controller action:</p>
  
  <pre><code>[HttpGet]
  [Route("[action]")]
  public IActionResult GetApiStatus(string token)
  {
      if (_token != token)
      {
          return StatusCode(401);
      }
  
      StatusModel status = _vesselUpdating.GetUpdatingStatus();
  
      return Ok(status);
  }
  </code></pre>
  
  <p>And action returns <code>StatusModel</code> type object. I could not manage how to test its return status.</p>
  
  <p>My test method is below:</p>
  
  <pre><code>[Theory]
  [InlineData("wrong_token", StatusCodes.Status401Unauthorized)]
  [InlineData("test_token", StatusCodes.Status200OK)]
  [InlineData("", StatusCodes.Status401Unauthorized)]
  [InlineData(null, StatusCodes.Status401Unauthorized)]
  public void Get_GetAnyAction_WithVariusTokens_ReturnsCorrectStatusCode(string token, int code)
  {
      _vesselUpdatingMock.Setup(v =&gt; v.GetUpdatingStatus()).Returns(_sampleStatusModel);
      IActionResult result;
  
      result = _updatesController.GetApiStatus(token);
      StatusCodeResult resultGetApiStatus = result as StatusCodeResult;
  
      Assert.Equal(code, resultGetApiStatus.StatusCode);
  }
  </code></pre>
  
  <p>When debugging on </p>
  
  <pre><code>result = _updatesController.GetApiStatus(token);
  </code></pre>
  
  <p>the <code>StatusCode</code> property of <code>IActionResult</code> is <strong>200</strong>, but only <code>DeclaredType</code> property of that is <strong>null</strong>. </p>
  
  <p><a href="https://i.stack.imgur.com/KdHYT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KdHYT.png" alt="result debug"></a></p>
  
  <p>And when Asserting, at the end I have in my <code>resultGetApiStatus</code> <strong>null</strong>.</p>
  
  <p><a href="https://i.stack.imgur.com/7qjbq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7qjbq.png" alt="assert null"></a></p>
  
  <p>I did not managed to find similar example. How can I project <code>result</code> properly?</p>
  
  <p><strong>IMPORTANT EDIT:</strong></p>
  
  <p>I found only <a href="https://stackoverflow.com/a/41293396/12603542">this approach</a>, that does not fix my problem, regarding variety of cases <code>[Theory]</code>, and not all my other actions returns <code>ObjectResult</code>, some of them return only <code>StatusCode</code>. Is there any universal approach for actions with and without <code>ObjectResult</code>? Or should I use different tests?</p>