public void Should_Map_ReadOnly_Dictionary_Values() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <ReadOnlyDictionarySettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(new[] { "--var", "foo=bar", "--var", "baz=qux", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <ReadOnlyDictionarySettings>().And(pair => { pair.Values.ShouldNotBeNull(); pair.Values.Count.ShouldBe(2); pair.Values["foo"].ShouldBe("bar"); pair.Values["baz"].ShouldBe("qux"); }); }
public void Should_Inject_Parameters() { // Given var app = new CommandAppFixture(); var dependency = new FakeDependency(); app.WithDefaultCommand <GenericCommand <InjectSettings> >(); app.Configure(config => { config.Settings.Registrar.RegisterInstance(dependency); config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(new[] { "--name", "foo", "--age", "35", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <InjectSettings>().And(injected => { injected.ShouldNotBeNull(); injected.Fake.ShouldBeSameAs(dependency); injected.Name.ShouldBe("Hello foo"); injected.Age.ShouldBe(35); }); }
public void Should_Map_Lookup_Values() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <LookupSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(new[] { "--var", "foo=bar", "--var", "foo=qux", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <LookupSettings>().And(pair => { pair.Values.ShouldNotBeNull(); pair.Values.Count.ShouldBe(1); pair.Values["foo"].ToList().Count.ShouldBe(2); }); }
public void Should_Map_Latest_Value_Of_Same_Key_When_Mapping_To_Dictionary() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <DictionarySettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(new[] { "--var", "foo=bar", "--var", "foo=qux", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <DictionarySettings>().And(pair => { pair.Values.ShouldNotBeNull(); pair.Values.Count.ShouldBe(1); pair.Values["foo"].ShouldBe("qux"); }); }
public void Should_Map_Pairs_To_Pair_Deconstructable_Collection_Using_Default_Deconstructort() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <DefaultPairDeconstructorSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(new[] { "--var", "foo=1", "--var", "foo=3", "--var", "bar=4", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <DefaultPairDeconstructorSettings>().And(pair => { pair.Values.ShouldNotBeNull(); pair.Values.Count.ShouldBe(2); pair.Values["foo"].ShouldBe(3); pair.Values["bar"].ShouldBe(4); }); }
public Task Should_Output_Default_Command_Correctly() { // Given var fixture = new CommandAppFixture(); fixture.WithDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var(_, output, _, _) = fixture.Run("--help"); // Then return(Verifier.Verify(output)); }
public Task Should_List_Arguments_In_Correct_Order() { // Given var fixture = new CommandAppFixture(); fixture.WithDefaultCommand <GenericCommand <ArgumentOrderSettings> >(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var(_, output, _, _) = fixture.Run("--help"); // Then return(Verifier.Verify(output)); }
public void Should_Output_Default_Command_Correctly(string expected) { // Given var fixture = new CommandAppFixture(); fixture.WithDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var(_, output, _, _) = fixture.Run("--help"); // Then output.ShouldBe(expected); }
public void Should_Throw_If_Value_Is_Not_In_A_Valid_Format_Using_Default_Deconstructor( string input, string expected) { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <DefaultPairDeconstructorSettings> >(); // When var(result, output, _, settings) = app.Run(new[] { "--var", input, }); // Then result.ShouldBe(-1); output.ShouldBe(expected); }
public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified() { // Given var fixture = new CommandAppFixture(); fixture.WithDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddExample(new[] { "12", "-c", "3" }); }); // When var(_, output, _, _) = fixture.Run("--help"); // Then return(Verifier.Verify(output)); }
public void Should_Output_Root_Examples_If_Default_Command_Is_Specified(string expected) { // Given var fixture = new CommandAppFixture(); fixture.WithDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddExample(new[] { "12", "-c", "3" }); }); // When var(_, output, _, _) = fixture.Run("--help"); // Then output.ShouldBe(expected); }
public void Should_Throw_If_Required_Argument_Have_Default_Value() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <RequiredArgumentWithDefaultValueSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var result = Record.Exception(() => app.Run(Array.Empty <string>())); // Then result.ShouldBeOfType <CommandConfigurationException>().And(ex => { ex.Message.ShouldBe("The required argument 'GREETING' cannot have a default value."); }); }
public void Should_Assign_Default_Value_To_Optional_Argument_Using_Converter_If_Necessary() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <GenericCommand <OptionalArgumentWithDefaultValueAndTypeConverterSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var(result, _, _, settings) = app.Run(Array.Empty <string>()); // Then result.ShouldBe(0); settings.ShouldBeOfType <OptionalArgumentWithDefaultValueAndTypeConverterSettings>().And(settings => { settings.Greeting.ShouldBe(5); }); }
public void Should_Be_Able_To_Set_The_Default_Command() { // Given var app = new CommandAppFixture(); app.WithDefaultCommand <DogCommand>(); // When var(result, _, _, settings) = app.Run(new[] { "4", "12", "--good-boy", "--name", "Rufus", }); // Then result.ShouldBe(0); settings.ShouldBeOfType <DogSettings>().And(dog => { dog.Legs.ShouldBe(4); dog.Age.ShouldBe(12); dog.GoodBoy.ShouldBe(true); dog.Name.ShouldBe("Rufus"); }); }