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]ValueTypes method to TypeSelector.cs #2083

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
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
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
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
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
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
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
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
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