Skip to content

Commit

Permalink
Add ThatAre[Not]Abstract to TypeSelector (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
94sedighi committed Dec 19, 2022
1 parent 9e0a2e9 commit a769c64
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Src/FluentAssertions/Types/TypeSelector.cs
Expand Up @@ -183,6 +183,24 @@ public TypeSelector ThatAreNotClasses()
return this;
}

/// <summary>
/// Filters and returns the types that are abstract
/// </summary>
public TypeSelector ThatAreAbstract()
{
types = types.Where(t => t.IsCSharpAbstract()).ToList();
return this;
}

/// <summary>
/// Filters and returns the types that are not abstract
/// </summary>
public TypeSelector ThatAreNotAbstract()
{
types = types.Where(t => !t.IsCSharpAbstract()).ToList();
return this;
}

/// <summary>
/// Determines whether the type is static
/// </summary>
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 @@ -2779,12 +2779,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 @@ -2651,12 +2651,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 @@ -2651,12 +2651,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 @@ -2600,12 +2600,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 @@ -2651,12 +2651,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
49 changes: 49 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,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<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()
.HaveCount(2);
}

[Fact]
public void When_selecting_types_that_are_static_classes_it_should_return_the_correct_types()
{
Expand Down Expand Up @@ -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
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` 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)
Expand Down

0 comments on commit a769c64

Please sign in to comment.