From 4c85719c04ec56e53af019ebfe29928cb5ffca17 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Sat, 14 Jul 2018 20:14:43 +0100 Subject: [PATCH] (GH-1612) Updated classes to override methods - To allow for correct generation of hash codes - This will be used to validate changes to chocolatey.config file --- .../configuration/ConfigFileApiKeySetting.cs | 21 ++++++++++ .../configuration/ConfigFileConfigSetting.cs | 23 +++++++++++ .../configuration/ConfigFileFeatureSetting.cs | 25 ++++++++++++ .../configuration/ConfigFileSettings.cs | 29 ++++++++++++++ .../configuration/ConfigFileSourceSetting.cs | 39 +++++++++++++++++++ 5 files changed, 137 insertions(+) diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileApiKeySetting.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileApiKeySetting.cs index 4d31ac8093..6913328737 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileApiKeySetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileApiKeySetting.cs @@ -31,5 +31,26 @@ public sealed class ConfigFileApiKeySetting [XmlAttribute(AttributeName = "key")] public string Key { get; set; } + + public override bool Equals(object obj) + { + // Check for null values and compare run-time types. + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + var item = (ConfigFileApiKeySetting) obj; + + return (Source == item.Source) + && (Key == item.Source); + } + + public override int GetHashCode() + { + return HashCode + .Of(Source) + .And(Key); + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs index 5c9dc161ae..bfcf975cac 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs @@ -34,5 +34,28 @@ public sealed class ConfigFileConfigSetting [XmlAttribute(AttributeName = "description")] public string Description { get; set; } + + public override bool Equals(object obj) + { + // Check for null values and compare run-time types. + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + var item = (ConfigFileConfigSetting) obj; + + return (Key == item.Key) + && (Value == item.Value) + && (Description == item.Description); + } + + public override int GetHashCode() + { + return HashCode + .Of(Key) + .And(Value) + .And(Description); + } } } diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileFeatureSetting.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileFeatureSetting.cs index ed921fbcc5..91b3e22774 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileFeatureSetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileFeatureSetting.cs @@ -37,5 +37,30 @@ public sealed class ConfigFileFeatureSetting [XmlAttribute(AttributeName = "description")] public string Description { get; set; } + + public override bool Equals(object obj) + { + // Check for null values and compare run-time types. + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + var item = (ConfigFileFeatureSetting) obj; + + return (Name == item.Name) + && (Enabled == item.Enabled) + && (SetExplicitly == item.SetExplicitly) + && (Description == item.Description); + } + + public override int GetHashCode() + { + return HashCode + .Of(Name) + .And(Enabled) + .And(SetExplicitly) + .And(Description); + } } } diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs index 8f76e9b3f1..95a36be745 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs @@ -46,5 +46,34 @@ public class ConfigFileSettings [XmlArray("apiKeys")] public HashSet ApiKeys { get; set; } + + public override bool Equals(object obj) + { + // Check for null values and compare run-time types. + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + var item = (ConfigFileSettings) obj; + + return (CacheLocation == item.CacheLocation) + && (CommandExecutionTimeoutSeconds == item.CommandExecutionTimeoutSeconds) + && (ConfigSettings == item.ConfigSettings) + && (Sources == item.Sources) + && (Features == item.Features) + && (ApiKeys == item.ApiKeys); + } + + public override int GetHashCode() + { + return HashCode + .Of(CacheLocation) + .And(CommandExecutionTimeoutSeconds) + .AndEach(ConfigSettings) + .AndEach(Sources) + .AndEach(Features) + .AndEach(ApiKeys); + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileSourceSetting.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileSourceSetting.cs index e91a049709..db149ee234 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileSourceSetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileSourceSetting.cs @@ -58,5 +58,44 @@ public sealed class ConfigFileSourceSetting [XmlAttribute(AttributeName = "certificatePassword")] public string CertificatePassword { get; set; } + + public override bool Equals(object obj) + { + // Check for null values and compare run-time types. + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + var item = (ConfigFileSourceSetting) obj; + + return (Id == item.Id) + && (Value == item.Value) + && (Disabled == item.Disabled) + && (BypassProxy == item.BypassProxy) + && (AllowSelfService == item.AllowSelfService) + && (VisibleToAdminsOnly == item.VisibleToAdminsOnly) + && (UserName == item.UserName) + && (Password == item.Password) + && (Priority == item.Priority) + && (Certificate == item.Certificate) + && (CertificatePassword == item.CertificatePassword); + } + + public override int GetHashCode() + { + return HashCode + .Of(Id) + .And(Value) + .And(Disabled) + .And(BypassProxy) + .And(AllowSelfService) + .And(VisibleToAdminsOnly) + .And(UserName) + .And(Password) + .And(Priority) + .And(Certificate) + .And(CertificatePassword); + } } } \ No newline at end of file