0

Using FitNesse with FitSharp (.Net), I've got a property of an object that is a HashSet of an enum, e.g.

public enum Fubar { Foo, Bar }

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

I'd like to test it simply, for example in an array fixture like so:

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

This simply results in all rows marked missing & red and a set of surplus rows showing something like:

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

What's the easiest way to get FitNesse with FitSharp (.Net) to understand HashSets?

Mike Scott
  • 12,274
  • 8
  • 40
  • 53

1 Answers1

0

You can write a parse operator. Here's a little example from http://fitsharp.github.io/Fit/WriteOurOwnCellOperator.html that parses the string"pi" into a numeric value.

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

The CanParse method override determines which cells are processed by our operator. We check for "pi" in the cell and also that we are working with a numeric type. This preserves normal behavior if we're using "pi" as a string input or expected value.

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

Overriding the Parse method changes the behavior when the cell is parsed to create an input or an expected value.

  public TypedValue Parse(Type type, TypedValue instance, TreeTree<Cell> parameters) {
    return new TypedValue(System.Math.PI);
  }
}
Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33
  • I already tried that at first. The code sample shows how to create a new parse operator but even though I registered it, I just couldn't get FitNesse to call the Parse method for the cell in question. In the end I gave up and went for a different solution. – Mike Scott Apr 02 '15 at 20:19