Exemple #1
0
        public void Should_return_default_value(PropertyInfo property, object value, object defaultValue, bool isSetting)
        {
            // Arrange
            object root = null;

            if (isSetting)
            {
                root = property.GetValue(null);

                property = property.PropertyType
                           .GetProperty(nameof(ISetting <string> .Value));
            }

            using TempFileCollection tempFiles = new();
            string filePath = tempFiles.AddExtension(".settings");

            tempFiles.AddFile(filePath + ".backup", keepFile: false);

            File.WriteAllText(filePath, SettingsFileContent);

            using GitExtSettingsCache cache = GitExtSettingsCache.Create(filePath);
            RepoDistSettings container   = new(null, cache, SettingLevel.Unknown);
            object           storedValue = null;

            // Act
            AppSettings.UsingContainer(container, () =>
            {
                storedValue = property.GetValue(root);
            });

            // Assert
            Assert.That(storedValue, Is.EqualTo(defaultValue));
        }
Exemple #2
0
        static AppSettings()
        {
            ApplicationDataPath = new Lazy <string>(() =>
            {
                if (IsPortable())
                {
                    return(GetGitExtensionsDirectory());
                }
                else
                {
                    //Make applicationdatapath version independent
                    return(Application.UserAppDataPath.Replace(Application.ProductVersion, string.Empty));
                }
            }
                                                    );

            _SettingsContainer = new RepoDistSettings(null, GitExtSettingsCache.FromCache(SettingsFilePath));

            GitLog = new CommandLogger();

            if (!File.Exists(SettingsFilePath))
            {
                ImportFromRegistry();
            }
        }
        public void Should_return_default_value(PropertyInfo property, object value, object defaultValue, bool isSetting)
        {
            // Arrange
            object root = null;

            if (isSetting)
            {
                root = property.GetValue(null);

                property = property.PropertyType
                           .GetProperty(nameof(ISetting <string> .Value));
            }

            var filePath = Path.GetTempFileName();

            File.WriteAllText(filePath, SettingsFileContent);

            var    container   = new RepoDistSettings(null, GitExtSettingsCache.Create(filePath), SettingLevel.Unknown);
            object storedValue = null;

            // Act
            AppSettings.UsingContainer(container, () =>
            {
                storedValue = property.GetValue(root);
            });

            // Assert
            Assert.That(storedValue, Is.EqualTo(defaultValue));
        }
Exemple #4
0
        public void Should_save_value(PropertyInfo property, object value, object defaultValue, bool isSetting)
        {
            // Arrange
            object root = null;

            if (isSetting)
            {
                root = property.GetValue(null);

                property = property.PropertyType
                           .GetProperty(nameof(ISetting <string> .Value));
            }

            using TempFileCollection tempFiles = new();
            string filePath = tempFiles.AddExtension(".settings");

            tempFiles.AddFile(filePath + ".backup", keepFile: false);

            File.WriteAllText(filePath, SettingsFileContent);

            using GitExtSettingsCache cache = GitExtSettingsCache.Create(filePath);
            RepoDistSettings container   = new(null, cache, SettingLevel.Unknown);
            object           storedValue = null;

            // Act
            AppSettings.UsingContainer(container, () =>
            {
                property.SetValue(root, value);

                storedValue = property.GetValue(root);
            });

            // Assert
            if (Type.GetTypeCode(property.PropertyType) == TypeCode.String)
            {
                if (isSetting)
                {
                    Assert.That(storedValue, Is.EqualTo(value ?? string.Empty));
                }
                else
                {
                    Assert.That(storedValue, Is.EqualTo(value ?? defaultValue));
                }
            }
            else if (Type.GetTypeCode(property.PropertyType) == TypeCode.DateTime)
            {
                // We keep only the date
                Assert.That(storedValue, Is.EqualTo(((DateTime)value).Date));
            }
            else
            {
                Assert.That(storedValue, Is.EqualTo(value));
            }
        }
Exemple #5
0
        public void Can_load_settings(string fileName, int expected)
        {
            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{fileName}.settings.xml");

            using var testHelper = new GitModuleTestHelper();
            var settingsFile = testHelper.CreateRepoFile(".git", "GitExtensions.settings", content);

            using var settingsCache = new GitExtSettingsCache(settingsFile);
            var settings = new RepoDistSettings(null, settingsCache, SettingLevel.Unknown);

            var definitions = _externalLinksStorage.Load(settings);

            definitions.Count.Should().Be(expected);
        }
        public void SetUp()
        {
            _executable = new MockExecutable();

            // Work around: When running unittest, Application.UserAppDataPath always points to
            // %APPDATA%Roaming\Microsoft Corporation\Microsoft.TestHost.x86
            // We need to correct it to %APPDATA%\GitExtensions\GitExtensions for v3 at least
            var userAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var settingPath     = Path.Combine(userAppDataPath, "GitExtensions\\GitExtensions\\GitExtensions.settings");
            RepoDistSettings settingContainer = new(null, GitExtSettingsCache.FromCache(settingPath), SettingLevel.Unknown);

            _appPath = settingContainer.GetString("gitcommand", "git.exe");

            // Execute process in GitExtension working directory, so that git will return success exit-code
            // git always return non-zero exit code when run git reset outside of git repository
            // NUnit working directory always default to MS test host
            var workingDir = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExecutableExtensionsTests)).Location);

            _gitExecutable = new Executable(_appPath, workingDir);
        }
Exemple #7
0
        static AppSettings()
        {
            ApplicationDataPath = new Lazy <string>(() =>
            {
                if (IsPortable())
                {
                    return(GetGitExtensionsDirectory());
                }
                else
                {
                    //Make applicationdatapath version independent
                    return(Application.UserAppDataPath.Replace(Application.ProductVersion, string.Empty));
                }
            }
                                                    );

            SettingsContainer = new SettingsContainer <RepoDistSettings>(null, GitExtSettingsCache.FromCache(SettingsFilePath));
            Version version = AppVersion;

            GitExtensionsVersionString = version.Major.ToString() + '.' + version.Minor.ToString();
            if (version.Build > 0)
            {
                GitExtensionsVersionString += '.' + version.Build.ToString();
            }
            if (!EnvUtils.RunningOnWindows())
            {
                PathSeparator      = '/';
                PathSeparatorWrong = '\\';
            }

            GitLog = new CommandLogger();

            if (!File.Exists(SettingsFilePath))
            {
                ImportFromRegistry();
            }
        }