|
13 | 13 | using JsonApiDotNetCoreExample.Data;
|
14 | 14 | using Bogus;
|
15 | 15 | using JsonApiDotNetCoreExample.Models;
|
| 16 | +using System.Linq; |
16 | 17 |
|
17 | 18 | namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec.DocumentTests
|
18 | 19 | {
|
@@ -207,5 +208,53 @@ public async Task Can_Include_MultipleRelationships()
|
207 | 208 | Assert.NotEmpty(document.Included);
|
208 | 209 | Assert.Equal(numberOfTodoItems + 1, document.Included.Count);
|
209 | 210 | }
|
| 211 | + |
| 212 | + [Fact] |
| 213 | + public async Task Request_ToIncludeUnknownRelationship_Returns_400() |
| 214 | + { |
| 215 | + // arrange |
| 216 | + var person = _context.People.First(); |
| 217 | + |
| 218 | + var builder = new WebHostBuilder() |
| 219 | + .UseStartup<Startup>(); |
| 220 | + |
| 221 | + var httpMethod = new HttpMethod("GET"); |
| 222 | + |
| 223 | + var route = $"/api/v1/people/{person.Id}?include=non-existent-relationship"; |
| 224 | + |
| 225 | + var server = new TestServer(builder); |
| 226 | + var client = server.CreateClient(); |
| 227 | + var request = new HttpRequestMessage(httpMethod, route); |
| 228 | + |
| 229 | + // act |
| 230 | + var response = await client.SendAsync(request); |
| 231 | + |
| 232 | + // assert |
| 233 | + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); |
| 234 | + } |
| 235 | + |
| 236 | + [Fact] |
| 237 | + public async Task Request_ToIncludeRelationshipPath_Returns_400() |
| 238 | + { |
| 239 | + // arrange |
| 240 | + var person = _context.People.First(); |
| 241 | + |
| 242 | + var builder = new WebHostBuilder() |
| 243 | + .UseStartup<Startup>(); |
| 244 | + |
| 245 | + var httpMethod = new HttpMethod("GET"); |
| 246 | + |
| 247 | + var route = $"/api/v1/people/{person.Id}?include=owner.name"; |
| 248 | + |
| 249 | + var server = new TestServer(builder); |
| 250 | + var client = server.CreateClient(); |
| 251 | + var request = new HttpRequestMessage(httpMethod, route); |
| 252 | + |
| 253 | + // act |
| 254 | + var response = await client.SendAsync(request); |
| 255 | + |
| 256 | + // assert |
| 257 | + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); |
| 258 | + } |
210 | 259 | }
|
211 | 260 | }
|
0 commit comments