Skip to content

Commit 425c4df

Browse files
author
Bart Koelman
committed
Removed base class: I can't think of a reason why we should have an intermediate base class for these tests
1 parent 562214a commit 425c4df

File tree

3 files changed

+55
-77
lines changed

3 files changed

+55
-77
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/ControllerActionResults/ActionResultTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
4747
public async Task Converts_empty_ActionResult_to_error_collection()
4848
{
4949
// Arrange
50-
string route = $"/toothbrushes/{BaseToothbrushesController.EmptyActionResultId}";
50+
string route = $"/toothbrushes/{ToothbrushesController.EmptyActionResultId}";
5151

5252
// Act
5353
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
@@ -67,7 +67,7 @@ public async Task Converts_empty_ActionResult_to_error_collection()
6767
public async Task Converts_ActionResult_with_error_object_to_error_collection()
6868
{
6969
// Arrange
70-
string route = $"/toothbrushes/{BaseToothbrushesController.ActionResultWithErrorObjectId}";
70+
string route = $"/toothbrushes/{ToothbrushesController.ActionResultWithErrorObjectId}";
7171

7272
// Act
7373
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
@@ -87,7 +87,7 @@ public async Task Converts_ActionResult_with_error_object_to_error_collection()
8787
public async Task Cannot_convert_ActionResult_with_string_parameter_to_error_collection()
8888
{
8989
// Arrange
90-
string route = $"/toothbrushes/{BaseToothbrushesController.ActionResultWithStringParameter}";
90+
string route = $"/toothbrushes/{ToothbrushesController.ActionResultWithStringParameter}";
9191

9292
// Act
9393
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
@@ -107,7 +107,7 @@ public async Task Cannot_convert_ActionResult_with_string_parameter_to_error_col
107107
public async Task Converts_ObjectResult_with_error_object_to_error_collection()
108108
{
109109
// Arrange
110-
string route = $"/toothbrushes/{BaseToothbrushesController.ObjectResultWithErrorObjectId}";
110+
string route = $"/toothbrushes/{ToothbrushesController.ObjectResultWithErrorObjectId}";
111111

112112
// Act
113113
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
@@ -127,7 +127,7 @@ public async Task Converts_ObjectResult_with_error_object_to_error_collection()
127127
public async Task Converts_ObjectResult_with_error_objects_to_error_collection()
128128
{
129129
// Arrange
130-
string route = $"/toothbrushes/{BaseToothbrushesController.ObjectResultWithErrorCollectionId}";
130+
string route = $"/toothbrushes/{ToothbrushesController.ObjectResultWithErrorCollectionId}";
131131

132132
// Act
133133
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);

test/JsonApiDotNetCoreTests/IntegrationTests/ControllerActionResults/BaseToothbrushesController.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,70 @@
1+
using System.Net;
12
using System.Threading;
23
using System.Threading.Tasks;
34
using JsonApiDotNetCore.Configuration;
5+
using JsonApiDotNetCore.Controllers;
6+
using JsonApiDotNetCore.Serialization.Objects;
47
using JsonApiDotNetCore.Services;
58
using Microsoft.AspNetCore.Mvc;
69
using Microsoft.Extensions.Logging;
710

811
namespace JsonApiDotNetCoreTests.IntegrationTests.ControllerActionResults
912
{
10-
public sealed class ToothbrushesController : BaseToothbrushesController
13+
public sealed class ToothbrushesController : BaseJsonApiController<Toothbrush, int>
1114
{
15+
internal const int EmptyActionResultId = 11111111;
16+
internal const int ActionResultWithErrorObjectId = 22222222;
17+
internal const int ActionResultWithStringParameter = 33333333;
18+
internal const int ObjectResultWithErrorObjectId = 44444444;
19+
internal const int ObjectResultWithErrorCollectionId = 55555555;
20+
1221
public ToothbrushesController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Toothbrush> resourceService)
1322
: base(options, loggerFactory, resourceService)
1423
{
1524
}
1625

1726
[HttpGet("{id}")]
18-
public override Task<IActionResult> GetAsync(int id, CancellationToken cancellationToken)
27+
public override async Task<IActionResult> GetAsync(int id, CancellationToken cancellationToken)
1928
{
20-
return base.GetAsync(id, cancellationToken);
29+
if (id == EmptyActionResultId)
30+
{
31+
return NotFound();
32+
}
33+
34+
if (id == ActionResultWithErrorObjectId)
35+
{
36+
return NotFound(new ErrorObject(HttpStatusCode.NotFound)
37+
{
38+
Title = "No toothbrush with that ID exists."
39+
});
40+
}
41+
42+
if (id == ActionResultWithStringParameter)
43+
{
44+
return Conflict("Something went wrong.");
45+
}
46+
47+
if (id == ObjectResultWithErrorObjectId)
48+
{
49+
return Error(new ErrorObject(HttpStatusCode.BadGateway));
50+
}
51+
52+
if (id == ObjectResultWithErrorCollectionId)
53+
{
54+
var errors = new[]
55+
{
56+
new ErrorObject(HttpStatusCode.PreconditionFailed),
57+
new ErrorObject(HttpStatusCode.Unauthorized),
58+
new ErrorObject(HttpStatusCode.ExpectationFailed)
59+
{
60+
Title = "This is not a very great request."
61+
}
62+
};
63+
64+
return Error(errors);
65+
}
66+
67+
return await base.GetAsync(id, cancellationToken);
2168
}
2269
}
2370
}

0 commit comments

Comments
 (0)