Skip to content

Commit 24e39a1

Browse files
committed
a
1 parent 9796074 commit 24e39a1

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

ReadMe.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ If the class implements `IDisposable` or `IAsyncDisposable`, the Dispose or Disp
299299

300300
### Nested command
301301

302-
You can create a deep command hierarchy by adding commands with paths separated by `/` when registering them. This allows you to add commands at nested levels.
302+
You can create a deep command hierarchy by adding commands with paths separated by ` ` when registering them. This allows you to add commands at nested levels.
303303

304304
```csharp
305305
var app = ConsoleApp.Create();
306306

307307
app.Add("foo", () => { });
308-
app.Add("foo/bar", () => { });
309-
app.Add("foo/bar/barbaz", () => { });
310-
app.Add("foo/baz", () => { });
308+
app.Add("foo bar", () => { });
309+
app.Add("foo bar barbaz", () => { });
310+
app.Add("foo baz", () => { });
311311

312312
// Commands:
313313
// foo
@@ -417,7 +417,8 @@ Attribute based parameters validation
417417
---
418418

419419

420-
420+
ConsoleAppContext
421+
---
421422

422423

423424

tests/ConsoleAppFramework.GeneratorTests/ConsoleAppContextTest.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Xunit.Abstractions;
7-
8-
namespace ConsoleAppFramework.GeneratorTests;
1+
namespace ConsoleAppFramework.GeneratorTests;
92

103
public class ConsoleAppContextTest(ITestOutputHelper output)
114
{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace ConsoleAppFramework.GeneratorTests;
2+
3+
public class DITest(ITestOutputHelper output)
4+
{
5+
VerifyHelper verifier = new VerifyHelper(output, "CAF");
6+
7+
[Fact]
8+
public void ServiceProvider()
9+
{
10+
verifier.Execute("""
11+
#nullable enable
12+
13+
var di = new MiniDI();
14+
di.Register(typeof(MyClass), new MyClass("foo"));
15+
ConsoleApp.ServiceProvider = di;
16+
17+
ConsoleApp.Run(args, ([FromServices] MyClass mc, int x, int y) => { Console.Write(mc.Name + ":" + x + ":" + y); });
18+
19+
20+
class MiniDI : IServiceProvider
21+
{
22+
System.Collections.Generic.Dictionary<Type, object> dict = new();
23+
24+
public void Register(Type type, object instance)
25+
{
26+
dict[type] = instance;
27+
}
28+
29+
public object? GetService(Type serviceType)
30+
{
31+
return dict.TryGetValue(serviceType, out var instance) ? instance : null;
32+
}
33+
}
34+
35+
class MyClass(string name)
36+
{
37+
public string Name => name;
38+
}
39+
""", args: "--x 10 --y 20", expected: "foo:10:20");
40+
}
41+
}

tests/ConsoleAppFramework.GeneratorTests/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using Xunit;
2+
global using Xunit.Abstractions;
23
global using FluentAssertions;
34

45
// CSharpGeneratorRunner.CompileAndExecute uses stdout hook(replace Console.Out)

0 commit comments

Comments
 (0)