diff --git a/Src/FluentAssertions/Types/TypeSelector.cs b/Src/FluentAssertions/Types/TypeSelector.cs
index 39200a9b9f..01781b9908 100644
--- a/Src/FluentAssertions/Types/TypeSelector.cs
+++ b/Src/FluentAssertions/Types/TypeSelector.cs
@@ -183,6 +183,24 @@ public TypeSelector ThatAreNotClasses()
return this;
}
+ ///
+ /// Filters and returns the types that are abstract
+ ///
+ public TypeSelector ThatAreAbstract()
+ {
+ types = types.Where(t => t.IsCSharpAbstract()).ToList();
+ return this;
+ }
+
+ ///
+ /// Filters and returns the types that are not abstract
+ ///
+ public TypeSelector ThatAreNotAbstract()
+ {
+ types = types.Where(t => !t.IsCSharpAbstract()).ToList();
+ return this;
+ }
+
///
/// Determines whether the type is static
///
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt
index 6acd2be185..a613c6f9d9 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt
@@ -2649,12 +2649,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
index 9978814b1e..155f3c8658 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
@@ -2779,12 +2779,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
index 11f115eb40..de57b3a0d0 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
@@ -2651,12 +2651,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
index 11f115eb40..de57b3a0d0 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
@@ -2651,12 +2651,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
index 3024af25dd..0b234fcec4 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
@@ -2600,12 +2600,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
index 11f115eb40..de57b3a0d0 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
@@ -2651,12 +2651,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator GetEnumerator() { }
+ public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
where TAttribute : System.Attribute { }
diff --git a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
index f07f962084..b9676fa4af 100644
--- a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
+++ b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
@@ -4,6 +4,7 @@
using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions.Types;
+using Internal.AbstractAndNotAbstractClasses.Test;
using Internal.Main.Test;
using Internal.NotOnlyClasses.Test;
using Internal.Other.Test;
@@ -495,6 +496,39 @@ 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_abstract_classes_it_should_return_the_correct_types()
+ {
+ // Arrange
+ Assembly assembly = typeof(AbstractClass).GetTypeInfo().Assembly;
+
+ // Act
+ IEnumerable types = AllTypes.From(assembly)
+ .ThatAreInNamespace("Internal.AbstractAndNotAbstractClasses.Test")
+ .ThatAreAbstract();
+
+ // Assert
+ types.Should()
+ .ContainSingle()
+ .Which.Should().Be(typeof(AbstractClass));
+ }
+
+ [Fact]
+ public void When_selecting_types_that_are_not_abstract_classes_it_should_return_the_correct_types()
+ {
+ // Arrange
+ Assembly assembly = typeof(NotAbstractClass).GetTypeInfo().Assembly;
+
+ // Act
+ IEnumerable types = AllTypes.From(assembly)
+ .ThatAreInNamespace("Internal.AbstractAndNotAbstractClasses.Test")
+ .ThatAreNotAbstract();
+
+ // Assert
+ types.Should()
+ .HaveCount(2);
+ }
+
[Fact]
public void When_selecting_types_that_are_static_classes_it_should_return_the_correct_types()
{
@@ -695,6 +729,21 @@ internal class NotAStaticClass
}
}
+namespace Internal.AbstractAndNotAbstractClasses.Test
+{
+ internal abstract class AbstractClass
+ {
+ }
+
+ internal class NotAbstractClass
+ {
+ }
+
+ internal static class NotAbstractStaticClass
+ {
+ }
+}
+
namespace Internal.UnwrapSelectorTestTypes.Test
{
internal class ClassToExploreUnwrappedTaskTypes
diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md
index cf8572970f..8d6542f666 100644
--- a/docs/_pages/releases.md
+++ b/docs/_pages/releases.md
@@ -10,6 +10,7 @@ sidebar:
## Unreleased
### What's new
+* Added `ThatAre[Not]Abstract` method for filtering the types - [#2058](https://github.com/fluentassertions/fluentassertions/pull/2058)
* Added `ThatAre[Not]Abstract` methods to `MethodInfoSelector.cs` for filtering the methods - [#2060](https://github.com/fluentassertions/fluentassertions/pull/2060)
* Added `ThatAre[Not]Abstract`, `ThatAre[Not]Static` and `ThatAre[Not]Virtual` properties for filtering in `PropertyInfoSelector.cs` - [#2054](https://github.com/fluentassertions/fluentassertions/pull/2054)
* Added `BeOneOf` methods for object comparisons and `IComparable`s - [#2028](https://github.com/fluentassertions/fluentassertions/pull/2028)