Skip to content

Commit 144a515

Browse files
committed
unit tests for object route handler
1 parent 4952683 commit 144a515

29 files changed

+529
-149
lines changed

.editorconfig

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,56 +269,56 @@ dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
269269

270270
dotnet_naming_symbols.class.applicable_kinds = class
271271
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
272-
dotnet_naming_symbols.class.required_modifiers =
272+
dotnet_naming_symbols.class.required_modifiers =
273273

274274
dotnet_naming_symbols.interface.applicable_kinds = interface
275275
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
276-
dotnet_naming_symbols.interface.required_modifiers =
276+
dotnet_naming_symbols.interface.required_modifiers =
277277

278278
dotnet_naming_symbols.struct.applicable_kinds = struct
279279
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
280-
dotnet_naming_symbols.struct.required_modifiers =
280+
dotnet_naming_symbols.struct.required_modifiers =
281281

282282
dotnet_naming_symbols.enum.applicable_kinds = enum
283283
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
284-
dotnet_naming_symbols.enum.required_modifiers =
284+
dotnet_naming_symbols.enum.required_modifiers =
285285

286286
dotnet_naming_symbols.delegate.applicable_kinds = delegate
287287
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
288-
dotnet_naming_symbols.delegate.required_modifiers =
288+
dotnet_naming_symbols.delegate.required_modifiers =
289289

290290
dotnet_naming_symbols.event.applicable_kinds = event
291291
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
292-
dotnet_naming_symbols.event.required_modifiers =
292+
dotnet_naming_symbols.event.required_modifiers =
293293

294294
dotnet_naming_symbols.method.applicable_kinds = method
295295
dotnet_naming_symbols.method.applicable_accessibilities = public
296-
dotnet_naming_symbols.method.required_modifiers =
296+
dotnet_naming_symbols.method.required_modifiers =
297297

298298
dotnet_naming_symbols.property.applicable_kinds = property
299299
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
300-
dotnet_naming_symbols.property.required_modifiers =
300+
dotnet_naming_symbols.property.required_modifiers =
301301

302302
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
303303
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
304-
dotnet_naming_symbols.types.required_modifiers =
304+
dotnet_naming_symbols.types.required_modifiers =
305305

306306
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
307307
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
308-
dotnet_naming_symbols.non_field_members.required_modifiers =
308+
dotnet_naming_symbols.non_field_members.required_modifiers =
309309

310310
# Naming styles
311311

312-
dotnet_naming_style.pascal_case.required_prefix =
313-
dotnet_naming_style.pascal_case.required_suffix =
314-
dotnet_naming_style.pascal_case.word_separator =
312+
dotnet_naming_style.pascal_case.required_prefix =
313+
dotnet_naming_style.pascal_case.required_suffix =
314+
dotnet_naming_style.pascal_case.word_separator =
315315
dotnet_naming_style.pascal_case.capitalization = pascal_case
316316

317317
# Other
318318

319319
dotnet_naming_style.begins_with_i.required_prefix = I
320-
dotnet_naming_style.begins_with_i.required_suffix =
321-
dotnet_naming_style.begins_with_i.word_separator =
320+
dotnet_naming_style.begins_with_i.required_suffix =
321+
dotnet_naming_style.begins_with_i.word_separator =
322322
dotnet_naming_style.begins_with_i.capitalization = pascal_case
323323

324324
dotnet_diagnostic.CA1002.severity = suggestion
@@ -340,9 +340,10 @@ dotnet_diagnostic.CS8602.severity = warning # do not change: DAT treats this as
340340

341341
dotnet_diagnostic.IDE0004.severity = suggestion
342342
dotnet_diagnostic.IDE0005.severity = warning
343+
dotnet_diagnostic.IDE0007.severity = error
343344
dotnet_diagnostic.IDE0009.severity = suggestion
344345
dotnet_diagnostic.IDE0010.severity = error
345-
dotnet_diagnostic.IDE0011.severity = suggestion
346+
dotnet_diagnostic.IDE0011.severity = error
346347
dotnet_diagnostic.IDE0016.severity = suggestion
347348
dotnet_diagnostic.IDE0017.severity = suggestion
348349
dotnet_diagnostic.IDE0018.severity = suggestion
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoAuthorEntryComparer : IEqualityComparer<DtoAuthorEntry>
6+
{
7+
public bool Equals(DtoAuthorEntry? x, DtoAuthorEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id && x.Name == y.Name;
15+
}
16+
17+
public int GetHashCode([DisallowNull] DtoAuthorEntry obj)
18+
=> HashCode.Combine(obj.Id, obj.Name);
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoDatObjectEntryComparer : IEqualityComparer<DtoDatObjectEntry>
6+
{
7+
public bool Equals(DtoDatObjectEntry? x, DtoDatObjectEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id
15+
&& x.DatName == y.DatName
16+
&& x.DatChecksum == y.DatChecksum
17+
&& x.xxHash3 == y.xxHash3
18+
&& x.ObjectId == y.ObjectId
19+
&& x.DatBytesAsBase64 == y.DatBytesAsBase64;
20+
}
21+
22+
public int GetHashCode([DisallowNull] DtoDatObjectEntry obj)
23+
=> HashCode.Combine(obj.Id, obj.DatName, obj.DatChecksum, obj.xxHash3, obj.ObjectId, obj.DatBytesAsBase64);
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoItemPackEntryComparer : IEqualityComparer<DtoItemPackEntry>
6+
{
7+
public bool Equals(DtoItemPackEntry? x, DtoItemPackEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id
15+
&& x.Name == y.Name
16+
&& x.Description == y.Description
17+
&& x.CreatedDate == y.CreatedDate
18+
&& x.ModifiedDate == y.ModifiedDate
19+
&& x.UploadedDate == y.UploadedDate
20+
&& new DtoLicenceEntryComparer().Equals(x.Licence, y.Licence);
21+
}
22+
23+
public int GetHashCode([DisallowNull] DtoItemPackEntry obj)
24+
=> HashCode.Combine(obj.Id, obj.Name, obj.Description, obj.CreatedDate, obj.ModifiedDate, obj.UploadedDate, obj.Licence);
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoLicenceEntryComparer : IEqualityComparer<DtoLicenceEntry>
6+
{
7+
public bool Equals(DtoLicenceEntry? x, DtoLicenceEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id
15+
&& x.Name == y.Name
16+
&& x.Text == y.Text;
17+
}
18+
19+
public int GetHashCode([DisallowNull] DtoLicenceEntry obj)
20+
=> HashCode.Combine(obj.Id, obj.Name, obj.Text);
21+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoObjectDescriptorComparer : IEqualityComparer<DtoObjectDescriptor>
6+
{
7+
public bool Equals(DtoObjectDescriptor? x, DtoObjectDescriptor? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id
15+
&& x.Name == y.Name
16+
&& x.DisplayName == y.DisplayName
17+
&& x.DatChecksum == y.DatChecksum
18+
&& x.Description == y.Description
19+
&& x.ObjectSource == y.ObjectSource
20+
&& x.ObjectType == y.ObjectType
21+
&& x.VehicleType == y.VehicleType
22+
&& x.Availability == y.Availability
23+
&& x.CreatedDate == y.CreatedDate
24+
&& x.ModifiedDate == y.ModifiedDate
25+
&& x.UploadedDate == y.UploadedDate
26+
&& new DtoLicenceEntryComparer().Equals(x.Licence, y.Licence)
27+
&& x.Authors.SequenceEqual(y.Authors, new DtoAuthorEntryComparer())
28+
&& x.Tags.SequenceEqual(y.Tags, new DtoTagEntryComparer())
29+
&& x.ObjectPacks.SequenceEqual(y.ObjectPacks, new DtoItemPackEntryComparer())
30+
&& x.DatObjects.SequenceEqual(y.DatObjects, new DtoDatObjectEntryComparer())
31+
&& x.StringTable.Equals(y.StringTable);
32+
}
33+
34+
public int GetHashCode([DisallowNull] DtoObjectDescriptor obj)
35+
=> obj.GetHashCode();
36+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoStringTableDescriptorComparer : IEqualityComparer<DtoStringTableDescriptor>
6+
{
7+
public bool Equals(DtoStringTableDescriptor? x, DtoStringTableDescriptor? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
if (x.ObjectId != y.ObjectId)
15+
{
16+
return false;
17+
}
18+
19+
if (x.Table.Count != y.Table.Count)
20+
{
21+
return false;
22+
}
23+
24+
foreach (var key in x.Table.Keys)
25+
{
26+
if (!y.Table.ContainsKey(key))
27+
{
28+
return false;
29+
}
30+
31+
var xLangDict = x.Table[key];
32+
var yLangDict = y.Table[key];
33+
34+
if (xLangDict.Count != yLangDict.Count)
35+
{
36+
return false;
37+
}
38+
39+
foreach (var lang in xLangDict.Keys)
40+
{
41+
if (!yLangDict.ContainsKey(lang))
42+
{
43+
return false;
44+
}
45+
46+
if (xLangDict[lang] != yLangDict[lang])
47+
{
48+
return false;
49+
}
50+
}
51+
}
52+
53+
return true;
54+
}
55+
56+
public int GetHashCode([DisallowNull] DtoStringTableDescriptor obj)
57+
{
58+
var hash = obj.ObjectId.GetHashCode();
59+
foreach (var (rowName, langDict) in obj.Table)
60+
{
61+
hash = HashCode.Combine(hash, rowName);
62+
foreach (var (lang, text) in langDict)
63+
{
64+
hash = HashCode.Combine(hash, lang, text);
65+
}
66+
}
67+
return hash;
68+
}
69+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoTagEntryComparer : IEqualityComparer<DtoTagEntry>
6+
{
7+
public bool Equals(DtoTagEntry? x, DtoTagEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return x.Id == y.Id && x.Name == y.Name;
15+
}
16+
17+
public int GetHashCode([DisallowNull] DtoTagEntry obj)
18+
=> HashCode.Combine(obj.Id, obj.Name);
19+
}

Definitions/DTO/DtoLicenceEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace Definitions.DTO;
33
public record DtoLicenceEntry(
44
UniqueObjectId Id,
55
string Name,
6-
string LicenceText) : IHasId;
6+
string Text) : IHasId;

Definitions/DTO/Mappers/DtoExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static DtoLicenceEntry ToDtoEntry(this TblLicence table)
122122
=> new(table.Id, table.Name, table.Text);
123123

124124
public static TblLicence ToTable(this DtoLicenceEntry dto)
125-
=> new() { Name = dto.Name, Id = dto.Id, Text = dto.LicenceText };
125+
=> new() { Name = dto.Name, Id = dto.Id, Text = dto.Text };
126126

127127
public static DtoUserEntry ToDtoEntry(this TblUser table)
128128
=> new(table.Id, table.UserName);

0 commit comments

Comments
 (0)