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]Sealed to TypeSelector.cs #2059

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 sealed
/// </summary>
public TypeSelector ThatAreSealed()
{
types = types.Where(t => t.IsSealed).ToList();
return this;
}

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

/// <summary>
/// Determines whether the type is static
/// </summary>
Expand Down
Expand Up @@ -2661,8 +2661,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
Expand Up @@ -2791,8 +2791,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
Expand Up @@ -2663,8 +2663,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
Expand Up @@ -2663,8 +2663,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
Expand Up @@ -2612,8 +2612,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
Expand Up @@ -2663,8 +2663,10 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.TypeSelector ThatAreNotInNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
Expand Down
46 changes: 46 additions & 0 deletions Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
Expand Up @@ -8,6 +8,7 @@
using Internal.NotOnlyClasses.Test;
using Internal.Other.Test;
using Internal.Other.Test.Common;
using Internal.SealedAndNotSealedClasses.Test;
using Internal.StaticAndNonStaticClasses.Test;
using Internal.UnwrapSelectorTestTypes.Test;
using Xunit;
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_sealed_classes_it_should_return_the_correct_types()
{
// Arrange
Assembly assembly = typeof(SealedClass).GetTypeInfo().Assembly;

// Act
IEnumerable<Type> types = AllTypes.From(assembly)
.ThatAreInNamespace("Internal.SealedAndNotSealedClasses.Test")
.ThatAreSealed();

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

[Fact]
public void When_selecting_types_that_are_not_sealed_classes_it_should_return_the_correct_types()
{
// Arrange
Assembly assembly = typeof(NotSealedClass).GetTypeInfo().Assembly;

// Act
IEnumerable<Type> types = AllTypes.From(assembly)
.ThatAreInNamespace("Internal.SealedAndNotSealedClasses.Test")
.ThatAreNotSealed();

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

[Fact]
public void When_selecting_types_that_are_static_classes_it_should_return_the_correct_types()
{
Expand Down Expand Up @@ -732,6 +767,17 @@ internal class ClassImplementingMultipleEnumerable : IEnumerable<int>, IEnumerab
}
}

namespace Internal.SealedAndNotSealedClasses.Test
{
internal sealed class SealedClass
{
}

internal class NotSealedClass
{
}
}

#pragma warning disable RCS1110 // Declare type inside namespace.
internal class ClassInGlobalNamespace { }
#pragma warning restore RCS1110
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]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)
* 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