From 2b25db1966c7f7a61c0e5cbfaf3b0d1abb3a87d4 Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Sun, 16 Jan 2022 10:10:32 +0100 Subject: [PATCH 1/2] Adjust Identifier property --- .../Primitives/HttpResponseMessageAssertions.cs | 2 ++ Src/FluentAssertions/Types/MethodBaseAssertions.cs | 2 -- Src/FluentAssertions/Xml/XmlElementAssertions.cs | 2 ++ Src/FluentAssertions/Xml/XmlNodeAssertions.cs | 2 +- .../ApprovedApi/FluentAssertions/net47.verified.txt | 3 ++- .../ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt | 3 ++- .../ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt | 3 ++- .../ApprovedApi/FluentAssertions/netstandard2.0.verified.txt | 3 ++- .../ApprovedApi/FluentAssertions/netstandard2.1.verified.txt | 3 ++- 9 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Src/FluentAssertions/Primitives/HttpResponseMessageAssertions.cs b/Src/FluentAssertions/Primitives/HttpResponseMessageAssertions.cs index 45010cb0ce..3b3e96779f 100644 --- a/Src/FluentAssertions/Primitives/HttpResponseMessageAssertions.cs +++ b/Src/FluentAssertions/Primitives/HttpResponseMessageAssertions.cs @@ -230,5 +230,7 @@ public AndConstraint NotHaveStatusCode(HttpStatusCode unexpected, s private bool IsServerError() => (int)Subject.StatusCode is >= 500 and <= 599; private bool IsClientError() => (int)Subject.StatusCode is >= 400 and <= 499; + + protected override string Identifier => "HTTP response message"; } } diff --git a/Src/FluentAssertions/Types/MethodBaseAssertions.cs b/Src/FluentAssertions/Types/MethodBaseAssertions.cs index ddf91bef42..2136b6a769 100644 --- a/Src/FluentAssertions/Types/MethodBaseAssertions.cs +++ b/Src/FluentAssertions/Types/MethodBaseAssertions.cs @@ -93,8 +93,6 @@ public AndConstraint NotHaveAccessModifier(CSharpAccessModifier acc return new AndConstraint((TAssertions)this); } - protected override string Identifier => "methodBase"; - internal static string GetParameterString(MethodBase methodBase) { IEnumerable parameterTypes = methodBase.GetParameters().Select(p => p.ParameterType); diff --git a/Src/FluentAssertions/Xml/XmlElementAssertions.cs b/Src/FluentAssertions/Xml/XmlElementAssertions.cs index 11283d19be..46814dc5fe 100644 --- a/Src/FluentAssertions/Xml/XmlElementAssertions.cs +++ b/Src/FluentAssertions/Xml/XmlElementAssertions.cs @@ -165,5 +165,7 @@ public XmlElementAssertions(XmlElement xmlElement) return new AndWhichConstraint(this, element); } + + protected override string Identifier => "XML element"; } } diff --git a/Src/FluentAssertions/Xml/XmlNodeAssertions.cs b/Src/FluentAssertions/Xml/XmlNodeAssertions.cs index 6abe32d325..a8d571f05d 100644 --- a/Src/FluentAssertions/Xml/XmlNodeAssertions.cs +++ b/Src/FluentAssertions/Xml/XmlNodeAssertions.cs @@ -80,6 +80,6 @@ public AndConstraint NotBeEquivalentTo(XmlNode unexpected, string b /// /// Returns the type of the subject the assertion applies on. /// - protected override string Identifier => "Xml Node"; + protected override string Identifier => "XML node"; } } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt index dbc62d6212..4f01de4ab7 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt @@ -1922,6 +1922,7 @@ namespace FluentAssertions.Primitives where TAssertions : FluentAssertions.Primitives.HttpResponseMessageAssertions { protected HttpResponseMessageAssertions(System.Net.Http.HttpResponseMessage value) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint BeRedirection(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint BeSuccessful(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveClientError(string because = "", params object[] becauseArgs) { } @@ -2348,7 +2349,6 @@ namespace FluentAssertions.Types where TAssertions : FluentAssertions.Types.MethodBaseAssertions { protected MethodBaseAssertions(TSubject subject) { } - protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint NotHaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } } @@ -2645,6 +2645,7 @@ namespace FluentAssertions.Xml public class XmlElementAssertions : FluentAssertions.Xml.XmlNodeAssertions { public XmlElementAssertions(System.Xml.XmlElement xmlElement) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAttribute(string expectedName, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveAttributeWithNamespace(string expectedName, string expectedNamespace, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndWhichConstraint HaveElement(string expectedName, string because = "", params object[] becauseArgs) { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt index 4cf77e0872..ee1154cbe1 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt @@ -1922,6 +1922,7 @@ namespace FluentAssertions.Primitives where TAssertions : FluentAssertions.Primitives.HttpResponseMessageAssertions { protected HttpResponseMessageAssertions(System.Net.Http.HttpResponseMessage value) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint BeRedirection(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint BeSuccessful(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveClientError(string because = "", params object[] becauseArgs) { } @@ -2350,7 +2351,6 @@ namespace FluentAssertions.Types where TAssertions : FluentAssertions.Types.MethodBaseAssertions { protected MethodBaseAssertions(TSubject subject) { } - protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint NotHaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } } @@ -2647,6 +2647,7 @@ namespace FluentAssertions.Xml public class XmlElementAssertions : FluentAssertions.Xml.XmlNodeAssertions { public XmlElementAssertions(System.Xml.XmlElement xmlElement) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAttribute(string expectedName, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveAttributeWithNamespace(string expectedName, string expectedNamespace, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndWhichConstraint HaveElement(string expectedName, string because = "", params object[] becauseArgs) { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt index f95ce03797..75bcd1c0bf 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt @@ -1922,6 +1922,7 @@ namespace FluentAssertions.Primitives where TAssertions : FluentAssertions.Primitives.HttpResponseMessageAssertions { protected HttpResponseMessageAssertions(System.Net.Http.HttpResponseMessage value) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint BeRedirection(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint BeSuccessful(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveClientError(string because = "", params object[] becauseArgs) { } @@ -2350,7 +2351,6 @@ namespace FluentAssertions.Types where TAssertions : FluentAssertions.Types.MethodBaseAssertions { protected MethodBaseAssertions(TSubject subject) { } - protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint NotHaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } } @@ -2647,6 +2647,7 @@ namespace FluentAssertions.Xml public class XmlElementAssertions : FluentAssertions.Xml.XmlNodeAssertions { public XmlElementAssertions(System.Xml.XmlElement xmlElement) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAttribute(string expectedName, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveAttributeWithNamespace(string expectedName, string expectedNamespace, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndWhichConstraint HaveElement(string expectedName, string because = "", params object[] becauseArgs) { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt index f213fcd302..4646a938bf 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt @@ -1875,6 +1875,7 @@ namespace FluentAssertions.Primitives where TAssertions : FluentAssertions.Primitives.HttpResponseMessageAssertions { protected HttpResponseMessageAssertions(System.Net.Http.HttpResponseMessage value) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint BeRedirection(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint BeSuccessful(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveClientError(string because = "", params object[] becauseArgs) { } @@ -2301,7 +2302,6 @@ namespace FluentAssertions.Types where TAssertions : FluentAssertions.Types.MethodBaseAssertions { protected MethodBaseAssertions(TSubject subject) { } - protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint NotHaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } } @@ -2598,6 +2598,7 @@ namespace FluentAssertions.Xml public class XmlElementAssertions : FluentAssertions.Xml.XmlNodeAssertions { public XmlElementAssertions(System.Xml.XmlElement xmlElement) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAttribute(string expectedName, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveAttributeWithNamespace(string expectedName, string expectedNamespace, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndWhichConstraint HaveElement(string expectedName, string because = "", params object[] becauseArgs) { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt index a92ed9ff80..7ec995f597 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt @@ -1922,6 +1922,7 @@ namespace FluentAssertions.Primitives where TAssertions : FluentAssertions.Primitives.HttpResponseMessageAssertions { protected HttpResponseMessageAssertions(System.Net.Http.HttpResponseMessage value) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint BeRedirection(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint BeSuccessful(string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveClientError(string because = "", params object[] becauseArgs) { } @@ -2350,7 +2351,6 @@ namespace FluentAssertions.Types where TAssertions : FluentAssertions.Types.MethodBaseAssertions { protected MethodBaseAssertions(TSubject subject) { } - protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint NotHaveAccessModifier(FluentAssertions.Common.CSharpAccessModifier accessModifier, string because = "", params object[] becauseArgs) { } } @@ -2647,6 +2647,7 @@ namespace FluentAssertions.Xml public class XmlElementAssertions : FluentAssertions.Xml.XmlNodeAssertions { public XmlElementAssertions(System.Xml.XmlElement xmlElement) { } + protected override string Identifier { get; } public FluentAssertions.AndConstraint HaveAttribute(string expectedName, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndConstraint HaveAttributeWithNamespace(string expectedName, string expectedNamespace, string expectedValue, string because = "", params object[] becauseArgs) { } public FluentAssertions.AndWhichConstraint HaveElement(string expectedName, string because = "", params object[] becauseArgs) { } From 4eacf0d9bcf27e3418b88c8c0f96b6a5a4418387 Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Sun, 16 Jan 2022 14:27:35 +0100 Subject: [PATCH 2/2] Add xml documentation on Identifier about user-friendliness --- Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs b/Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs index b3a56a1e56..80e53e1490 100644 --- a/Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs +++ b/Src/FluentAssertions/Primitives/ReferenceTypeAssertions.cs @@ -416,6 +416,7 @@ public AndConstraint NotBeAssignableTo(Type type, string because = /// /// Returns the type of the subject the assertion applies on. + /// It should be a user-friendly name as it is included in the failure message. /// protected abstract string Identifier { get; }