public void WhenParentAndChildNonDefault_ThenOverlayByReturnsCorrectValues() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var parent = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Black, key); parent.Value = ConsoleColor.Red; Assert.IsFalse(parent.IsDefault); var child = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Black, key); child.Value = ConsoleColor.Green; Assert.IsFalse(child.IsDefault); var effective = parent.OverlayBy(child); Assert.AreNotSame(effective, parent); Assert.AreNotSame(effective, child); Assert.AreEqual(ConsoleColor.Green, effective.Value); Assert.AreEqual(ConsoleColor.Red, effective.DefaultValue); Assert.IsFalse(effective.IsDefault); } }
public void WhenRegistryValueExists_ThenFromKeyUsesValue() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { key.SetValue( "test", (int)(Toppings.Cheese | Toppings.Chocolate), RegistryValueKind.DWord); var setting = RegistryEnumSetting <Toppings> .FromKey( "test", "title", "description", "category", Toppings.None, key); Assert.AreEqual("test", setting.Key); Assert.AreEqual("title", setting.Title); Assert.AreEqual("description", setting.Description); Assert.AreEqual("category", setting.Category); Assert.AreEqual(Toppings.Cheese | Toppings.Chocolate, setting.Value); Assert.IsFalse(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
public void WhenValueIsOfWrongType_ThenSetValueRaisesInvalidCastException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); Assert.Throws <InvalidCastException>(() => setting.Value = false); } }
public void WhenValueIsInvalid_ThenSetValueRaisesArgumentOutOfRangeException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); Assert.Throws <ArgumentOutOfRangeException>(() => setting.Value = (ConsoleColor)100); } }
public void WhenValueIsUnparsable_ThenSetValueRaisesFormatException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); Assert.Throws <FormatException>(() => setting.Value = ""); } }
public void WhenParentIsNonDefaultAndChildSetToOriginalDefault_ThenIsDefaultReturnsFalse() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var parent = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Black, key); parent.Value = ConsoleColor.Red; Assert.IsFalse(parent.IsDefault); var intermediate = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Black, key); Assert.IsTrue(intermediate.IsDefault); var child = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Black, key); var effective = parent .OverlayBy(intermediate) .OverlayBy(child); Assert.AreNotSame(effective, parent); Assert.AreNotSame(effective, intermediate); Assert.AreNotSame(effective, child); effective.Value = ConsoleColor.Black; Assert.AreEqual(ConsoleColor.Black, effective.Value); Assert.AreEqual(ConsoleColor.Red, effective.DefaultValue); Assert.IsFalse(effective.IsDefault); } }
public void WhenValueDiffersFromDefault_ThenSetValueSucceedsAndSettingIsDirty() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); setting.Value = ConsoleColor.Yellow; Assert.IsFalse(setting.IsDefault); Assert.IsTrue(setting.IsDirty); } }
public void WhenSettingIsNonNull_ThenSaveUpdatesRegistry() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); setting.Value = ConsoleColor.Green; setting.Save(key); Assert.AreEqual((int)ConsoleColor.Green, key.GetValue("test")); } }
public void WhenValueEqualsDefault_ThenSetValueSucceedsAndSettingIsNotDirty() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <Toppings> .FromKey( "test", "title", "description", "category", Toppings.None, key); setting.Value = Toppings.None; Assert.IsTrue(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
public void WhenSettingIsNonNull_ThenSaveUpdatesRegistry() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <Toppings> .FromKey( "test", "title", "description", "category", Toppings.None, key); setting.Value = Toppings.Cream | Toppings.Chocolate; setting.Save(key); Assert.AreEqual((int)(Toppings.Cream | Toppings.Chocolate), key.GetValue("test")); } }
public static ToolWindowStateSettings FromKey( string windowName, DockState defaultState, RegistryKey registryKey) { Debug.Assert(!windowName.Contains(' ')); return(new ToolWindowStateSettings() { DockState = RegistryEnumSetting <DockState> .FromKey( windowName, null, null, null, defaultState, registryKey) }); }
public void WhenValueIsNumericString_ThenSetValueSucceeds() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); setting.Value = ((int)ConsoleColor.Yellow).ToString(); Assert.AreEqual(ConsoleColor.Yellow, setting.Value); Assert.IsFalse(setting.IsDefault); Assert.IsTrue(setting.IsDirty); } }
public void WhenValueIsNumericString_ThenSetValueSucceeds() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <Toppings> .FromKey( "test", "title", "description", "category", Toppings.None, key); setting.Value = ((int)Toppings.Cream).ToString(); Assert.AreEqual(Toppings.Cream, setting.Value); Assert.IsFalse(setting.IsDefault); Assert.IsTrue(setting.IsDirty); } }
public void WhenValueIsNull_ThenSetValueResetsToDefault() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); setting.Value = ConsoleColor.Blue; setting.Value = null; Assert.AreEqual(ConsoleColor.Blue, setting.Value); Assert.IsTrue(setting.IsDefault); } }
public void WhenSettingIsNull_ThenSaveResetsRegistry() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { key.SetValue("test", (int)ConsoleColor.Red, RegistryValueKind.DWord); var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, 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 = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); Assert.AreEqual("test", setting.Key); Assert.AreEqual("title", setting.Title); Assert.AreEqual("description", setting.Description); Assert.AreEqual("category", setting.Category); Assert.AreEqual(ConsoleColor.Blue, setting.Value); Assert.IsTrue(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
public void WhenRegistryKeyIsNull_ThenFromKeyUsesDefaults() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryEnumSetting <Toppings> .FromKey( "test", "title", "description", "category", Toppings.None, null); Assert.AreEqual("test", setting.Key); Assert.AreEqual("title", setting.Title); Assert.AreEqual("description", setting.Description); Assert.AreEqual("category", setting.Category); Assert.AreEqual(Toppings.None, setting.Value); Assert.IsTrue(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
public void WhenRegistryValueExists_ThenFromKeyUsesValue() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { key.SetValue("test", (int)ConsoleColor.Red, RegistryValueKind.DWord); var setting = RegistryEnumSetting <ConsoleColor> .FromKey( "test", "title", "description", "category", ConsoleColor.Blue, key); Assert.AreEqual("test", setting.Key); Assert.AreEqual("title", setting.Title); Assert.AreEqual("description", setting.Description); Assert.AreEqual("category", setting.Category); Assert.AreEqual(ConsoleColor.Red, setting.Value); Assert.IsFalse(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
protected void InitializeFromKey(RegistryKey key) { // // RDP Settings. // this.RdpUsername = RegistryStringSetting.FromKey( "Username", "Username", "Windows logon username", Categories.RdpCredentials, null, key, _ => true); this.RdpPassword = RegistrySecureStringSetting.FromKey( "Password", "Password", "Windows logon password", Categories.RdpCredentials, key, DataProtectionScope.CurrentUser); this.RdpDomain = RegistryStringSetting.FromKey( "Domain", "Domain", "Windows logon domain", Categories.RdpCredentials, null, key, _ => true); this.RdpConnectionBar = RegistryEnumSetting <RdpConnectionBarState> .FromKey( "ConnectionBar", "Show connection bar", "Show connection bar in full-screen mode", Categories.RdpDisplay, RdpConnectionBarState._Default, key); this.RdpDesktopSize = RegistryEnumSetting <RdpDesktopSize> .FromKey( "DesktopSize", "Desktop size", "Size of remote desktop", Categories.RdpDisplay, ConnectionSettings.RdpDesktopSize._Default, key); this.RdpAuthenticationLevel = RegistryEnumSetting <RdpAuthenticationLevel> .FromKey( "AuthenticationLevel", "Server authentication", "Require server authentication when connecting", Categories.RdpConnection, ConnectionSettings.RdpAuthenticationLevel._Default, key); this.RdpColorDepth = RegistryEnumSetting <RdpColorDepth> .FromKey( "ColorDepth", "Color depth", "Color depth of remote desktop", Categories.RdpDisplay, ConnectionSettings.RdpColorDepth._Default, key); this.RdpAudioMode = RegistryEnumSetting <RdpAudioMode> .FromKey( "AudioMode", "Audio mode", "Redirect audio when playing on server", Categories.RdpResources, ConnectionSettings.RdpAudioMode._Default, key); this.RdpRedirectClipboard = RegistryEnumSetting <RdpRedirectClipboard> .FromKey( "RedirectClipboard", "Redirect clipboard", "Allow clipboard contents to be shared with remote desktop", Categories.RdpResources, ConnectionSettings.RdpRedirectClipboard._Default, key); this.RdpUserAuthenticationBehavior = RegistryEnumSetting <RdpUserAuthenticationBehavior> .FromKey( "RdpUserAuthenticationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. ConnectionSettings.RdpUserAuthenticationBehavior._Default, key); this.RdpBitmapPersistence = RegistryEnumSetting <RdpBitmapPersistence> .FromKey( "BitmapPersistence", "Bitmap caching", "Use persistent bitmap cache", Categories.RdpResources, ConnectionSettings.RdpBitmapPersistence._Default, key); this.RdpConnectionTimeout = RegistryDwordSetting.FromKey( "ConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); this.RdpCredentialGenerationBehavior = RegistryEnumSetting <RdpCredentialGenerationBehavior> .FromKey( "CredentialGenerationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. ConnectionSettings.RdpCredentialGenerationBehavior._Default, key); this.RdpPort = RegistryDwordSetting.FromKey( "RdpPort", "Server port", "Server port", Categories.RdpConnection, 3389, key, 1, ushort.MaxValue); // // SSH Settings. // this.SshPort = RegistryDwordSetting.FromKey( "SshPort", "Server port", "Server port", Categories.SshConnection, 22, key, 1, ushort.MaxValue); this.SshUsername = RegistryStringSetting.FromKey( "SshUsername", "Username", "Preferred Linux username (only applicable if OS Login is disabled)", Categories.SshCredentials, null, key, username => string.IsNullOrEmpty(username) || AuthorizedKey.IsValidUsername(username)); this.SshConnectionTimeout = RegistryDwordSetting.FromKey( "SshConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); Debug.Assert(this.Settings.All(s => s != null)); }
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) });
protected void InitializeFromKey(RegistryKey key) { this.Username = RegistryStringSetting.FromKey( "Username", "Username", "Windows logon username", "Credentials", null, key, _ => true); this.Password = RegistrySecureStringSetting.FromKey( "Password", "Password", "Windows logon password", "Credentials", key, DataProtectionScope.CurrentUser); this.Domain = RegistryStringSetting.FromKey( "Domain", "Domain", "Windows logon domain", "Credentials", null, key, _ => true); this.ConnectionBar = RegistryEnumSetting <RdpConnectionBarState> .FromKey( "ConnectionBar", "Show connection bar", "Show connection bar in full-screen mode", "Display", RdpConnectionBarState._Default, key); this.DesktopSize = RegistryEnumSetting <RdpDesktopSize> .FromKey( "DesktopSize", "Desktop size", "Size of remote desktop", "Display", RdpDesktopSize._Default, key); this.AuthenticationLevel = RegistryEnumSetting <RdpAuthenticationLevel> .FromKey( "AuthenticationLevel", "Server authentication", "Require server authentication when connecting", "Connection", RdpAuthenticationLevel._Default, key); this.ColorDepth = RegistryEnumSetting <RdpColorDepth> .FromKey( "ColorDepth", "Color depth", "Color depth of remote desktop", "Display", RdpColorDepth._Default, key); this.AudioMode = RegistryEnumSetting <RdpAudioMode> .FromKey( "AudioMode", "Audio mode", "Redirect audio when playing on server", "Local resources", RdpAudioMode._Default, key); this.RedirectClipboard = RegistryEnumSetting <RdpRedirectClipboard> .FromKey( "RedirectClipboard", "Redirect clipboard", "Allow clipboard contents to be shared with remote desktop", "Local resources", RdpRedirectClipboard._Default, key); this.UserAuthenticationBehavior = RegistryEnumSetting <RdpUserAuthenticationBehavior> .FromKey( "RdpUserAuthenticationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. RdpUserAuthenticationBehavior._Default, key); this.BitmapPersistence = RegistryEnumSetting <RdpBitmapPersistence> .FromKey( "BitmapPersistence", "Bitmap caching", "Use persistent bitmap cache", "Performance", RdpBitmapPersistence._Default, key); this.ConnectionTimeout = RegistryDwordSetting.FromKey( "ConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); this.CredentialGenerationBehavior = RegistryEnumSetting <RdpCredentialGenerationBehavior> .FromKey( "CredentialGenerationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. RdpCredentialGenerationBehavior._Default, key); this.RdpPort = RegistryDwordSetting.FromKey( "RdpPort", "RDP port", "RDP port", "Connection", 3389, key, 1, ushort.MaxValue); Debug.Assert(this.Settings.All(s => s != null)); }