title: Testing API Controller that returns ActionResult<T>
body: <p>Testing the following controller</p>
  
  <pre><code>public class AnnouncementController : Controller
  {
  
      IConfiguration _configuration;
  
      IHostingEnvironment _env;
  
      ILoggerManager _logger;
  
      public AnnouncementController(IConfiguration configuration, IHostingEnvironment env, ILoggerManager logger)
      {
          _configuration = configuration;
          _env = env;
          _logger = logger;
      }
  
      [HttpGet ("{employeeID}/{moduleID}")]
      public ActionResult&lt;Announcements&gt; GetAnnouncements([FromRoute]int employeeID, [FromRoute] int moduleID)
      {
         try
         { 
            Services.Interface.IAnnouncementService service = new Services.Imp.AnnouncementService(_configuration, _logger);///establishing new Service connection
  
             if (service != null)
             {
                 Announcements announcements = service.GetAnnouncements(employeeID, moduleID);       
  
                 return announcements;
             }
             else
             {
                 return BadRequest("Unable to establish connection.");
            }
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.Message, ex);//log error
          return BadRequest(ex.Message);
        }
      }
  }
  </code></pre>
  
  <p>With the following testing code:</p>
  
  <pre><code>public void ForSessionActionResult_ReturnsObjectResult()
  {
      IConfiguration _configuration;
      IHostingEnvironment _env;
      ILoggerManager _logger;
  
      var mock_logger = new Mock&lt;ILoggerManager&gt;();
      _logger = mock_logger.Object;
      var mock_configuration = new Mock&lt;IConfiguration&gt;();
      _configuration = mock_configuration.Object;
      var mock_env = new Mock&lt;IHostingEnvironment&gt;();
      _env = mock_env.Object;
  
      var sut = new AnnouncementController(_configuration, _env, _logger);
      int employeeID = 1;
      int moduleID = 1;
      var result = sut.GetAnnouncements(employeeID, moduleID);
  
      var actionResult = Assert.IsType&lt;ActionResult&lt;Announcements&gt;&gt;(result);
      Assert.IsType&lt;NotFoundObjectResult&gt;(actionResult.Result);
  
  }
  </code></pre>
  
  <p>I'm getting <code>BadRequestObjectResult</code> on <code>Assert.IsType NotFoundObjectResult</code> on the controller being tested. </p>
  
  <p>I am not sure if I am mocking correctly the controller constructor to begin with. </p>
  
  <p>But on the last Assert I'm getting <code>BadRequestObjectResult</code>.</p>