FluentAssertions and record struct

Viewed 24

I'm writing some basic tests for record struct and use FluentAssertions. Here's the record struct:

internal readonly record struct CrawlRequest
{
    internal CrawlRequest(Uri targetSiteUri, uint pagesLimit, TimeSpan waitUntilNextCrawl)
    {
        Id = Guid.NewGuid();
        if (!targetSiteUri.IsAbsoluteUri) throw new ArgumentException("targetSiteUri must be an absolute Uri");
        TargetSiteUri = targetSiteUri;

        if (pagesLimit is 0 or > 1000) throw new ArgumentOutOfRangeException("pagesLimit", "PagesLimit must be between 1 and 1000");
        PagesLimit = pagesLimit;

        ValidateWaitUntilNextCrawl(waitUntilNextCrawl);
        WaitUntilNextCrawl = waitUntilNextCrawl;
    }

    internal uint PagesLimit { get; }
    internal Uri TargetSiteUri { get; }

    internal TimeSpan WaitUntilNextCrawl { get; }

    internal Guid Id { get; }
}

And here's the test which fails at either BeEquivalentTo():

    [Test]
    public void BeEquivalentWithoutId()
    {
        Uri u1 = new("https://whatever.com", UriKind.Absolute);
        Uri u2 = new("https://whatever.com", UriKind.Absolute);
        u1.Should().Be(u2);

        TimeSpan ts1 = TimeSpan.FromHours(2);
        TimeSpan ts2 = TimeSpan.FromHours(2);
        ts1.Should().Be(ts2);

        uint x1 = 50;
        uint x2 = 50;
        x1.Should().Be(x2);

        CrawlRequest r1 = new(u1, 50, TimeSpan.FromHours(2));
        CrawlRequest r2 = new(u2, 50, TimeSpan.FromHours(2));
        // r1.Should().BeEquivalentTo(r2, options => options.ComparingByValue<CrawlRequest>().Excluding(o => o.Id));
        r1.Should().BeEquivalentTo(r2, options => options.IncludingInternalProperties().Excluding(o => o.Id));
    }

Why is it failing? I don't get it.

0 Answers
Related