Skip to content

Compare table to dynamic set

Marcus Hammarberg edited this page Jan 6, 2015 · 5 revisions

Comparisons can also be made on sets created from a tables (see Table to dynamic set). This comparisons are done row by row and column by column. For now the order DOES matter.

If the table and your dynamic doesn't match up an hopefully informative exception is thrown.

So with this scenario:

Scenario: Comparing against an identical table should match
    Given I create a set of dynamic instances from this table
        | Name   | Age | Birth date | Length in meters |
        | Marcus | 39  | 1972-10-09 | 1.96             |
        | Albert | 3   | 2008-01-24 | 1.03             |
        | Gustav | 1   | 2010-03-19 | 0.84             |
        | Arvid  | 1   | 2010-03-19 | 0.85             |
    When I compare the set to this table
        | Name   | Age | Birth date | Length in meters |
        | Marcus | 39  | 1972-10-09 | 1.96             |
        | Albert | 3   | 2008-01-24 | 1.03             |
        | Gustav | 1   | 2010-03-19 | 0.84             |
        | Arvid  | 1   | 2010-03-19 | 0.85             |
    Then no set comparison exception should have been thrown

You can use these steps to compare the set against the table:

private IList<dynamic> _set; // holds state for the set between the steps

private DynamicSetComparisonException _exception; // Hold any exception thrown

[Given(@"I create a set of dynamic instances from this table")]
public void WithMethodBInding(Table table)
{
    _set = table.CreateDynamicSet().ToList();
}

[When(@"I compare the set to this table")]
public void CompareSetToInstance(Table table)
{
    try
    {
        // COMPARISON DONE HERE!
        table.CompareToDynamicSet(_set);
    }
    catch (DynamicSetComparisonException ex)
    {
        _exception = ex;
    }
}

[Then(@"no set comparison exception should have been thrown")]
public void NoSetExceptionThrown()
{
    _exception.Should().Be.Null();
}