public void WhenParentAndChildNonDefault_ThenOverlayByReturnsCorrectValues()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var parent = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);
                parent.Value = true;
                Assert.IsFalse(parent.IsDefault);

                var child = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);
                child.Value = true;
                Assert.IsFalse(child.IsDefault);

                var effective = parent.OverlayBy(child);
                Assert.AreNotSame(effective, parent);
                Assert.AreNotSame(effective, child);

                Assert.IsTrue((bool)effective.Value);
                Assert.IsTrue((bool)effective.DefaultValue);
                Assert.IsTrue(effective.IsDefault);
            }
        }
        public void WhenValueIsUnparsable_ThenSetValueRaisesFormatException()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                Assert.Throws <FormatException>(() => setting.Value = "maybe");
            }
        }
        public void WhenValueIsOfWrongType_ThenSetValueRaisesInvalidCastException()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                Assert.Throws <InvalidCastException>(() => setting.Value = -1);
            }
        }
示例#4
0
 public static TerminalSettings FromKey(RegistryKey registryKey)
 {
     return(new TerminalSettings()
     {
         IsCopyPasteUsingCtrlCAndCtrlVEnabled = RegistryBoolSetting.FromKey(
             "IsCopyPasteUsingCtrlCAndCtrlVEnabled",
             "IsCopyPasteUsingCtrlCAndCtrlVEnabled",
             null,
             null,
             true,
             registryKey),
         IsSelectAllUsingCtrlAEnabled = RegistryBoolSetting.FromKey(
             "IsSelectAllUsingCtrlAEnabled",
             "IsSelectAllUsingCtrlAEnabled",
             null,
             null,
             false,
             registryKey),
         IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled = RegistryBoolSetting.FromKey(
             "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled",
             "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled",
             null,
             null,
             true,
             registryKey),
         IsSelectUsingShiftArrrowEnabled = RegistryBoolSetting.FromKey(
             "IsSelectUsingShiftArrrowEnabled",
             "IsSelectUsingShiftArrrowEnabled",
             null,
             null,
             true,
             registryKey),
         IsQuoteConvertionOnPasteEnabled = RegistryBoolSetting.FromKey(
             "IsQuoteConvertionOnPasteEnabled",
             "IsQuoteConvertionOnPasteEnabled",
             null,
             null,
             true,
             registryKey),
         IsNavigationUsingControlArrrowEnabled = RegistryBoolSetting.FromKey(
             "IsNavigationUsingControlArrrowEnabled",
             "IsNavigationUsingControlArrrowEnabled",
             null,
             null,
             true,
             registryKey),
     });
 }
        public void WhenValueIsString_ThenSetValueParsesValue()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                setting.Value = "TRUE";

                Assert.AreEqual(true, setting.Value);
            }
        }
        public void WhenParentIsNonDefaultAndChildSetToOriginalDefault_ThenIsDefaultReturnsFalse()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var parent = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);
                parent.Value = true;
                Assert.IsFalse(parent.IsDefault);

                var intermediate = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);
                Assert.IsTrue(intermediate.IsDefault);

                var child = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                var effective = parent
                                .OverlayBy(intermediate)
                                .OverlayBy(child);
                Assert.AreNotSame(effective, parent);
                Assert.AreNotSame(effective, intermediate);
                Assert.AreNotSame(effective, child);

                effective.Value = false;

                Assert.IsFalse((bool)effective.Value);
                Assert.IsTrue((bool)effective.DefaultValue);
                Assert.IsFalse(effective.IsDefault);
            }
        }
        public void WhenValueDiffersFromDefault_ThenSetValueSucceedsAndSettingIsDirty()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                setting.Value = true;

                Assert.IsFalse(setting.IsDefault);
                Assert.IsTrue(setting.IsDirty);
            }
        }
        public void WhenSettingIsNonNull_ThenSaveUpdatesRegistry()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                setting.Value = true;
                setting.Save(key);

                Assert.AreEqual(1, key.GetValue("test"));
            }
        }
        public void WhenValueIsNull_ThenSetValueResetsToDefault()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                setting.Value = true;
                setting.Value = null;

                Assert.AreEqual(false, setting.Value);
                Assert.IsTrue(setting.IsDefault);
            }
        }
        public void WhenSettingIsNull_ThenSaveResetsRegistry()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                key.SetValue("test", 1, RegistryValueKind.DWord);

                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                setting.Value = null;
                setting.Save(key);

                Assert.IsNull(key.GetValue("test"));
            }
        }
        public void WhenRegistryValueDoesNotExist_ThenFromKeyUsesDefaults()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    true,
                    key);

                Assert.AreEqual("test", setting.Key);
                Assert.AreEqual("title", setting.Title);
                Assert.AreEqual("description", setting.Description);
                Assert.AreEqual("category", setting.Category);
                Assert.IsTrue((bool)setting.Value);
                Assert.IsTrue(setting.IsDefault);
                Assert.IsFalse(setting.IsDirty);
            }
        }
 public static SshSettings FromKey(RegistryKey registryKey)
 {
     return(new SshSettings()
     {
         IsPropagateLocaleEnabled = RegistryBoolSetting.FromKey(
             "IsPropagateLocaleEnabled",
             "IsPropagateLocaleEnabled",
             null,
             null,
             true,
             registryKey),
         PublicKeyValidity = RegistryDwordSetting.FromKey(
             "PublicKeyValidity",
             "PublicKeyValidity",
             "Validity of (OS Login/Metadata) keys in seconds",
             null,
             (int)TimeSpan.FromDays(30).TotalSeconds,
             registryKey,
             (int)TimeSpan.FromMinutes(1).TotalSeconds,
             int.MaxValue)
     });
 }
        public void WhenRegistryValueExists_ThenFromKeyUsesValue()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                key.SetValue("test", 1, RegistryValueKind.DWord);

                var setting = RegistryBoolSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    false,
                    key);

                Assert.AreEqual("test", setting.Key);
                Assert.AreEqual("title", setting.Title);
                Assert.AreEqual("description", setting.Description);
                Assert.AreEqual("category", setting.Category);
                Assert.IsTrue((bool)setting.Value);
                Assert.IsFalse(setting.IsDefault);
                Assert.IsFalse(setting.IsDirty);
            }
        }
 public static ApplicationSettings FromKey(RegistryKey registryKey)
 {
     return(new ApplicationSettings()
     {
         IsMainWindowMaximized = RegistryBoolSetting.FromKey(
             "IsMainWindowMaximized",
             "IsMainWindowMaximized",
             null,
             null,
             false,
             registryKey),
         MainWindowHeight = RegistryDwordSetting.FromKey(
             "MainWindowHeight",
             "MainWindowHeight",
             null,
             null,
             0,
             registryKey,
             0,
             ushort.MaxValue),
         MainWindowWidth = RegistryDwordSetting.FromKey(
             "WindowWidth",
             "WindowWidth",
             null,
             null,
             0,
             registryKey,
             0,
             ushort.MaxValue),
         IsUpdateCheckEnabled = RegistryBoolSetting.FromKey(
             "IsUpdateCheckEnabled",
             "IsUpdateCheckEnabled",
             null,
             null,
             true,
             registryKey),
         LastUpdateCheck = RegistryQwordSetting.FromKey(
             "LastUpdateCheck",
             "LastUpdateCheck",
             null,
             null,
             0,
             registryKey,
             0,
             long.MaxValue),
         IsPreviewFeatureSetEnabled = RegistryBoolSetting.FromKey(
             "IsPreviewFeatureSetEnabled",
             "IsPreviewFeatureSetEnabled",
             null,
             null,
             false,
             registryKey),
         ProxyUrl = RegistryStringSetting.FromKey(
             "ProxyUrl",
             "ProxyUrl",
             null,
             null,
             null,
             registryKey,
             url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)),
     });
 public static ApplicationSettings FromKey(RegistryKey registryKey)
 {
     return(new ApplicationSettings()
     {
         IsMainWindowMaximized = RegistryBoolSetting.FromKey(
             "IsMainWindowMaximized",
             "IsMainWindowMaximized",
             null,
             null,
             false,
             registryKey),
         MainWindowHeight = RegistryDwordSetting.FromKey(
             "MainWindowHeight",
             "MainWindowHeight",
             null,
             null,
             0,
             registryKey,
             0,
             ushort.MaxValue),
         MainWindowWidth = RegistryDwordSetting.FromKey(
             "WindowWidth",
             "WindowWidth",
             null,
             null,
             0,
             registryKey,
             0,
             ushort.MaxValue),
         IsUpdateCheckEnabled = RegistryBoolSetting.FromKey(
             "IsUpdateCheckEnabled",
             "IsUpdateCheckEnabled",
             null,
             null,
             true,
             registryKey),
         LastUpdateCheck = RegistryQwordSetting.FromKey(
             "LastUpdateCheck",
             "LastUpdateCheck",
             null,
             null,
             0,
             registryKey,
             0,
             long.MaxValue),
         IsPreviewFeatureSetEnabled = RegistryBoolSetting.FromKey(
             "IsPreviewFeatureSetEnabled",
             "IsPreviewFeatureSetEnabled",
             null,
             null,
             false,
             registryKey),
         ProxyUrl = RegistryStringSetting.FromKey(
             "ProxyUrl",
             "ProxyUrl",
             null,
             null,
             null,
             registryKey,
             url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)),
         ProxyPacUrl = RegistryStringSetting.FromKey(
             "ProxyPacUrl",
             "ProxyPacUrl",
             null,
             null,
             null,
             registryKey,
             url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)),
         ProxyUsername = RegistryStringSetting.FromKey(
             "ProxyUsername",
             "ProxyUsername",
             null,
             null,
             null,
             registryKey,
             _ => true),
         ProxyPassword = RegistrySecureStringSetting.FromKey(
             "ProxyPassword",
             "ProxyPassword",
             null,
             null,
             registryKey,
             DataProtectionScope.CurrentUser),
         IsDeviceCertificateAuthenticationEnabled = RegistryBoolSetting.FromKey(
             "IsDeviceCertificateAuthenticationEnabled",
             "IsDeviceCertificateAuthenticationEnabled",
             null,
             null,
             false,
             registryKey),
         FullScreenDevices = RegistryStringSetting.FromKey(
             "FullScreenDevices",
             "FullScreenDevices",
             null,
             null,
             null,
             registryKey,
             _ => true),
         IncludeOperatingSystems = RegistryEnumSetting <OperatingSystems> .FromKey(
             "IncludeOperatingSystems",
             "IncludeOperatingSystems",
             null,
             null,
             OperatingSystems.Windows,
             registryKey)
     });
 public static TerminalSettings FromKey(RegistryKey registryKey)
 {
     return(new TerminalSettings()
     {
         IsCopyPasteUsingCtrlCAndCtrlVEnabled = RegistryBoolSetting.FromKey(
             "IsCopyPasteUsingCtrlCAndCtrlVEnabled",
             "IsCopyPasteUsingCtrlCAndCtrlVEnabled",
             null,
             null,
             true,
             registryKey),
         IsSelectAllUsingCtrlAEnabled = RegistryBoolSetting.FromKey(
             "IsSelectAllUsingCtrlAEnabled",
             "IsSelectAllUsingCtrlAEnabled",
             null,
             null,
             false,
             registryKey),
         IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled = RegistryBoolSetting.FromKey(
             "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled",
             "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled",
             null,
             null,
             true,
             registryKey),
         IsSelectUsingShiftArrrowEnabled = RegistryBoolSetting.FromKey(
             "IsSelectUsingShiftArrrowEnabled",
             "IsSelectUsingShiftArrrowEnabled",
             null,
             null,
             true,
             registryKey),
         IsQuoteConvertionOnPasteEnabled = RegistryBoolSetting.FromKey(
             "IsQuoteConvertionOnPasteEnabled",
             "IsQuoteConvertionOnPasteEnabled",
             null,
             null,
             true,
             registryKey),
         IsNavigationUsingControlArrrowEnabled = RegistryBoolSetting.FromKey(
             "IsNavigationUsingControlArrrowEnabled",
             "IsNavigationUsingControlArrrowEnabled",
             null,
             null,
             true,
             registryKey),
         IsScrollingUsingCtrlUpDownEnabled = RegistryBoolSetting.FromKey(
             "IsScrollingUsingCtrlUpDownEnabled",
             "IsScrollingUsingCtrlUpDownEnabled",
             null,
             null,
             true,
             registryKey),
         IsScrollingUsingCtrlHomeEndEnabled = RegistryBoolSetting.FromKey(
             "IsScrollingUsingCtrlHomeEndEnabled",
             "IsScrollingUsingCtrlHomeEndEnabled",
             null,
             null,
             true,
             registryKey),
         FontFamily = RegistryStringSetting.FromKey(
             "FontFamily",
             "FontFamily",
             null,
             null,
             TerminalFont.DefaultFontFamily,
             registryKey,
             f => f == null || TerminalFont.IsValidFont(f)),
         FontSizeAsDword = RegistryDwordSetting.FromKey(
             "FontSize",
             "FontSize",
             null,
             null,
             DwordFromFontSize(TerminalFont.DefaultSize),
             registryKey,
             DwordFromFontSize(TerminalFont.MinimumSize),
             DwordFromFontSize(TerminalFont.MaximumSize))
     });
 }