public void Should_Register_Remaining_Parsed_Arguments_With_Context() { // Given var capturedContext = default(CommandContext); var resolver = new FakeTypeResolver(); var command = new InterceptingCommand <DogSettings>((context, _) => { capturedContext = context; }); resolver.Register(new DogSettings()); resolver.Register(command); var app = new CommandApp(new FakeTypeRegistrar(resolver)); app.Configure(config => { config.PropagateExceptions(); config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <InterceptingCommand <DogSettings> >("dog"); }); }); // When app.Run(new[] { "animal", "4", "dog", "12", "--", "--foo", "bar", "--foo", "baz", "-bar", "\"baz\"", "qux" }); // Then capturedContext.Remaining.Parsed.Count.ShouldBe(4); capturedContext.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" }); capturedContext.ShouldHaveRemainingArgument("b", values: new[] { (string)null }); capturedContext.ShouldHaveRemainingArgument("a", values: new[] { (string)null }); capturedContext.ShouldHaveRemainingArgument("r", values: new[] { (string)null }); }
public void Should_Register_Remaining_Raw_Arguments_With_Context() { // Given var capturedContext = default(CommandContext); var resolver = new FakeTypeResolver(); var command = new InterceptingCommand <DogSettings>((context, _) => { capturedContext = context; }); resolver.Register(new DogSettings()); resolver.Register(command); var app = new CommandApp(new FakeTypeRegistrar(resolver)); app.Configure(config => { config.PropagateExceptions(); config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <InterceptingCommand <DogSettings> >("dog"); }); }); // When app.Run(new[] { "animal", "4", "dog", "12", "--", "--foo", "bar", "-bar", "\"baz\"", "qux" }); // Then capturedContext.Remaining.Raw.Count.ShouldBe(5); capturedContext.Remaining.Raw[0].ShouldBe("--foo"); capturedContext.Remaining.Raw[1].ShouldBe("bar"); capturedContext.Remaining.Raw[2].ShouldBe("-bar"); capturedContext.Remaining.Raw[3].ShouldBe("\"baz\""); capturedContext.Remaining.Raw[4].ShouldBe("qux"); }
public void Should_Add_Unknown_Boolean_Option_To_Remaining_Arguments_In_Relaxed_Mode() { // Given var capturedContext = default(CommandContext); var resolver = new FakeTypeResolver(); var command = new InterceptingCommand <DogSettings>((context, _) => { capturedContext = context; }); resolver.Register(new DogSettings()); resolver.Register(command); var registrar = new FakeTypeRegistrar(resolver); var app = new CommandApp(registrar); app.Configure(config => { config.PropagateExceptions(); config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <InterceptingCommand <DogSettings> >("dog"); }); }); // When var result = app.Run(new[] { "animal", "4", "dog", "12", "--foo" }); // Then capturedContext.ShouldNotBeNull(); capturedContext.Remaining.Parsed.Count.ShouldBe(1); capturedContext.ShouldHaveRemainingArgument("foo", values: new[] { (string)null }); }