From 060a3d35b6355771820a1662ecb4a3d0510d4eb1 Mon Sep 17 00:00:00 2001
From: Abdol Baset Sedighi <118891407+94sedighi@users.noreply.github.com>
Date: Wed, 21 Dec 2022 16:42:49 +0100
Subject: [PATCH] Add `ThatAre[Not]Interfaces` to `TypeSelector.cs` (#2057)
---
Src/FluentAssertions/Types/TypeSelector.cs | 18 +++++++
.../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 | 51 +++++++++++++++++++
docs/_pages/releases.md | 1 +
9 files changed, 82 insertions(+)
diff --git a/Src/FluentAssertions/Types/TypeSelector.cs b/Src/FluentAssertions/Types/TypeSelector.cs
index b22f059d79..d5e3cb62b8 100644
--- a/Src/FluentAssertions/Types/TypeSelector.cs
+++ b/Src/FluentAssertions/Types/TypeSelector.cs
@@ -219,6 +219,24 @@ public TypeSelector ThatAreNotSealed()
return this;
}
+ ///
+ /// Filters and returns only the types that are interfaces
+ ///
+ public TypeSelector ThatAreInterfaces()
+ {
+ types = types.Where(t => t.IsInterface).ToList();
+ return this;
+ }
+
+ ///
+ /// Filters and returns only the types that are not interfaces
+ ///
+ public TypeSelector ThatAreNotInterfaces()
+ {
+ types = types.Where(t => !t.IsInterface).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 e4791ac991..225201d49e 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt
@@ -2656,6 +2656,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2663,6 +2664,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
index 029ff8811d..e7bdbbf01f 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/net6.0.verified.txt
@@ -2786,6 +2786,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2793,6 +2794,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
index 8c05e9795d..2943c1c55b 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp2.1.verified.txt
@@ -2658,6 +2658,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2665,6 +2666,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
index 8c05e9795d..2943c1c55b 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netcoreapp3.0.verified.txt
@@ -2658,6 +2658,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2665,6 +2666,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
index 6af101d69f..2d81d1b460 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.0.verified.txt
@@ -2607,6 +2607,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2614,6 +2615,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
index 8c05e9795d..2943c1c55b 100644
--- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
+++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions/netstandard2.1.verified.txt
@@ -2658,6 +2658,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreNotClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWith()
@@ -2665,6 +2666,7 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
+ public FluentAssertions.Types.TypeSelector ThatAreNotInterfaces() { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
diff --git a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
index ec0872031f..af2c740f4f 100644
--- a/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
+++ b/Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
@@ -5,6 +5,7 @@
using System.Threading.Tasks;
using FluentAssertions.Types;
using Internal.AbstractAndNotAbstractClasses.Test;
+using Internal.InterfaceAndClasses.Test;
using Internal.Main.Test;
using Internal.NotOnlyClasses.Test;
using Internal.Other.Test;
@@ -643,6 +644,41 @@ public void When_unwrap_enumerable_types_it_should_return_the_correct_types()
.And.Contain(typeof(int))
.And.Contain(typeof(string));
}
+
+ [Fact]
+ public void When_selecting_types_that_are_interfaces_it_should_return_the_correct_types()
+ {
+ // Arrange
+ Assembly assembly = typeof(InternalInterface).GetTypeInfo().Assembly;
+
+ // Act
+ IEnumerable types = AllTypes.From(assembly)
+ .ThatAreInNamespace("Internal.InterfaceAndClasses.Test")
+ .ThatAreInterfaces();
+
+ // Assert
+ types.Should()
+ .ContainSingle()
+ .Which.Should().Be(typeof(InternalInterface));
+ }
+
+ [Fact]
+ public void When_selecting_types_that_are_not_interfaces_it_should_return_the_correct_types()
+ {
+ // Arrange
+ Assembly assembly = typeof(InternalNotInterfaceClass).GetTypeInfo().Assembly;
+
+ // Act
+ IEnumerable types = AllTypes.From(assembly)
+ .ThatAreInNamespace("Internal.InterfaceAndClasses.Test")
+ .ThatAreNotInterfaces();
+
+ // Assert
+ types.Should()
+ .HaveCount(2)
+ .And.Contain(typeof(InternalNotInterfaceClass))
+ .And.Contain(typeof(InternalAbstractClass));
+ }
}
}
@@ -779,6 +815,21 @@ internal static class NotAbstractStaticClass
}
}
+namespace Internal.InterfaceAndClasses.Test
+{
+ internal interface InternalInterface
+ {
+ }
+
+ internal abstract class InternalAbstractClass
+ {
+ }
+
+ internal class InternalNotInterfaceClass
+ {
+ }
+}
+
namespace Internal.UnwrapSelectorTestTypes.Test
{
internal class ClassToExploreUnwrappedTaskTypes
diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md
index 0c5c3a0afb..ef1a285352 100644
--- a/docs/_pages/releases.md
+++ b/docs/_pages/releases.md
@@ -10,6 +10,7 @@ sidebar:
## Unreleased
### What's new
+* 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)
* Added `ThatAre[Not]Abstract` methods to `MethodInfoSelector.cs` for filtering the methods - [#2060](https://github.com/fluentassertions/fluentassertions/pull/2060)