【发布时间】:2021-01-19 05:48:35
【问题描述】:
谁能帮我为以下单元测试编写第二个断言?实际上我想测试 CategoryId 是否大于 0 并且我想使用我的响应数据(CategoryId 由于 Identity 列而在此处自动生成)
[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);
}
我尝试了以下方法,但没有成功:
Assert.NotEqual(0,(response.Value as CategoryDTO).CategoryId);
Assert.True(((response.Value as CategoryDTO).CategoryId) > 0);
【问题讨论】:
-
请提供任何可能发生的错误详情。
-
错误提示:“ActionResult”不包含值的定义
标签: c# asp.net unit-testing asp.net-web-api xunit