public async Task ConfigureServices_() { const int expectedReturnCode = 123456; const string expectedTextValue = "TestText"; var testService = A.Fake <ITestService>(); A.CallTo(() => testService.ReturnCode).Returns(expectedReturnCode); A.CallTo(() => testService.TextValue).Returns(expectedTextValue); var consoleApp = new ConsoleAppBuilder(Array.Empty <string>()) .ConfigureServices(x => x.AddTransient(_ => testService)) .UseProgramMain <TestServiceProgramMain>() .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(expectedReturnCode); TestServiceProgramMain.TextValue .Should() .Be(expectedTextValue); }
public async Task RunSync_DifferentRoutesToDefaultAction_ActionIsExecuted(params string[] args) { var consoleApp = new ConsoleAppBuilder(args) .UseActions(x => x.AddController <TestMultiRouteCliController>().UseMiddleware <CliRoutingMiddleware>()) .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(TestMultiRouteCliController.ExecuteReturnCode); }
public async Task RunAsync_ConsoleAppControllerDo_ReturnsCorrectReturnCode() { var args = new[] { "test", "do" }; var consoleApp = new ConsoleAppBuilder(args) .UseActions <Startup>() .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(ConsoleAppTestController.DoReturnCode); }
public async Task UseVerbObjects_NoObjectFound_MatchingPureVerbIsCalled() { var args = new[] { "test", "something" }; var consoleApp = new ConsoleAppBuilder(args) .UseCli(x => x .AddCommandGroup(groupBuilder => groupBuilder.SetName("demo").AddCommand <DemoGroupTestCommand>()) .AddCommand <TestFallbackCommand>()) .Build(); // Act var result = await consoleApp.RunAsync().ConfigureAwait(false); // Assert result .Should() .Be(TestFallbackCommand.ReturnCode); }
public async Task UseCli_CallDemoGroupsCommand_CommandIsExecuted() { var args = new[] { "demo", "test" }; var consoleApp = new ConsoleAppBuilder(args) .UseCli(x => x.AddCommandGroup(groupBuilder => groupBuilder.SetName("demo").AddCommand <DemoGroupTestCommand>())) .Build(); // Act var result = await consoleApp.RunAsync().ConfigureAwait(false); // Assert result .Should() .Be(DemoGroupTestCommand.ReturnCode); }
public async Task RunAsync_WithCommandNotMatchingCommand_ReturnsDefaultErrorReturnCode() { const int expectedReturnCode = -1357; var args = new[] { "test1", "arg0" }; var consoleApp = new ConsoleAppBuilder(args) .UseCli(x => x .SetDefaultErrorReturnCode(expectedReturnCode) .AddCommand <TestCommand>()) .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(expectedReturnCode); }
public async Task UseConfiguration_ConfigurationValuesGiven_ReturnsReturnCodeFromConfiguration() { const int returnCode = 4567; var consoleApp = new ConsoleAppBuilder(Array.Empty <string>()) .UseProgramMain <TestProgramMainWithConfiguration>() .UseConfiguration(x => x.AddInMemoryCollection(new Dictionary <string, string> { { "ReturnCode", returnCode.ToString() } })) .Build(); // Act var result = await consoleApp.RunAsync().ConfigureAwait(false); // Assert result .Should() .Be(returnCode); }
public async Task RunAsync_WithCommand_CommandIsExecuted() { var args = new[] { "test", "arg0" }; var consoleApp = new ConsoleAppBuilder(args) .UseCli(x => x .AddCommand <TestCommand>()) .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(TestCommand.ReturnCode); TestCommand.OptionsFirstArg .Should() .Be("arg0"); }