Can anyone help me to write the second assert for the following unit test? Actually I want to test if CategoryId is greater than 0 and I want to use my response data (CategoryId is auto generated here because of Identity column)
[Fact]
public async Task PostValidObjectReturnsOkResult()
{
//Arrange
Mock <ICategoryService> m = new Mock <ICategoryService>();
CategoryDTO myData = new CategoryDTO()
{
CategoryName = "Items"
};
m.Setup(repo => repo.CreateCategory(myData));
CategoryController c = new CategoryController(m.Object);
//Act
ActionResult response = await c.Post(myData);//response data
//Assert
Assert.IsType <OkObjectResult>(response);
}
I tried the followings but it did not work:
Assert.NotEqual(0,(response.Value as CategoryDTO).CategoryId);
Assert.True(((response.Value as CategoryDTO).CategoryId) > 0);