0

使用 FitNesse 和 FitSharp (.Net),我有一个对象的属性,它是一个枚举的 HashSet,例如

public enum Fubar { Foo, Bar }

public class Test
{
   public HashSet<Fubar> SetOfFubar { get; set; }
}

我想简单地测试它,例如在这样的数组夹具中:

|MyArrayFixture|
|SetOfFubar|
|Foo|
|Foo,Bar|
|Bar|
||

这只会导致所有行标记为缺失和红色,以及一组多余的行显示如下:

System.Collections.Generic.HashSet`1[MyNamespace.Fubar] surplus

使用 FitSharp (.Net) 获取 FitNesse 以了解 HashSet 的最简单方法是什么?

4

1 回答 1

0

您可以编写解析运算符。这是来自http://fitsharp.github.io/Fit/WriteOurOwnCellOperator.html的一个小示例,它将字符串“pi”解析为数值。

using fitSharp.Fit.Operators;
using fitSharp.Machine.Engine;
public class ParsePi: CellOperator, ParseOperator<Cell> {

CanParse 方法覆盖确定我们的操作员处理哪些单元格。我们检查单元格中的“pi”,并且我们正在使用数字类型。如果我们使用“pi”作为字符串输入或期望值,这将保留正常行为。

  public bool CanParse(Type type, TypedValue instance, Tree<Cell> parameters) {
    return type == typeof(double) && parameters.Value.Text == "pi";
  }

当解析单元格以创建输入或预期值时,重写 Parse 方法会更改行为。

  public TypedValue Parse(Type type, TypedValue instance, TreeTree<Cell> parameters) {
    return new TypedValue(System.Math.PI);
  }
}
于 2015-03-30T15:01:26.577 回答