Hi I am writing unit test cases for the following method in my controller.
[HttpGet]
[Route("GetList")]
public IHttpActionResult GetAllMasterList()
{
var MasterList = _masterListRepo.GetAll().Select(t => new { t.MASTER_ID, t.MASTER_NAME }).OrderBy(t=>t.MASTER_NAME).ToList();
return Ok(MasterList);
}
For the above method the unit test case method is as follows.
[TestMethod]
public void AllMastersList()
{
//Arrange
var controller = new MastersController();
var actualResults = _masterListRepo.GetAll().ToList();
//Act
var actionResult = controller.GetAllMasterList();
//Assert
Assert.IsTrue(actionResult.GetType().GetGenericTypeDefinition() == typeof(OkNegotiatedContentResult<>));
var contentExpected = actionResult as OkNegotiatedContentResult<IEnumerable<dynamic>>;
Assert.IsNotNull(contentExpected.Content.ToList());
Assert.AreEqual(contentExpected.Content.Count(), actualResults.Count);
}
I am getting contentExpected as null. How do I cast this Ok() result to get the value. How to do it?