コード例 #1
0
 public async Task TwoArgsWithOptionTest()
 {
     {
         var args = "-n foo -r 3".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoArgsWithOption>(args);
         log.InfoLogShouldBe(0, "name:foo");
         log.InfoLogShouldBe(1, "repeat:3");
     }
     {
         var log = new LogStack();
         using (TextWriterBridge.BeginSetConsoleOut(testOutput, log))
         {
             var args = new string[0];
             await new HostBuilder().RunBatchEngineAsync <TwoArgsWithOption>(args);
             var strAssertion = log.ToStringInfo().Should();
             strAssertion.Contain("argument list:"); // ok to show help
             strAssertion.Contain("-n");
             strAssertion.Contain("name of this");
             strAssertion.Contain("-r");
             strAssertion.Contain("repeat msg");
         }
     }
 }
コード例 #2
0
        public async Task SimpleTwoArgsTest()
        {
            {
                var args = "-name foo -repeat 3".Split(' ');
                var log  = new LogStack();
                await new HostBuilder()
                .ConfigureTestLogging(testOutput, log, true)
                .RunBatchEngineAsync <SimpleTwoArgs>(args);
                log.InfoLogShouldBe(0, "name:foo");
                log.InfoLogShouldBe(1, "repeat:3");
            }
            {
                var args = "-repeat 3".Split(' ');
                var log  = new LogStack();
                var ex   = await Assert.ThrowsAsync <AggregateException>(async() =>
                {
                    await new HostBuilder()
                    .ConfigureTestLogging(testOutput, log, true)
                    .RunBatchEngineAsync <SimpleTwoArgs>(args);
                });

                ex.Flatten().InnerException.Should().BeAssignableTo <TestLogException>()
                .Subject.InnerException.Message.Should().Contain("Required parameter \"name\" not found in argument");
            }
            {
                var log = new LogStack();
                using (TextWriterBridge.BeginSetConsoleOut(testOutput, log))
                {
                    var args = new string[0];
                    await new HostBuilder().RunBatchEngineAsync <SimpleTwoArgs>(args);
                    log.ToStringInfo().Should().Contain("argument list:"); // ok to show help
                }
            }
        }
コード例 #3
0
 public async Task SimpleComplexArgsTest()
 {
     {
         var args = "-person {\"Age\":10,\"Name\":\"foo\"} -repeat 3".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <SimpleComplexArgs>(args);
         log.InfoLogShouldBe(0, "person.Age:10 person.Name:foo");
         log.InfoLogShouldBe(1, "repeat:3");
     }
 }
コード例 #4
0
 public async Task AllDefaultParametersTest()
 {
     {
         var args = new string[0];
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <AllDefaultParameters>(args);
         log.InfoLogShouldBe(0, "name:aaa");
         log.InfoLogShouldBe(1, "repeat:100");
         log.InfoLogShouldBe(2, "hoo:");
     }
 }
コード例 #5
0
 public async Task TwoArgsWithDefaultTest()
 {
     {
         var args = "-name foo".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoArgsWithDefault>(args);
         log.InfoLogShouldBe(0, "name:foo");
         log.InfoLogShouldBe(1, "repeat:100");
         log.InfoLogShouldBe(2, "hoo:");
     }
 }
コード例 #6
0
 public async Task OverrideDefaultCommandTest()
 {
     {
         var args = "list".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <OverrideDefaultCommand>(args);
         log.InfoLogShouldBe(0, "lst");
     }
     {
         var args = "help".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <OverrideDefaultCommand>(args);
         log.InfoLogShouldBe(0, "hlp");
     }
     {
         var args = "h".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <OverrideDefaultCommand>(args);
         log.InfoLogShouldBe(0, "hlp");
     }
 }
コード例 #7
0
 public async Task MultiContained()
 {
     {
         var args = "Multi1.Hello1".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync(args);
         log.InfoLogShouldBe(0, "ok");
     }
     {
         var args = "Multi1.Hello2 -input yeah".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync(args);
         log.InfoLogShouldBe(0, "yeah");
     }
     {
         var args = "Multi2.Hello1 -x 20 -y 30".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync(args);
         log.InfoLogShouldBe(0, "20:30");
     }
     {
         var args = "Multi2.Hello2 -x -y -foo yeah".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync(args);
         log.InfoLogShouldBe(0, "True:True:yeah:999");
     }
 }
コード例 #8
0
        public async Task SimpleZeroArgsTest()
        {
            var log = new LogStack();

            await new HostBuilder()
            .ConfigureTestLogging(testOutput, log, true)
            .RunBatchEngineAsync <SimpleZeroArgs>(new string[0]);
            log.InfoLogShouldBe(0, "ok");
        }
コード例 #9
0
 public async Task TwoSubCommandTest()
 {
     {
         var args = "-d 12345.12345".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoSubCommand>(args);
         log.InfoLogShouldBe(0, "d:12345.12345");
     }
     {
         var args = "run -path foo -pfx bar".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoSubCommand>(args);
         log.InfoLogShouldBe(0, "path:foo");
         log.InfoLogShouldBe(1, "pfx:bar");
     }
     {
         var args = "sum 10 20".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoSubCommand>(args);
         log.InfoLogShouldBe(0, "x:10");
         log.InfoLogShouldBe(1, "y:20");
     }
     {
         var args = "opt foobarbaz -x 10 -y 20".Split(' ');
         var log  = new LogStack();
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <TwoSubCommand>(args);
         log.InfoLogShouldBe(0, "input:foobarbaz");
         log.InfoLogShouldBe(1, "x:10");
         log.InfoLogShouldBe(2, "y:20");
     }
 }
コード例 #10
0
 public async Task BooleanSwitchTest()
 {
     {
         var log  = new LogStack();
         var args = "-x foo -foo -yeah".Split(' ');
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <BooleanSwitch>(args);
         log.InfoLogShouldBe(0, "x:foo");
         log.InfoLogShouldBe(1, "foo:True");
         log.InfoLogShouldBe(2, "yeah:True");
     }
     {
         var log  = new LogStack();
         var args = "-x foo -foo".Split(' ');
         await new HostBuilder()
         .ConfigureTestLogging(testOutput, log, true)
         .RunBatchEngineAsync <BooleanSwitch>(args);
         log.InfoLogShouldBe(0, "x:foo");
         log.InfoLogShouldBe(1, "foo:True");
         log.InfoLogShouldBe(2, "yeah:False");
     }
 }
コード例 #11
0
 public async Task AliasCommandTest()
 {
     {
         var collection = new[] {
             "r -path foo -pfx bar".Split(' '),
             "run -path foo -pfx bar".Split(' '),
         };
         foreach (var args in collection)
         {
             var log = new LogStack();
             await new HostBuilder()
             .ConfigureTestLogging(testOutput, log, true)
             .RunBatchEngineAsync <AliasCommand>(args);
             log.InfoLogShouldBe(0, "path:foo");
             log.InfoLogShouldBe(1, "pfx:bar");
         }
     }
     {
         {
             var args = "su 10 20".Split(' ');
             var log  = new LogStack();
             await new HostBuilder()
             .ConfigureTestLogging(testOutput, log, true)
             .RunBatchEngineAsync <AliasCommand>(args);
             log.InfoLogShouldBe(0, "30");
         }
         {
             var args = "summmm 99 100".Split(' ');
             var log  = new LogStack();
             await new HostBuilder()
             .ConfigureTestLogging(testOutput, log, true)
             .RunBatchEngineAsync <AliasCommand>(args);
             log.InfoLogShouldBe(0, "199");
         }
     }
 }