示例#1
0
文件: InitTests.cs 项目: zanedp/Nett
        public void SaveSetting_WhenMovedBetweenConfigScopes_SavesThatSettingCorrectly()
        {
            using (var scenario = GitScenario.Setup(nameof(SaveSetting_WhenMovedBetweenConfigScopes_SavesThatSettingCorrectly)))
            {
                // Arrange
                var cfg = scenario.CreateMergedFromDefaults();

                // Act
                cfg.Set(c => c.Core.AutoClrf, true, scenario.UserSource);

                // Assert
                File.ReadAllText(scenario.UserFile).Should().Be("\r\n[User]\r\nName = \"Test User\"\r\nEMail = \"[email protected]\"\r\n\r\n[Core]\r\nAutoClrf = true\r\n");
            }
        }
示例#2
0
        public void ClearSetting_WhenNoTargetSpecifiedAndRepoIsSource_NewSourceWillBeUserFile()
        {
            using (var scenario = GitScenario.Setup(nameof(ClearSetting_WhenNoTargetSpecifiedAndRepoIsSource_NewSourceWillBeUserFile))
                                  .UseSystemDefaultContentForeachSource())
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();

                // Act
                bool r = config.Clear(c => c.Core.Symlinks);

                r.Should().Be(true);
                config.GetSource(c => c.Core.Symlinks).Should().Be(scenario.UserSource);
            }
        }
示例#3
0
        public void ClearSetting_WhenSourceSpecifiedButSettingDoesnExist_NothingHappens()
        {
            using (var scenario = GitScenario.Setup(nameof(ClearSetting_WhenSourceSpecifiedButSettingDoesnExist_NothingHappens))
                                  .UseSystemDefaultContentForeachSource())
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();
                config.Clear(c => c.Core.Symlinks, scenario.UserSource);

                // Act
                var r = config.Clear(c => c.Core.Symlinks, scenario.UserSource);

                // Assert
                r.Should().Be(false);
            }
        }
示例#4
0
        public void ClearSetting_WhenNoTargetSpecifiedAndRepoIsSystem_NewSourceWillBeNull()
        {
            using (var scenario = GitScenario.Setup(nameof(ClearSetting_WhenNoTargetSpecifiedAndRepoIsSystem_NewSourceWillBeNull))
                                  .UseSystemDefaultContentForeachSource())
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();
                config.Clear(c => c.Core.Symlinks); // removes it from repo source
                config.Clear(c => c.Core.Symlinks); // removes it from user source

                // Act
                var r = config.Clear(c => c.Core.Symlinks); // removes it completely

                r.Should().Be(true);
                config.GetSource(c => c.Core.Symlinks).Should().Be(null);
            }
        }
示例#5
0
        public void Merge_WhenUsingGitScenario_MergesConfigCorrectly()
        {
            using (var s = GitScenario.Setup(nameof(Merge_WhenUsingGitScenario_MergesConfigCorrectly)))
            {
                // Act
                var cfg = Config.CreateAs()
                          .MappedToType(() => new GitScenario.GitConfig())
                          .StoredAs(store =>
                                    store.File(s.SystemFile).MergeWith(
                                        store.File(s.UserFile).MergeWith(
                                            store.File(s.RepoFile))))
                          .Initialize();

                // Assert
                var x = cfg.Unmanaged();
                Assert.True(cfg.Unmanaged().Equals(GitScenario.MergedDefault));
            }
        }
示例#6
0
        public void GetSettingSource_ReturnsCorrectSource()
        {
            using (var scenario = GitScenario.Setup(nameof(GetSettingSource_ReturnsCorrectSource)))
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();

                // Act
                var s0 = config.GetSource(c => c.Core.Symlinks);
                var s1 = config.GetSource(c => c.User.EMail);
                var s2 = config.GetSource(c => c.Core.IgnoreCase);

                // Assert
                s0.Should().BeSameAs(scenario.SystemSource);
                s1.Should().BeSameAs(scenario.UserSource);
                s2.Should().BeSameAs(scenario.RepoSource);
            }
        }
示例#7
0
        public void SaveMergeConfig_WhenHelpFormatInGitScenarioIsChanged_ValueGetSavedBackToSytemWideFileBecauseItOriginateFromThere()
        {
            using (var scenario = GitScenario.Setup(nameof(SaveMergeConfig_WhenHelpFormatInGitScenarioIsChanged_ValueGetSavedBackToSytemWideFileBecauseItOriginateFromThere)))
            {
                // Arrange
                var updated = GitScenario.GitConfig.HelpConfig.HelpFormat.Info;
                var cfg     = scenario.CreateMergedFromDefaults();

                // Act
                cfg.Set(c => c.Core.Help.Format, updated);

                // Assert
                var tbl = Toml.ReadFile(scenario.SystemFile);
                tbl.Get <TomlTable>("Core")
                .Get <TomlTable>("Help")
                .Get <GitScenario.GitConfig.HelpConfig.HelpFormat>("Format").Should().Be(updated);
            }
        }
示例#8
0
        public void ClearSetting_WhenSourceSpecifiedAndSettingExists_SettingIsClearedFromThatSource()
        {
            using (var scenario = GitScenario.Setup(nameof(ClearSetting_WhenSourceSpecifiedAndSettingExists_SettingIsClearedFromThatSource))
                                  .UseSystemDefaultContentForeachSource())
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();
                var tbl    = (TomlTable)Toml.ReadFile(scenario.UserFile)["Core"];
                tbl.ContainsKey(nameof(GitScenario.GitConfig.CoreConfig.Symlinks)).Should().Be(true);

                // Act
                var r = config.Clear(c => c.Core.Symlinks, scenario.UserSource);

                // Assert
                r.Should().Be(true);
                tbl = (TomlTable)Toml.ReadFile(scenario.UserFile)["Core"];
                tbl.ContainsKey(nameof(GitScenario.GitConfig.CoreConfig.Symlinks)).Should().Be(false);
            }
        }
示例#9
0
        public void ClearSetting_WhenNoTargetSpecifiedSourceIsNull_NothingWillHappen()
        {
            using (var scenario = GitScenario.Setup(nameof(ClearSetting_WhenNoTargetSpecifiedSourceIsNull_NothingWillHappen))
                                  .UseSystemDefaultContentForeachSource())
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();
                config.Clear(c => c.Core.Symlinks); // removes it from repo source
                config.Clear(c => c.Core.Symlinks); // removes it from user source
                config.Clear(c => c.Core.Symlinks); // removes it completely

                // Act
                var r = config.Clear(c => c.Core.Symlinks); // nothing happens

                // Assert
                r.Should().Be(false);
                config.GetSource(c => c.Core.Symlinks).Should().Be(null);
            }
        }
示例#10
0
        public void SetSource_WhenExplitSourceSpecified_SettingGetsSavedToThatSource()
        {
            using (var scenario = GitScenario.Setup(nameof(SetSource_WhenExplitSourceSpecified_SettingGetsSavedToThatSource)))
            {
                // Arrange
                var config = scenario.CreateMergedFromDefaults();
                var oldVal = config.Get(c => c.Core.Symlinks);
                var newVal = !oldVal;

                // Act
                config.Set(c => c.Core.Symlinks, newVal, scenario.RepoSource);

                // Assert
                var repoContent = Toml.ReadFile <GitScenario.GitConfig>(scenario.RepoFile);
                repoContent.Core.Symlinks.Should().Be(newVal, "because as scope repo file was specified the value in that file needs to change");

                var sysContent = Toml.ReadFile <GitScenario.GitConfig>(scenario.SystemFile);
                sysContent.Core.Symlinks.Should().Be(oldVal, "because the setting in the not used scope should not change");
            }
        }