예제 #1
0
        public async Task CanExecuteMultipleCommands()
        {
            var counters = new Dictionary <Identifier, int>();

            using (var context = CreateContext(
                       commands => commands
                       .Add(Identifier.Create("a"), ExecuteHelper.Count <SimpleBag>(counters))
                       .Add(Identifier.Create("b"), ExecuteHelper.Count <SimpleBag>(counters))
                       ))
            {
                await context.Executor.ExecuteAsync <object>("a|b", default);

                Assert.Equal(1, counters["a"]);
                Assert.Equal(1, counters["b"]);
            }
        }
예제 #2
0
        public async Task CanCreateBagWithCommandLineValues()
        {
            var tracker = new BagTracker();

            using (var context = CreateContext(
                       commands => commands
                       .Add("c", ExecuteHelper.Track <BagWithMappedValues>(tracker))
                       ))
            {
                await context.Executor.ExecuteAsync <object>("c", default);

                tracker.Assert <BagWithMappedValues>(
                    "c",
                    bag => { }
                    );
            }
        }
예제 #3
0
        public async Task CanMapParameterByPosition()
        {
            var tracker = new BagTracker();

            using (var context = CreateContext(
                       commands => commands.Add("c", ExecuteHelper.Track <BagWithPositionalValues>(tracker)),
                       (ExecuteExceptionCallback)(ex => throw ex)
                       ))
            {
                await context.Executor.ExecuteAsync <object>("c 3 kmh -ismetric", default);

                tracker.Assert <BagWithPositionalValues>("c", bag =>
                {
                    Assert.Equal(3, bag.Speed);
                    Assert.Equal("kmh", bag.Unit);
                    Assert.Equal(true, bag.IsMetric);
                });
            }
        }
예제 #4
0
        public async Task CanCreateBagWithFlagValues()
        {
            var tracker = new BagTracker();

            using (var context = CreateContext(
                       commands => commands
                       .Add("c", ExecuteHelper.Track <SimpleBag>(tracker))
                       ))
            {
                await context.Executor.ExecuteAsync <object>("c -async -canthrow=true", default);

                tracker.Assert <SimpleBag>(
                    "c",
                    bag =>
                {
                    Assert.True(bag.Async);
                    //Assert.True(bag.CanThrow);
                }
                    );
            }
        }
예제 #5
0
        public async Task CanMapParameterByAlias()
        {
            var tracker = new BagTracker();

            using (var context = CreateContext(
                       commands => commands
                       .Add("c", ExecuteHelper.Track <BagWithAliases>(tracker))
                       ))
            {
                await context.Executor.ExecuteAsync <object>("c -swa=abc", default);

                tracker.Assert <BagWithAliases>(
                    "c",
                    bag =>
                {
                    Assert.False(bag.Async);
                    //Assert.False(bag.CanThrow);
                    Assert.Equal("abc", bag.StringWithAlias);
                }
                    );
            }
        }