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"]); } }
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 => { } ); } }
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); }); } }
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); } ); } }
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); } ); } }