-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add unit test to demonstrate interaction of ClassNameHint with other hints #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,7 +269,208 @@ public int GetHashCode(FileData obj) | |
} | ||
} | ||
}" | ||
) | ||
), | ||
|
||
new TestCase( | ||
"Renamed class has a base class", | ||
@"{ | ||
""type"": ""object"", | ||
""properties"": { | ||
""file"": { | ||
""$ref"": ""#/definitions/file"" | ||
} | ||
}, | ||
""definitions"": { | ||
""file"": { | ||
""type"": ""object"", | ||
""properties"": { | ||
""path"": { | ||
""type"": ""string"" | ||
} | ||
} | ||
} | ||
} | ||
}", | ||
|
||
"FileData", | ||
|
||
@"{ | ||
""file"": [ | ||
{ | ||
""kind"": ""ClassNameHint"", | ||
""arguments"": { | ||
""className"": ""FileData"" | ||
} | ||
} | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
""fileData"": [ | ||
{ | ||
""kind"": ""BaseTypeHint"", | ||
""arguments"": { | ||
""baseTypeNames"": [ | ||
""PropertyBagHolder"" | ||
] | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
] | ||
}", | ||
|
||
// PrimaryClassText | ||
@"using System; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
namespace N | ||
{ | ||
[DataContract] | ||
[GeneratedCode(""Microsoft.Json.Schema.ToDotNet"", """ + VersionConstants.FileVersion + @""")] | ||
public partial class C | ||
{ | ||
public static IEqualityComparer<C> ValueComparer => CEqualityComparer.Instance; | ||
|
||
public bool ValueEquals(C other) => ValueComparer.Equals(this, other); | ||
public int ValueGetHashCode() => ValueComparer.GetHashCode(this); | ||
|
||
[DataMember(Name = ""file"", IsRequired = false, EmitDefaultValue = false)] | ||
public FileData File { get; set; } | ||
} | ||
}", | ||
|
||
// PrimaryClassComparerText | ||
@"using System; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
|
||
namespace N | ||
{ | ||
/// <summary> | ||
/// Defines methods to support the comparison of objects of type C for equality. | ||
/// </summary> | ||
[GeneratedCode(""Microsoft.Json.Schema.ToDotNet"", """ + VersionConstants.FileVersion + @""")] | ||
internal sealed class CEqualityComparer : IEqualityComparer<C> | ||
{ | ||
internal static readonly CEqualityComparer Instance = new CEqualityComparer(); | ||
|
||
public bool Equals(C left, C right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (ReferenceEquals(left, null) || ReferenceEquals(right, null)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!FileData.ValueComparer.Equals(left.File, right.File)) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public int GetHashCode(C obj) | ||
{ | ||
if (ReferenceEquals(obj, null)) | ||
{ | ||
return 0; | ||
} | ||
|
||
int result = 17; | ||
unchecked | ||
{ | ||
if (obj.File != null) | ||
{ | ||
result = (result * 31) + obj.File.ValueGetHashCode(); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
}", | ||
|
||
// HintedClassText | ||
@"using System; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
namespace N | ||
{ | ||
[DataContract] | ||
[GeneratedCode(""Microsoft.Json.Schema.ToDotNet"", """ + VersionConstants.FileVersion + @""")] | ||
public partial class FileData : PropertyBagHolder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The renamed class has the correct base type. #ByDesign |
||
{ | ||
public static IEqualityComparer<FileData> ValueComparer => FileDataEqualityComparer.Instance; | ||
|
||
public bool ValueEquals(FileData other) => ValueComparer.Equals(this, other); | ||
public int ValueGetHashCode() => ValueComparer.GetHashCode(this); | ||
|
||
[DataMember(Name = ""path"", IsRequired = false, EmitDefaultValue = false)] | ||
public string Path { get; set; } | ||
} | ||
}", | ||
|
||
// HintedClassComparerText | ||
@"using System; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
|
||
namespace N | ||
{ | ||
/// <summary> | ||
/// Defines methods to support the comparison of objects of type FileData for equality. | ||
/// </summary> | ||
[GeneratedCode(""Microsoft.Json.Schema.ToDotNet"", """ + VersionConstants.FileVersion + @""")] | ||
internal sealed class FileDataEqualityComparer : IEqualityComparer<FileData> | ||
{ | ||
internal static readonly FileDataEqualityComparer Instance = new FileDataEqualityComparer(); | ||
|
||
public bool Equals(FileData left, FileData right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (ReferenceEquals(left, null) || ReferenceEquals(right, null)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (left.Path != right.Path) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Now this is a separate, existing, bug, which I will file. The generated equality comparer doesn't compare the base classes! #Pending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelcfanning Microsoft/jschema#55, "Equality comparer doesn't compare base types". In reply to: 226104727 [](ancestors = 226104727) |
||
|
||
public int GetHashCode(FileData obj) | ||
{ | ||
if (ReferenceEquals(obj, null)) | ||
{ | ||
return 0; | ||
} | ||
|
||
int result = 17; | ||
unchecked | ||
{ | ||
if (obj.Path != null) | ||
{ | ||
result = (result * 31) + obj.Path.GetHashCode(); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
}" | ||
) | ||
}; | ||
|
||
[Theory(DisplayName = nameof(ClassNameHint))] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schema defines a root object with a single property named
file
of typefile
. #ByDesign