如何在Fluent Assertions中指定用于检查词典的键和值比较器?

时间:2015-12-18 13:14:19

标签: c# unit-testing fluent-assertions

我刚刚开始使用Fluent断言4.1.1。看起来比较字典的代码是

 actualDictionary.ShouldAllBeEquivalentTo(expectedDictionary);

但如果我不想使用他们的Equals()实现,如何为键和值指定我自己的相等函数(comparer)?

对于收藏品,似乎是:

actualCollection.Should().Equal(expectedCollection, MyComparisonFunc);

我正在寻找IDictionary<K,V>IReadOnlyDictionary<K,V>等价物。

编辑:集合中包含()的相同问题。

1 个答案:

答案 0 :(得分:1)

对于带有谓词的集合,$rspShould().Contain()都有重载,但遗憾的是,字典中不存在。但是,等效规则是高度可扩展的。查看unit tests以查看一些示例