Skip to content

Comparison

Robert Wagner edited this page Nov 2, 2016 · 2 revisions

By default a simple string comparison is used to compare the received and approved values. This can be customised by:

Implementing IComparer<string>:

public class CustomComparer : IComparer<string>
{
    public CompareResult Compare(string received, string approved)
    {
        return received == approved 
            ? CompareResult.Pass()
            : CompareResult.Fail("Strings differ");
    }
}

configuration.UsingComparer(new CustomComparer);

A delegate that throws an exception (example uses FluentAssertions)

configuration.UsingComparer((recieved, approved) => recieved.Should().Be(approved));

A delegate that returns a CompareResult

configuration.UsingComparer(
    (recieved, approved) => received == approved 
        ? CompareResult.Pass()
        : CompareResult.Fail("Strings differ");
);
Clone this wiki locally