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]Abstract to MethodInfoSelector #2060

Merged
Merged
18 changes: 18 additions & 0 deletions Src/FluentAssertions/Types/MethodInfoSelector.cs
Expand Up @@ -133,6 +133,24 @@ public MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
return this;
}

/// <summary>
/// Only return methods that are abstract
/// </summary>
public MethodInfoSelector ThatAreAbstract()
{
selectedMethods = selectedMethods.Where(method => method.IsAbstract);
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
return this;
}

/// <summary>
/// Only return methods that are not abstract
/// </summary>
public MethodInfoSelector ThatAreNotAbstract()
{
selectedMethods = selectedMethods.Where(method => !method.IsAbstract);
return this;
}

/// <summary>
/// Only return methods that are async.
/// </summary>
Expand Down
Expand Up @@ -2466,11 +2466,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2596,11 +2596,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2468,11 +2468,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2468,11 +2468,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2417,11 +2417,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
Expand Up @@ -2468,11 +2468,13 @@ namespace FluentAssertions.Types
public FluentAssertions.Types.MethodInfoSelector ThatReturnVoid { get; }
public System.Collections.Generic.IEnumerator<System.Reflection.MethodInfo> GetEnumerator() { }
public FluentAssertions.Types.TypeSelector ReturnTypes() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAbstract() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotAsync() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>()
where TAttribute : System.Attribute { }
Expand Down
49 changes: 49 additions & 0 deletions Tests/FluentAssertions.Specs/Types/MethodInfoSelectorSpecs.cs
Expand Up @@ -273,6 +273,32 @@ public void When_selecting_methods_not_decorated_with_a_noninheritable_attribute
methods.Should().ContainSingle();
}

[Fact]
public void When_selecting_methods_that_are_abstract_it_should_only_return_the_applicable_methods()
{
// Arrange
Type type = typeof(TestClassForMethodSelectorWithAbstractAndVirtualMethods);

// Act
IEnumerable<MethodInfo> methods = type.Methods().ThatAreAbstract().ToArray();

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

[Fact]
public void When_selecting_methods_that_are_not_abstract_it_should_only_return_the_applicable_methods()
{
// Arrange
Type type = typeof(TestClassForMethodSelectorWithAbstractAndVirtualMethods);

// Act
IEnumerable<MethodInfo> methods = type.Methods().ThatAreNotAbstract().ToArray();

// Assert
methods.Should().HaveCount(7);
}

[Fact]
public void When_selecting_methods_that_are_async_it_should_only_return_the_applicable_methods()
{
Expand Down Expand Up @@ -504,4 +530,27 @@ public class DummyMethodAttribute : Attribute
public bool Filter { get; set; }
}

internal abstract class TestClassForMethodSelectorWithAbstractAndVirtualMethods
{
public abstract void PublicAbstractMethod();

protected abstract void ProtectedAbstractMethod();

internal abstract void InternalAbstractMethod();

public virtual void PublicVirtualMethod() { }

protected virtual void ProptectedVirtualMethod() { }

internal virtual void InternalVirtualMethod() { }

public void PublicNotAbstractMethod() { }

protected void ProtectedNotAbstractMethod() { }

internal void InternalNotAbstractMethod() { }

private void PrivateAbstractMethod() { }
}

#endregion
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` 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)
* Added `BeCloseTo` and `NotBeCloseTo` to `TimeOnly` - [#2030](https://github.com/fluentassertions/fluentassertions/pull/2030)
Expand Down