小编cap*_*ang的帖子

在 net core 2.2 中隐藏 swagger 不良响应示例模型

我将我的 netcore 2.1 项目升级到 2.2 并且我的 swagger 页面有问题。

以前在 swagger bad response 中,它只显示没有模型的“错误请求”。

但是在我升级到 net core 2.2 后,错误请求示例中显示了一个模型。下图。

我如何隐藏它以便它只显示“错误的请求”。

我已经使用 CustomApiConvention 进行了测试,但到目前为止还没有成功。

    [HttpGet("{id}")]
    [ProducesResponseType(StatusCodes.Status204NoContent)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesDefaultResponseType]
    public async Task<ActionResult<Employee>> GetEmployee(int id)
    {
        var employee = await _context.Employee.FindAsync(id);

        if (employee == null)
        {
            return NotFound();
        }

        return employee;
    }
Run Code Online (Sandbox Code Playgroud)

我如何隐藏它以便它只显示“错误的请求”?

在此处输入图片说明

c# swagger-2.0 asp.net-core-2.2

9
推荐指数
1
解决办法
2555
查看次数

单元测试 xunit 以下构造函数参数没有匹配的夹具数据

以下构造函数参数没有用于使用 moq 和 xunit 进行单元测试的匹配装置数据。

已经使用依赖注入和模拟来测试类。

//this is how i register the DI.
services.AddScoped<IWaktuSolatServiceApi, WaktuSolatServiceApi>(); 


 public interface IWaktuSolatServiceApi
 {
    Task<Solat> GetAsyncSet();
 }


// the unit test. 
public class UnitTest1 
{
    Mock<IWaktuSolatServiceApi> waktu;

    public UnitTest1(IWaktuSolatServiceApi waktu)
    {
        this.waktu = new Mock<IWaktuSolatServiceApi>();
    }

    [Fact]
    public async Task ShoudReturn()
    {
        var request = new Solat
        {
            zone = "lala"
        };

        var response = waktu.Setup(x => 
        x.GetAsyncSet()).Returns(Task.FromResult(request));
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到此错误以下构造函数参数没有匹配的夹具数据。

c# testing moq xunit

-1
推荐指数
1
解决办法
2153
查看次数

标签 统计

c# ×2

asp.net-core-2.2 ×1

moq ×1

swagger-2.0 ×1

testing ×1

xunit ×1