Skip to content

Commit b597996

Browse files
authored
Add tests (#378)
* [Equality] Improvements * [Packages] Bump up * [Tests] Fix namespace * [Tests] Host * [Tests] RedmineFixture * [Tests] XmlSerializerFixture * [Tests] JsonSerializerFixture * [Tests] Xml deserializer tests * [Tests] Json deserializer tests * [Tests ] Add clonable tests * [#229] Add tests * [Tests] RedmineApiUrls * [#371] Add tests * [Tests] Equality
1 parent ba344ae commit b597996

File tree

115 files changed

+4594
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+4594
-226
lines changed

Diff for: src/redmine-net-api/Internals/HashCodeHelper.cs

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ public static int GetHashCode<T>(IList<T> list, int hash) where T : class
5757
return hashCode;
5858
}
5959
}
60+
61+
public static int GetHashCode<T>(List<T> list, int hash) where T : class
62+
{
63+
unchecked
64+
{
65+
var hashCode = hash;
66+
if (list == null)
67+
{
68+
return hashCode;
69+
}
70+
71+
hashCode = (hashCode * 17) + list.Count;
72+
73+
foreach (var t in list)
74+
{
75+
hashCode *= 17;
76+
if (t != null)
77+
{
78+
hashCode += t.GetHashCode();
79+
}
80+
}
81+
82+
return hashCode;
83+
}
84+
}
6085

6186
/// <summary>
6287
/// Returns a hash code for this instance.

Diff for: src/redmine-net-api/Types/Attachment.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ public override bool Equals(Attachment other)
189189
{
190190
if (other == null) return false;
191191
return base.Equals(other)
192-
&& string.Equals(FileName, other.FileName, StringComparison.OrdinalIgnoreCase)
193-
&& string.Equals(ContentType, other.ContentType, StringComparison.OrdinalIgnoreCase)
194-
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
195-
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.OrdinalIgnoreCase)
196-
&& string.Equals(ThumbnailUrl, other.ThumbnailUrl, StringComparison.OrdinalIgnoreCase)
197-
&& Equals(Author, other.Author)
192+
&& string.Equals(FileName, other.FileName, StringComparison.Ordinal)
193+
&& string.Equals(ContentType, other.ContentType, StringComparison.Ordinal)
194+
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
195+
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.Ordinal)
196+
&& string.Equals(ThumbnailUrl, other.ThumbnailUrl, StringComparison.Ordinal)
197+
&& Author == other.Author
198198
&& FileSize == other.FileSize
199199
&& CreatedOn == other.CreatedOn;
200200
}

Diff for: src/redmine-net-api/Types/ChangeSet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public bool Equals(ChangeSet other)
154154

155155
return Revision == other.Revision
156156
&& User == other.User
157-
&& Comments == other.Comments
157+
&& string.Equals(Comments, other.Comments, StringComparison.Ordinal)
158158
&& CommittedOn == other.CommittedOn;
159159
}
160160

Diff for: src/redmine-net-api/Types/CustomField.cs

+17-16
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,23 @@ public bool Equals(CustomField other)
207207
{
208208
if (other == null) return false;
209209

210-
return base.Equals(other)
211-
&& string.Equals(CustomizedType, other.CustomizedType, StringComparison.OrdinalIgnoreCase)
212-
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
213-
&& string.Equals(FieldFormat, other.FieldFormat, StringComparison.OrdinalIgnoreCase)
214-
&& string.Equals(Regexp, other.Regexp, StringComparison.OrdinalIgnoreCase)
215-
&& string.Equals(DefaultValue, other.DefaultValue, StringComparison.Ordinal)
216-
&& MinLength == other.MinLength
217-
&& MaxLength == other.MaxLength
218-
&& IsRequired == other.IsRequired
219-
&& IsFilter == other.IsFilter
220-
&& Searchable == other.Searchable
221-
&& Multiple == other.Multiple
222-
&& Visible == other.Visible
223-
&& Equals(PossibleValues, other.PossibleValues)
224-
&& Equals(Trackers, other.Trackers)
225-
&& Equals(Roles, other.Roles);
210+
var result = base.Equals(other)
211+
&& string.Equals(CustomizedType, other.CustomizedType, StringComparison.Ordinal)
212+
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
213+
&& string.Equals(FieldFormat, other.FieldFormat, StringComparison.Ordinal)
214+
&& string.Equals(Regexp, other.Regexp, StringComparison.Ordinal)
215+
&& string.Equals(DefaultValue, other.DefaultValue, StringComparison.Ordinal)
216+
&& MinLength == other.MinLength
217+
&& MaxLength == other.MaxLength
218+
&& IsRequired == other.IsRequired
219+
&& IsFilter == other.IsFilter
220+
&& Searchable == other.Searchable
221+
&& Multiple == other.Multiple
222+
&& Visible == other.Visible
223+
&& (PossibleValues?.Equals<CustomFieldPossibleValue>(other.PossibleValues) ?? other.PossibleValues == null)
224+
&& (Trackers?.Equals<TrackerCustomField>(other.Trackers) ?? other.Trackers == null)
225+
&& (Roles?.Equals<CustomFieldRole>(other.Roles) ?? other.Roles == null);
226+
return result;
226227
}
227228

228229
/// <summary>

Diff for: src/redmine-net-api/Types/CustomFieldPossibleValue.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ public void ReadXml(XmlReader reader)
7373
switch (reader.Name)
7474
{
7575
case RedmineKeys.LABEL: Label = reader.ReadElementContentAsString(); break;
76-
7776
case RedmineKeys.VALUE: Value = reader.ReadElementContentAsString(); break;
78-
7977
default: reader.Read(); break;
8078
}
8179
}
@@ -111,14 +109,9 @@ public void ReadJson(JsonReader reader)
111109

112110
switch (reader.Value)
113111
{
114-
case RedmineKeys.LABEL:
115-
Label = reader.ReadAsString(); break;
116-
117-
case RedmineKeys.VALUE:
118-
119-
Value = reader.ReadAsString(); break;
120-
default:
121-
reader.Read(); break;
112+
case RedmineKeys.LABEL: Label = reader.ReadAsString(); break;
113+
case RedmineKeys.VALUE: Value = reader.ReadAsString(); break;
114+
default: reader.Read(); break;
122115
}
123116
}
124117
}
@@ -139,8 +132,9 @@ public void WriteJson(JsonWriter writer) { }
139132
public bool Equals(CustomFieldPossibleValue other)
140133
{
141134
if (other == null) return false;
142-
return string.Equals(Value, other.Value, StringComparison.Ordinal)
135+
var result = string.Equals(Value, other.Value, StringComparison.Ordinal)
143136
&& string.Equals(Label, other.Label, StringComparison.Ordinal);
137+
return result;
144138
}
145139

146140
/// <summary>

Diff for: src/redmine-net-api/Types/CustomFieldValue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void WriteJson(JsonWriter writer)
146146
public bool Equals(CustomFieldValue other)
147147
{
148148
if (other == null) return false;
149-
return string.Equals(Info, other.Info, StringComparison.OrdinalIgnoreCase);
149+
return string.Equals(Info, other.Info, StringComparison.Ordinal);
150150
}
151151

152152
/// <summary>

Diff for: src/redmine-net-api/Types/Detail.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ public void ReadJson(JsonReader reader)
177177
public bool Equals(Detail other)
178178
{
179179
if (other == null) return false;
180-
return string.Equals(Property, other.Property, StringComparison.OrdinalIgnoreCase)
181-
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
182-
&& string.Equals(OldValue, other.OldValue, StringComparison.OrdinalIgnoreCase)
183-
&& string.Equals(NewValue, other.NewValue, StringComparison.OrdinalIgnoreCase);
180+
return string.Equals(Property, other.Property, StringComparison.Ordinal)
181+
&& string.Equals(Name, other.Name, StringComparison.Ordinal)
182+
&& string.Equals(OldValue, other.OldValue, StringComparison.Ordinal)
183+
&& string.Equals(NewValue, other.NewValue, StringComparison.Ordinal);
184184
}
185185

186186
/// <summary>

Diff for: src/redmine-net-api/Types/DocumentCategory.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public bool Equals(DocumentCategory other)
132132
{
133133
if (other == null) return false;
134134

135-
return Id == other.Id
136-
&& Name == other.Name
135+
return base.Equals(other)
137136
&& IsDefault == other.IsDefault
138137
&& IsActive == other.IsActive;
139138
}

Diff for: src/redmine-net-api/Types/Error.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public bool Equals(Error other)
119119
{
120120
if (other == null) return false;
121121

122-
return string.Equals(Info,other.Info, StringComparison.OrdinalIgnoreCase);
122+
return string.Equals(Info, other.Info, StringComparison.Ordinal);
123123
}
124124

125125
/// <summary>

Diff for: src/redmine-net-api/Types/File.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ public override bool Equals(File other)
210210
{
211211
if (other == null) return false;
212212
return base.Equals(other)
213-
&& string.Equals(Filename, other.Filename, StringComparison.OrdinalIgnoreCase)
214-
&& string.Equals(ContentType, other.ContentType, StringComparison.OrdinalIgnoreCase)
215-
&& string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase)
216-
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.OrdinalIgnoreCase)
217-
&& string.Equals(Digest, other.Digest, StringComparison.OrdinalIgnoreCase)
218-
&& Equals(Author, other.Author)
213+
&& string.Equals(Filename, other.Filename, StringComparison.Ordinal)
214+
&& string.Equals(ContentType, other.ContentType, StringComparison.Ordinal)
215+
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
216+
&& string.Equals(ContentUrl, other.ContentUrl, StringComparison.Ordinal)
217+
&& string.Equals(Digest, other.Digest, StringComparison.Ordinal)
218+
&& Author == other.Author
219219
&& FileSize == other.FileSize
220220
&& CreatedOn == other.CreatedOn
221221
&& Version == other.Version

Diff for: src/redmine-net-api/Types/Group.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ public bool Equals(Group other)
165165
{
166166
if (other == null) return false;
167167
return base.Equals(other)
168-
&& Equals(Users, other.Users)
169-
&& Equals(CustomFields, other.CustomFields)
170-
&& Equals(Memberships, other.Memberships);
168+
&& Users != null ? Users.Equals<GroupUser>(other.Users) : other.Users == null
169+
&& CustomFields != null ? CustomFields.Equals<IssueCustomField>(other.CustomFields) : other.CustomFields == null
170+
&& Memberships != null ? Memberships.Equals<Membership>(other.Memberships) : other.Memberships == null;
171171
}
172172

173173
/// <summary>

Diff for: src/redmine-net-api/Types/Identifiable.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright 2011 - 2023 Adrian Popescu
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +41,7 @@ public abstract class Identifiable<T> : IXmlSerializable, IJsonSerializable, IEq
4141
/// Gets the id.
4242
/// </summary>
4343
/// <value>The id.</value>
44-
public int Id { get; protected set; }
44+
public int Id { get; protected internal set; }
4545
#endregion
4646

4747
#region Implementation of IXmlSerialization

Diff for: src/redmine-net-api/Types/IdentifiableName.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public override void WriteJson(JsonWriter writer)
167167
public override bool Equals(IdentifiableName other)
168168
{
169169
if (other == null) return false;
170-
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
170+
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.Ordinal);
171171
}
172172

173173
/// <summary>

Diff for: src/redmine-net-api/Types/Issue.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ public override bool Equals(Issue other)
484484
&& Priority == other.Priority
485485
&& Author == other.Author
486486
&& Category == other.Category
487-
&& Subject == other.Subject
488-
&& Description == other.Description
487+
&& string.Equals(Subject, other.Subject, StringComparison.Ordinal)
488+
&& string.Equals(Description, other.Description, StringComparison.Ordinal)
489489
&& StartDate == other.StartDate
490490
&& DueDate == other.DueDate
491491
&& DoneRatio == other.DoneRatio
@@ -495,16 +495,16 @@ public override bool Equals(Issue other)
495495
&& UpdatedOn == other.UpdatedOn
496496
&& AssignedTo == other.AssignedTo
497497
&& FixedVersion == other.FixedVersion
498-
&& Notes == other.Notes
498+
&& string.Equals(Notes, other.Notes, StringComparison.Ordinal)
499499
&& ClosedOn == other.ClosedOn
500500
&& PrivateNotes == other.PrivateNotes
501-
&& Attachments.Equals(other.Attachments)
502-
&& CustomFields.Equals(other.CustomFields)
503-
&& ChangeSets.Equals(other.ChangeSets)
504-
&& Children.Equals(other.Children)
505-
&& Journals.Equals(other.Journals)
506-
&& Relations.Equals(other.Relations)
507-
&& Watchers.Equals(other.Watchers);
501+
&& (Attachments?.Equals<Attachment>(other.Attachments) ?? other.Attachments == null)
502+
&& (CustomFields?.Equals<IssueCustomField>(other.CustomFields) ?? other.CustomFields == null)
503+
&& (ChangeSets?.Equals<ChangeSet>(other.ChangeSets) ?? other.ChangeSets == null)
504+
&& (Children?.Equals<IssueChild>(other.Children) ?? other.Children == null)
505+
&& (Journals?.Equals<Journal>(other.Journals) ?? other.Journals == null)
506+
&& (Relations?.Equals<IssueRelation>(other.Relations) ?? other.Relations == null)
507+
&& (Watchers?.Equals<Watcher>(other.Watchers) ?? other.Watchers == null);
508508
}
509509

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

531531
hashCode = HashCodeHelper.GetHashCode(Project, hashCode);
532+
532533
hashCode = HashCodeHelper.GetHashCode(Tracker, hashCode);
533534
hashCode = HashCodeHelper.GetHashCode(Status, hashCode);
534535
hashCode = HashCodeHelper.GetHashCode(Priority, hashCode);
535536
hashCode = HashCodeHelper.GetHashCode(Author, hashCode);
536537
hashCode = HashCodeHelper.GetHashCode(Category, hashCode);
537-
538+
538539
hashCode = HashCodeHelper.GetHashCode(Subject, hashCode);
539540
hashCode = HashCodeHelper.GetHashCode(Description, hashCode);
540541
hashCode = HashCodeHelper.GetHashCode(StartDate, hashCode);
541542
hashCode = HashCodeHelper.GetHashCode(Project, hashCode);
542543
hashCode = HashCodeHelper.GetHashCode(DueDate, hashCode);
543544
hashCode = HashCodeHelper.GetHashCode(DoneRatio, hashCode);
544-
545545
hashCode = HashCodeHelper.GetHashCode(PrivateNotes, hashCode);
546546
hashCode = HashCodeHelper.GetHashCode(EstimatedHours, hashCode);
547547
hashCode = HashCodeHelper.GetHashCode(SpentHours, hashCode);

Diff for: src/redmine-net-api/Types/IssueChild.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public override bool Equals(IssueChild other)
115115
{
116116
if (other == null) return false;
117117
return base.Equals(other)
118-
&& Tracker == other.Tracker && Subject == other.Subject;
118+
&& Tracker == other.Tracker
119+
&& string.Equals(Subject, other.Subject, StringComparison.Ordinal);
119120
}
120121

121122
/// <summary>

Diff for: src/redmine-net-api/Types/IssueCustomField.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ public override void ReadJson(JsonReader reader)
214214
public bool Equals(IssueCustomField other)
215215
{
216216
if (other == null) return false;
217-
return Id == other.Id
218-
&& Name == other.Name
217+
return base.Equals(other)
219218
&& Multiple == other.Multiple
220-
&& Values.Equals(other.Values);
219+
&& (Values?.Equals<CustomFieldValue>(other.Values) ?? other.Values == null);
221220
}
222221

223222
/// <summary>

Diff for: src/redmine-net-api/Types/IssuePriority.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public bool Equals(IssuePriority other)
116116
{
117117
if (other == null) return false;
118118

119-
return Id == other.Id && Name == other.Name
119+
return base.Equals(other)
120120
&& IsDefault == other.IsDefault
121121
&& IsActive == other.IsActive;
122122
}

Diff for: src/redmine-net-api/Types/IssueRelation.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ private static IssueRelationType ReadIssueRelationType(string value)
219219
public override bool Equals(IssueRelation other)
220220
{
221221
if (other == null) return false;
222-
return Id == other.Id && IssueId == other.IssueId && IssueToId == other.IssueToId && Type == other.Type && Delay == other.Delay;
222+
return Id == other.Id
223+
&& IssueId == other.IssueId
224+
&& IssueToId == other.IssueToId
225+
&& Type == other.Type
226+
&& Delay == other.Delay;
223227
}
224228

225229
/// <summary>

Diff for: src/redmine-net-api/Types/IssueStatus.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ public override void ReadJson(JsonReader reader)
116116
public bool Equals(IssueStatus other)
117117
{
118118
if (other == null) return false;
119-
return Id == other.Id && Name == other.Name && IsClosed == other.IsClosed && IsDefault == other.IsDefault;
119+
return base.Equals(other)
120+
&& IsClosed == other.IsClosed
121+
&& IsDefault == other.IsDefault;
120122
}
121123

122124
/// <summary>

Diff for: src/redmine-net-api/Types/Journal.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ public override void WriteXml(XmlWriter writer)
130130
#endregion
131131

132132
#region Implementation of IJsonSerialization
133-
134-
135133
/// <summary>
136134
///
137135
/// </summary>
@@ -182,14 +180,15 @@ public override void WriteJson(JsonWriter writer)
182180
public override bool Equals(Journal other)
183181
{
184182
if (other == null) return false;
185-
return base.Equals(other)
186-
&& Equals(User, other.User)
187-
&& Equals(Details, other.Details)
188-
&& string.Equals(Notes, other.Notes, StringComparison.OrdinalIgnoreCase)
189-
&& CreatedOn == other.CreatedOn
190-
&& UpdatedOn == other.UpdatedOn
191-
&& Equals(UpdatedBy, other.UpdatedBy)
192-
&& PrivateNotes == other.PrivateNotes;
183+
var result = base.Equals(other);
184+
result = result && User == other.User;
185+
result = result && UpdatedBy == other.UpdatedBy;
186+
result = result && (Details?.Equals<Detail>(other.Details) ?? other.Details == null);
187+
result = result && string.Equals(Notes, other.Notes, StringComparison.Ordinal);
188+
result = result && CreatedOn == other.CreatedOn;
189+
result = result && UpdatedOn == other.UpdatedOn;
190+
result = result && PrivateNotes == other.PrivateNotes;
191+
return result;
193192
}
194193

195194
/// <summary>

Diff for: src/redmine-net-api/Types/Membership.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public override bool Equals(Membership other)
125125
{
126126
if (other == null) return false;
127127
return Id == other.Id
128-
&& Project != null ? Project.Equals(other.Project) : other.Project == null
128+
&& Project == other.Project
129129
&& Roles != null ? Roles.Equals<MembershipRole>(other.Roles) : other.Roles == null;
130130
}
131131

0 commit comments

Comments
 (0)