diff --git a/Src/FluentAssertions/Types/TypeSelector.cs b/Src/FluentAssertions/Types/TypeSelector.cs index b02cee59ed..60c007295e 100644 --- a/Src/FluentAssertions/Types/TypeSelector.cs +++ b/Src/FluentAssertions/Types/TypeSelector.cs @@ -169,6 +169,24 @@ 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 95a7383374..35ba3945ee 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt @@ -2675,9 +2675,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 4a46ba3331..1d2c37fec9 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt @@ -2805,9 +2805,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 44c526e0d1..fde342567f 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt @@ -2677,9 +2677,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 44c526e0d1..fde342567f 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt @@ -2677,9 +2677,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 4d5ee76869..ba3dcd2112 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt @@ -2626,9 +2626,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 44c526e0d1..fde342567f 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt @@ -2677,9 +2677,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..0d0d76e485 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).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).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 a3ff65ae2f..7996def235 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 `Imply` method to `BooleanAssertions` - [#2074](https://github.com/fluentassertions/fluentassertions/pull/2074) * 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)