我正在使用 nunit 创建一个单元测试,并且所有这些代码在运行时都可以正常工作。
我在HttpResponseMessage
下面有这个受保护的代码,当它返回时由我的控制器调用。
然而,一个错误:
“值不能为空。参数名称:请求”正在显示。
当我检查请求时,它实际上是null
.
问题:我将如何编码我的单元测试以返回HttpResponseMessage
?
错误显示在这一行:
protected HttpResponseMessage Created<T>(T result) => Request.CreateResponse(HttpStatusCode.Created, Envelope.Ok(result));
这是我的控制器:
[Route("employees")]
[HttpPost]
public HttpResponseMessage CreateEmployee([FromBody] CreateEmployeeModel model)
{
//**Some code here**//
return Created(new EmployeeModel
{
EmployeeId = employee.Id,
CustomerId = employee.CustomerId,
UserId = employee.UserId,
FirstName = employee.User.FirstName,
LastName = employee.User.LastName,
Email = employee.User.Email,
MobileNumber = employee.MobileNumber,
IsPrimaryContact = employee.IsPrimaryContact,
OnlineRoleId = RoleManager.GetOnlineRole(employee.CustomerId, employee.UserId).Id,
HasMultipleCompanies = EmployeeManager.HasMultipleCompanies(employee.UserId)
});
}