From 8c879bf268ca8fceffbcdce64971449530c56e0e Mon Sep 17 00:00:00 2001 From: Jonathan Gilbert Date: Thu, 17 Mar 2022 02:16:33 -0500 Subject: [PATCH] Baleeted TypeDescriptionUtility, per @dennisdoomen. --- .../Common/TypeDescriptionUtility.cs | 20 ------ ...DataColumnCollectionAssertionExtensions.cs | 8 +-- .../DataRowCollectionAssertionExtensions.cs | 8 +-- .../DataTableCollectionAssertionExtensions.cs | 8 +-- .../Common/TypeDescriptionUtilitySpecs.cs | 67 ------------------- 5 files changed, 12 insertions(+), 99 deletions(-) delete mode 100644 Src/FluentAssertions/Common/TypeDescriptionUtility.cs delete mode 100644 Tests/FluentAssertions.Specs/Common/TypeDescriptionUtilitySpecs.cs diff --git a/Src/FluentAssertions/Common/TypeDescriptionUtility.cs b/Src/FluentAssertions/Common/TypeDescriptionUtility.cs deleted file mode 100644 index 50a4ca684b..0000000000 --- a/Src/FluentAssertions/Common/TypeDescriptionUtility.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace FluentAssertions.Common -{ - internal static class TypeDescriptionUtility - { - public static string GetDescriptionOfObjectType(object obj) - { - return (obj is null) ? "" : GetTypeDescription(obj.GetType()); - } - - private static string GetTypeDescription(Type type) - { - return - ((type.Namespace == "System.Linq") && type.IsGenericType) - ? "an anonymous iterator from a LINQ expression with element type " + type.GetGenericArguments()[0].FullName - : (type.IsValueType ? "a value of type " : "an instance of ") + type.FullName; - } - } -} diff --git a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs index 7f7e303aa4..8cc8362408 100644 --- a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs @@ -48,8 +48,8 @@ public static class DataColumnCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to an instance of " + - "DataColumnCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataColumnCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); @@ -89,8 +89,8 @@ public static class DataColumnCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + - "DataColumnCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataColumnCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); diff --git a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs index b966bfba3f..ea5e745ff3 100644 --- a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs @@ -46,8 +46,8 @@ public static class DataRowCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to an instance of " + - "DataRowCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataRowCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); @@ -84,8 +84,8 @@ public static class DataRowCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + - "DataRowCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataRowCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); diff --git a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs index 5c30a822b2..76cdf9ea64 100644 --- a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs @@ -43,8 +43,8 @@ public static class DataTableCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to an instance of " + - "DataTableCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataTableCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); @@ -81,8 +81,8 @@ public static class DataTableCollectionAssertionExtensions .BecauseOf(because, becauseArgs) .FailWith( "Invalid expectation: Expected {context:column collection} to refer to a different instance of " + - "DataTableCollection{reason}, but found " + - TypeDescriptionUtility.GetDescriptionOfObjectType(assertion.Subject) + "."); + "DataTableCollection{reason}, but found {0}.", + assertion.Subject); } return new AndConstraint>(assertion); diff --git a/Tests/FluentAssertions.Specs/Common/TypeDescriptionUtilitySpecs.cs b/Tests/FluentAssertions.Specs/Common/TypeDescriptionUtilitySpecs.cs deleted file mode 100644 index 16a67c5f35..0000000000 --- a/Tests/FluentAssertions.Specs/Common/TypeDescriptionUtilitySpecs.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -using FluentAssertions.Common; - -using Xunit; - -namespace FluentAssertions.Specs -{ - public class TypeDescriptionUtilitySpecs - { - [Fact] - public void When_object_is_null_it_should_work() - { - // Act & Assert - TypeDescriptionUtility.GetDescriptionOfObjectType(null).Should().Be(""); - } - - [Fact] - public void When_object_is_value_type_it_should_work() - { - // Act & Assert - TypeDescriptionUtility.GetDescriptionOfObjectType(37).Should().Be("a value of type System.Int32"); - } - - [Fact] - public void When_object_is_reference_type_it_should_work() - { - // Act & Assert - TypeDescriptionUtility.GetDescriptionOfObjectType(new object()).Should().Be("an instance of System.Object"); - } - - [Fact] - public void When_object_is_generic_value_type_it_should_work() - { - // Arrange - var box = new Box() { Value = 37 }; - - // Act & Assert - TypeDescriptionUtility.GetDescriptionOfObjectType(box).Should() - .Match("a value of type *+Box`1[[System.Int32*]]"); - } - - [Fact] - public void When_object_is_generic_reference_type_it_should_work() - { - // Act & Assert - TypeDescriptionUtility.GetDescriptionOfObjectType(new List()).Should() - .Match("an instance of System.Collections.Generic.List`1[[System.Int32*]]"); - } - - [Fact] - public void When_object_is_LINQ_anonymous_iterator_type_it_should_work() - { - // Arrange - var value = new[] { 1, 2, 3 }.Select(x => 2 * x); - - TypeDescriptionUtility.GetDescriptionOfObjectType(value).Should().Be( - "an anonymous iterator from a LINQ expression with element type System.Int32"); - } - - private struct Box - { - public T Value { get; set; } - } - } -}