c# - N-Unit Has.Exactly(n).Items 断言抛出错误
问题描述
为什么下面的断言不起作用?
代码:
[Test]
public void CreateNewTemplateTest()
{
OnlineSignupModel model = new OnlineSignupModel
{
SalesRepId = 68,
PriceAdvanced = (decimal)22.33,
PriceComplete = (decimal)44.33,
PriceMvr = (decimal)6.33,
SetupFee = (decimal)2.33,
};
Assert.That(model, Has.Exactly(5).Items);
}
错误:
System.ArgumentException : The actual value must be an IEnumerable
Parameter name: actual
at NUnit.Framework.Constraints.ExactCountConstraint.ApplyTo[TActual](TActual actual)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression)
我试图断言对象中有 5 个属性。
解决方案
避免对此任务的有用性进行任何评论,断言您的模型恰好具有 5 个属性,您可以使用类似Assert.That(typeof(model).GetProperties().Length == 5);
推荐阅读
- c# - 使用 safebrowsinglookup 库的 GoogleSafeBrowsing api
- sql - 查询输出
- sql-server - 将总计算百分比保留在堆积条形图的顶部 - SSRS
- node.js - 无法访问托管在我的公共 IP 上的网页
- python - 发布网络抓取数据并在 Pandas 中创建数据框(可能是一个简单的答案)
- android - 在android回收器视图中确定快照结束事件
- python - 什么是切换 Python 字符串输入的好选择?
- python - 如何在没有 Selenium 的情况下抓取 JavaScript 呈现的页面
- javascript - rails 5.2 Webpacker 资产管道
- amazon-web-services - 尝试将第三方模板加载到我的 AWS 托管的 wordpress 站点时,我收到超时错误 408。我该如何解决?