Skip to content

Commit f163fb4

Browse files
committed
test(todo-items): verify relationships can be included
1 parent bcf8fbb commit f163fb4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/JsonApiDotNetCoreExampleTests/IntegrationTests/TodoItemsControllerTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public async Task Can_Get_TodoItems()
6464
Assert.True(deserializedBody.Count <= expectedEntitiesPerPage);
6565
}
6666

67+
6768
[Fact]
6869
public async Task Can_Paginate_TodoItems()
6970
{
@@ -153,6 +154,37 @@ public async Task Can_Get_TodoItem_ById()
153154
Assert.Equal(todoItem.Ordinal, deserializedBody.Ordinal);
154155
}
155156

157+
[Fact]
158+
public async Task Can_Get_TodoItem_WithOwner()
159+
{
160+
// Arrange
161+
var person = new Person();
162+
var todoItem = _todoItemFaker.Generate();
163+
todoItem.Owner = person;
164+
_context.TodoItems.Add(todoItem);
165+
_context.SaveChanges();
166+
167+
var httpMethod = new HttpMethod("GET");
168+
var route = $"/api/v1/todo-items/{todoItem.Id}?include=owner";
169+
170+
var description = new RequestProperties("Get TodoItem By Id", new Dictionary<string, string> {
171+
{ "/todo-items/{id}", "TodoItem Id" },
172+
{ "?include={relationship}", "Included Relationship" }
173+
});
174+
175+
// Act
176+
var response = await _fixture.MakeRequest<TodoItem>(description, httpMethod, route);
177+
var body = await response.Content.ReadAsStringAsync();
178+
var deserializedBody = (TodoItem)JsonApiDeSerializer.Deserialize(body, _jsonApiContext);
179+
180+
// Assert
181+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
182+
Assert.Equal(person.Id, deserializedBody.OwnerId);
183+
Assert.Equal(todoItem.Id, deserializedBody.Id);
184+
Assert.Equal(todoItem.Description, deserializedBody.Description);
185+
Assert.Equal(todoItem.Ordinal, deserializedBody.Ordinal);
186+
}
187+
156188
[Fact]
157189
public async Task Can_Post_TodoItem()
158190
{

0 commit comments

Comments
 (0)