FluentAssertions等效于xUnit Assert.Collection

时间:2018-05-22 15:57:07

标签: c# xunit.net fluent-assertions

最接近的FluentAssertions与以下xUnit / 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

0 个答案:

没有答案