Skip to content

Commit 1226898

Browse files
add cli test
1 parent fad0fce commit 1226898

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

tests/CommandLineTests/CliTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212

1313
namespace Microstack.Tests.CommandLineTests
1414
{
15-
public class CliTests : IClassFixture<IHttpClientFactory>, IDisposable
15+
public class CliTests : IDisposable
1616
{
1717
private bool disposedValue;
1818
private CancellationTokenSource _cts;
1919
private HttpClient _client;
2020

21-
public CliTests(IHttpClientFactory factory)
21+
public CliTests()
2222
{
2323
_cts = new CancellationTokenSource();
24-
_client = factory.CreateClient();
24+
_client = new HttpClient();
2525
}
2626

2727
[Fact]
2828
public async Task ShouldOverrideConfigValues_WhenSpecifiedInConfiguration()
2929
{
3030
var cts = new CancellationTokenSource();
3131
var testAdapter = new ProgramTest();
32-
testAdapter.StartDaemon();
33-
testAdapter.StartHost(new string[] { "run", "-v", "-c", Path.Combine("config", ".mstkc.json"), "-p", "profile2" }, cts);
32+
var daemonTask = testAdapter.StartDaemon();
33+
var cliHost = testAdapter.StartHost(new string[] { "run", "-v", "-c", Path.Combine("config", ".mstkc.json"), "-p", "profile2" }, cts);
3434

3535
Thread.Sleep(1000 * 5);
3636

@@ -39,7 +39,7 @@ public async Task ShouldOverrideConfigValues_WhenSpecifiedInConfiguration()
3939

4040
Assert.Equal("app1", response1);
4141
Assert.Equal("app2", response2);
42-
//cts.Cancel();
42+
cts.Cancel();
4343
}
4444

4545
protected virtual void Dispose(bool disposing)

tests/CommandLineTests/ProgramTest.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55
using System.Runtime.InteropServices;
66
using System.Text;
77
using System.Threading;
8+
using System.Threading.Tasks;
89

910
namespace Microstack.Tests.CommandLineTests
1011
{
1112
public class ProgramTest
1213
{
13-
public void StartHost(string[] args, CancellationTokenSource cts)
14+
public Task StartHost(string[] args, CancellationTokenSource cts)
1415
{
15-
Program.CreateHostBuilder(args)
16-
.RunCommandLineApplicationAsync<Microstack.CLI.Commands.MicroStack>(args, cts.Token);
16+
return Task.Run(() =>
17+
{
18+
cts.Token.ThrowIfCancellationRequested();
19+
Program.CreateHostBuilder(args)
20+
.RunCommandLineApplicationAsync<Microstack.CLI.Commands.MicroStack>(args, cts.Token);
21+
}, cts.Token);
1722
}
1823

19-
public void StartDaemon()
24+
public Task StartDaemon()
2025
{
2126
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2227
{
23-
Microstack.Daemon.WindowsService.Program.CreateHostBuilder(new string[] { }).Build().RunAsync();
28+
return Microstack.Daemon.WindowsService.Program.CreateHostBuilder(new string[] { }).Build().RunAsync();
2429
}
30+
return Task.CompletedTask;
2531
}
2632
}
2733
}

tests/config/.mstkc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"Port": 5004,
2424
"Verbose": false,
2525
"ConfigOverrides": {
26-
"ComplexObj:ComplexKey": "app1"
26+
"ComplexObj:ComplexKey": "app1",
27+
"ASPNETCORE_ENVIRONMENT": "Development"
2728
}
2829
},
2930
{
@@ -39,7 +40,8 @@
3940
"Port": 5005,
4041
"Verbose": false,
4142
"ConfigOverrides": {
42-
"ComplexObj:ComplexKey": "app2"
43+
"ComplexObj:ComplexKey": "app2",
44+
"ASPNETCORE_ENVIRONMENT": "Development"
4345
}
4446
}
4547
]

0 commit comments

Comments
 (0)