@@ -26,21 +26,24 @@ public void Can_Deserialize_Complex_Types()
26
26
jsonApiContextMock . SetupAllProperties ( ) ;
27
27
jsonApiContextMock . Setup ( m => m . ContextGraph ) . Returns ( contextGraph ) ;
28
28
jsonApiContextMock . Setup ( m => m . AttributesToUpdate ) . Returns ( new Dictionary < AttrAttribute , object > ( ) ) ;
29
- jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions {
30
- JsonContractResolver = new CamelCasePropertyNamesContractResolver ( )
29
+ jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions
30
+ {
31
+ JsonContractResolver = new CamelCasePropertyNamesContractResolver ( )
31
32
} ) ;
32
33
33
34
var genericProcessorFactoryMock = new Mock < IGenericProcessorFactory > ( ) ;
34
35
35
36
var deserializer = new JsonApiDeSerializer ( jsonApiContextMock . Object , genericProcessorFactoryMock . Object ) ;
36
37
37
- var content = new Document {
38
- Data = new DocumentData {
38
+ var content = new Document
39
+ {
40
+ Data = new DocumentData
41
+ {
39
42
Type = "test-resource" ,
40
43
Id = "1" ,
41
44
Attributes = new Dictionary < string , object > {
42
- {
43
- "complex-member" , new { compoundName = "testName" }
45
+ {
46
+ "complex-member" , new { compoundName = "testName" }
44
47
}
45
48
}
46
49
}
@@ -66,23 +69,26 @@ public void Can_Deserialize_Complex_List_Types()
66
69
jsonApiContextMock . SetupAllProperties ( ) ;
67
70
jsonApiContextMock . Setup ( m => m . ContextGraph ) . Returns ( contextGraph ) ;
68
71
jsonApiContextMock . Setup ( m => m . AttributesToUpdate ) . Returns ( new Dictionary < AttrAttribute , object > ( ) ) ;
69
- jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions {
70
- JsonContractResolver = new CamelCasePropertyNamesContractResolver ( )
72
+ jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions
73
+ {
74
+ JsonContractResolver = new CamelCasePropertyNamesContractResolver ( )
71
75
} ) ;
72
76
73
77
var genericProcessorFactoryMock = new Mock < IGenericProcessorFactory > ( ) ;
74
78
75
79
var deserializer = new JsonApiDeSerializer ( jsonApiContextMock . Object , genericProcessorFactoryMock . Object ) ;
76
80
77
- var content = new Document {
78
- Data = new DocumentData {
81
+ var content = new Document
82
+ {
83
+ Data = new DocumentData
84
+ {
79
85
Type = "test-resource" ,
80
86
Id = "1" ,
81
87
Attributes = new Dictionary < string , object > {
82
- {
83
- "complex-members" , new [ ] {
88
+ {
89
+ "complex-members" , new [ ] {
84
90
new { compoundName = "testName" }
85
- }
91
+ }
86
92
}
87
93
}
88
94
}
@@ -110,20 +116,23 @@ public void Can_Deserialize_Complex_Types_With_Dasherized_Attrs()
110
116
jsonApiContextMock . Setup ( m => m . ContextGraph ) . Returns ( contextGraph ) ;
111
117
jsonApiContextMock . Setup ( m => m . AttributesToUpdate ) . Returns ( new Dictionary < AttrAttribute , object > ( ) ) ;
112
118
113
- jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions {
114
- JsonContractResolver = new DasherizedResolver ( ) // <---
119
+ jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions
120
+ {
121
+ JsonContractResolver = new DasherizedResolver ( ) // <---
115
122
} ) ;
116
123
117
124
var genericProcessorFactoryMock = new Mock < IGenericProcessorFactory > ( ) ;
118
125
119
126
var deserializer = new JsonApiDeSerializer ( jsonApiContextMock . Object , genericProcessorFactoryMock . Object ) ;
120
127
121
- var content = new Document {
122
- Data = new DocumentData {
128
+ var content = new Document
129
+ {
130
+ Data = new DocumentData
131
+ {
123
132
Type = "test-resource" ,
124
133
Id = "1" ,
125
134
Attributes = new Dictionary < string , object > {
126
- {
135
+ {
127
136
"complex-member" , new Dictionary < string , string > { { "compound-name" , "testName" } }
128
137
}
129
138
}
@@ -138,10 +147,65 @@ public void Can_Deserialize_Complex_Types_With_Dasherized_Attrs()
138
147
Assert . Equal ( "testName" , result . ComplexMember . CompoundName ) ;
139
148
}
140
149
150
+ [ Fact ]
151
+ public void Immutable_Attrs_Are_Not_Included_In_AttributesToUpdate ( )
152
+ {
153
+ // arrange
154
+ var contextGraphBuilder = new ContextGraphBuilder ( ) ;
155
+ contextGraphBuilder . AddResource < TestResource > ( "test-resource" ) ;
156
+ var contextGraph = contextGraphBuilder . Build ( ) ;
157
+
158
+ var attributesToUpdate = new Dictionary < AttrAttribute , object > ( ) ;
159
+
160
+ var jsonApiContextMock = new Mock < IJsonApiContext > ( ) ;
161
+ jsonApiContextMock . SetupAllProperties ( ) ;
162
+ jsonApiContextMock . Setup ( m => m . ContextGraph ) . Returns ( contextGraph ) ;
163
+ jsonApiContextMock . Setup ( m => m . AttributesToUpdate ) . Returns ( attributesToUpdate ) ;
164
+
165
+ jsonApiContextMock . Setup ( m => m . Options ) . Returns ( new JsonApiOptions
166
+ {
167
+ JsonContractResolver = new DasherizedResolver ( )
168
+ } ) ;
169
+
170
+ var genericProcessorFactoryMock = new Mock < IGenericProcessorFactory > ( ) ;
171
+
172
+ var deserializer = new JsonApiDeSerializer ( jsonApiContextMock . Object , genericProcessorFactoryMock . Object ) ;
173
+
174
+ var content = new Document
175
+ {
176
+ Data = new DocumentData
177
+ {
178
+ Type = "test-resource" ,
179
+ Id = "1" ,
180
+ Attributes = new Dictionary < string , object > {
181
+ { "complex-member" , new Dictionary < string , string > {
182
+ { "compound-name" , "testName" } }
183
+ } ,
184
+ { "immutable" , "value" }
185
+ }
186
+ }
187
+ } ;
188
+
189
+ var contentString = JsonConvert . SerializeObject ( content ) ;
190
+
191
+ // act
192
+ var result = deserializer . Deserialize < TestResource > ( contentString ) ;
193
+
194
+ // assert
195
+ Assert . NotNull ( result . ComplexMember ) ;
196
+ Assert . Equal ( 1 , attributesToUpdate . Count ) ;
197
+
198
+ foreach ( var attr in attributesToUpdate )
199
+ Assert . False ( attr . Key . IsImmutable ) ;
200
+ }
201
+
141
202
private class TestResource : Identifiable
142
203
{
143
204
[ Attr ( "complex-member" ) ]
144
205
public ComplexType ComplexMember { get ; set ; }
206
+
207
+ [ Attr ( "immutable" , isImmutable : true ) ]
208
+ public string Immutable { get ; set ; }
145
209
}
146
210
147
211
private class TestResourceWithList : Identifiable
0 commit comments