【发布时间】:2017-01-18 20:04:11
【问题描述】:
我有以下(简化的)控制器:
public async Task<IHttpActionResult> Profile(UpdateProfileModelAllowNulls modelNullable)
{
ServiceResult<ProfileModelDto> result = await _profileService.UpdateProfile(1);
return Ok(result);
}
还有:
public async Task<ServiceResult<ProfileModelDto>> UpdateProfile(ApplicationUserDto user, UpdateProfileModel profile)
{
//Do something...
}
以及以下 NUnit 测试:
[Test]
public async Task Post_Profile()
{
var result = _controller.Profile(new UpdateProfileModelAllowNulls() { Email = "testEmail@tt.co.uk", DisplayName = "TestDisplay"}) as OkNegotiatedContentResult<Task<<ProfileModelDto>>;
Assert.IsNotNull(result);
}
在我的 NUnit 测试中,我正在尝试使用本教程 https://www.asp.net/web-api/overview/testing-and-debugging/unit-testing-with-aspnet-web-api 来检查一个 Ok 结果。
我的问题是我无法转换为OkNegotiatedContentResult,我假设是因为我没有传入正确的对象,但我看不到我应该传入什么对象。据我所知,我正在通过在正确的对象中,例如:OkNegotiatedContentResult<Task<<ProfileModelDto>>;
但这不起作用。
我也试过了:
var result = _controller.Profile(new UpdateProfileModelAllowNulls() { Email = "testEmail@tt.co.uk", DisplayName = "TestDisplay"}) as OkNegotiatedContentResult<Task<IHttpActionResult>>;
但这也不起作用。
谁能帮忙?
【问题讨论】:
-
你有什么错误吗?
-
作为 OkNegotiatedContentResult
?
标签: c# unit-testing httpresponse