Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
1.3 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using FluentAssertions.Execution;
using FluentAssertions.Numeric;
using NodaTime;
namespace Squidex.Shared;
public static class TestExtensions
{
public static ComparableTypeAssertions<Instant> BeCloseTo(this ComparableTypeAssertions<Instant> assertions, Instant expected, Duration precision,
string because = "", params object[] becauseArgs)
{
if (assertions.Subject is not Instant instant)
{
throw new InvalidOperationException("Not an instant value.");
}
var difference = instant - expected;
var absoluteTicks = Math.Abs(difference.TotalTicks);
var absoluteDiff = Duration.FromTicks(absoluteTicks);
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(absoluteDiff <= precision)
.FailWith("Expected {context:instant} to be within {0} of {1}{reason}, but it differed by {2}.",
precision, expected, difference);
return assertions;
}
}