Skip to content

Add tests #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 30, 2025
25 changes: 25 additions & 0 deletions src/redmine-net-api/Internals/HashCodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ public static int GetHashCode<T>(IList<T> list, int hash) where T : class
return hashCode;
}
}

public static int GetHashCode<T>(List<T> list, int hash) where T : class
{
unchecked
{
var hashCode = hash;
if (list == null)
{
return hashCode;
}

hashCode = (hashCode * 17) + list.Count;

foreach (var t in list)
{
hashCode *= 17;
if (t != null)
{
hashCode += t.GetHashCode();
}
}

return hashCode;
}
}

/// <summary>
/// Returns a hash code for this instance.
Expand Down
12 changes: 6 additions & 6 deletions src/redmine-net-api/Types/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ public override bool Equals(Attachment other)
{
if (other == null) return false;
return base.Equals(other)
&& string.Equals(FileName, other.FileName, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ContentType, other.ContentType, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ThumbnailUrl, other.ThumbnailUrl, StringComparison.OrdinalIgnoreCase)
&& Equals(Author, other.Author)
&& string.Equals(FileName, other.FileName, StringComparison.Ordinal)
&& string.Equals(ContentType, other.ContentType, StringComparison.Ordinal)
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.Ordinal)
&& string.Equals(ThumbnailUrl, other.ThumbnailUrl, StringComparison.Ordinal)
&& Author == other.Author
&& FileSize == other.FileSize
&& CreatedOn == other.CreatedOn;
}
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/ChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public bool Equals(ChangeSet other)

return Revision == other.Revision
&& User == other.User
&& Comments == other.Comments
&& string.Equals(Comments, other.Comments, StringComparison.Ordinal)
&& CommittedOn == other.CommittedOn;
}

Expand Down
33 changes: 17 additions & 16 deletions src/redmine-net-api/Types/CustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,23 @@ public bool Equals(CustomField other)
{
if (other == null) return false;

return base.Equals(other)
&& string.Equals(CustomizedType, other.CustomizedType, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
&& string.Equals(FieldFormat, other.FieldFormat, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Regexp, other.Regexp, StringComparison.OrdinalIgnoreCase)
&& string.Equals(DefaultValue, other.DefaultValue, StringComparison.Ordinal)
&& MinLength == other.MinLength
&& MaxLength == other.MaxLength
&& IsRequired == other.IsRequired
&& IsFilter == other.IsFilter
&& Searchable == other.Searchable
&& Multiple == other.Multiple
&& Visible == other.Visible
&& Equals(PossibleValues, other.PossibleValues)
&& Equals(Trackers, other.Trackers)
&& Equals(Roles, other.Roles);
var result = base.Equals(other)
&& string.Equals(CustomizedType, other.CustomizedType, StringComparison.Ordinal)
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
&& string.Equals(FieldFormat, other.FieldFormat, StringComparison.Ordinal)
&& string.Equals(Regexp, other.Regexp, StringComparison.Ordinal)
&& string.Equals(DefaultValue, other.DefaultValue, StringComparison.Ordinal)
&& MinLength == other.MinLength
&& MaxLength == other.MaxLength
&& IsRequired == other.IsRequired
&& IsFilter == other.IsFilter
&& Searchable == other.Searchable
&& Multiple == other.Multiple
&& Visible == other.Visible
&& (PossibleValues?.Equals<CustomFieldPossibleValue>(other.PossibleValues) ?? other.PossibleValues == null)
&& (Trackers?.Equals<TrackerCustomField>(other.Trackers) ?? other.Trackers == null)
&& (Roles?.Equals<CustomFieldRole>(other.Roles) ?? other.Roles == null);
return result;
}

/// <summary>
Expand Down
16 changes: 5 additions & 11 deletions src/redmine-net-api/Types/CustomFieldPossibleValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void ReadXml(XmlReader reader)
switch (reader.Name)
{
case RedmineKeys.LABEL: Label = reader.ReadElementContentAsString(); break;

case RedmineKeys.VALUE: Value = reader.ReadElementContentAsString(); break;

default: reader.Read(); break;
}
}
Expand Down Expand Up @@ -111,14 +109,9 @@ public void ReadJson(JsonReader reader)

switch (reader.Value)
{
case RedmineKeys.LABEL:
Label = reader.ReadAsString(); break;

case RedmineKeys.VALUE:

Value = reader.ReadAsString(); break;
default:
reader.Read(); break;
case RedmineKeys.LABEL: Label = reader.ReadAsString(); break;
case RedmineKeys.VALUE: Value = reader.ReadAsString(); break;
default: reader.Read(); break;
}
}
}
Expand All @@ -139,8 +132,9 @@ public void WriteJson(JsonWriter writer) { }
public bool Equals(CustomFieldPossibleValue other)
{
if (other == null) return false;
return string.Equals(Value, other.Value, StringComparison.Ordinal)
var result = string.Equals(Value, other.Value, StringComparison.Ordinal)
&& string.Equals(Label, other.Label, StringComparison.Ordinal);
return result;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/CustomFieldValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void WriteJson(JsonWriter writer)
public bool Equals(CustomFieldValue other)
{
if (other == null) return false;
return string.Equals(Info, other.Info, StringComparison.OrdinalIgnoreCase);
return string.Equals(Info, other.Info, StringComparison.Ordinal);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/redmine-net-api/Types/Detail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ public void ReadJson(JsonReader reader)
public bool Equals(Detail other)
{
if (other == null) return false;
return string.Equals(Property, other.Property, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(OldValue, other.OldValue, StringComparison.OrdinalIgnoreCase)
&& string.Equals(NewValue, other.NewValue, StringComparison.OrdinalIgnoreCase);
return string.Equals(Property, other.Property, StringComparison.Ordinal)
&& string.Equals(Name, other.Name, StringComparison.Ordinal)
&& string.Equals(OldValue, other.OldValue, StringComparison.Ordinal)
&& string.Equals(NewValue, other.NewValue, StringComparison.Ordinal);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/redmine-net-api/Types/DocumentCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public bool Equals(DocumentCategory other)
{
if (other == null) return false;

return Id == other.Id
&& Name == other.Name
return base.Equals(other)
&& IsDefault == other.IsDefault
&& IsActive == other.IsActive;
}
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public bool Equals(Error other)
{
if (other == null) return false;

return string.Equals(Info,other.Info, StringComparison.OrdinalIgnoreCase);
return string.Equals(Info, other.Info, StringComparison.Ordinal);
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/redmine-net-api/Types/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ public override bool Equals(File other)
{
if (other == null) return false;
return base.Equals(other)
&& string.Equals(Filename, other.Filename, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ContentType, other.ContentType, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Digest, other.Digest, StringComparison.OrdinalIgnoreCase)
&& Equals(Author, other.Author)
&& string.Equals(Filename, other.Filename, StringComparison.Ordinal)
&& string.Equals(ContentType, other.ContentType, StringComparison.Ordinal)
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.Ordinal)
&& string.Equals(Digest, other.Digest, StringComparison.Ordinal)
&& Author == other.Author
&& FileSize == other.FileSize
&& CreatedOn == other.CreatedOn
&& Version == other.Version
Expand Down
6 changes: 3 additions & 3 deletions src/redmine-net-api/Types/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public bool Equals(Group other)
{
if (other == null) return false;
return base.Equals(other)
&& Equals(Users, other.Users)
&& Equals(CustomFields, other.CustomFields)
&& Equals(Memberships, other.Memberships);
&& Users != null ? Users.Equals<GroupUser>(other.Users) : other.Users == null
&& CustomFields != null ? CustomFields.Equals<IssueCustomField>(other.CustomFields) : other.CustomFields == null
&& Memberships != null ? Memberships.Equals<Membership>(other.Memberships) : other.Memberships == null;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/redmine-net-api/Types/Identifiable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Copyright 2011 - 2023 Adrian Popescu

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,7 +41,7 @@ public abstract class Identifiable<T> : IXmlSerializable, IJsonSerializable, IEq
/// Gets the id.
/// </summary>
/// <value>The id.</value>
public int Id { get; protected set; }
public int Id { get; protected internal set; }
#endregion

#region Implementation of IXmlSerialization
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/IdentifiableName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public override void WriteJson(JsonWriter writer)
public override bool Equals(IdentifiableName other)
{
if (other == null) return false;
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.Ordinal);
}

/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions src/redmine-net-api/Types/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ public override bool Equals(Issue other)
&& Priority == other.Priority
&& Author == other.Author
&& Category == other.Category
&& Subject == other.Subject
&& Description == other.Description
&& string.Equals(Subject, other.Subject, StringComparison.Ordinal)
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
&& StartDate == other.StartDate
&& DueDate == other.DueDate
&& DoneRatio == other.DoneRatio
Expand All @@ -495,16 +495,16 @@ public override bool Equals(Issue other)
&& UpdatedOn == other.UpdatedOn
&& AssignedTo == other.AssignedTo
&& FixedVersion == other.FixedVersion
&& Notes == other.Notes
&& string.Equals(Notes, other.Notes, StringComparison.Ordinal)
&& ClosedOn == other.ClosedOn
&& PrivateNotes == other.PrivateNotes
&& Attachments.Equals(other.Attachments)
&& CustomFields.Equals(other.CustomFields)
&& ChangeSets.Equals(other.ChangeSets)
&& Children.Equals(other.Children)
&& Journals.Equals(other.Journals)
&& Relations.Equals(other.Relations)
&& Watchers.Equals(other.Watchers);
&& (Attachments?.Equals<Attachment>(other.Attachments) ?? other.Attachments == null)
&& (CustomFields?.Equals<IssueCustomField>(other.CustomFields) ?? other.CustomFields == null)
&& (ChangeSets?.Equals<ChangeSet>(other.ChangeSets) ?? other.ChangeSets == null)
&& (Children?.Equals<IssueChild>(other.Children) ?? other.Children == null)
&& (Journals?.Equals<Journal>(other.Journals) ?? other.Journals == null)
&& (Relations?.Equals<IssueRelation>(other.Relations) ?? other.Relations == null)
&& (Watchers?.Equals<Watcher>(other.Watchers) ?? other.Watchers == null);
}

/// <summary>
Expand All @@ -529,19 +529,19 @@ public override int GetHashCode()
var hashCode = base.GetHashCode();

hashCode = HashCodeHelper.GetHashCode(Project, hashCode);

hashCode = HashCodeHelper.GetHashCode(Tracker, hashCode);
hashCode = HashCodeHelper.GetHashCode(Status, hashCode);
hashCode = HashCodeHelper.GetHashCode(Priority, hashCode);
hashCode = HashCodeHelper.GetHashCode(Author, hashCode);
hashCode = HashCodeHelper.GetHashCode(Category, hashCode);

hashCode = HashCodeHelper.GetHashCode(Subject, hashCode);
hashCode = HashCodeHelper.GetHashCode(Description, hashCode);
hashCode = HashCodeHelper.GetHashCode(StartDate, hashCode);
hashCode = HashCodeHelper.GetHashCode(Project, hashCode);
hashCode = HashCodeHelper.GetHashCode(DueDate, hashCode);
hashCode = HashCodeHelper.GetHashCode(DoneRatio, hashCode);

hashCode = HashCodeHelper.GetHashCode(PrivateNotes, hashCode);
hashCode = HashCodeHelper.GetHashCode(EstimatedHours, hashCode);
hashCode = HashCodeHelper.GetHashCode(SpentHours, hashCode);
Expand Down
3 changes: 2 additions & 1 deletion src/redmine-net-api/Types/IssueChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public override bool Equals(IssueChild other)
{
if (other == null) return false;
return base.Equals(other)
&& Tracker == other.Tracker && Subject == other.Subject;
&& Tracker == other.Tracker
&& string.Equals(Subject, other.Subject, StringComparison.Ordinal);
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/redmine-net-api/Types/IssueCustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ public override void ReadJson(JsonReader reader)
public bool Equals(IssueCustomField other)
{
if (other == null) return false;
return Id == other.Id
&& Name == other.Name
return base.Equals(other)
&& Multiple == other.Multiple
&& Values.Equals(other.Values);
&& (Values?.Equals<CustomFieldValue>(other.Values) ?? other.Values == null);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/IssuePriority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public bool Equals(IssuePriority other)
{
if (other == null) return false;

return Id == other.Id && Name == other.Name
return base.Equals(other)
&& IsDefault == other.IsDefault
&& IsActive == other.IsActive;
}
Expand Down
6 changes: 5 additions & 1 deletion src/redmine-net-api/Types/IssueRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ private static IssueRelationType ReadIssueRelationType(string value)
public override bool Equals(IssueRelation other)
{
if (other == null) return false;
return Id == other.Id && IssueId == other.IssueId && IssueToId == other.IssueToId && Type == other.Type && Delay == other.Delay;
return Id == other.Id
&& IssueId == other.IssueId
&& IssueToId == other.IssueToId
&& Type == other.Type
&& Delay == other.Delay;
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/redmine-net-api/Types/IssueStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public override void ReadJson(JsonReader reader)
public bool Equals(IssueStatus other)
{
if (other == null) return false;
return Id == other.Id && Name == other.Name && IsClosed == other.IsClosed && IsDefault == other.IsDefault;
return base.Equals(other)
&& IsClosed == other.IsClosed
&& IsDefault == other.IsDefault;
}

/// <summary>
Expand Down
19 changes: 9 additions & 10 deletions src/redmine-net-api/Types/Journal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public override void WriteXml(XmlWriter writer)
#endregion

#region Implementation of IJsonSerialization


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -182,14 +180,15 @@ public override void WriteJson(JsonWriter writer)
public override bool Equals(Journal other)
{
if (other == null) return false;
return base.Equals(other)
&& Equals(User, other.User)
&& Equals(Details, other.Details)
&& string.Equals(Notes, other.Notes, StringComparison.OrdinalIgnoreCase)
&& CreatedOn == other.CreatedOn
&& UpdatedOn == other.UpdatedOn
&& Equals(UpdatedBy, other.UpdatedBy)
&& PrivateNotes == other.PrivateNotes;
var result = base.Equals(other);
result = result && User == other.User;
result = result && UpdatedBy == other.UpdatedBy;
result = result && (Details?.Equals<Detail>(other.Details) ?? other.Details == null);
result = result && string.Equals(Notes, other.Notes, StringComparison.Ordinal);
result = result && CreatedOn == other.CreatedOn;
result = result && UpdatedOn == other.UpdatedOn;
result = result && PrivateNotes == other.PrivateNotes;
return result;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Types/Membership.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public override bool Equals(Membership other)
{
if (other == null) return false;
return Id == other.Id
&& Project != null ? Project.Equals(other.Project) : other.Project == null
&& Project == other.Project
&& Roles != null ? Roles.Equals<MembershipRole>(other.Roles) : other.Roles == null;
}

Expand Down
Loading
Loading