expectedObjects icon indicating copy to clipboard operation
expectedObjects copied to clipboard

Wrong comparision if using LINQ in ignore statements

Open Zyertdox opened this issue 3 years ago • 0 comments

The following test should fail (different Ids), but it passes. The reason is in attempt to ignore field inside collection using LINQ.

public void Test()
{
    var guid = Guid.NewGuid();
    var expected = (Id: guid, Arr: new List<(Guid, DateTime)> { (Guid.Empty, DateTime.UtcNow) });
    var actual = (Id: Guid.Empty, Arr: new List<(Guid, DateTime)> { (Guid.Empty, DateTime.UtcNow) });

    var expectedObject = expected.ToExpectedObject(context =>
    {
        context.UseOrdinalComparison();

        context.Ignore(tuple => tuple.Arr.Select(a => a.Item2));
        //context.Ignore(tuple => tuple.Arr.First().Item2);
        //context.Ignore(tuple => tuple.Arr.Single().Item2);
    });

    expectedObject.ShouldMatch(actual);
}

It do not fail also for First() and Single() calls (commented).

Zyertdox avatar Sep 21 '21 10:09 Zyertdox