File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public DocumentBuilder_Tests()
2828 _options . BuildContextGraph ( builder =>
2929 {
3030 builder . AddResource < Model > ( "models" ) ;
31+ builder . AddResource < RelatedModel > ( "related-models" ) ;
3132 } ) ;
3233
3334 _jsonApiContextMock
@@ -121,6 +122,37 @@ public void Related_Links_Can_Be_Disabled()
121122 Assert . Null ( document . Data . Relationships [ "related-model" ] . Links ) ;
122123 }
123124
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+
124156 [ Fact ]
125157 public void Build_Can_Build_Arrays ( )
126158 {
You can’t perform that action at this time.
0 commit comments