0

Is there a way for asserting Tuples using Fluent Assertions?

var t1 = new Tuple<Guid, IEnumerable<Guid>>(Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}"),
    new [] { Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}") });

var t2 = new Tuple<Guid, IEnumerable<Guid>>(Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}"),
    new[] { Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}") });

This is asserted using either of the following:

t1.Should().ShouldBeEquivalentTo(t2);
t1.ShouldBeEquivalentTo(t2);

Results in:

Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException : Expected item[0] to be (da18b047-2f62-45f0-a437-748976b41d22, System.Collections.Generic.List`1[System.Guid]), but found (da18b047-2f62-45f0-a437-748976b41d22, System.Collections.Generic.List`1[System.Guid]).

Expected item[1] to be (119d681c-9171-4ecd-86b6-3b4417ad167c, System.Collections.Generic.List`1[System.Guid]), but found (119d681c-9171-4ecd-86b6-3b4417ad167c, System.Collections.Generic.List`1[System.Guid]).

I have also tried:

t1.Should().Be(t2);

Also, I am not to bothered about the order of Guids either.

Update

I am currently using 4.1.1 for this. Upgrading to 4.19.4 yields the same result.

I have also tried in v5 pre-release using:

t1.Should().BeEquivalentTo(t2);
Andez
  • 5,588
  • 20
  • 75
  • 116
  • I have a feeling this relates to [this bug](https://github.com/fluentassertions/fluentassertions/issues/544). – Chris Pickford Jan 16 '18 at 10:38
  • 3
    Nope. It is not related. A tuple implements `Equals` by comparing the individual types in that tulpe using `Equals`. Since one of the types is an `IEnumerable`, this is never going to work. – Dennis Doomen Jan 16 '18 at 13:04
  • I guess the comment above should be the accepted answer? I went with just using anonymous types for my scenario in the end. – Andez Jan 16 '18 at 15:27

1 Answers1

2

Use t1.ShouldBeEquivalentTo(t2) if you use 4.x. If you use 5.x, use t1.Should().BeEquivalentTo(t2).

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • Thanks Dennis. Just updated the question with a bit more info as to what I was doing and have tried. – Andez Jan 16 '18 at 15:25
  • 1
    In the final release, I've decided to deal with tuples in a specific way. https://github.com/fluentassertions/fluentassertions/commit/530de04c6dc2c109434b191c0c9544bf04606b91 – Dennis Doomen Feb 06 '18 at 10:33