Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CollectionAssert.Are在FluentAssertions中等效吗?_C#_Fluent Assertions - Fatal编程技术网

C# CollectionAssert.Are在FluentAssertions中等效吗?

C# CollectionAssert.Are在FluentAssertions中等效吗?,c#,fluent-assertions,C#,Fluent Assertions,我试图用FluentAssertion替换“CollectionAssert.AreEquivalent()”的用法 我尝试过使用shouldallbeeEquivalento,但在比较不同类型的类似对象时,该函数并没有失败 在下面的示例中,两个调用都成功。我希望第二个调用失败 new int[] { 1, 2 }.ShouldAllBeEquivalentTo( new int[] { 2, 1 } ); new int[] { 1, 2 }.ShouldAllBeEquival

我试图用FluentAssertion替换“CollectionAssert.AreEquivalent()”的用法

我尝试过使用shouldallbeeEquivalento,但在比较不同类型的类似对象时,该函数并没有失败

在下面的示例中,两个调用都成功。我希望第二个调用失败

new int[] { 1, 2 }.ShouldAllBeEquivalentTo( new int[] { 2, 1 } );       
new int[] { 1, 2 }.ShouldAllBeEquivalentTo( new string[] {"1", "2"} );  

是否有替代功能或某个选项会导致第二行失败?

这是因为默认情况下使用了
tryconversionequivalencycystep
,并且它会将
“1”
1
视为相等(在尝试转换后)

首先尝试删除它:

AssertionOptions.EquivalencySteps.Remove<TryConversionEquivalencyStep>();
AssertionOptions.equalencycysteps.Remove();

请参见

如何添加此断言:assert.AreEqual(list1.GetType(),list2.GetType())?@KernelMode-这适用于该特定示例,但我的实际案例涉及一个字典。我需要检查每个值的运行时类型。CollectionAssert执行此操作,以及在添加接受答案中详细说明的步骤后的FluentAssertions。谢谢您的回答!在阅读了更多相关内容后,似乎这将转到be FluentAssertions 5-中的默认值。