Skip to content

Commit

Permalink
Add ThatAre[Not]Interfaces to TypeSelector.cs (#2057)
Browse files Browse the repository at this point in the history
  • Loading branch information
94sedighi committed Dec 21, 2022
1 parent 6c1d92c commit 060a3d3
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Src/FluentAssertions/Types/TypeSelector.cs
Expand Up @@ -219,6 +219,24 @@ public TypeSelector ThatAreNotSealed()
return this;
}

/// <summary>
/// Filters and returns only the types that are interfaces
/// </summary>
public TypeSelector ThatAreInterfaces()
{
types = types.Where(t => t.IsInterface).ToList();
return this;
}

/// <summary>
/// Filters and returns only the types that are not interfaces
/// </summary>
public TypeSelector ThatAreNotInterfaces()
{
types = types.Where(t => !t.IsInterface).ToList();
return this;
}

/// <summary>
/// Determines whether the type is static
/// </summary>
Expand Down
Expand Up @@ -2656,13 +2656,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
Expand Up @@ -2786,13 +2786,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
Expand Up @@ -2658,13 +2658,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
Expand Up @@ -2658,13 +2658,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
Expand Up @@ -2607,13 +2607,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
Expand Up @@ -2658,13 +2658,15 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
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) { }
Expand Down
51 changes: 51 additions & 0 deletions Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Type> 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<Type> types = AllTypes.From(assembly)
.ThatAreInNamespace("Internal.InterfaceAndClasses.Test")
.ThatAreNotInterfaces();

// Assert
types.Should()
.HaveCount(2)
.And.Contain(typeof(InternalNotInterfaceClass))
.And.Contain(typeof(InternalAbstractClass));
}
}
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Expand Up @@ -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)
Expand Down

0 comments on commit 060a3d3

Please sign in to comment.