-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseContractWithCustomDelimiterSerializationTests.MySecondJsonSerializerContext.cs
More file actions
63 lines (53 loc) · 2.1 KB
/
BaseContractWithCustomDelimiterSerializationTests.MySecondJsonSerializerContext.cs
File metadata and controls
63 lines (53 loc) · 2.1 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
using Aviationexam.GeneratedJsonConverters.SourceGenerator.Target.ContractWithCustomDelimiter;
using System;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using Xunit;
namespace Aviationexam.GeneratedJsonConverters.SourceGenerator.Target.Tests;
public partial class BaseContractWithCustomDelimiterSerializationTests
{
private JsonSerializerOptions CreateMySecondJsonSerializerOptions()
{
IJsonTypeInfoResolver jsonTypeInfoResolver = MySecondJsonSerializerContext.Default;
foreach (var jsonTypeInfoConfiguration in MySecondJsonSerializerContext.GetPolymorphicJsonTypeInfoConfigurations())
{
jsonTypeInfoResolver = jsonTypeInfoResolver.WithAddedModifier(jsonTypeInfoConfiguration);
}
var jsonOptions = new JsonSerializerOptions(MySecondJsonSerializerContext.Default.Options)
{
TypeInfoResolver = jsonTypeInfoResolver,
};
return jsonOptions;
}
[Theory]
[MemberData(nameof(BaseJsonContractData))]
public void DeserializeBaseContractWorks_withMySecondJsonSerializerContext(string json, Type targetType)
{
var baseContract = JsonSerializer.Deserialize<BaseContractWithCustomDelimiter>(
json,
CreateMySecondJsonSerializerOptions()
);
Assert.NotNull(baseContract);
Assert.Equal(1, baseContract.BaseProperty);
Assert.IsType(targetType, baseContract);
if (baseContract is LeafContractWithCustomDelimiter leafContract)
{
Assert.Equal(2, leafContract.LeafProperty);
}
}
[Theory]
[MemberData(nameof(LeafContractData))]
public Task SerializeBaseContractWorks_withMySecondJsonSerializerContext(int testId, BaseContractWithCustomDelimiter contract)
{
var json = JsonSerializer.Serialize(
contract,
CreateMySecondJsonSerializerOptions()
);
var settings = new VerifySettings();
settings.UseParameters(testId);
return Verifier.VerifyJson(json, settings);
}
}