diff --git a/Src/FluentAssertions/AssertionExtensions.cs b/Src/FluentAssertions/AssertionExtensions.cs index aa0b65309a..9a571bc755 100644 --- a/Src/FluentAssertions/AssertionExtensions.cs +++ b/Src/FluentAssertions/AssertionExtensions.cs @@ -1028,6 +1028,22 @@ public static void Should(this TypeSelectorAssertions _) InvalidShouldCall(); } + /// + [Obsolete("You are asserting the 'AndConstraint' itself. Remove the 'Should()' method directly following 'And'", error: true)] + public static void Should(this DateTimeRangeAssertions _) + where TAssertions : DateTimeAssertions + { + InvalidShouldCall(); + } + + /// + [Obsolete("You are asserting the 'AndConstraint' itself. Remove the 'Should()' method directly following 'And'", error: true)] + public static void Should(this DateTimeOffsetRangeAssertions _) + where TAssertions : DateTimeOffsetAssertions + { + InvalidShouldCall(); + } + [DoesNotReturn] private static void InvalidShouldCall() { diff --git a/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs b/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs index e9f4bb26a5..288f92eb2f 100644 --- a/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs @@ -39,7 +39,9 @@ private static bool OverridesEquals(Type t) [InlineData(typeof(ReferenceTypeAssertions))] [InlineData(typeof(BooleanAssertions))] [InlineData(typeof(DateTimeAssertions))] + [InlineData(typeof(DateTimeRangeAssertions))] [InlineData(typeof(DateTimeOffsetAssertions))] + [InlineData(typeof(DateTimeOffsetRangeAssertions))] #if NET6_0_OR_GREATER [InlineData(typeof(DateOnlyAssertions))] [InlineData(typeof(TimeOnlyAssertions))] @@ -95,6 +97,11 @@ public void Should_methods_have_a_matching_overload_to_guard_against_chaining_an .Where(m => !IsGuardOverload(m)) .Select(t => GetMostParentType(t.ReturnType)) .Distinct() + .Concat(new[] + { + typeof(DateTimeRangeAssertions<>), + typeof(DateTimeOffsetRangeAssertions<>) + }) .ToList(); List fakeOverloads = shouldOverloads