|
4 | 4 | using JsonApiDotNetCore.Serialization.Objects; |
5 | 5 | using JsonApiDotNetCore.Serialization.Request.Adapters; |
6 | 6 | using JsonApiDotNetCore.Serialization.Response; |
| 7 | +using Microsoft.EntityFrameworkCore; |
7 | 8 | using Microsoft.Extensions.DependencyInjection; |
8 | 9 | using TestBuildingBlocks; |
9 | 10 | using Xunit; |
@@ -274,6 +275,54 @@ await _testContext.RunOnDatabaseAsync(async dbContext => |
274 | 275 | ValidateMetaData(store.Document.Meta); |
275 | 276 | } |
276 | 277 |
|
| 278 | + [Fact] |
| 279 | + public async Task Accepts_top_level_meta_in_atomic_update_resource_operation() |
| 280 | + { |
| 281 | + // Arrange |
| 282 | + var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>(); |
| 283 | + |
| 284 | + SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne(); |
| 285 | + |
| 286 | + await _testContext.RunOnDatabaseAsync(async dbContext => |
| 287 | + { |
| 288 | + dbContext.SupportTickets.Add(existingTicket); |
| 289 | + await dbContext.SaveChangesAsync(); |
| 290 | + }); |
| 291 | + |
| 292 | + var requestBody = new |
| 293 | + { |
| 294 | + atomic__operations = new[] |
| 295 | + { |
| 296 | + new |
| 297 | + { |
| 298 | + op = "update", |
| 299 | + data = new |
| 300 | + { |
| 301 | + type = "supportTickets", |
| 302 | + id = existingTicket.StringId, |
| 303 | + attributes = new |
| 304 | + { |
| 305 | + description = existingTicket.Description |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + }, |
| 310 | + meta = GetExampleMetaData() |
| 311 | + }; |
| 312 | + |
| 313 | + string route = $"/operations"; |
| 314 | + |
| 315 | + // Act |
| 316 | + (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody); |
| 317 | + |
| 318 | + // Assert |
| 319 | + httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent); |
| 320 | + |
| 321 | + store.Document.Should().NotBeNull(); |
| 322 | + |
| 323 | + ValidateMetaData(store.Document.Meta); |
| 324 | + } |
| 325 | + |
277 | 326 | private static Object GetExampleMetaData() |
278 | 327 | { |
279 | 328 | return new |
|
0 commit comments