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
