forked from json-api-dotnet/JsonApiDotNetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializationBenchmarkBase.cs
More file actions
120 lines (91 loc) · 3.85 KB
/
SerializationBenchmarkBase.cs
File metadata and controls
120 lines (91 loc) · 3.85 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System.Text.Json;
using System.Text.Json.Serialization;
using Benchmarks.Tools;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;
using JsonApiDotNetCore.Serialization.Response;
using Microsoft.Extensions.Logging.Abstractions;
namespace Benchmarks.Serialization;
public abstract class SerializationBenchmarkBase
{
protected JsonSerializerOptions SerializerWriteOptions { get; }
protected IResponseModelAdapter ResponseModelAdapter { get; }
protected IResourceGraph ResourceGraph { get; }
protected SerializationBenchmarkBase()
{
var options = new JsonApiOptions
{
SerializerOptions =
{
Converters =
{
new JsonStringEnumConverter()
}
}
};
ResourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<OutgoingResource, long>().Build();
SerializerWriteOptions = ((IJsonApiOptions)options).SerializerWriteOptions;
// ReSharper disable VirtualMemberCallInConstructor
JsonApiRequest request = CreateJsonApiRequest(ResourceGraph);
IEvaluatedIncludeCache evaluatedIncludeCache = CreateEvaluatedIncludeCache(ResourceGraph);
// ReSharper restore VirtualMemberCallInConstructor
var linkBuilder = new FakeLinkBuilder();
var metaBuilder = new NoMetaBuilder();
IQueryConstraintProvider[] constraintProviders = [];
var resourceDefinitionAccessor = new NeverResourceDefinitionAccessor();
var sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
var requestQueryStringAccessor = new FakeRequestQueryStringAccessor();
ResponseModelAdapter = new ResponseModelAdapter(request, options, linkBuilder, metaBuilder, resourceDefinitionAccessor, evaluatedIncludeCache,
sparseFieldSetCache, requestQueryStringAccessor);
}
protected abstract JsonApiRequest CreateJsonApiRequest(IResourceGraph resourceGraph);
protected abstract IEvaluatedIncludeCache CreateEvaluatedIncludeCache(IResourceGraph resourceGraph);
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class OutgoingResource : Identifiable<long>
{
[Attr]
public bool Attribute01 { get; set; }
[Attr]
public char Attribute02 { get; set; }
[Attr]
public ulong? Attribute03 { get; set; }
[Attr]
public decimal Attribute04 { get; set; }
[Attr]
public float? Attribute05 { get; set; }
[Attr]
public required string Attribute06 { get; set; }
[Attr]
public DateTime? Attribute07 { get; set; }
[Attr]
public DateTimeOffset? Attribute08 { get; set; }
[Attr]
public TimeSpan? Attribute09 { get; set; }
[Attr]
public DayOfWeek Attribute10 { get; set; }
[HasOne]
public OutgoingResource Single1 { get; set; } = null!;
[HasOne]
public OutgoingResource Single2 { get; set; } = null!;
[HasOne]
public OutgoingResource Single3 { get; set; } = null!;
[HasOne]
public OutgoingResource Single4 { get; set; } = null!;
[HasOne]
public OutgoingResource Single5 { get; set; } = null!;
[HasMany]
public ISet<OutgoingResource> Multi1 { get; set; } = null!;
[HasMany]
public ISet<OutgoingResource> Multi2 { get; set; } = null!;
[HasMany]
public ISet<OutgoingResource> Multi3 { get; set; } = null!;
[HasMany]
public ISet<OutgoingResource> Multi4 { get; set; } = null!;
[HasMany]
public ISet<OutgoingResource> Multi5 { get; set; } = null!;
}
}