File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -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
@@ -121,6 +122,37 @@ 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 relationshipName = "related-models" ;
130
+ const int relatedId = 1 ;
131
+ _jsonApiContextMock
132
+ . Setup ( m => m . ContextGraph )
133
+ . Returns ( _options . ContextGraph ) ;
134
+
135
+ var documentBuilder = new DocumentBuilder ( _jsonApiContextMock . Object ) ;
136
+ var entity = new Model
137
+ {
138
+ RelatedModel = new RelatedModel
139
+ {
140
+ Id = relatedId
141
+ }
142
+ } ;
143
+
144
+ // act
145
+ var document = documentBuilder . Build ( entity ) ;
146
+
147
+ // assert
148
+ var relationshipData = document . Data . Relationships [ relationshipName ] ;
149
+ Assert . NotNull ( relationshipData ) ;
150
+ Assert . NotNull ( relationshipData . SingleData ) ;
151
+ Assert . NotNull ( relationshipData . SingleData ) ;
152
+ Assert . Equal ( relatedId . ToString ( ) , relationshipData . SingleData . Id ) ;
153
+ Assert . Equal ( relationshipName , relationshipData . SingleData . Type ) ;
154
+ }
155
+
124
156
[ Fact ]
125
157
public void Build_Can_Build_Arrays ( )
126
158
{
You can’t perform that action at this time.
0 commit comments