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]Abstract to TypeSelector #2058

Merged
Merged
20 changes: 20 additions & 0 deletions Src/FluentAssertions/Types/TypeSelector.cs
Expand Up @@ -183,6 +183,26 @@ public TypeSelector ThatAreNotClasses()
return this;
}

/// <summary>
/// Determines the type is abstract and must be overridden
94sedighi marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <returns></returns>
public TypeSelector ThatAreAbstract()
{
types = types.Where(t => t.IsAbstract).ToList();
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
return this;
}

/// <summary>
/// Determines wheter the type is not abstract
94sedighi marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <returns></returns>
public TypeSelector ThatAreNotAbstract()
{
types = types.Where(t => !t.IsAbstract).ToList();
return this;
}

/// <summary>
/// Determines whether the type is static
/// </summary>
Expand Down
Expand Up @@ -2647,12 +2647,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2777,12 +2777,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2649,12 +2649,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2649,12 +2649,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2598,12 +2598,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2649,12 +2649,14 @@ namespace FluentAssertions.Types
public TypeSelector(System.Collections.Generic.IEnumerable<System.Type> types) { }
public TypeSelector(System.Type type) { }
public System.Collections.Generic.IEnumerator<System.Type> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ThatAreAbstract() { }
public FluentAssertions.Types.TypeSelector ThatAreClasses() { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreDecoratedWithOrInherit<TAttribute>()
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<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
46 changes: 46 additions & 0 deletions Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -495,6 +496,40 @@ 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<Type> 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<Type> types = AllTypes.From(assembly)
.ThatAreInNamespace("Internal.AbstractAndNotAbstractClasses.Test")
.ThatAreNotAbstract();

// Assert
types.Should()
.ContainSingle()
.Which.Should().Be(typeof(NotAbstractClass));
}

[Fact]
public void When_selecting_types_that_are_static_classes_it_should_return_the_correct_types()
{
Expand Down Expand Up @@ -695,6 +730,17 @@ internal class NotAStaticClass
}
}

namespace Internal.AbstractAndNotAbstractClasses.Test
{
internal abstract class AbstractClass
{
}

internal class NotAbstractClass
{
}
}

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]Abstract` method for filtering the types - [#2058](https://github.com/fluentassertions/fluentassertions/pull/2058)
* 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)
* Added `BeCloseTo` and `NotBeCloseTo` to `TimeOnly` - [#2030](https://github.com/fluentassertions/fluentassertions/pull/2030)
Expand Down