Skip to content

Added support for bulk/batch requests (atomic:operations) #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 126 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
da055ae
Resurrected original operations code
Nov 23, 2020
91d4429
Getting the code to build and tests to succeed.
Nov 23, 2020
f21e317
Removed option to enable the atomic-operations feature. It is implici…
Nov 24, 2020
6d8aa36
Renames and namespace moves
Nov 24, 2020
88f5eee
Change patch to post
Nov 25, 2020
0d616c6
Separate controller layers, align naming in deserializer, move reques…
Nov 25, 2020
4dc7e4a
Updated json document structure, based on atomic:operations spec
Nov 25, 2020
ee52719
Simplified processor resolver
Nov 25, 2020
fc00620
Converted atomic:operations Add tests
Nov 26, 2020
9d534e4
Converted atomic:operations Remove tests
Nov 26, 2020
de2c3d3
Converted atomic:operations Update tests
Nov 26, 2020
07cb792
Converted rollback test and removed separate projects
Nov 26, 2020
f191bc0
Rename plus overridable ToString
Nov 26, 2020
8fcedb6
Added local ID tracking
Nov 26, 2020
b4be29c
Added support for atomic:operations extension in ContentType header
Nov 27, 2020
9b6e6b8
Added support for atomic:operations extension in Accept headers
Nov 27, 2020
7b5a0d2
Moved existing local-id tests
Nov 30, 2020
a7c06c6
Improvements on local ID usage (see tests).
Nov 30, 2020
31c3efa
Block query string parameters on atomic:operations request
Dec 1, 2020
21c4d30
Fixed broken tests
Dec 1, 2020
aa5e454
Return NoContent when data for all operations is null
Dec 1, 2020
01e113c
Corrected example
Dec 1, 2020
6b74ded
Fail on local ID usage outside of operations
Dec 1, 2020
e0f6482
Added ModelState validation
Dec 1, 2020
0aafb84
Fixes in handling add-to and remove-from to-many relationships
Dec 2, 2020
4d4e5d7
Run model state validation for all operations up-front
Dec 2, 2020
e5237df
Fix broken test after rebase
Dec 15, 2020
56b8a84
Added tests for delete resource
Dec 15, 2020
cd51071
File rename
Dec 16, 2020
2efc6f9
added tests for Remove from to-many
Dec 16, 2020
ce0cd4c
added tests for Add to to-many
Dec 17, 2020
204b320
added tests for Replace to-many
Dec 17, 2020
36c4023
added tests for Replace to-one
Dec 17, 2020
f72d7b2
reorder tests
Dec 17, 2020
4be8af6
fail on href usage
Dec 17, 2020
87d2bda
Fail when using both 'id' and 'lid'
Dec 17, 2020
fca7192
Tests for create resource
Dec 18, 2020
0dfb323
Pushed down all operation serialization/deserialization into the Seri…
Jan 5, 2021
175215c
Fixed skipped tests
Jan 7, 2021
de2acf2
Added test for read-only attribute
Jan 7, 2021
626d58b
Added operation tests for Create resource with client-generated ID
Jan 7, 2021
f4a3447
Reordered tests
Jan 7, 2021
0b824e3
Added operation tests for Create resource with ToOne relationship
Jan 7, 2021
6e1b9d5
Added operation tests for Create resource with ToMany relationship
Jan 7, 2021
a090abb
Added tests for unknown ID in ref
Jan 7, 2021
fc63438
Reordered tests
Jan 7, 2021
5167fdc
Fixed: exclude attributes without AttrCapabilities.AllowView flag in …
Jan 12, 2021
10b8c1b
Added operation tests for Update resource
Jan 13, 2021
7bbe3aa
Cleanup tests
Jan 13, 2021
5ce2218
Added tests for error cases
Jan 13, 2021
1b00d34
Fixed: Both id and lid in create resource operation should not be all…
Jan 13, 2021
6dc7e43
Added option: MaximumOperationsPerRequest
Jan 13, 2021
de58379
Added operation tests for Update resource with to-one/to-many relatio…
Jan 14, 2021
b43fe8e
Fixed links rendering in operation responses
Jan 15, 2021
cf01dba
Separated transaction support from operations processing.
Jan 15, 2021
82d3dee
Automatic routing setup for operations controller
Jan 18, 2021
e6baf42
Fixed: top-level meta in atomic:operation responses
Jan 18, 2021
1d6065b
Fixed: resource-level meta in atomic:operation responses
Jan 19, 2021
79af8f1
Renames
Jan 19, 2021
bb7c7c7
Fixed: duplicate calls to ResourceDefinition.GetMeta
Jan 19, 2021
24a4ccc
Fixes resource definition callbacks for sparse fieldsets
Jan 19, 2021
25ba724
Fixed broken build after rebase master
Jan 20, 2021
ca14023
Reduce diff with master branch
Jan 20, 2021
4291a90
Renames
Jan 20, 2021
a5f191e
Simplified processors
Jan 20, 2021
b95cc88
Removed dependency on GenericServiceFactory
Jan 20, 2021
9119575
Corrected error message
Jan 20, 2021
b8fec24
API review
Jan 20, 2021
06b3604
More API review
Jan 21, 2021
aa8084c
Cleanup RequestDeserializer
Jan 21, 2021
7954882
Small name tweaks
Jan 22, 2021
3f3667c
API shape tweaks
Jan 22, 2021
42c1ede
Validate local ID usage upfront
Jan 22, 2021
f451fc7
Added documentation
Jan 22, 2021
f91b25b
Small tweaks
Jan 23, 2021
355083c
Refactored tests for HttpReadOnly/NoHttpPost/Patch/Delete controller …
Jan 26, 2021
90274c6
Refactored tests for casing convention
Jan 26, 2021
4bdb3e8
Refactored tests for custom exception handler
Jan 26, 2021
cbe01c2
Refactored tests for nulls/default query string parameters; removed s…
Jan 26, 2021
0c5d5e8
Refactored tests for DisableQueryStringAttribute
Jan 27, 2021
7057c89
Refactored tests for resource injection
Jan 28, 2021
8756f25
Fixed assertions on DateTime/DateTimeOffset in tests
Jan 28, 2021
44653f8
Refactored tests for non-json:api controllers
Jan 28, 2021
22738b6
Refactored tests for ActionResult usage
Jan 28, 2021
e12d27f
Refactored tests for custom routes
Feb 2, 2021
ddcd4ac
Refactored tests for links rendering
Feb 2, 2021
8b443d8
Refactored tests for exception handling in serializer
Feb 2, 2021
64e09db
Refactored tests for serialization
Feb 2, 2021
8bf0989
Refactored tests for resource hooks
Feb 2, 2021
255ed36
General cleanup
Feb 3, 2021
c7000b8
Extracted test building blocks in shared project
Feb 4, 2021
db9778e
Auto-adjust namespaces
Feb 4, 2021
d9a2ac7
Refactored tests for service discovery
Feb 4, 2021
53f8c82
Refactored tests for no EF Core
Feb 4, 2021
86bac20
Renamed IntegrationTestContext to ExampleIntegrationTestContext becau…
Feb 4, 2021
d94235d
Adjusted test names for ModelStateValidationTests
Feb 4, 2021
c8a6012
Adjusted test names for pagination
Feb 4, 2021
cb983b9
Adjusted test names for meta
Feb 4, 2021
5ad5c76
Fixed broken tests; simpler bootstrap setup
Feb 4, 2021
838a158
Adjusted test names for hooks
Feb 4, 2021
d3ff09a
Enable concurrent testruns (makes running all tests 60% faster)
Feb 4, 2021
64c5b4a
Removed unused using
Feb 4, 2021
e2a2bb0
Merge branch 'master' into refactor-tests
Feb 4, 2021
bcb7320
Cleanup tests for hooks
Feb 4, 2021
60ac856
Cleanup example models
Feb 4, 2021
de40fb7
Revert "Enable concurrent testruns (makes running all tests 60% faste…
Feb 4, 2021
bd11b52
fixed failing testrunner
Feb 4, 2021
b0ac024
Enable running integration tests in parallel
Feb 4, 2021
f343d08
test
Feb 4, 2021
38c127a
Disable duplicate builds
Feb 4, 2021
9ee3fc5
Revert "Disable duplicate builds"
Feb 4, 2021
59fccd8
Addressed review feedback
Feb 5, 2021
21b94c5
Moved integration tests for filter/include/page/sort/fields into Quer…
Feb 5, 2021
a044cf0
Move types into separate files
Feb 5, 2021
78bc0c3
Moved unit tests for query string parameters into ExampleTests projec…
Feb 5, 2021
c2da909
Refactored query string integration tests to use private models. Chan…
Feb 5, 2021
e594391
Refactored query string unit tests to use private models.
Feb 5, 2021
f2fd733
Cleanup models in example project
Feb 6, 2021
f97b81f
Addressed review feedback
Feb 8, 2021
7c7fbe4
Added option to set transaction isolation level
Feb 8, 2021
2516d2e
Rename
Feb 8, 2021
114dc07
Refactored tests for logging
Feb 8, 2021
37487cf
Refactored tests for meta
Feb 8, 2021
dd9f1fb
Merge branch 'refactor-tests' into atomic-operations-merge
Feb 8, 2021
d9df27d
Post-merge fixes
Feb 8, 2021
2d3771d
Merge branch 'master' into atomic-operations-merge
Feb 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored tests for exception handling in serializer
  • Loading branch information
Bart Koelman committed Feb 2, 2021
commit 8b443d89f0a683c6b8c4920dd923c019755ee2e4

This file was deleted.

2 changes: 0 additions & 2 deletions src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public AppDbContext(DbContextOptions<AppDbContext> options, ISystemClock systemC

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ThrowingResource>();

modelBuilder.Entity<SuperUser>().HasBaseType<User>();

modelBuilder.Entity<TodoItem>()
Expand Down
30 changes: 0 additions & 30 deletions src/Examples/JsonApiDotNetCoreExample/Models/ThrowingResource.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace JsonApiDotNetCoreExampleTests.IntegrationTests.ExceptionHandling
public sealed class ErrorDbContext : DbContext
{
public DbSet<ConsumerArticle> ConsumerArticles { get; set; }
public DbSet<ThrowingArticle> ThrowingArticles { get; set; }

public ErrorDbContext(DbContextOptions<ErrorDbContext> options)
: base(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JsonApiDotNetCore.Serialization.Objects;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Xunit;

namespace JsonApiDotNetCoreExampleTests.IntegrationTests.ExceptionHandling
Expand Down Expand Up @@ -79,7 +80,46 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Errors[0].Meta.Data["support"].Should().Be("Please contact us for info about similar articles at company@email.com.");

loggerFactory.Logger.Messages.Should().HaveCount(1);
loggerFactory.Logger.Messages.Single().LogLevel.Should().Be(LogLevel.Warning);
loggerFactory.Logger.Messages.Single().Text.Should().Contain("Article with code 'X123' is no longer available.");
}

[Fact]
public async Task Logs_and_produces_error_response_on_serialization_failure()
{
// Arrange
var loggerFactory = _testContext.Factory.Services.GetRequiredService<FakeLoggerFactory>();
loggerFactory.Logger.Clear();

var throwingArticle = new ThrowingArticle();

await _testContext.RunOnDatabaseAsync(async dbContext =>
{
dbContext.ThrowingArticles.Add(throwingArticle);
await dbContext.SaveChangesAsync();
});

var route = "/throwingArticles/" + throwingArticle.StringId;

// Act
var (httpResponse, responseDocument) = await _testContext.ExecuteGetAsync<ErrorDocument>(route);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError);

responseDocument.Errors.Should().HaveCount(1);
responseDocument.Errors[0].StatusCode.Should().Be(HttpStatusCode.InternalServerError);
responseDocument.Errors[0].Title.Should().Be("An unhandled error occurred while processing this request.");
responseDocument.Errors[0].Detail.Should().Be("Exception has been thrown by the target of an invocation.");

var stackTraceLines =
((JArray) responseDocument.Errors[0].Meta.Data["stackTrace"]).Select(token => token.Value<string>());

stackTraceLines.Should().ContainMatch("* System.InvalidOperationException: Article status could not be determined.*");

loggerFactory.Logger.Messages.Should().HaveCount(1);
loggerFactory.Logger.Messages.Single().LogLevel.Should().Be(LogLevel.Error);
loggerFactory.Logger.Messages.Single().Text.Should().Contain("Exception has been thrown by the target of an invocation.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCoreExampleTests.IntegrationTests.ExceptionHandling
{
public sealed class ThrowingArticle : Identifiable
{
[Attr]
[NotMapped]
public string Status => throw new InvalidOperationException("Article status could not be determined.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace JsonApiDotNetCoreExampleTests.IntegrationTests.ExceptionHandling
{
public sealed class ThrowingArticlesController : JsonApiController<ThrowingArticle>
{
public ThrowingArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
IResourceService<ThrowingArticle> resourceService)
: base(options, loggerFactory, resourceService)
{
}
}
}