Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,17 @@ In addition to [access modifiers](#access-modifiers),
| static / abstract / sealed / generic | `.WhichAreStatic()` … | `.IsStatic()` … | `.AreStatic()` … |
| returns type (or a subtype) | `.WhichReturn<T>()` | `.Returns<T>()` | `.Return<T>()` |
| returns exactly | `.WhichReturnExactly<T>()` | `.ReturnsExactly<T>()` | `.ReturnExactly<T>()` |
| returns void | `.WhichReturnVoid()` | `.ReturnsVoid()` | `.ReturnVoid()` |
| no parameters | `.WithoutParameters()` | `.HasNoParameters()` | `.HaveNoParameters()` |
| parameter of type (or subtype) | `.WithParameter<T>()` / `.WithParameter<T>("name")` | `.HasParameter<T>()` / `.HasParameter<T>("name")` | `.HaveParameter<T>()` |
| parameter of exact type | `.WithParameterExactly<T>()` | `.HasParameterExactly<T>()` / `.HasParameterExactly<T>("name")` | `.HaveParameterExactly<T>()` |
| parameter count | `.WithParameterCount(n)` | `.HasParameterCount(n)` | `.HaveParameterCount(n)` |
| custom predicate | `.Which(m => …)` | `.Satisfies(m => …)` | `.All().Satisfy(m => …)` |

`WhichReturn<Task>()` and `Returns<Task>()` also match `Task<T>`; the `…Exactly` variants match only the
exact type. Use `OrReturn<T>()` / `OrReturnExactly<T>()` to allow several return types.
exact type. Use `OrReturn<T>()` / `OrReturnExactly<T>()` to allow several return types. Since `void` cannot be
used as a generic type argument, use `WhichReturnVoid()` / `ReturnsVoid()` / `ReturnVoid()` to match
void-returning methods.

```csharp
In.AllLoadedAssemblies().Methods()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class MethodFilters
{
/// <summary>
/// Filter for methods which return <see langword="void" />.
/// </summary>
public static MethodsWhichReturn WhichReturnVoid(this Filtered.Methods @this)
=> WhichReturn(@this, typeof(void));
}
14 changes: 14 additions & 0 deletions Source/aweXpect.Reflection/ThatMethod.ReturnsVoid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
using aweXpect.Core;

namespace aweXpect.Reflection;

public static partial class ThatMethod
{
/// <summary>
/// Verifies that the method returns <see langword="void" />.
/// </summary>
public static MethodReturnResult<MethodInfo?, IThat<MethodInfo?>> ReturnsVoid(
this IThat<MethodInfo?> subject)
=> Returns(subject, typeof(void));
}
24 changes: 24 additions & 0 deletions Source/aweXpect.Reflection/ThatMethods.ReturnVoid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Reflection;
using aweXpect.Core;

namespace aweXpect.Reflection;

public static partial class ThatMethods
{
/// <summary>
/// Verifies that all methods in the filtered collection return <see langword="void" />.
/// </summary>
public static MethodsReturnResult<IEnumerable<MethodInfo>, IThat<IEnumerable<MethodInfo>>> ReturnVoid(
this IThat<IEnumerable<MethodInfo>> subject)
=> Return(subject, typeof(void));

#if NET8_0_OR_GREATER
/// <summary>
/// Verifies that all methods in the filtered collection return <see langword="void" />.
/// </summary>
public static MethodsReturnResult<IAsyncEnumerable<MethodInfo>, IThat<IAsyncEnumerable<MethodInfo>>> ReturnVoid(
this IThat<IAsyncEnumerable<MethodInfo>> subject)
=> Return(subject, typeof(void));
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturn<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Type returnType) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnVoid(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, bool inherit = true)
where TAttribute : System.Attribute { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Func<TAttribute, bool>? predicate, bool inherit = true, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
Expand Down Expand Up @@ -1045,6 +1046,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> Returns<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsVoid(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public sealed class MethodReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down Expand Up @@ -1211,6 +1213,8 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>>> ReturnExactly<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>>> ReturnVoid(this aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnVoid(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public sealed class MethodsReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturn<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Type returnType) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnVoid(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, bool inherit = true)
where TAttribute : System.Attribute { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Func<TAttribute, bool>? predicate, bool inherit = true, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
Expand Down Expand Up @@ -1045,6 +1046,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> Returns<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsVoid(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public sealed class MethodReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down Expand Up @@ -1211,6 +1213,8 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>>> ReturnExactly<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>>> ReturnVoid(this aweXpect.Core.IThat<System.Collections.Generic.IAsyncEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnVoid(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public sealed class MethodsReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturn<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Type returnType) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnExactly<TReturn>(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWhichReturn WhichReturnVoid(this aweXpect.Reflection.Collections.Filtered.Methods @this) { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, bool inherit = true)
where TAttribute : System.Attribute { }
public static aweXpect.Reflection.MethodFilters.MethodsWith With<TAttribute>(this aweXpect.Reflection.Collections.Filtered.Methods @this, System.Func<TAttribute, bool>? predicate, bool inherit = true, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
Expand Down Expand Up @@ -920,6 +921,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> Returns<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsExactly<TReturn>(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public static aweXpect.Reflection.ThatMethod.MethodReturnResult<System.Reflection.MethodInfo?, aweXpect.Core.IThat<System.Reflection.MethodInfo?>> ReturnsVoid(this aweXpect.Core.IThat<System.Reflection.MethodInfo?> subject) { }
public sealed class MethodReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down Expand Up @@ -1009,6 +1011,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> Return<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject, System.Type returnType) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnExactly<TReturn>(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public static aweXpect.Reflection.ThatMethods.MethodsReturnResult<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>, aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>>> ReturnVoid(this aweXpect.Core.IThat<System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>> subject) { }
public sealed class MethodsReturnResult<TValue, TResult> : aweXpect.Results.AndOrResult<TValue, TResult>, aweXpect.Core.IOptionsProvider<aweXpect.Reflection.Options.TypeFilterOptions>
where TResult : aweXpect.Core.IThat<TValue>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection.Tests.Filters;

public sealed partial class MethodFilters
{
public sealed class WhichReturnVoid
{
public sealed class Tests
{
[Fact]
public async Task ShouldFilterForMethodsWhichReturnVoid()
{
Filtered.Methods methods = In.Type<TestClass>()
.Methods().WhichReturnVoid();

await That(methods).IsEqualTo([
typeof(TestClass).GetMethod(nameof(TestClass.VoidMethod))!,
]).InAnyOrder();
await That(methods.GetDescription())
.IsEqualTo("methods which return void in")
.AsPrefix();
}

[Fact]
public async Task ShouldAllowChainingAlternativeReturnType()
{
Filtered.Methods methods = In.Type<TestClass>()
.Methods().WhichReturnVoid().OrReturn<string>();

await That(methods).IsEqualTo([
typeof(TestClass).GetMethod(nameof(TestClass.VoidMethod))!,
typeof(TestClass).GetMethod(nameof(TestClass.GetString))!,
]).InAnyOrder();
await That(methods.GetDescription())
.IsEqualTo("methods which return void or return string in")
.AsPrefix();
}
}

#pragma warning disable CA1822 // Mark members as static
private class TestClass
{
public string GetString() => "test";
public int GetInt() => 42;
public void VoidMethod() { }
}
#pragma warning restore CA1822
}
}
Loading
Loading