c# - 预计一个但发现了一个“你调用的对象是空的。”
问题描述
我为空参数检查创建了一个测试用例,但出现此错误:预期会抛出 <System.ArgumentNullException>,但发现 <System.NullReferenceException>: System.NullReferenceException 并显示消息“对象引用未设置为对象的实例。”
[Fact]
public void GivenNull_WhenMapIsCalled_ThenArgumentNullExceptionIsThrown()
{
//Given
Request request = null;
//When
Action action = () => new ConsumerServiceWrapper().IndividualsSearch(request);
//Then
action.ShouldThrow<ArgumentNullException>();
}
个人搜索
public List<Response> IndividualsSearch(Request request)
{
var response = new List<Response>();
//some code
return response;
}
解决方案
推荐阅读
- ruby-on-rails - Rails admin gem co-related 下拉菜单不起作用
- forms - 在 WTForms 中,如果另一个字段为空,我如何制作可选的必填字段?
- yaml - 如何在 YAML 中重用列表条目锚点?
- php - 如何使用 FOSRestBundle 在 Symfony 4 控制器的所有方法中设置自定义标头?
- javascript - 循环依赖 - Eloquent Javascript 书中的练习
- python - pybind11 python 在 Windows 10 上嵌入,致命的 Python 错误:initfsencoding:无法加载文件系统编解码器 #1930
- c# - 将所有数据表值显示到文本框中
- node.js - mongodb链接回存储在目录中的图像
- tensorflow - TensorflowJs conv2d - 张量形状
- google-cloud-dataflow - 需要从 apache 光束(数据流)在 clickhouseIO 中插入行