c# - FluentAssertions 等价于 xUnit Assert.Collection
问题描述
与以下 xUnit/FluentAssertions 组合最接近的 FluentAssertions 是什么?
Assert.Collection(things,
thing =>
{
thing.Id.Should().Be(guid1);
thing.Name.Should().Be("Thing1");
thing.Attributes.Should().NotBeNull();
thing.FullName.Should().MatchRegex("^Thing1 [^ ]+$");
},
thing =>
{
thing.Id.Should().Be(guid2);
thing.Name.Should().Be("Thing2");
thing.Attributes.Should().NotBeNull();
thing.FullName.Should().MatchRegex("^Thing2 [^ ]+$");
});
在某些情况下,我发现这种风格比断言集合相等或等价的 FluentAssertions 方法更具表现力和/或简洁。
Assert.Collection 签名:
/// <summary>
/// Verifies that a collection contains exactly a given number of elements, which meet
/// the criteria provided by the element inspectors.
/// </summary>
/// <typeparam name="T">The type of the object to be verified</typeparam>
/// <param name="collection">The collection to be inspected</param>
/// <param name="elementInspectors">The element inspectors, which inspect each element in turn. The
/// total number of element inspectors must exactly match the number of elements in the collection.</param>
public static void Collection<T>(IEnumerable<T> collection, params Action<T>[] elementInspectors)
相关问题:https ://github.com/fluentassertions/fluentassertions/issues/118
解决方案
推荐阅读
- python - 我应该为生成器表达式编写一个内部函数吗?
- python - Python subprocess.Popen 与 var/args
- c# - 属性 asp:Table 设置为 class 或 void
- javascript - Javascript - 带有 JSON 数组的 Array.isArray
- angular - 打字稿 - 通用约束 - 不接受匹配类型的对象文字
- javascript - 通过 github api 的 access_token 获取私有仓库?
- hive - 为什么需要对 Hive 表进行分桶以支持 ACID 事务?
- linux - 如何创建一个 linux shell 别名来为 g++ 编译器提供要编译的文件的路径?
- tensorflow - 如何为 csv 数据集创建模型并使用 TensorFlow JS 计算预测结果
- node.js - 如何在流星中正确使用expose-gc?