コード例 #1
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
                }
            }
        }
コード例 #2
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");
         }
     }
 }