Esempio n. 1
0
        public static void Overwrite_XWithYWithSourceOnlyRows_AddsTheRowThatOnlyExistedInYToResultTable()
        {
            // Act
            var r = TomlTable.Combine(op => op.Overwrite(X).With(Y).ForRowsOnlyInSource());

            // Assert
            AssertYOnlyRowWasAddedTo(r);
            AssertSubTableNotTouched(r);
            AssertSameKeyNotTouched(r);
        }
Esempio n. 2
0
        public static void Overwrite_XWithYForAllTargetRows_OverwritesRowsThatExistInTarget()
        {
            // Act
            var r = TomlTable.Combine(op => op.Overwrite(X).With(Y).ForAllTargetRows());

            // Assert
            AssertNoRowWasAdded(r);
            AssertSameKeyRowWasOverwritten(r);
            AssertSubTableRowWasOverwritten(r);
        }
Esempio n. 3
0
        public static void Overwrite_XWithYForAllSourceRows_AddsAndOverwritesXRowsWithYRows()
        {
            // Act
            var r = TomlTable.Combine(op => op.Overwrite(X).With(Y).ForAllSourceRows());

            // Assert
            AssertYOnlyRowWasAddedTo(r);
            AssertSameKeyRowWasOverwritten(r);
            AssertSubTableRowWasOverwritten(r);
        }
Esempio n. 4
0
        public void Overwrite_XWithY_ForDocExampleR3_ProducesCorrectResultTables()
        {
            // Act
            var r1 = TomlTable.Combine(op => op.Overwrite(Dx).With(Dy).ForAllTargetRows());

            // Assert
            r1.Count.Should().Be(2);
            r1.Get <int>("a").Should().Be(1);
            r1.Get <int>("c").Should().Be(4);
        }
Esempio n. 5
0
        public static void Overwrite_XWithYIncludingAllComments_OverwritesCommendsWithSourceComments()
        {
            // Act
            var r = TomlTable.Combine(op => op.Overwrite(Dx)
                                      .With(Dy)
                                      .IncludingAllComments()
                                      .ForAllSourceRows());

            // Assert
            AssertCommentsAre(r["a"], new string[] { });
            AssertCommentsAre(r["b"], "ybc");
            AssertCommentsAre(r["c"], "ycc");
        }
Esempio n. 6
0
        public static void Overwrite_XWithYExcludingComments_KeepsOriginalComments()
        {
            // Act
            var r = TomlTable.Combine(op => op.Overwrite(Dx)
                                      .With(Dy)
                                      .ExcludingComments()
                                      .ForAllSourceRows());

            // Assert
            AssertCommentsAre(r["a"], new string[] { });
            AssertCommentsAre(r["b"], new string[] { }); // Do not copy comment => still empty
            AssertCommentsAre(r["c"], "xcc");
        }
Esempio n. 7
0
        public bool EnsureExists(TomlTable content)
        {
            if (File.Exists(_filePath))
            {
                var table              = Load();
                var newDataTable       = TomlTable.Combine(s => s.Overwrite(table).With(content).IncludingAllComments().ForRowsOnlyInSource());
                var removeOldDataTable = TomlTable.Combine(s => s.Overwrite(content).With(newDataTable).ExcludingComments().ForAllTargetRows());
                Save(removeOldDataTable);
            }
            else
            {
                Save(content);
            }

            return(true);
        }