Skip to content

Commit e0a9583

Browse files
committed
test(fetching): request for non-existant relationship ret 404
Issue #21 - 3
1 parent 2b3aecb commit e0a9583

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net;
45
using System.Net.Http;
56
using System.Threading.Tasks;
@@ -66,5 +67,33 @@ public async Task Request_UnsetRelationship_Returns_Null_DataObject()
6667

6768
context.Dispose();
6869
}
70+
71+
[Fact]
72+
public async Task Request_ForRelationshipLink_ThatDoesNotExist_Returns_404()
73+
{
74+
// arrange
75+
var context = _fixture.GetService<AppDbContext>();
76+
var todoItem = context.TodoItems.First();
77+
var todoItemId = todoItem.Id;
78+
context.TodoItems.Remove(todoItem);
79+
await context.SaveChangesAsync();
80+
81+
var builder = new WebHostBuilder()
82+
.UseStartup<Startup>();
83+
84+
var httpMethod = new HttpMethod("GET");
85+
var route = $"/api/v1/todo-items/{todoItemId}/owner";
86+
var server = new TestServer(builder);
87+
var client = server.CreateClient();
88+
var request = new HttpRequestMessage(httpMethod, route);
89+
90+
// act
91+
var response = await client.SendAsync(request);
92+
93+
// assert
94+
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
95+
96+
context.Dispose();
97+
}
6998
}
7099
}

0 commit comments

Comments
 (0)