Skip to content

Commit

Permalink
Merge pull request #1744 from chvollm/MethodInfoSelector-Virtual
Browse files Browse the repository at this point in the history
Adds ThatAre(Not)Virtual to MethodInfoSelector
  • Loading branch information
jnyrup committed Nov 19, 2021
2 parents 124fcca + 6c66708 commit 1aaa84f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 1 deletion.
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

0 comments on commit 1aaa84f

Please sign in to comment.