title: Unit Test - Assert object returned by a controller action
body: <p>How can I check if the value returned as part of that OkObjectResult has a count of 2 without changing any code in the controller action?</p>
  
  <p>Here is my controller action</p>
  
  <pre><code>public IActionResult GetUserNames()
  {
      var users = _repository.GetUsers();
      return Ok(users.Select(u =&gt; u.Name));
  }
  </code></pre>
  
  <p>My unit test looks like this</p>
  
  <pre><code>[Fact]
  public void GetUserNames_ValidRequest_ShouldReturnOk()
  {
      _repository
          .Setup(r =&gt; r.GetUsers())
          .Return(new List&lt;User&gt; 
              {
                  new User { Name = "SomeRandomName" },
                  new User { Name = "SomeRandomName2" }  
              });
  
      var result = _controller.GetUserNames();
  
      result.Should().BeOfType&lt;OkObjectResult&gt;();
      // Code to check if 2 names are returned
  }
  </code></pre>
  
  <p>I am using Mock and FluentAssertions in my unit test.</p>