Skip to content

Commit

Permalink
Verify that guarding Equals method throws
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Apr 15, 2022
1 parent 37c8e6b commit 9987ff3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Expand Up @@ -503,7 +503,7 @@ public void When_overriding_with_custom_assertion_it_should_be_chainable()
}

[Fact]
public void When_a_nullable_property_is_overriden_with_a_custom_assertion_it_should_use_it()
public void When_a_nullable_property_is_overridden_with_a_custom_assertion_it_should_use_it()
{
// Arrange
var actual = new SimpleWithNullable
Expand Down
37 changes: 36 additions & 1 deletion Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions.Common;
using FluentAssertions.Numeric;
using FluentAssertions.Primitives;
using FluentAssertions.Specialized;
Expand All @@ -13,7 +14,7 @@ namespace FluentAssertions.Specs
public class AssertionExtensionsSpecs
{
[Fact]
public void Assertions_classes_have_overriden_equals()
public void Assertions_classes_override_equals()
{
// Arrange / Act
var equalsOverloads = AllTypes.From(typeof(FluentAssertions.AssertionExtensions).Assembly)
Expand All @@ -35,6 +36,40 @@ private static bool OverridesEquals(Type t)
return equals is not null;
}

public static object[][] ClassesWithGuardEquals() => new object[][]
{
new object[] { new ObjectAssertions<object, ObjectAssertions>(default) },
new object[] { new BooleanAssertions<BooleanAssertions>(default) },
new object[] { new DateTimeAssertions<DateTimeAssertions>(default) },
new object[] { new DateTimeRangeAssertions<DateTimeAssertions>(default, default, default, default) },
new object[] { new DateTimeOffsetAssertions<DateTimeOffsetAssertions>(default) },
new object[] { new DateTimeOffsetRangeAssertions<DateTimeOffsetAssertions>(default, default, default, default) },
#if NET6_0_OR_GREATER
new object[] { new DateOnlyAssertions<DateOnlyAssertions>(default) },
new object[] { new TimeOnlyAssertions<TimeOnlyAssertions>(default) },
#endif
new object[] { new ExecutionTimeAssertions(new ExecutionTime(() => { }, () => new StopwatchTimer())) },
new object[] { new GuidAssertions<GuidAssertions>(default) },
new object[] { new MethodInfoSelectorAssertions() },
new object[] { new NumericAssertions<int, NumericAssertions<int>>(default) },
new object[] { new PropertyInfoSelectorAssertions() },
new object[] { new SimpleTimeSpanAssertions<SimpleTimeSpanAssertions>(default) },
new object[] { new TaskCompletionSourceAssertions<int>(default) },
new object[] { new TypeSelectorAssertions() },
new object[] { new EnumAssertions<StringComparison, EnumAssertions<StringComparison>>(default) }
};

[Theory]
[MemberData(nameof(ClassesWithGuardEquals))]
public void Guarding_equals_throws(object obj)
{
// Act
Action act = () => obj.Equals(null);

// Assert
act.Should().ThrowExactly<NotSupportedException>();
}

[Theory]
[InlineData(typeof(ReferenceTypeAssertions<object, ObjectAssertions>))]
[InlineData(typeof(BooleanAssertions<BooleanAssertions>))]
Expand Down

0 comments on commit 9987ff3

Please sign in to comment.