Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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# MbUnit:测试定制的有序集合_C#_Unit Testing_Sorting_Collections_Mbunit - Fatal编程技术网

C# MbUnit:测试定制的有序集合

C# MbUnit:测试定制的有序集合,c#,unit-testing,sorting,collections,mbunit,C#,Unit Testing,Sorting,Collections,Mbunit,我有一个自定义的数据收集类型。此数据按三个属性的顺序进行排序,例如,以以下示例为例: class Data { public int PropertyA() { get; set; } public int PropertyB() { get; set; } public int PropertyC() { get; set; } } 托收必须保持A、B、C的顺序,例如: [A, B, C] [1, 2, 5] [1, 3, 3] [1, 3, 4] [1, 4, 1] [2, 1

我有一个自定义的数据收集类型。此数据按三个属性的顺序进行排序,例如,以以下示例为例:

class Data
{
  public int PropertyA() { get; set; }
  public int PropertyB() { get; set; }
  public int PropertyC() { get; set; }
}
托收必须保持A、B、C的顺序,例如:

[A, B, C]
[1, 2, 5]
[1, 3, 3]
[1, 3, 4]
[1, 4, 1]
[2, 1, 2]
[3, 3, 1]
[3, 4, 2]

我想编写一些测试,以确保通过通常的可疑添加和删除操作在集合中维护此顺序。我正在使用Gallio和Mbunit3,我想一定有一种简单的方法可以利用它们的属性来实现这一点,我现在还不明白。有什么想法吗?

在MbUnit v2中,您可以使用。。虽然Yann Trevin一直在为MbUnit v3制定“收集合同”,但找不到它。我认为它现在还不能处理有序集合,但我相信如果有一个合适的比较委托来描述有序不变量,他会有兴趣添加该功能

您将在MbUnit v3.0.6中的MbUnit.Samples项目的“SampleCollectionTest”夹具中找到这方面的示例

我建议您将您的想法发布到mbunitdev邮件列表中,在那里他可以看到:

有一个新的有用方法。您只需要传递枚举实例进行计算。如果枚举对象实现了IEquatable,那么一切都是自动的

[Test]
public void MySimpleTest
{
   var array = new int[] { 1, 5, 9, 12, 26 };
   Assert.Sorted(array);
}
否则,您仍然可以指定自定义比较标准(例如,使用新的handy)

[测试]
公共空间MyComplexTest
{
var数组=newfoo[]{newfoo(123)、newfoo(456)、newfoo(789)};
Assert.Sorted(数组,新结构均衡比较程序)
{
{x=>x.Value}
});
}

查看Gallio/MbUnit以了解更多详细信息。

不幸的是,MbUnit v3中似乎没有这种功能。谢谢你的帮助,我会给你一个正确的答案!我将使用新的ContractVerifiers()在v3中实现这一点。请尝试在开发组中询问()v3中可能有替代品。谢谢,稍后我将在那里发布我的请求。也许这个小组也有更好的想法。
[Test]
public void MyComplexTest
{
   var array = new Foo[] { new Foo(123), new Foo(456), new Foo(789) };
   Assert.Sorted(array, new StructuralEqualityComparer<Foo>
   {
      { x => x.Value }
   });
}