Skip to content

Commit

Permalink
(GH-1612) Updated classes to override methods
Browse files Browse the repository at this point in the history
- To allow for correct generation of hash codes
- This will be used to validate changes to chocolatey.config file
  • Loading branch information
gep13 committed Oct 9, 2018
1 parent 134596e commit 4c85719
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,34 @@ public class ConfigFileSettings

[XmlArray("apiKeys")]
public HashSet<ConfigFileApiKeySetting> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 4c85719

Please sign in to comment.