Skip to content

Commit e12d27f

Browse files
author
Bart Koelman
committed
Refactored tests for custom routes
1 parent 22738b6 commit e12d27f

File tree

10 files changed

+250
-308
lines changed

10 files changed

+250
-308
lines changed

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs

Lines changed: 0 additions & 149 deletions
This file was deleted.

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/CustomControllerTests.cs

Lines changed: 0 additions & 159 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Net;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
4+
using JsonApiDotNetCore.Serialization.Objects;
5+
using Xunit;
6+
7+
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.CustomRoutes
8+
{
9+
public sealed class ApiControllerAttributeTests
10+
: IClassFixture<IntegrationTestContext<TestableStartup<CustomRouteDbContext>, CustomRouteDbContext>>
11+
{
12+
private readonly IntegrationTestContext<TestableStartup<CustomRouteDbContext>, CustomRouteDbContext> _testContext;
13+
14+
public ApiControllerAttributeTests(IntegrationTestContext<TestableStartup<CustomRouteDbContext>, CustomRouteDbContext> testContext)
15+
{
16+
_testContext = testContext;
17+
}
18+
19+
[Fact]
20+
public async Task ApiController_attribute_transforms_NotFound_action_result_without_arguments_into_ProblemDetails()
21+
{
22+
// Arrange
23+
var route = "/world-civilians/missing";
24+
25+
// Act
26+
var (httpResponse, responseDocument) = await _testContext.ExecuteGetAsync<ErrorDocument>(route);
27+
28+
// Assert
29+
httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
30+
31+
responseDocument.Errors.Should().HaveCount(1);
32+
responseDocument.Errors[0].Links.About.Should().Be("https://tools.ietf.org/html/rfc7231#section-6.5.4");
33+
}
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using JsonApiDotNetCore.Resources;
2+
using JsonApiDotNetCore.Resources.Annotations;
3+
4+
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.CustomRoutes
5+
{
6+
public sealed class Civilian : Identifiable
7+
{
8+
[Attr]
9+
public string Name { get; set; }
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Threading.Tasks;
2+
using JsonApiDotNetCore.Configuration;
3+
using JsonApiDotNetCore.Controllers;
4+
using JsonApiDotNetCore.Controllers.Annotations;
5+
using JsonApiDotNetCore.Services;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.CustomRoutes
10+
{
11+
[ApiController]
12+
[DisableRoutingConvention, Route("world-civilians")]
13+
public sealed class CiviliansController : JsonApiController<Civilian>
14+
{
15+
public CiviliansController(IJsonApiOptions options, ILoggerFactory loggerFactory,
16+
IResourceService<Civilian> resourceService)
17+
: base(options, loggerFactory, resourceService)
18+
{
19+
}
20+
21+
[HttpGet("missing")]
22+
public async Task<IActionResult> GetMissingAsync()
23+
{
24+
await Task.Yield();
25+
return NotFound();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)