Skip to content

Commit 8d28c80

Browse files
committed
test(inclusion): multiple relationships can be included
1 parent 8b366d9 commit 8d28c80

File tree

1 file changed

+44
-0
lines changed
  • test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests

1 file changed

+44
-0
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Included.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Included
2323
private AppDbContext _context;
2424
private Faker<Person> _personFaker;
2525
private Faker<TodoItem> _todoItemFaker;
26+
private Faker<TodoItemCollection> _todoItemCollectionFaker;
2627

2728
public Included(DocsFixture<Startup, JsonDocWriter> fixture)
2829
{
@@ -35,6 +36,9 @@ public Included(DocsFixture<Startup, JsonDocWriter> fixture)
3536
_todoItemFaker = new Faker<TodoItem>()
3637
.RuleFor(t => t.Description, f => f.Lorem.Sentence())
3738
.RuleFor(t => t.Ordinal, f => f.Random.Number());
39+
40+
_todoItemCollectionFaker = new Faker<TodoItemCollection>()
41+
.RuleFor(t => t.Name, f => f.Company.CatchPhrase());
3842
}
3943

4044
[Fact]
@@ -163,5 +167,45 @@ public async Task GET_ById_Included_Contains_SideloadedData_ForOneToMany()
163167
Assert.NotEmpty(document.Included);
164168
Assert.Equal(numberOfTodoItems, document.Included.Count);
165169
}
170+
171+
[Fact]
172+
public async Task Can_Include_MultipleRelationships()
173+
{
174+
// arrange
175+
var person = _personFaker.Generate();
176+
var todoItemCollection = _todoItemCollectionFaker.Generate();
177+
todoItemCollection.Owner = person;
178+
179+
const int numberOfTodoItems = 5;
180+
for (var i = 0; i < numberOfTodoItems; i++)
181+
{
182+
var todoItem = _todoItemFaker.Generate();
183+
todoItem.Owner = person;
184+
todoItem.Collection = todoItemCollection;
185+
_context.TodoItems.Add(todoItem);
186+
_context.SaveChanges();
187+
}
188+
189+
var builder = new WebHostBuilder()
190+
.UseStartup<Startup>();
191+
192+
var httpMethod = new HttpMethod("GET");
193+
194+
var route = $"/api/v1/people/{person.Id}?include=todo-items,todo-item-collections";
195+
196+
var server = new TestServer(builder);
197+
var client = server.CreateClient();
198+
var request = new HttpRequestMessage(httpMethod, route);
199+
200+
// act
201+
var response = await client.SendAsync(request);
202+
var responseString = await response.Content.ReadAsStringAsync();
203+
var document = JsonConvert.DeserializeObject<Document>(responseString);
204+
205+
// assert
206+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
207+
Assert.NotEmpty(document.Included);
208+
Assert.Equal(numberOfTodoItems + 1, document.Included.Count);
209+
}
166210
}
167211
}

0 commit comments

Comments
 (0)