Skip to content

Commit

Permalink
Throw exception when calling object.Equals on Assertions class
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Dec 30, 2021
1 parent f6c65c1 commit 7b1dff5
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Numeric/NumericAssertions.cs
Expand Up @@ -22,6 +22,8 @@ public NumericAssertions(T value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that an <see cref="IComparable{T}"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -443,5 +445,9 @@ public AndConstraint<TAssertions> NotBeOfType(Type unexpectedType, string becaus

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
9 changes: 8 additions & 1 deletion Src/FluentAssertions/Primitives/BooleanAssertions.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using FluentAssertions.Execution;

namespace FluentAssertions.Primitives
Expand All @@ -16,6 +17,8 @@ public BooleanAssertions(bool? value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a <see cref="bool"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -114,5 +117,9 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/DateTimeAssertions.cs
Expand Up @@ -22,6 +22,8 @@ public DateTimeAssertions(DateTime? value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a <see cref="DateTime"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -920,5 +922,9 @@ public AndConstraint<TAssertions> BeIn(DateTimeKind expectedKind, string because

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/DateTimeOffsetAssertions.cs
Expand Up @@ -23,6 +23,8 @@ public DateTimeOffsetAssertions(DateTimeOffset? value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a <see cref="DateTimeOffset"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -1089,5 +1091,9 @@ public AndConstraint<TAssertions> BeOneOf(IEnumerable<DateTimeOffset?> validValu

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
Expand Up @@ -6,6 +6,8 @@

namespace FluentAssertions.Primitives
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that two <see cref="DateTime"/> objects differ in the expected way.
/// </summary>
Expand Down Expand Up @@ -127,5 +129,9 @@ private static string PositionRelativeToTarget(DateTimeOffset actual, DateTimeOf
{
return actual - target >= TimeSpan.Zero ? "ahead" : "behind";
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/DateTimeRangeAssertions.cs
Expand Up @@ -5,6 +5,8 @@

namespace FluentAssertions.Primitives
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that two <see cref="DateTime"/> objects differ in the expected way.
/// </summary>
Expand Down Expand Up @@ -130,5 +132,9 @@ private static string PositionRelativeToTarget(DateTime actual, DateTime target)
{
return actual - target >= TimeSpan.Zero ? "ahead" : "behind";
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/EnumAssertions.cs
Expand Up @@ -20,6 +20,8 @@ public EnumAssertions(TEnum subject)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a <typeparamref name="TEnum"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -386,5 +388,9 @@ private static string GetName<T>(T @enum)
{
return @enum.ToString();
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/GuidAssertions.cs
Expand Up @@ -16,6 +16,8 @@ public GuidAssertions(Guid? value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a <see cref="Guid"/> is in the correct state.
/// </summary>
Expand Down Expand Up @@ -166,5 +168,9 @@ public AndConstraint<TAssertions> NotBe(Guid unexpected, string because = "", pa
}

#endregion

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs
Expand Up @@ -6,6 +6,8 @@

namespace FluentAssertions.Primitives
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a reference type object is in the expected state.
/// </summary>
Expand Down Expand Up @@ -416,5 +418,9 @@ public AndConstraint<TAssertions> NotBeAssignableTo(Type type, string because =
/// Returns the type of the subject the assertion applies on.
/// </summary>
protected abstract string Identifier { get; }

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Primitives/SimpleTimeSpanAssertions.cs
Expand Up @@ -17,6 +17,8 @@ public SimpleTimeSpanAssertions(TimeSpan? value)
}
}

#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that a nullable <see cref="TimeSpan"/> is in the expected state.
/// </summary>
Expand Down Expand Up @@ -338,5 +340,9 @@ public AndConstraint<TAssertions> BeGreaterThan(TimeSpan expected, string becaus

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Specialized/ExecutionTimeAssertions.cs
Expand Up @@ -4,6 +4,8 @@

namespace FluentAssertions.Specialized
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Provides methods for asserting that the execution time of an <see cref="Action"/> satisfies certain conditions.
/// </summary>
Expand Down Expand Up @@ -225,5 +227,9 @@ public AndConstraint<ExecutionTimeAssertions> BeCloseTo(TimeSpan expectedDuratio

return new AndConstraint<ExecutionTimeAssertions>(this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
Expand Up @@ -6,6 +6,8 @@

namespace FluentAssertions.Specialized
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
public class TaskCompletionSourceAssertions<T>
{
private readonly TaskCompletionSource<T> subject;
Expand Down Expand Up @@ -95,5 +97,9 @@ public TaskCompletionSourceAssertions(TaskCompletionSource<T> tcs, IClock clock)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:task} to not complete within {0}{reason}.", timeSpan);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Types/MethodInfoSelectorAssertions.cs
Expand Up @@ -9,6 +9,8 @@

namespace FluentAssertions.Types
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains assertions for the <see cref="MethodInfo"/> objects returned by the parent <see cref="MethodInfoSelector"/>.
/// </summary>
Expand Down Expand Up @@ -325,5 +327,9 @@ private static string GetDescriptionsFor(IEnumerable<MethodInfo> methods)
#pragma warning disable CA1822 // Do not change signature of a public member
protected string Context => "method";
#pragma warning restore CA1822

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Types/PropertyInfoSelectorAssertions.cs
Expand Up @@ -8,6 +8,8 @@

namespace FluentAssertions.Types
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains assertions for the <see cref="PropertyInfo"/> objects returned by the parent <see cref="PropertyInfoSelector"/>.
/// </summary>
Expand Down Expand Up @@ -224,5 +226,9 @@ private static string GetDescriptionsFor(IEnumerable<PropertyInfo> properties)
#pragma warning disable CA1822 // Do not change signature of a public member
protected string Context => "property info";
#pragma warning restore CA1822

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}
6 changes: 6 additions & 0 deletions Src/FluentAssertions/Types/TypeSelectorAssertions.cs
Expand Up @@ -8,6 +8,8 @@

namespace FluentAssertions.Types
{
#pragma warning disable CS0659 // Ignore not overriding Object.GetHashCode()
#pragma warning disable CA1065 // Ignore throwing NotSupportedException from Equals
/// <summary>
/// Contains a number of methods to assert that all <see cref="Type"/>s in a <see cref="TypeSelector"/>
/// meet certain expectations.
Expand Down Expand Up @@ -472,5 +474,9 @@ private static string GetDescriptionFor(Type type)
{
return type.ToString();
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Calling Equals on Assertion classes is not supported.");
}
}

0 comments on commit 7b1dff5

Please sign in to comment.