3

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 ?

NiceGuy
  • 133
  • 1
  • 14
  • Not sure what you're trying to do. Are you creating an instance of pojoType and assigning properties Name = a or are the columns constructor parameters? What is pojoName? And what would you do with pojo when it's created? – Mike Stockdale Jun 27 '17 at 03:20
  • The main point of my question is. How could I read the entire column in FitNesse and create the binding by myself. Creating an instance for my pojo etc. would be the next step, but isn't the problem. – NiceGuy Jun 28 '17 at 12:17

1 Answers1

3

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.

Mike Stockdale
  • 5,201
  • 3
  • 27
  • 33