@@ -28,6 +28,7 @@ public DocumentBuilder_Tests()
28
28
_options . BuildContextGraph ( builder =>
29
29
{
30
30
builder . AddResource < Model > ( "models" ) ;
31
+ builder . AddResource < RelatedModel > ( "related-models" ) ;
31
32
} ) ;
32
33
33
34
_jsonApiContextMock
@@ -59,7 +60,7 @@ public DocumentBuilder_Tests()
59
60
[ Fact ]
60
61
public void Includes_Paging_Links_By_Default ( )
61
62
{
62
- // arrange
63
+ // arrange
63
64
_pageManager . PageSize = 1 ;
64
65
_pageManager . TotalRecords = 1 ;
65
66
_pageManager . CurrentPage = 1 ;
@@ -121,6 +122,38 @@ public void Related_Links_Can_Be_Disabled()
121
122
Assert . Null ( document . Data . Relationships [ "related-model" ] . Links ) ;
122
123
}
123
124
125
+ [ Fact ]
126
+ public void Related_Data_Included_In_Relationships_By_Default ( )
127
+ {
128
+ // arrange
129
+ const string relatedTypeName = "related-models" ;
130
+ const string relationshipName = "related-model" ;
131
+ const int relatedId = 1 ;
132
+ _jsonApiContextMock
133
+ . Setup ( m => m . ContextGraph )
134
+ . Returns ( _options . ContextGraph ) ;
135
+
136
+ var documentBuilder = new DocumentBuilder ( _jsonApiContextMock . Object ) ;
137
+ var entity = new Model
138
+ {
139
+ RelatedModel = new RelatedModel
140
+ {
141
+ Id = relatedId
142
+ }
143
+ } ;
144
+
145
+ // act
146
+ var document = documentBuilder . Build ( entity ) ;
147
+
148
+ // assert
149
+ var relationshipData = document . Data . Relationships [ relationshipName ] ;
150
+ Assert . NotNull ( relationshipData ) ;
151
+ Assert . NotNull ( relationshipData . SingleData ) ;
152
+ Assert . NotNull ( relationshipData . SingleData ) ;
153
+ Assert . Equal ( relatedId . ToString ( ) , relationshipData . SingleData . Id ) ;
154
+ Assert . Equal ( relatedTypeName , relationshipData . SingleData . Type ) ;
155
+ }
156
+
124
157
[ Fact ]
125
158
public void Build_Can_Build_Arrays ( )
126
159
{
@@ -145,12 +178,12 @@ public void Build_Can_Build_CustomIEnumerables()
145
178
146
179
147
180
[ Theory ]
148
- [ InlineData ( null , null , true ) ]
149
- [ InlineData ( false , null , true ) ]
150
- [ InlineData ( true , null , false ) ]
151
- [ InlineData ( null , "foo" , true ) ]
152
- [ InlineData ( false , "foo" , true ) ]
153
- [ InlineData ( true , "foo" , true ) ]
181
+ [ InlineData ( null , null , true ) ]
182
+ [ InlineData ( false , null , true ) ]
183
+ [ InlineData ( true , null , false ) ]
184
+ [ InlineData ( null , "foo" , true ) ]
185
+ [ InlineData ( false , "foo" , true ) ]
186
+ [ InlineData ( true , "foo" , true ) ]
154
187
public void DocumentBuilderOptions ( bool ? omitNullValuedAttributes ,
155
188
string attributeValue ,
156
189
bool resultContainsAttribute )
@@ -162,7 +195,7 @@ public void DocumentBuilderOptions(bool? omitNullValuedAttributes,
162
195
. Returns ( new DocumentBuilderOptions ( omitNullValuedAttributes . Value ) ) ;
163
196
}
164
197
var documentBuilder = new DocumentBuilder ( _jsonApiContextMock . Object , null , omitNullValuedAttributes . HasValue ? documentBuilderBehaviourMock . Object : null ) ;
165
- var document = documentBuilder . Build ( new Model ( ) { StringProperty = attributeValue } ) ;
198
+ var document = documentBuilder . Build ( new Model ( ) { StringProperty = attributeValue } ) ;
166
199
167
200
Assert . Equal ( resultContainsAttribute , document . Data . Attributes . ContainsKey ( "StringProperty" ) ) ;
168
201
}
0 commit comments