4
4
using System . Threading . Tasks ;
5
5
using FluentAssertions ;
6
6
using JsonApiDotNetCore . Configuration ;
7
- using JsonApiDotNetCore . Resources ;
8
7
using Microsoft . Extensions . DependencyInjection ;
9
8
using TestBuildingBlocks ;
10
9
using Xunit ;
@@ -13,8 +12,6 @@ namespace JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations.Mixed
13
12
{
14
13
public sealed class AtomicSerializationTests : IClassFixture < IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > >
15
14
{
16
- private const string JsonDateTimeOffsetFormatSpecifier = "yyyy-MM-ddTHH:mm:ss.FFFFFFFK" ;
17
-
18
15
private readonly IntegrationTestContext < TestableStartup < OperationsDbContext > , OperationsDbContext > _testContext ;
19
16
private readonly OperationsFakers _fakers = new ( ) ;
20
17
@@ -25,11 +22,11 @@ public AtomicSerializationTests(IntegrationTestContext<TestableStartup<Operation
25
22
testContext . UseController < OperationsController > ( ) ;
26
23
27
24
// These routes need to be registered in ASP.NET for rendering links to resource/relationship endpoints.
28
- testContext . UseController < PerformersController > ( ) ;
25
+ testContext . UseController < TextLanguagesController > ( ) ;
29
26
30
27
testContext . ConfigureServicesAfterStartup ( services =>
31
28
{
32
- services . AddScoped ( typeof ( IResourceChangeTracker < > ) , typeof ( NeverSameResourceChangeTracker < > ) ) ;
29
+ services . AddResourceDefinition < ImplicitlyChangingTextLanguageDefinition > ( ) ;
33
30
} ) ;
34
31
35
32
var options = ( JsonApiOptions ) testContext . Factory . Services . GetRequiredService < IJsonApiOptions > ( ) ;
@@ -39,32 +36,46 @@ public AtomicSerializationTests(IntegrationTestContext<TestableStartup<Operation
39
36
}
40
37
41
38
[ Fact ]
42
- public async Task Includes_version_with_ext_on_operations_endpoint ( )
39
+ public async Task Hides_data_for_void_operation ( )
43
40
{
44
41
// Arrange
45
- Performer newPerformer = _fakers . Performer . Generate ( ) ;
46
- newPerformer . Id = Unknown . TypedId . Int32 ;
42
+ Performer existingPerformer = _fakers . Performer . Generate ( ) ;
43
+
44
+ TextLanguage newLanguage = _fakers . TextLanguage . Generate ( ) ;
45
+ newLanguage . Id = Guid . NewGuid ( ) ;
47
46
48
47
await _testContext . RunOnDatabaseAsync ( async dbContext =>
49
48
{
50
- await dbContext . ClearTableAsync < Performer > ( ) ;
49
+ dbContext . Performers . Add ( existingPerformer ) ;
50
+ await dbContext . SaveChangesAsync ( ) ;
51
51
} ) ;
52
52
53
53
var requestBody = new
54
54
{
55
- atomic__operations = new [ ]
55
+ atomic__operations = new object [ ]
56
56
{
57
57
new
58
58
{
59
- op = "add " ,
59
+ op = "update " ,
60
60
data = new
61
61
{
62
62
type = "performers" ,
63
- id = newPerformer . StringId ,
63
+ id = existingPerformer . StringId ,
64
64
attributes = new
65
65
{
66
- artistName = newPerformer . ArtistName ,
67
- bornAt = newPerformer . BornAt
66
+ }
67
+ }
68
+ } ,
69
+ new
70
+ {
71
+ op = "add" ,
72
+ data = new
73
+ {
74
+ type = "textLanguages" ,
75
+ id = newLanguage . StringId ,
76
+ attributes = new
77
+ {
78
+ isoCode = newLanguage . IsoCode
68
79
}
69
80
}
70
81
}
@@ -87,16 +98,26 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
87
98
]
88
99
},
89
100
""atomic:results"": [
101
+ {
102
+ ""data"": null
103
+ },
90
104
{
91
105
""data"": {
92
- ""type"": ""performers "",
93
- ""id"": """ + newPerformer . StringId + @""",
106
+ ""type"": ""textLanguages "",
107
+ ""id"": """ + newLanguage . StringId + @""",
94
108
""attributes"": {
95
- ""artistName"": """ + newPerformer . ArtistName + @""",
96
- ""bornAt"": """ + newPerformer . BornAt . ToString ( JsonDateTimeOffsetFormatSpecifier ) + @"""
109
+ ""isoCode"": """ + newLanguage . IsoCode + @" (changed)""
110
+ },
111
+ ""relationships"": {
112
+ ""lyrics"": {
113
+ ""links"": {
114
+ ""self"": ""http://localhost/textLanguages/" + newLanguage . StringId + @"/relationships/lyrics"",
115
+ ""related"": ""http://localhost/textLanguages/" + newLanguage . StringId + @"/lyrics""
116
+ }
117
+ }
97
118
},
98
119
""links"": {
99
- ""self"": ""http://localhost/performers /" + newPerformer . StringId + @"""
120
+ ""self"": ""http://localhost/textLanguages /" + newLanguage . StringId + @"""
100
121
}
101
122
}
102
123
}
0 commit comments