Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ThatAre[Not]Interfaces to TypeSelector.cs #2057

Merged
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