|
1 | | -using System.Collections.Immutable; |
2 | 1 | using System.Text.Json;
|
3 | 2 | using System.Text.Json.Serialization;
|
| 3 | +using Benchmarks.Tools; |
4 | 4 | using JetBrains.Annotations;
|
5 | 5 | using JsonApiDotNetCore.Configuration;
|
6 | 6 | using JsonApiDotNetCore.Middleware;
|
7 | 7 | using JsonApiDotNetCore.Queries;
|
8 | | -using JsonApiDotNetCore.Queries.Expressions; |
9 | 8 | using JsonApiDotNetCore.Queries.Internal;
|
10 | | -using JsonApiDotNetCore.QueryStrings; |
11 | 9 | using JsonApiDotNetCore.Resources;
|
12 | 10 | using JsonApiDotNetCore.Resources.Annotations;
|
13 | | -using JsonApiDotNetCore.Serialization.Objects; |
14 | 11 | using JsonApiDotNetCore.Serialization.Response;
|
15 | | -using Microsoft.AspNetCore.Http; |
16 | 12 | using Microsoft.Extensions.Logging.Abstractions;
|
17 | 13 |
|
18 | 14 | namespace Benchmarks.Serialization;
|
@@ -45,9 +41,9 @@ protected SerializationBenchmarkBase()
|
45 | 41 | // ReSharper restore VirtualMemberCallInConstructor
|
46 | 42 |
|
47 | 43 | var linkBuilder = new FakeLinkBuilder();
|
48 | | - var metaBuilder = new FakeMetaBuilder(); |
| 44 | + var metaBuilder = new NoMetaBuilder(); |
49 | 45 | IQueryConstraintProvider[] constraintProviders = Array.Empty<IQueryConstraintProvider>();
|
50 | | - var resourceDefinitionAccessor = new FakeResourceDefinitionAccessor(); |
| 46 | + var resourceDefinitionAccessor = new NeverResourceDefinitionAccessor(); |
51 | 47 | var sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
|
52 | 48 | var requestQueryStringAccessor = new FakeRequestQueryStringAccessor();
|
53 | 49 |
|
@@ -122,141 +118,4 @@ public sealed class OutgoingResource : Identifiable<int>
|
122 | 118 | [HasMany]
|
123 | 119 | public ISet<OutgoingResource> Multi5 { get; set; } = null!;
|
124 | 120 | }
|
125 | | - |
126 | | - private sealed class FakeResourceDefinitionAccessor : IResourceDefinitionAccessor |
127 | | - { |
128 | | - public IImmutableSet<IncludeElementExpression> OnApplyIncludes(ResourceType resourceType, IImmutableSet<IncludeElementExpression> existingIncludes) |
129 | | - { |
130 | | - return existingIncludes; |
131 | | - } |
132 | | - |
133 | | - public FilterExpression? OnApplyFilter(ResourceType resourceType, FilterExpression? existingFilter) |
134 | | - { |
135 | | - return existingFilter; |
136 | | - } |
137 | | - |
138 | | - public SortExpression? OnApplySort(ResourceType resourceType, SortExpression? existingSort) |
139 | | - { |
140 | | - return existingSort; |
141 | | - } |
142 | | - |
143 | | - public PaginationExpression? OnApplyPagination(ResourceType resourceType, PaginationExpression? existingPagination) |
144 | | - { |
145 | | - return existingPagination; |
146 | | - } |
147 | | - |
148 | | - public SparseFieldSetExpression? OnApplySparseFieldSet(ResourceType resourceType, SparseFieldSetExpression? existingSparseFieldSet) |
149 | | - { |
150 | | - return existingSparseFieldSet; |
151 | | - } |
152 | | - |
153 | | - public object? GetQueryableHandlerForQueryStringParameter(Type resourceClrType, string parameterName) |
154 | | - { |
155 | | - return null; |
156 | | - } |
157 | | - |
158 | | - public IDictionary<string, object?>? GetMeta(ResourceType resourceType, IIdentifiable resourceInstance) |
159 | | - { |
160 | | - return null; |
161 | | - } |
162 | | - |
163 | | - public Task OnPrepareWriteAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) |
164 | | - where TResource : class, IIdentifiable |
165 | | - { |
166 | | - return Task.CompletedTask; |
167 | | - } |
168 | | - |
169 | | - public Task<IIdentifiable?> OnSetToOneRelationshipAsync<TResource>(TResource leftResource, HasOneAttribute hasOneRelationship, |
170 | | - IIdentifiable? rightResourceId, WriteOperationKind writeOperation, CancellationToken cancellationToken) |
171 | | - where TResource : class, IIdentifiable |
172 | | - { |
173 | | - return Task.FromResult(rightResourceId); |
174 | | - } |
175 | | - |
176 | | - public Task OnSetToManyRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds, |
177 | | - WriteOperationKind writeOperation, CancellationToken cancellationToken) |
178 | | - where TResource : class, IIdentifiable |
179 | | - { |
180 | | - return Task.CompletedTask; |
181 | | - } |
182 | | - |
183 | | - public Task OnAddToRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds, |
184 | | - CancellationToken cancellationToken) |
185 | | - where TResource : class, IIdentifiable |
186 | | - { |
187 | | - return Task.CompletedTask; |
188 | | - } |
189 | | - |
190 | | - public Task OnRemoveFromRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds, |
191 | | - CancellationToken cancellationToken) |
192 | | - where TResource : class, IIdentifiable |
193 | | - { |
194 | | - return Task.CompletedTask; |
195 | | - } |
196 | | - |
197 | | - public Task OnWritingAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) |
198 | | - where TResource : class, IIdentifiable |
199 | | - { |
200 | | - return Task.CompletedTask; |
201 | | - } |
202 | | - |
203 | | - public Task OnWriteSucceededAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken) |
204 | | - where TResource : class, IIdentifiable |
205 | | - { |
206 | | - return Task.CompletedTask; |
207 | | - } |
208 | | - |
209 | | - public void OnDeserialize(IIdentifiable resource) |
210 | | - { |
211 | | - } |
212 | | - |
213 | | - public void OnSerialize(IIdentifiable resource) |
214 | | - { |
215 | | - } |
216 | | - } |
217 | | - |
218 | | - private sealed class FakeLinkBuilder : ILinkBuilder |
219 | | - { |
220 | | - public TopLevelLinks GetTopLevelLinks() |
221 | | - { |
222 | | - return new TopLevelLinks |
223 | | - { |
224 | | - Self = "TopLevel:Self" |
225 | | - }; |
226 | | - } |
227 | | - |
228 | | - public ResourceLinks GetResourceLinks(ResourceType resourceType, IIdentifiable resource) |
229 | | - { |
230 | | - return new ResourceLinks |
231 | | - { |
232 | | - Self = "Resource:Self" |
233 | | - }; |
234 | | - } |
235 | | - |
236 | | - public RelationshipLinks GetRelationshipLinks(RelationshipAttribute relationship, IIdentifiable leftResource) |
237 | | - { |
238 | | - return new RelationshipLinks |
239 | | - { |
240 | | - Self = "Relationship:Self", |
241 | | - Related = "Relationship:Related" |
242 | | - }; |
243 | | - } |
244 | | - } |
245 | | - |
246 | | - private sealed class FakeMetaBuilder : IMetaBuilder |
247 | | - { |
248 | | - public void Add(IDictionary<string, object?> values) |
249 | | - { |
250 | | - } |
251 | | - |
252 | | - public IDictionary<string, object?>? Build() |
253 | | - { |
254 | | - return null; |
255 | | - } |
256 | | - } |
257 | | - |
258 | | - private sealed class FakeRequestQueryStringAccessor : IRequestQueryStringAccessor |
259 | | - { |
260 | | - public IQueryCollection Query { get; } = new QueryCollection(0); |
261 | | - } |
262 | 121 | }
|
0 commit comments