diff --git a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs index 1186557657..bbb84c2321 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs @@ -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 diff --git a/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs b/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs index 288f92eb2f..b30c6052e5 100644 --- a/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/AssertionExtensionsSpecs.cs @@ -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; @@ -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) @@ -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(default) }, + new object[] { new BooleanAssertions(default) }, + new object[] { new DateTimeAssertions(default) }, + new object[] { new DateTimeRangeAssertions(default, default, default, default) }, + new object[] { new DateTimeOffsetAssertions(default) }, + new object[] { new DateTimeOffsetRangeAssertions(default, default, default, default) }, +#if NET6_0_OR_GREATER + new object[] { new DateOnlyAssertions(default) }, + new object[] { new TimeOnlyAssertions(default) }, +#endif + new object[] { new ExecutionTimeAssertions(new ExecutionTime(() => { }, () => new StopwatchTimer())) }, + new object[] { new GuidAssertions(default) }, + new object[] { new MethodInfoSelectorAssertions() }, + new object[] { new NumericAssertions>(default) }, + new object[] { new PropertyInfoSelectorAssertions() }, + new object[] { new SimpleTimeSpanAssertions(default) }, + new object[] { new TaskCompletionSourceAssertions(default) }, + new object[] { new TypeSelectorAssertions() }, + new object[] { new EnumAssertions>(default) } + }; + + [Theory] + [MemberData(nameof(ClassesWithGuardEquals))] + public void Guarding_equals_throws(object obj) + { + // Act + Action act = () => obj.Equals(null); + + // Assert + act.Should().ThrowExactly(); + } + [Theory] [InlineData(typeof(ReferenceTypeAssertions))] [InlineData(typeof(BooleanAssertions))]