From a8dd823bee4a55b6b5bc960d6eabdfee123a1703 Mon Sep 17 00:00:00 2001 From: 94sedighi Date: Mon, 2 Jan 2023 13:04:54 +0100 Subject: [PATCH 1/2] Add ThatAre[Not]ValueTypes method to TypeSelector.cs --- Src/FluentAssertions/Types/TypeSelector.cs | 20 +++++++ .../FluentAssertions/net47.verified.txt | 2 + .../FluentAssertions/net6.0.verified.txt | 2 + .../netcoreapp2.1.verified.txt | 2 + .../netcoreapp3.0.verified.txt | 2 + .../netstandard2.0.verified.txt | 2 + .../netstandard2.1.verified.txt | 2 + .../Types/TypeSelectorSpecs.cs | 60 +++++++++++++++++++ docs/_pages/releases.md | 1 + 9 files changed, 93 insertions(+) diff --git a/Src/FluentAssertions/Types/TypeSelector.cs b/Src/FluentAssertions/Types/TypeSelector.cs index b02cee59ed..32e4ff49ae 100644 --- a/Src/FluentAssertions/Types/TypeSelector.cs +++ b/Src/FluentAssertions/Types/TypeSelector.cs @@ -169,6 +169,26 @@ public TypeSelector ThatAreNotUnderNamespace(string @namespace) return this; } + /// + /// Filters and returns the types that are value types + /// + public TypeSelector ThatAreValueTypes() + { + types = types.Where(t => t.IsValueType) + .ToList(); + return this; + } + + /// + /// Filters and returns the types that are not value types + /// + public TypeSelector ThatAreNotValueTypes() + { + types = types.Where(t => !t.IsValueType) + .ToList(); + return this; + } + /// /// Determines whether the type is a class /// diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt index 0d33701140..a8e7431a10 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt @@ -2674,9 +2674,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt index e30d2876a4..18c4c5a2ce 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt @@ -2804,9 +2804,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt index 3fe8827c14..5c59fabdc4 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt @@ -2676,9 +2676,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt index 3fe8827c14..5c59fabdc4 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt @@ -2676,9 +2676,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt index 6269525f6b..5a59ddd988 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt @@ -2625,9 +2625,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt index 3fe8827c14..5c59fabdc4 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt @@ -2676,9 +2676,11 @@ namespace FluentAssertions.Types public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { } public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { } public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { } public FluentAssertions.Types.TypeSelector ThatAreSealed() { } public FluentAssertions.Types.TypeSelector ThatAreStatic() { } public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { } + public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { } public FluentAssertions.Types.TypeSelector ThatDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom() { } public FluentAssertions.Types.TypeSelector ThatDoNotImplement() { } diff --git a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs index af2c740f4f..ca584a686e 100644 --- a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs +++ b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs @@ -13,6 +13,7 @@ using Internal.SealedAndNotSealedClasses.Test; using Internal.StaticAndNonStaticClasses.Test; using Internal.UnwrapSelectorTestTypes.Test; +using Internal.ValueTypesAndNotValueTypes.Test; using Xunit; using ISomeInterface = Internal.Main.Test.ISomeInterface; @@ -498,6 +499,38 @@ public void When_selecting_types_that_are_not_classes_it_should_return_the_corre .And.Contain(typeof(NotOnlyClassesEnumeration)); } + [Fact] + public void When_selecting_types_that_are_value_types_it_should_return_the_correct_types() + { + // Arrange + Assembly assembly = typeof(InternalEnumValueType).GetTypeInfo().Assembly; + + // Act + IEnumerable types = AllTypes.From(assembly) + .ThatAreInNamespace("Internal.ValueTypesAndNotValueTypes.Test") + .ThatAreValueTypes(); + + // Assert + types.Should() + .HaveCount(3); + } + + [Fact] + public void When_selecting_types_that_are_not_value_types_it_should_return_the_correct_types() + { + // Arrange + Assembly assembly = typeof(InternalEnumValueType).GetTypeInfo().Assembly; + + // Act + IEnumerable types = AllTypes.From(assembly) + .ThatAreInNamespace("Internal.ValueTypesAndNotValueTypes.Test") + .ThatAreNotValueTypes(); + + // Assert + types.Should() + .HaveCount(3); + } + [Fact] public void When_selecting_types_that_are_abstract_classes_it_should_return_the_correct_types() { @@ -878,6 +911,33 @@ internal class NotSealedClass } } +namespace Internal.ValueTypesAndNotValueTypes.Test +{ + internal struct InternalStructValueType + { + } + + internal record struct InternalRecordStructValueType + { + } + + internal class InternalClassNotValueType + { + } + + internal record class InternalRecordClass + { + } + + internal enum InternalEnumValueType + { + } + + internal interface InternalInterfaceNotValueType + { + } +} + #pragma warning disable RCS1110 // Declare type inside namespace. internal class ClassInGlobalNamespace { } #pragma warning restore RCS1110 diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index 4230326b81..ea9411a748 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -10,6 +10,7 @@ sidebar: ## Unreleased ### What's new +* Added `ThatAre[Not]ValueTypes` method for filtering the types - [#2083](https://github.com/fluentassertions/fluentassertions/pull/2083) * Added `ThatAre[Not]Interfaces` method for filtering the types - [#2057](https://github.com/fluentassertions/fluentassertions/pull/2057) * Added `ThatAre[Not]Abstract` method for filtering the types - [#2058](https://github.com/fluentassertions/fluentassertions/pull/2058) * Added `ThatAre[Not]Sealed` method for filtering the types - [#2059](https://github.com/fluentassertions/fluentassertions/pull/2059) From b78e82e0c4abcf90debf8f6d50b2a436eabb861b Mon Sep 17 00:00:00 2001 From: 94sedighi Date: Tue, 3 Jan 2023 11:58:41 +0100 Subject: [PATCH 2/2] rebase and refactoring --- Src/FluentAssertions/Types/TypeSelector.cs | 6 ++---- Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Src/FluentAssertions/Types/TypeSelector.cs b/Src/FluentAssertions/Types/TypeSelector.cs index 32e4ff49ae..60c007295e 100644 --- a/Src/FluentAssertions/Types/TypeSelector.cs +++ b/Src/FluentAssertions/Types/TypeSelector.cs @@ -174,8 +174,7 @@ public TypeSelector ThatAreNotUnderNamespace(string @namespace) /// public TypeSelector ThatAreValueTypes() { - types = types.Where(t => t.IsValueType) - .ToList(); + types = types.Where(t => t.IsValueType).ToList(); return this; } @@ -184,8 +183,7 @@ public TypeSelector ThatAreValueTypes() /// public TypeSelector ThatAreNotValueTypes() { - types = types.Where(t => !t.IsValueType) - .ToList(); + types = types.Where(t => !t.IsValueType).ToList(); return this; } diff --git a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs index ca584a686e..0d0d76e485 100644 --- a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs +++ b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs @@ -503,7 +503,7 @@ public void When_selecting_types_that_are_not_classes_it_should_return_the_corre public void When_selecting_types_that_are_value_types_it_should_return_the_correct_types() { // Arrange - Assembly assembly = typeof(InternalEnumValueType).GetTypeInfo().Assembly; + Assembly assembly = typeof(InternalEnumValueType).Assembly; // Act IEnumerable types = AllTypes.From(assembly) @@ -519,7 +519,7 @@ public void When_selecting_types_that_are_value_types_it_should_return_the_corre public void When_selecting_types_that_are_not_value_types_it_should_return_the_correct_types() { // Arrange - Assembly assembly = typeof(InternalEnumValueType).GetTypeInfo().Assembly; + Assembly assembly = typeof(InternalEnumValueType).Assembly; // Act IEnumerable types = AllTypes.From(assembly)