public void MapperBindingTest() { 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 sut = new CommandLineConfigurationProvider <CmdOptions, TestConfig>(cmd, mapper => { mapper .Map(x => x.DeliveryState, x => x.DeliveryAddress.State) .Map(x => x.Name, x => x.Name); }); sut.Load(); string value = null; Assert.True(sut.TryGet("TestConfig:DeliveryAddress:State", out value)); Assert.Equal("OtherState", value); value = null; Assert.True(sut.TryGet("TestConfig:Name", out value)); Assert.Equal("Richard", value); }
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")); }
public void MapperWithDefaultOptionValues() { var config = new TestConfig { Name = "Anne", BirthDate = new DateTime(1980, 12, 21), DeliveryMethod = DeliveryMethod.Standard }; config.DeliveryAddress.Street = "Main Street"; config.DeliveryAddress.PostalCode = "10180"; config.DeliveryAddress.State = "MyState"; var cmd = new CmdOptions { DeliveryState = "OtherState" }; var sut = new CommandLineConfigurationProvider <CmdOptions, TestConfig>(cmd, mapper => { mapper .Map(x => x.DeliveryState, x => x.DeliveryAddress.State) .Map(x => x.DeliveryPostalCode, x => x.DeliveryAddress.PostalCode) .Map(x => x.DeliveryMethod, x => x.DeliveryMethod) .Map(x => x.Name, x => x.Name); }); sut.Load(); string value = null; Assert.True(sut.TryGet("TestConfig:DeliveryAddress:State", out value)); Assert.Equal("OtherState", value); //Values not set in CmdOptions are missing in the provider collection. If they exist //in a configuration file they will be added by the configuration provider Assert.False(sut.TryGet("TestConfig:DeliveryAddress:PostalCode", out value)); Assert.False(sut.TryGet("TestConfig:DeliveryMethod", out value)); Assert.False(sut.TryGet("TestConfig:Name", out value)); }