Is there an easy way in xunit.net to compare two collections without regarding the items' order?

后端 未结 5 524
借酒劲吻你
借酒劲吻你 2021-01-01 11:08

In one of my tests, I want to ensure that a collection has certain items. Therefore, I want to compare this collection with the items of an expected collection not r

5条回答
  •  星月不相逢
    2021-01-01 11:49

    Not a Xunit, but a Linq answer :

    bool areSame = !expected.Except(actual).Any() && expected.Count == actual.Count;
    

    So in XUnit :

    Assert.True(!expected.Except(actual).Any() && expected.Count == actual.Count));
    

    As @robi-y said, in Microsoft.VisualStudio.QualityTools.UnitTestFramework there is CollectionAssert.AreEquivalent

提交回复
热议问题