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

Adds ThatAre(Not)Virtual to MethodInfoSelector #1744

Merged
merged 2 commits into from Nov 19, 2021
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/MethodInfoSelector.cs
Expand Up @@ -151,6 +151,24 @@ public MethodInfoSelector ThatAreNotAsync()
return this;
}

/// <summary>
/// Only return methods that are virtual.
/// </summary>
public MethodInfoSelector ThatAreVirtual()
{
selectedMethods = selectedMethods.Where(method => !method.IsNonVirtual());
return this;
}

/// <summary>
/// Only return methods that are not virtual.
/// </summary>
public MethodInfoSelector ThatAreNotVirtual()
{
selectedMethods = selectedMethods.Where(method => method.IsNonVirtual());
return this;
}

/// <summary>
/// Select return types of the methods
/// </summary>
Expand Down
Expand Up @@ -2351,6 +2351,8 @@ namespace FluentAssertions.Types
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatDoNotReturn<TReturn>() { }
public FluentAssertions.Types.MethodInfoSelector ThatReturn<TReturn>() { }
public System.Reflection.MethodInfo[] ToArray() { }
Expand Down
Expand Up @@ -2353,6 +2353,8 @@ namespace FluentAssertions.Types
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatDoNotReturn<TReturn>() { }
public FluentAssertions.Types.MethodInfoSelector ThatReturn<TReturn>() { }
public System.Reflection.MethodInfo[] ToArray() { }
Expand Down
Expand Up @@ -2353,6 +2353,8 @@ namespace FluentAssertions.Types
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatDoNotReturn<TReturn>() { }
public FluentAssertions.Types.MethodInfoSelector ThatReturn<TReturn>() { }
public System.Reflection.MethodInfo[] ToArray() { }
Expand Down
Expand Up @@ -2304,6 +2304,8 @@ namespace FluentAssertions.Types
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatDoNotReturn<TReturn>() { }
public FluentAssertions.Types.MethodInfoSelector ThatReturn<TReturn>() { }
public System.Reflection.MethodInfo[] ToArray() { }
Expand Down
Expand Up @@ -2353,6 +2353,8 @@ namespace FluentAssertions.Types
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : System.Attribute { }
public FluentAssertions.Types.MethodInfoSelector ThatAreNotVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatAreVirtual() { }
public FluentAssertions.Types.MethodInfoSelector ThatDoNotReturn<TReturn>() { }
public FluentAssertions.Types.MethodInfoSelector ThatReturn<TReturn>() { }
public System.Reflection.MethodInfo[] ToArray() { }
Expand Down
32 changes: 32 additions & 0 deletions Tests/FluentAssertions.Specs/Types/MethodInfoSelectorSpecs.cs
Expand Up @@ -301,6 +301,38 @@ public void When_selecting_methods_that_are_not_async_it_should_only_return_the_
.Which.Name.Should().Be("PublicNonAsyncMethod");
}

[Fact]
public void When_selecting_methods_that_are_virtual_it_should_only_return_the_applicable_methods()
{
// Arrange
Type type = typeof(TestClassForMethodSelector);

// Act
MethodInfo[] methods = type.Methods().ThatAreVirtual().ToArray();

// Assert
methods.Should()
.NotBeEmpty()
.And.Contain(m => m.Name == "PublicVirtualVoidMethodWithAttribute")
.And.Contain(m => m.Name == "ProtectedVirtualVoidMethodWithAttribute");
}

[Fact]
public void When_selecting_methods_that_are_not_virtual_it_should_only_return_the_applicable_methods()
{
// Arrange
Type type = typeof(TestClassForMethodSelector);

// Act
MethodInfo[] methods = type.Methods().ThatAreNotVirtual().ToArray();

// Assert
methods.Should()
.NotBeEmpty()
.And.NotContain(m => m.Name == "PublicVirtualVoidMethodWithAttribute")
.And.NotContain(m => m.Name == "ProtectedVirtualVoidMethodWithAttribute");
}

[Fact]
public void When_selecting_methods_not_decorated_with_or_inheriting_a_noninheritable_attribute_it_should_only_return_the_applicable_methods()
{
Expand Down
2 changes: 1 addition & 1 deletion docs/_pages/releases.md
Expand Up @@ -11,7 +11,7 @@ sidebar:

### What's New
* Adding `ThatAreAsync()` and `ThatAreNotAsync()` for filtering in method assertions - [#1725](https://github.com/fluentassertions/fluentassertions/pull/1725)

* Adding `ThatAreVirtual()` and `ThatAreNotVirtual()` for filtering in method assertions - [#1744](https://github.com/fluentassertions/fluentassertions/pull/1744)
### Fixes

## 6.2.0
Expand Down