我正在尝试使用我的控制器进行测试,xUnit但在执行Customer Controller的过程中收到以下错误:
“以下构造函数参数没有匹配的夹具数据:CustomerController customerController”
测试班
public class UnitTest1
{
CustomerController _customerController;
public UnitTest1(CustomerController customerController)
{
_customerController = customerController;
}
[Fact]
public void PostTestSuccessful()
{
Guid guid = Guid.NewGuid();
CustomerViewModel model = new CustomerViewModel()
{
Id = guid,
Name = "testName",
Email = "test email",
PhoneNumber = "test phone",
Address = "test address",
City = "test city",
Gender = "Male"
};
var actionResult = _customerController.Post(model);
Assert.NotNull(actionResult);
Assert.IsType<Task<IActionResult>>(actionResult);
Assert.True(actionResult.IsCompletedSuccessfully);
}
Run Code Online (Sandbox Code Playgroud)
CustomerController类
[Route("customers")]
public class CustomerController : ControllerBase
{
private readonly …Run Code Online (Sandbox Code Playgroud)