FitNesse.NET
Write Your Own Cell Handler
Cell Handlers are classes that change the default handling of cells containing input values and expected values. For example, we can write a cell handler that lets us put the string "pi" in a cell and treats this as a numeric value instead of as a string.

Our cell handler class inherits from fitnesse.handlers.AbstractCellHandler.
using fitnesse.handlers;
public class PiHandler: AbstractCellHandler {
The Match method override determines which cells are processed by our handler. 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 override bool Match(string cellContent, Type type) {
    return cellContent != null
           && cellContent == "pi"
           && type == typeof(double));
  }
Overriding the HandleEvaluate method changes the behavior for expected value cells. We can use the Accessor parameter to get the actual value to compare to "pi".
  public override bool HandleEvaluate(Fixture fixture, Parse expectedValueCell, Accessor accessor) {
    object actual = accessor.Get(fixture);
    return actual != null && (double)actual == System.Math.PI;
  }
Overriding the HandleInput method lets us change the value supplied by input cells. Once again, we use the Accessor parameter to set the input value.
  public override void HandleInput(Fixture fixture, Parse inputValueCell, Accessor accessor) {
    accessor.Set(fixture, System.Math.PI);
  }
}

© Copyright 2007,2008 Syterra Software Inc. All rights reserved.