Search code examples
c#testingfitnessefitsharp

FitNesse / FitSharp - Read columns of ColumnFixture dynamically


I am using the FitNesse / FitSharp (c#) for testing purposes.

I can create normal fixture like ColumnFixtures, RowFixtures, DoFixtures etc. but not I am looking for a way to read columns and bind them dynamically.

The reason for this is, I still already have a huge amount of Pojo objects in my own library and don't want to repeat all class members again. Therefor i am searching for a way to handle column dynamically.

e.g.

!|Create| pojoType | record | pojoName |
 |Name  | LastName | Address| Misc     |
 | a    | b        | c      | d        |


public class DynamicHandling : DoFixture () {
   public void CreateRecord(string type, string name) {
      var clazz = GetClazzOfType();

      var headers = GetHeadersOfColumn();
      var values = GetValuesOfColumn();

      var pojo = DoBindingAndAssignValues(headers, rows, clazz);

      // ... Continue with whatever e.g.  ...

      var name = pojo.Name;
      var lastName = pojo.LastName;
      var address = pojo.Address;

      address.split(';') ... 
   }
}

Any idea ?


Solution

  • Take a look at the source code for the Compute fixture (https://fitsharp.github.io/Fit/ComputeFixture.html) and see if it helps.

    You can write a fixture that processes cells dynamically like this:

    public class MyFixture: Interpreter {
      public void Interpret(CellProcessor processor, Tree<Cell> table) {
        new Traverse<Cell>()
          .Rows.Header(row => FunctionThatDoesSomethingWithTheHeaderRow(row))
          .Rows.Rest(row => FunctionThatDoesSomethingWithEachSubsequentRow(row))
          .VisitTable(table);
      }
      ...
    }
    

    There's other sets of rows you can traverse - check out the Traverse source code.