Skip to content

Commit 80de1b5

Browse files
committed
CommandFilterTest to reproduce bug
1 parent 61357c2 commit 80de1b5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
4+
using Microsoft.Extensions.Hosting;
5+
using Xunit;
6+
// ReSharper disable UnusedMember.Local
7+
// ReSharper disable ClassNeverInstantiated.Local
8+
9+
namespace ConsoleAppFramework.Integration.Test;
10+
11+
public class FilterTest
12+
{
13+
[Fact]
14+
public void ApplyAttributeFilterTest()
15+
{
16+
using var console = new CaptureConsoleOutput();
17+
var args = new[] { "test-argument-name" };
18+
Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<TestConsoleApp>(args);
19+
console.Output.Should().Contain("[in filter] before");
20+
console.Output.Should().Contain(args[0]);
21+
console.Output.Should().Contain("[in filter] after");
22+
}
23+
24+
/// <inheritdoc />
25+
private class TestConsoleApp : ConsoleAppBase
26+
{
27+
[RootCommand]
28+
[ConsoleAppFilter(typeof(TestFilter))]
29+
public void RootCommand([Option(index: 0)]string someArgument) => Console.WriteLine(someArgument);
30+
}
31+
32+
/// <inheritdoc />
33+
private class TestFilter : ConsoleAppFilter
34+
{
35+
/// <inheritdoc />
36+
public override async ValueTask Invoke(ConsoleAppContext context, Func<ConsoleAppContext, ValueTask> next)
37+
{
38+
Console.WriteLine("[in filter] before");
39+
await next(context);
40+
Console.WriteLine("[in filter] after");
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)