Exemplo n.º 1
0
        public void SetConfigProperty_WhenMultiLevelTypeHasConverter_WritesTheSubPropertyCorrectly()
        {
            using (var fn = TestFileName.Create("file", Toml.FileExtension))
            {
                // Arrange
                var tmlCfg = TomlSettings.Create(c => c
                                                 .ConfigureType <MultiTableConverterObject>(tc => tc
                                                                                            .WithConversionFor <TomlString>(conv => conv
                                                                                                                            .ToToml(o => o.ToString())
                                                                                                                            .FromToml(s => MultiTableConverterObject.Parse(s.Value)))));

                var cfg = Config.CreateAs()
                          .MappedToType(() => new Root())
                          .UseTomlConfiguration(tmlCfg)
                          .StoredAs(s => s.File(fn))
                          .Initialize();

                // Act
                cfg.Set(c => c.ConvertedItem.UnitItem.Unit, "B");

                // Assert
                var tbl = Toml.ReadFile <Root>(fn, tmlCfg);
                tbl.ConvertedItem.UnitItem.Unit.Should().Be("B");
            }
        }
Exemplo n.º 2
0
        public void ReadConfigPropertyAfterInit_WhenMultiLevelTypeHasConverterInSpecializedScope_ReadsItemFromSpecScope()
        {
            using (var main = TestFileName.Create("main", Toml.FileExtension))
                using (var spec = TestFileName.Create("spec", Toml.FileExtension))
                {
                    // Arrange
                    var tmlCfg = TomlSettings.Create(c => c
                                                     .ConfigureType <MultiTableConverterObject>(tc => tc
                                                                                                .WithConversionFor <TomlString>(conv => conv
                                                                                                                                .ToToml(o => o.ToString())
                                                                                                                                .FromToml(s => MultiTableConverterObject.Parse(s.Value)))));

                    Toml.WriteFile(Toml.Create(), main, tmlCfg);;
                    Toml.WriteFile(Toml.Create(CreateWithUnitItem(2.0, "X")), spec, tmlCfg);

                    var cfg = Config.CreateAs()
                              .MappedToType(() => new Root())
                              .UseTomlConfiguration(tmlCfg)
                              .StoredAs(s =>
                                        s.File(main).AccessedBySource("main", out var _).MergeWith(
                                            s.File(spec).AccessedBySource("spec", out var _)))
                              .Initialize();

                    // Act
                    var val = cfg.Get(c => c.ConvertedItem.UnitItem.Unit);
                    var src = cfg.GetSource(c => c.ConvertedItem.UnitItem.Unit);

                    // Assert
                    val.Should().Be("X");
                    src.Name.Should().Be("spec");
                }
        }
Exemplo n.º 3
0
        public void SetProperty_InSpecializedScopeForConvertedMultiLevelType_WritesItBackToSpecScope()
        {
            using (var main = TestFileName.Create("main", Toml.FileExtension))
                using (var spec = TestFileName.Create("spec", Toml.FileExtension))
                {
                    // Arrange
                    var tmlCfg = TomlSettings.Create(c => c
                                                     .ConfigureType <MultiTableConverterObject>(tc => tc
                                                                                                .WithConversionFor <TomlString>(conv => conv
                                                                                                                                .ToToml(o => o.ToString())
                                                                                                                                .FromToml(s => MultiTableConverterObject.Parse(s.Value)))));

                    Toml.WriteFile(Toml.Create(), main, tmlCfg);;
                    Toml.WriteFile(Toml.Create(CreateWithUnitItem(2.0, "X")), spec, tmlCfg);

                    var cfg = Config.CreateAs()
                              .MappedToType(() => new Root())
                              .UseTomlConfiguration(tmlCfg)
                              .StoredAs(s => s
                                        .File(main).MergeWith(
                                            s.File(spec)))
                              .Initialize();

                    // Act
                    cfg.Set(c => c.ConvertedItem.UnitItem.Unit, "EX");


                    // Assert
                    var root = Toml.ReadFile <Root>(spec, tmlCfg);
                    root.ConvertedItem.UnitItem.Unit.Should().Be("EX");
                }
        }