我有一个 xUnit 测试,如:
[Fact]
public async void GetLocationsCountAsync_WhenCalled_ReturnsLocationsCount()
{
_locationsService.Setup(s => s.GetLocationsCountAsync("123")).ReturnsAsync(10);
var controller = new LocationsController(_locationsService.Object, null)
{
ControllerContext = { HttpContext = SetupHttpContext().Object }
};
var actionResult = await controller.GetLocationsCountAsync();
actionResult.Value.Should().Be(10);
VerifyAll();
}
来源是
/// <summary>
/// Get the current number of locations for a user.
/// </summary>
/// <returns>A <see cref="int"></see>.</returns>
/// <response code="200">The current number of locations.</response>
[HttpGet]
[Route("count")]
public async Task<ActionResult<int>> GetLocationsCountAsync()
{
return Ok(await _locations.GetLocationsCountAsync(User.APropertyOfTheUser()));
}
结果的值为空,导致我的测试失败,但如果您查看ActionResult.Result.Value(内部属性),它包含预期的解析值。
请参阅以下调试器的屏幕截图。

如何在单元测试中填充 actionResult.Value?
 神不在的星期二
神不在的星期二 
					互换的青春
 
					忽然笑
 随时随地看视频慕课网APP
随时随地看视频慕课网APP
相关分类