Skip to content

Commit

Permalink
Add ThatAre[Not]ValueTypes method to TypeSelector.cs (#2083)
Browse files Browse the repository at this point in the history
  • Loading branch information
94sedighi committed Jan 3, 2023
1 parent 482d5a0 commit 07db76d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Src/FluentAssertions/Types/TypeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ public TypeSelector ThatAreNotUnderNamespace(string @namespace)
return this;
}

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

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

/// <summary>
/// Determines whether the type is a class
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2675,9 +2675,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2805,9 +2805,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2677,9 +2677,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2677,9 +2677,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2626,9 +2626,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2677,9 +2677,11 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.TypeSelector ThatAreNotSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreNotStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreNotUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreNotValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatAreSealed() { }
public FluentAssertions.Types.TypeSelector ThatAreStatic() { }
public FluentAssertions.Types.TypeSelector ThatAreUnderNamespace(string @namespace) { }
public FluentAssertions.Types.TypeSelector ThatAreValueTypes() { }
public FluentAssertions.Types.TypeSelector ThatDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotDeriveFrom<TBase>() { }
public FluentAssertions.Types.TypeSelector ThatDoNotImplement<TInterface>() { }
Expand Down
60 changes: 60 additions & 0 deletions Tests/FluentAssertions.Specs/Types/TypeSelectorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Internal.SealedAndNotSealedClasses.Test;
using Internal.StaticAndNonStaticClasses.Test;
using Internal.UnwrapSelectorTestTypes.Test;
using Internal.ValueTypesAndNotValueTypes.Test;
using Xunit;
using ISomeInterface = Internal.Main.Test.ISomeInterface;

Expand Down Expand Up @@ -498,6 +499,38 @@ 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_value_types_it_should_return_the_correct_types()
{
// Arrange
Assembly assembly = typeof(InternalEnumValueType).Assembly;

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

// Assert
types.Should()
.HaveCount(3);
}

[Fact]
public void When_selecting_types_that_are_not_value_types_it_should_return_the_correct_types()
{
// Arrange
Assembly assembly = typeof(InternalEnumValueType).Assembly;

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

// Assert
types.Should()
.HaveCount(3);
}

[Fact]
public void When_selecting_types_that_are_abstract_classes_it_should_return_the_correct_types()
{
Expand Down Expand Up @@ -878,6 +911,33 @@ internal class NotSealedClass
}
}

namespace Internal.ValueTypesAndNotValueTypes.Test
{
internal struct InternalStructValueType
{
}

internal record struct InternalRecordStructValueType
{
}

internal class InternalClassNotValueType
{
}

internal record class InternalRecordClass
{
}

internal enum InternalEnumValueType
{
}

internal interface InternalInterfaceNotValueType
{
}
}

#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]ValueTypes` method for filtering the types - [#2083](https://github.com/fluentassertions/fluentassertions/pull/2083)
* Added `Imply` method to `BooleanAssertions` - [#2074](https://github.com/fluentassertions/fluentassertions/pull/2074)
* 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)
Expand Down

0 comments on commit 07db76d

Please sign in to comment.