Skip to content

Commit

Permalink
Add guarding Should to range assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Apr 15, 2022
1 parent 9e03620 commit 582d75c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Src/FluentAssertions/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,22 @@ public static void Should(this TypeSelectorAssertions _)
InvalidShouldCall();
}

/// <inheritdoc cref="Should(ExecutionTimeAssertions)" />
[Obsolete("You are asserting the 'AndConstraint' itself. Remove the 'Should()' method directly following 'And'", error: true)]
public static void Should<TAssertions>(this DateTimeRangeAssertions<TAssertions> _)
where TAssertions : DateTimeAssertions<TAssertions>
{
InvalidShouldCall();
}

/// <inheritdoc cref="Should(ExecutionTimeAssertions)" />
[Obsolete("You are asserting the 'AndConstraint' itself. Remove the 'Should()' method directly following 'And'", error: true)]
public static void Should<TAssertions>(this DateTimeOffsetRangeAssertions<TAssertions> _)
where TAssertions : DateTimeOffsetAssertions<TAssertions>
{
InvalidShouldCall();
}

[DoesNotReturn]
private static void InvalidShouldCall()
{
Expand Down
7 changes: 7 additions & 0 deletions Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ private static bool OverridesEquals(Type t)
[InlineData(typeof(ReferenceTypeAssertions<object, ObjectAssertions>))]
[InlineData(typeof(BooleanAssertions<BooleanAssertions>))]
[InlineData(typeof(DateTimeAssertions<DateTimeAssertions>))]
[InlineData(typeof(DateTimeRangeAssertions<DateTimeAssertions>))]
[InlineData(typeof(DateTimeOffsetAssertions<DateTimeOffsetAssertions>))]
[InlineData(typeof(DateTimeOffsetRangeAssertions<DateTimeOffsetAssertions>))]
#if NET6_0_OR_GREATER
[InlineData(typeof(DateOnlyAssertions<DateOnlyAssertions>))]
[InlineData(typeof(TimeOnlyAssertions<TimeOnlyAssertions>))]
Expand Down Expand Up @@ -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<Type> fakeOverloads = shouldOverloads
Expand Down

0 comments on commit 582d75c

Please sign in to comment.