-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathMetadataAndSerializationContextTests.cs
More file actions
71 lines (67 loc) · 4.42 KB
/
MetadataAndSerializationContextTests.cs
File metadata and controls
71 lines (67 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json.Serialization;
using Xunit;
namespace System.Text.Json.SourceGeneration.Tests
{
[JsonSerializable(typeof(Location))]
[JsonSerializable(typeof(RepeatedTypes.Location), TypeInfoPropertyName = "RepeatedLocation")]
[JsonSerializable(typeof(NumberTypes))]
[JsonSerializable(typeof(ActiveOrUpcomingEvent))]
[JsonSerializable(typeof(CampaignSummaryViewModel))]
[JsonSerializable(typeof(IndexViewModel))]
[JsonSerializable(typeof(WeatherForecastWithPOCOs))]
[JsonSerializable(typeof(EmptyPoco))]
// Ensure no errors when type of member in previously specified object graph is passed as input type to generator.
[JsonSerializable(typeof(HighLowTemps))]
[JsonSerializable(typeof(MyType))]
[JsonSerializable(typeof(MyType2))]
[JsonSerializable(typeof(MyTypeWithCallbacks))]
[JsonSerializable(typeof(MyTypeWithPropertyOrdering))]
[JsonSerializable(typeof(MyIntermediateType))]
[JsonSerializable(typeof(HighLowTempsImmutable))]
[JsonSerializable(typeof(RealWorldContextTests.MyNestedClass))]
[JsonSerializable(typeof(RealWorldContextTests.MyNestedClass.MyNestedNestedClass))]
[JsonSerializable(typeof(object[]))]
[JsonSerializable(typeof(string))]
[JsonSerializable(typeof(RealWorldContextTests.ClassWithEnumAndNullable))]
[JsonSerializable(typeof(ClassWithCustomConverter))]
[JsonSerializable(typeof(StructWithCustomConverter))]
[JsonSerializable(typeof(ClassWithBadCustomConverter))]
[JsonSerializable(typeof(StructWithBadCustomConverter))]
internal partial class MetadataAndSerializationContext : JsonSerializerContext, ITestContext
{
}
public sealed class MetadataAndSerializationContextTests : RealWorldContextTests
{
public MetadataAndSerializationContextTests() : base(MetadataAndSerializationContext.Default, (options) => new MetadataAndSerializationContext(options)) { }
[Fact]
public override void EnsureFastPathGeneratedAsExpected()
{
Assert.NotNull(MetadataAndSerializationContext.Default.Location.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.NumberTypes.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.RepeatedLocation.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.ActiveOrUpcomingEvent.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.CampaignSummaryViewModel.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.IndexViewModel.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.WeatherForecastWithPOCOs.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.EmptyPoco.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.HighLowTemps.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyType.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyType2.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyTypeWithCallbacks.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyTypeWithPropertyOrdering.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyIntermediateType.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.HighLowTempsImmutable.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyNestedClass.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.MyNestedNestedClass.Serialize);
Assert.Null(MetadataAndSerializationContext.Default.ObjectArray.Serialize);
Assert.Null(MetadataAndSerializationContext.Default.String.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.ClassWithEnumAndNullable.Serialize);
Assert.NotNull(MetadataAndSerializationContext.Default.ClassWithCustomConverter);
Assert.NotNull(MetadataAndSerializationContext.Default.StructWithCustomConverter);
Assert.Throws<InvalidOperationException>(() => MetadataAndSerializationContext.Default.ClassWithBadCustomConverter);
Assert.Throws<InvalidOperationException>(() => MetadataAndSerializationContext.Default.StructWithBadCustomConverter);
}
}
}