liveBook · Manning

CompareToSet

As explained in Effective Behavior-Driven Development

A Reqnroll method that compares data-table rows with a collection of objects and reports differences.

When a Then step repeats assertions for each expected property, CompareToSet can move the comparison out of that step’s logic. It asserts that a data table’s expected rows match a collection of objects, keeping the step focused on what data to compare. section 14.6

Listing 14.27 Step definition with data table comparison that uses CompareToSet
*** StepDefinitions/OrderingStepDefinitions.cs ***
[Then("the following items should be offered")]
public void ThenTheFollowingItemsShouldBeOffered(
              DataTable expectedOfferedItemsTable)
{
  var offeredItems = activePromotion?.OfferedItems 
      ?? throw new InvalidOperationException("No active promotion");

  // assert that the actual list matches the expecetd data table
  expectedOfferedItemsTable.CompareToSet(offeredItems);
} 

The step passes the expected data table and actual offered-items collection to CompareToSet. section 14.6

Reading a failed comparison

If the expected row is Pepperoni but the actual row is BBQ, the diff-style output marks Pepperoni with a minus sign and BBQ with a plus sign. section 14.6

How Effective Behavior-Driven Development covers it

How deep it goes
Explains the assertion and diff-style failure output, without describing implementation internals.
Examples
Compares offered pizza-promotion items and shows Pepperoni expected but BBQ received.
What it assumes
Assumes an expected data table and an actual collection of objects to compare.
What you can do after
Diagnose mismatches by reading expected and actual rows in diff-style output.
How it connects
Connects data tables, step definitions, and the Data Table Accessor pattern.

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.