public void Missing_Required_Value_Should_Throw() { Assert.Throws <ConsoleUsageException>(() => { var subject = new RequiredSubject(); CommandLineMapper.Map(subject, new string[] { }); }, "Expected argument '--foo', but was not received"); }
public void Invalid_Arg_Value_Should_Throw() { Assert.Throws <ConsoleUsageException>(() => { var subject = new ComplexConverterSubject(); CommandLineMapper.Map(subject, new[] { "--foo:bar" }); }, "Argument '--foo' has an invalid value 'bar'"); }
public void Can_Handle_Path_Values() { var subject = new StringsSubject(); CommandLineMapper.Map(subject, new[] { "--foo:\"C:\\a\\b c\\d\"", "--bar:barrrr" }); Assert.That(subject.Foo, Is.EqualTo("C:\\a\\b c\\d")); Assert.That(subject.Bar, Is.EqualTo("barrrr")); }
public void Invalid_Arg_Syntax_Should_Throw(string invalidArg) { Assert.Throws <ConsoleUsageException>(() => { var subject = new StringsSubject(); CommandLineMapper.Map(subject, new[] { invalidArg }); }); }
public void Can_Map_Strings() { var subject = new StringsSubject(); CommandLineMapper.Map(subject, new[] { "--foo:bar", "--bar:baz" }); Assert.That(subject.Foo, Is.EqualTo("bar")); Assert.That(subject.Bar, Is.EqualTo("baz")); Assert.That(subject.Baz, Is.False); }
public void Can_Map_Complex_Converters() { var subject = new ComplexConverterSubject(); CommandLineMapper.Map(subject, new [] { "--foo:Png" }); Assert.That(subject.Foo, Is.EqualTo(ImageFormat.Png)); CommandLineMapper.Map(subject, new[] { "--foo:Jpeg" }); Assert.That(subject.Foo, Is.EqualTo(ImageFormat.Jpeg)); CommandLineMapper.Map(subject, new[] { "--foo:gif" }); Assert.That(subject.Foo, Is.EqualTo(ImageFormat.Gif)); }
public void Can_Map_Nullable_Booleans() { var subject = new BooleansSubject(); CommandLineMapper.Map(subject, new[] { "--bar" }); Assert.That(subject.Foo, Is.False); Assert.That(subject.Bar.GetValueOrDefault(), Is.True); Assert.That(subject.Baz, Is.False); CommandLineMapper.Map(subject, new[] { "--bar:true" }); Assert.That(subject.Foo, Is.False); Assert.That(subject.Bar.GetValueOrDefault(), Is.True); Assert.That(subject.Baz, Is.False); CommandLineMapper.Map(subject, new[] { "--bar:false" }); Assert.That(subject.Foo, Is.False); Assert.That(subject.Bar.GetValueOrDefault(), Is.False); Assert.That(subject.Baz, Is.False); }
public void Can_Map_Booleans_Switch_Or_Value() { var subject = new BooleansSubject(); CommandLineMapper.Map(subject, new[] { "--foo" }); Assert.That(subject.Foo, Is.True); Assert.That(subject.Bar, Is.Null); Assert.That(subject.Baz, Is.False); CommandLineMapper.Map(subject, new[] { "--foo:true" }); Assert.That(subject.Foo, Is.True); Assert.That(subject.Bar, Is.Null); Assert.That(subject.Baz, Is.False); CommandLineMapper.Map(subject, new[] { "--foo:false" }); Assert.That(subject.Foo, Is.False); Assert.That(subject.Bar, Is.Null); Assert.That(subject.Baz, Is.False); }
public void CommandLineMapperTest() { var config = new TestConfig { Name = "Anne", BirthDate = new DateTime(1980, 12, 21) }; config.DeliveryAddress.Street = "Main Street"; config.DeliveryAddress.PostalCode = "10180"; config.DeliveryAddress.State = "MyState"; var cmd = new CmdOptions { Name = "Richard", DeliveryState = "OtherState" }; var configurator = new CommandLineMapper <CmdOptions, TestConfig>(cmd); configurator.Map(x => x.DeliveryState, x => x.DeliveryAddress.State); Assert.Equal("TestConfig:DeliveryAddress:State", configurator.Path("DeliveryState")); Assert.Equal("OtherState", configurator.Value("DeliveryState")); }