c# - 如何最小起订量为空或空异常
问题描述
我正在为 .NET CORE 5 Web API 项目开发 xUnit 自动化。我有一个响应对象,它有一个属性作为异常。我正在使用夹具来创建最小起订量数据。在不需要抛出异常的情况下,如何使用夹具创建空异常或空异常。
在运动中,夹具会产生异常,这对我来说是不正确的。我试图通过 Null 但它抛出异常
查询响应
public class QueryResultSummary
{
public int RecordsCount { get; set; }
public bool IsRecordExist { get; set; }
public bool Error { get; set; }
public string ExecutionMessage { get; set; }
public string CustomMessage { get; set; }
public Exception Exceptions { get; set; }
}
xUnit
public async Task APIMethodX_ShouldReturn_DoesNotExist_When_SiteNotFound()
{
//Arrange
var fixture = new Fixture();
long startDateTimeUtc = 1626994800000;
int siteId = 5588;
fixture.Customize<QueryResultSummary>(c => c
.With(x => x.RecordsCount, 0)
.With(x => x.IsRecordExist, false)
.With(x => x.Error, false)
.With(x => x.ExecutionMessage, QueryExecutionStatusEnum.DoesNotExist.ToString())
.With(x => x.Exceptions, null) // need help here
);
解决方案
使用时省略属性的正确方法Customize
是使用Without()
.
fixture.Customize<QueryResultSummary>(c => c
.Without(x => x.Exceptions));
如果您需要省略所有自动属性,您可以使用该OmitAutoProperties
方法。
fixture.Customize<QueryResultSummary>(c => c
.OmitAutoProperties());
推荐阅读
- c# - 有没有办法在写入工作表数据后添加列而不导致应用程序挂起?
- cuda - Nsight Eclipse not found/CUDA11.1安装问题
- regex - 尝试在 Selenium 中断言文本但出现错误
- prolog - SWI-Prolog 解析输入而不查询
- gradle - Gradle - 列出子项目的任务
- laravel - 使用 livewire 让我的模态拥有正确的产品
- android - 某些设备/地区的 Android SQLite 异常
- php - 在 Laravel 中使用数字前缀和其他字符串前缀制作代码
- reactjs - componentDidUpdate() 进入无限循环
- visual-studio-code - 如何通过拆分在单个 VSCode 集成终端中启动应用程序的多个实例?