예제 #1
0
        public void UseTransaction_OnlyOneTransactionAllowed()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_OnlyOneTransactionAllowed)))
            {
                // Arrange
                var cfg = scenario.CreateConfig();
                cfg.StartTransaction();

                // Act
                Action a = () => cfg.StartTransaction();

                // Assert
                a.ShouldThrow <InvalidOperationException>().WithMessage("*transaction*");
            }
        }
예제 #2
0
파일: InitTests.cs 프로젝트: zanedp/Nett
        public void SaveSetting_WhenItDoesNotExistYetInConfigFile_GetsCreatedAndSaved()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(SaveSetting_WhenItDoesNotExistYetInConfigFile_GetsCreatedAndSaved)))
            {
                // Arrange
                var cfg = Config.CreateAs()
                          .MappedToType(() => new SingleConfigFileScenario.ConfigContent())
                          .StoredAs(store => store.File(scenario.File))
                          .Initialize();

                // Act
                cfg.Set(c => c.Sub.Z, 1);

                // Assert
                File.ReadAllText(scenario.File).Should().Be("X = 1\r\nY = \"Y\"\r\n\r\n[Sub]\r\nZ = 1\r\n");
            }
        }
예제 #3
0
파일: InitTests.cs 프로젝트: zanedp/Nett
        public void SaveSetting_WhenItDoesNotExistYetInConfigFileAndTargetExplicitelySpecified_GetsCreatedAndSaved()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(SaveSetting_WhenItDoesNotExistYetInConfigFileAndTargetExplicitelySpecified_GetsCreatedAndSaved)))
            {
                // Arrange
                IConfigSource src = null;
                var           cfg = Config.CreateAs()
                                    .MappedToType(() => new SingleConfigFileScenario.ConfigContent())
                                    .StoredAs(store => store.File(scenario.File).AccessedBySource("main", out src))
                                    .Initialize();

                // Act
                cfg.Set(c => c.Sub.Z, 1, src);

                // Assert
                File.ReadAllText(scenario.File).Should().Be("X = 1\r\nY = \"Y\"\r\n\r\n[Sub]\r\nZ = 1\r\n");
            }
        }
예제 #4
0
        public void UseTransaction_ChangesNotSavedUntilTransactionIsDisposed()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_ChangesNotSavedUntilTransactionIsDisposed)))
            {
                // Arrange
                const int ChangedX = 234;
                var       cfg      = scenario.CreateConfig();
                int       original = cfg.Get(c => c.X);
                cfg.StartTransaction();

                // Act
                cfg.Set(c => c.X, 2);
                cfg.Set(c => c.X, 23);
                cfg.Set(c => c.X, ChangedX);

                // Assert
                scenario.ReadFile().X.Should().Be(original);
            }
        }
예제 #5
0
        public void UseTransaction_AfterTransactionIsClosed_SaveWillSaveDirectlyAgain()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_AfterTransactionIsClosed_SaveWillSaveDirectlyAgain)))
            {
                // Arrange
                const int ChangedX = 234;
                var       cfg      = scenario.CreateConfig();
                using (cfg.StartTransaction())
                {
                    cfg.Set(c => c.X, 2);
                    cfg.Set(c => c.X, 23);
                }

                // Act
                cfg.Set(c => c.X, ChangedX);

                // Assert
                scenario.ReadFile().X.Should().Be(ChangedX);
            }
        }
예제 #6
0
        public void UseTransaction_WillApplySettings()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_WillApplySettings)))
            {
                // Arrange
                const int ChangedX = 234;
                var       cfg      = scenario.CreateConfig();

                // Act
                using (cfg.StartTransaction())
                {
                    cfg.Set(c => c.X, 2);
                    cfg.Set(c => c.X, 23);
                    cfg.Set(c => c.X, ChangedX);
                }

                // Assert
                scenario.ReadFile().X.Should().Be(ChangedX);
            }
        }
예제 #7
0
        public void UseTransaction_ExternalChangesAreLoaded()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_ExternalChangesAreLoaded)))
            {
                // Arrange
                var cfg = scenario.CreateConfig();
                cfg.StartTransaction();
                int       originalValue = cfg.Get(c => c.X);
                const int newValue      = 123;
                Toml.WriteFile(new SingleConfigFileScenario.ConfigContent()
                {
                    X = newValue
                }, scenario.File);

                // Act
                var v = cfg.Get(c => c.X);

                // Assert
                v.Should().Be(originalValue);
            }
        }
예제 #8
0
        public void UseTransaction_ExternalChangesNotIncorporatedAndSavedBack()
        {
            using (var scenario = SingleConfigFileScenario.Setup(nameof(UseTransaction_ExternalChangesAreLoaded)))
            {
                // Arrange
                var          cfg       = scenario.CreateConfig();
                var          trans     = cfg.StartTransaction();
                const int    newXValue = 123;
                const string newYValue = "New Y";
                Toml.WriteFile(new SingleConfigFileScenario.ConfigContent()
                {
                    X = newXValue
                }, scenario.File);

                // Act
                cfg.Set(c => c.Y, newYValue);
                Action a = () => trans.Dispose();

                // Assert
                a.ShouldThrow <InvalidOperationException>().WithMessage("*externally*");
            }
        }