-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic regression testing for .NET 6 source generated JsonSerializ…
…erContext. (#71850) * Add basic regression testing for .NET 6 source generated JsonSerializerContext. * Add a negative test for combined v6 contexts * Add README.md
- Loading branch information
1 parent
4dd047a
commit d3222ff
Showing
16 changed files
with
1,059 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
....Tests/SourceGenRegressionTests/Net60/Net60GeneratedContext.ClassWithCustomConverter.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter>? _ClassWithCustomConverter; | ||
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter> ClassWithCustomConverter | ||
{ | ||
get | ||
{ | ||
if (_ClassWithCustomConverter == null) | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter? customConverter; | ||
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter))) != null) | ||
{ | ||
_ClassWithCustomConverter = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter>(Options, customConverter); | ||
} | ||
else | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter converter = new global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter.CustomConverter(); | ||
global::System.Type typeToConvert = typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter); | ||
if (!converter.CanConvert(typeToConvert)) | ||
{ | ||
throw new global::System.InvalidOperationException(string.Format("The converter '{0}' is not compatible with the type '{1}'.", converter.GetType(), typeToConvert)); | ||
} | ||
_ClassWithCustomConverter = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter> (Options, converter); | ||
} | ||
} | ||
|
||
return _ClassWithCustomConverter; | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
....Text.Json.Tests/SourceGenRegressionTests/Net60/Net60GeneratedContext.DateTimeOffset.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset>? _DateTimeOffset; | ||
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset> DateTimeOffset | ||
{ | ||
get | ||
{ | ||
if (_DateTimeOffset == null) | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter? customConverter; | ||
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::System.DateTimeOffset))) != null) | ||
{ | ||
_DateTimeOffset = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.DateTimeOffset>(Options, customConverter); | ||
} | ||
else | ||
{ | ||
_DateTimeOffset = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.DateTimeOffset>(Options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DateTimeOffsetConverter); | ||
} | ||
} | ||
|
||
return _DateTimeOffset; | ||
} | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ts/SourceGenRegressionTests/Net60/Net60GeneratedContext.DictionaryStringHighLowTemps.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>>? _DictionaryStringHighLowTemps; | ||
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>> DictionaryStringHighLowTemps | ||
{ | ||
get | ||
{ | ||
if (_DictionaryStringHighLowTemps == null) | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter? customConverter; | ||
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>))) != null) | ||
{ | ||
_DictionaryStringHighLowTemps = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>>(Options, customConverter); | ||
} | ||
else | ||
{ | ||
global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>> info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>>() | ||
{ | ||
ObjectCreator = () => new global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>(), | ||
KeyInfo = this.String, | ||
ElementInfo = this.HighLowTemps, | ||
NumberHandling = default, | ||
SerializeHandler = DictionaryStringHighLowTempsSerializeHandler | ||
}; | ||
|
||
_DictionaryStringHighLowTemps = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateDictionaryInfo<global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>, global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>(Options, info); | ||
|
||
} | ||
} | ||
|
||
return _DictionaryStringHighLowTemps; | ||
} | ||
} | ||
|
||
private static void DictionaryStringHighLowTempsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.Dictionary<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>? value) | ||
{ | ||
if (value == null) | ||
{ | ||
writer.WriteNullValue(); | ||
return; | ||
} | ||
|
||
writer.WriteStartObject(); | ||
|
||
foreach (global::System.Collections.Generic.KeyValuePair<global::System.String, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps> pair in value) | ||
{ | ||
writer.WritePropertyName(pair.Key); | ||
HighLowTempsSerializeHandler(writer, pair.Value!); | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...Text.Json.Tests/SourceGenRegressionTests/Net60/Net60GeneratedContext.GetJsonTypeInfo.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
public override global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetTypeInfo(global::System.Type type) | ||
{ | ||
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.WeatherForecastWithPOCOs)) | ||
{ | ||
return this.WeatherForecastWithPOCOs; | ||
} | ||
|
||
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.ClassWithCustomConverter)) | ||
{ | ||
return this.ClassWithCustomConverter; | ||
} | ||
|
||
return null!; | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...em.Text.Json.Tests/SourceGenRegressionTests/Net60/Net60GeneratedContext.HighLowTemps.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>? _HighLowTemps; | ||
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps> HighLowTemps | ||
{ | ||
get | ||
{ | ||
if (_HighLowTemps == null) | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter? customConverter; | ||
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps))) != null) | ||
{ | ||
_HighLowTemps = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>(Options, customConverter); | ||
} | ||
else | ||
{ | ||
global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps> objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>() | ||
{ | ||
ObjectCreator = static () => new global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps(), | ||
ObjectWithParameterizedConstructorCreator = null, | ||
PropertyMetadataInitializer = HighLowTempsPropInit, | ||
ConstructorParameterMetadataInitializer = null, | ||
NumberHandling = default, | ||
SerializeHandler = HighLowTempsSerializeHandler | ||
}; | ||
|
||
_HighLowTemps = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps>(Options, objectInfo); | ||
} | ||
} | ||
|
||
return _HighLowTemps; | ||
} | ||
} | ||
|
||
private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] HighLowTempsPropInit(global::System.Text.Json.Serialization.JsonSerializerContext context) | ||
{ | ||
global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.Net60GeneratedContext jsonContext = (global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.Net60GeneratedContext)context; | ||
global::System.Text.Json.JsonSerializerOptions options = context.Options; | ||
|
||
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2]; | ||
|
||
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Int32> info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Int32>() | ||
{ | ||
IsProperty = true, | ||
IsPublic = true, | ||
IsVirtual = false, | ||
DeclaringType = typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps), | ||
PropertyTypeInfo = jsonContext.Int32, | ||
Converter = null, | ||
Getter = static (obj) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps)obj).High, | ||
Setter = static (obj, value) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps)obj).High = value!, | ||
IgnoreCondition = null, | ||
HasJsonInclude = false, | ||
IsExtensionData = false, | ||
NumberHandling = default, | ||
PropertyName = "High", | ||
JsonPropertyName = null | ||
}; | ||
|
||
properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Int32>(options, info0); | ||
|
||
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Int32> info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Int32>() | ||
{ | ||
IsProperty = true, | ||
IsPublic = true, | ||
IsVirtual = false, | ||
DeclaringType = typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps), | ||
PropertyTypeInfo = jsonContext.Int32, | ||
Converter = null, | ||
Getter = static (obj) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps)obj).Low, | ||
Setter = static (obj, value) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps)obj).Low = value!, | ||
IgnoreCondition = null, | ||
HasJsonInclude = false, | ||
IsExtensionData = false, | ||
NumberHandling = default, | ||
PropertyName = "Low", | ||
JsonPropertyName = null | ||
}; | ||
|
||
properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Int32>(options, info1); | ||
|
||
return properties; | ||
} | ||
|
||
private static void HighLowTempsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Text.Json.Tests.SourceGenRegressionTests.Net60.HighLowTemps? value) | ||
{ | ||
if (value == null) | ||
{ | ||
writer.WriteNullValue(); | ||
return; | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WriteNumber(PropName_High, value.High); | ||
writer.WriteNumber(PropName_Low, value.Low); | ||
|
||
writer.WriteEndObject(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ts/System.Text.Json.Tests/SourceGenRegressionTests/Net60/Net60GeneratedContext.Int32.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Source files represent a source generated JsonSerializerContext as produced by the .NET 6 SDK. | ||
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components. | ||
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests. | ||
|
||
// <auto-generated/> | ||
#nullable enable | ||
|
||
// Suppress warnings about [Obsolete] member usage in generated code. | ||
#pragma warning disable CS0618 | ||
|
||
namespace System.Text.Json.Tests.SourceGenRegressionTests.Net60 | ||
{ | ||
public partial class Net60GeneratedContext | ||
{ | ||
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Int32>? _Int32; | ||
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Int32> Int32 | ||
{ | ||
get | ||
{ | ||
if (_Int32 == null) | ||
{ | ||
global::System.Text.Json.Serialization.JsonConverter? customConverter; | ||
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::System.Int32))) != null) | ||
{ | ||
_Int32 = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Int32>(Options, customConverter); | ||
} | ||
else | ||
{ | ||
_Int32 = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Int32>(Options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.Int32Converter); | ||
} | ||
} | ||
|
||
return _Int32; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.