Esempio n. 1
0
        public void TestNonExistingFile()
        {
            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("directory.first", @"c:\program files\gitextensions\gitextensions.exe");
                configFile.Save();
            }

            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"c:/program files/gitextensions/gitextensions.exe", configFile.GetValue("directory.first"));
            }
        }
Esempio n. 2
0
        public void TestWithDirectories()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Encoding.UTF8);
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("directory.first", @"c:\program files\gitextensions\gitextensions.exe");
                configFile.Save();
            }

            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"c:/program files/gitextensions/gitextensions.exe", configFile.GetValue("directory.first"));
            }
        }
Esempio n. 3
0
        public void RandomTestCase1()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[mergetool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");
                content.AppendLine("[user]");
                content.AppendLine("	name = Sergey Pustovit");
                content.AppendLine("	email = [email protected]");
                content.AppendLine("[core]");
                content.AppendLine("	safecrlf = false");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[diff]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[difftool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("Sergey Pustovit", configFile.GetValue("user.name"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("user.name", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("user.name"));
            }
        }
Esempio n. 4
0
        public void TestWithHiddenFile()
        {
            { //TESTDATA
                //Write test config
                File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), Encoding.UTF8);

                //Make sure it is hidden
                FileInfo configFile = new FileInfo(GetConfigFileName());
                configFile.Attributes = FileAttributes.Hidden;
            }

            { //PERFORM TEST
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("value1", configFile.GetValue("section1.key1"));
                Assert.AreEqual("value2", configFile.GetValue("section2.subsection.key2"));
                Assert.AreEqual("value3", configFile.GetValue("section3.subsection.key3"));

                configFile.SetValue("section1.key1", "newvalue1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue1", configFile.GetValue("section1.key1"));
            }
        }
Esempio n. 5
0
        public void TestWithSectionWithDot2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[submodule.test.test]");
                content.AppendLine("path = test.test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("test.test", configFile.GetValue("submodule.test.test.path"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("submodule.test.test.path", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("submodule.test.test.path"));
            }
        }
Esempio n. 6
0
        public void RandomTestCase2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[core]");
                content.AppendLine("	repositoryformatversion = 0");
                content.AppendLine("	filemode = false");
                content.AppendLine("	bare = false");
                content.AppendLine("	logallrefupdates = true");
                content.AppendLine("	symlinks = false");
                content.AppendLine("	ignorecase = true");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[remote \"origin\"]");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/origin/*");
                content.AppendLine("	url = [email protected]:SDWH_Project_01.git");
                content.AppendLine("	puttykeyfile = C:\\Users\\sergiy.pustovit\\spustovit_sintez_key_1.ppk");
                content.AppendLine("[branch \"master\"]");
                content.AppendLine("	remote = origin");
                content.AppendLine("	merge = refs/heads/master");
                content.AppendLine("[gui]");
                content.AppendLine("	geometry = 917x503+25+25 201 191");
                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[remote \"test\"]");
                content.AppendLine("	url = [email protected]:project1.git");
                content.AppendLine("	fetch = +refs/heads/*:refs/remotes/test/*");
                content.AppendLine("	puttykeyfile = C:/Users/sergiy.pustovit/spustovit_sintez_key_1.ppk");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("0", configFile.GetValue("core.repositoryformatversion"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("core.repositoryformatversion", "1");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("1", configFile.GetValue("core.repositoryformatversion"));
            }
        }
Esempio n. 7
0
        public void UncPathTest2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine(@"[path]");
                content.AppendLine(@"	unc = \\\\test\\"); //<- escaped value in config file

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\", configFile.GetValue("path.unc"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("path.unc", @"\\test\test2\");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\test2\", configFile.GetValue("path.unc"));
            }
        }
Esempio n. 8
0
        public void SpacesInSubSectionTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test", configFile.GetValue("section.sub section.test"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test2", configFile.GetValue("section.sub section.test"));
            }
        }
Esempio n. 9
0
 private static void SetGlobalDiffToolToConfig(ConfigFile configFile, string diffTool)
 {
     if (GitCommands.GitCommands.VersionInUse.GuiDiffToolExist)
         configFile.SetValue("diff.guitool", diffTool);
     else
         configFile.SetValue("diff.tool", diffTool);
 }