Skip to content

Commit

Permalink
Merge c429f45 into 3999d05
Browse files Browse the repository at this point in the history
  • Loading branch information
94sedighi committed Dec 13, 2022
2 parents 3999d05 + c429f45 commit fd9046f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Src/FluentAssertions/Types/TypeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ public TypeSelector ThatAreNotClasses()
return this;
}

/// <summary>
/// Determines wether the type is sealed
/// </summary>
/// <returns></returns>
public TypeSelector ThatAreSealed()
{
types = types.Where(t => t.IsSealed).ToList();
return this;
}

/// <summary>
/// Determines wheter the type is not sealed
/// </summary>
/// <returns></returns>
public TypeSelector ThatAreNotSealed()
{
types = types.Where(t => !t.IsSealed).ToList();
return this;
}

/// <summary>
/// Determines whether the type is static
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit fd9046f

Please sign in to comment.