相关疑难解决方法(0)

以下构造函数参数没有匹配的灯具数据

我正在尝试使用我的控制器进行测试,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)

.net c# unit-testing xunit .net-core

9
推荐指数
4
解决办法
2万
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1

unit-testing ×1

xunit ×1