4

我有以下规格

BidirectionalGraph Fixture = new BidirectionalGraph();

public void VerticesShouldBeAbleToAssociateMultipleEdges()
{
    int a = 0;
    int b = 1;
    int c = 2;

    Fixture.AddEdge(a, b);
    Fixture.AddEdge(b, c);
    Fixture.AddEdge(c, a);

    Fixture.EdgesFrom(a).Should().BeEquivalentTo
        ( new []{a, b} 
        , new []{a, c});
}

其中 EdgesFrom 被定义为

public IEnumerable<int[]> EdgesFrom(int vertex)

但是我的测试失败了

Result Message: Expected collection 

    {{0, 1}, {0, 2}} to be equivalent to 
    {{0, 1}, {0, 2}}.

这对我来说不太有意义,因为它们显然是等价的。FluentAssertions比较集合集合时不起作用?

4

1 回答 1

2

这是因为 collection.Should().BeEquivalentTo() 使用您的类型的默认 Equals() 实现来确保第一个集合中的每个项目都出现在第二个集合中的某个位置。您真正需要的是我在 Fluent Assertions 2.0 中引入的新等效功能。不幸的是,我最近才意识到令人困惑的语法(collection.Should().BeEquivalentTo() 与 ShouldAllBeEquivalentTo())。

于 2013-05-10T19:37:51.920 回答