-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathToothbrushesController.cs
58 lines (49 loc) · 1.74 KB
/
ToothbrushesController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Net;
using JsonApiDotNetCore.Serialization.Objects;
using Microsoft.AspNetCore.Mvc;
namespace JsonApiDotNetCoreTests.IntegrationTests.ControllerActionResults;
partial class ToothbrushesController
{
internal const int EmptyActionResultId = 11111111;
internal const int ActionResultWithErrorObjectId = 22222222;
internal const int ActionResultWithStringParameter = 33333333;
internal const int ObjectResultWithErrorObjectId = 44444444;
internal const int ObjectResultWithErrorCollectionId = 55555555;
[HttpGet("{id}")]
public override async Task<IActionResult> GetAsync(int id, CancellationToken cancellationToken)
{
if (id == EmptyActionResultId)
{
return NotFound();
}
if (id == ActionResultWithErrorObjectId)
{
return NotFound(new ErrorObject(HttpStatusCode.NotFound)
{
Title = "No toothbrush with that ID exists."
});
}
if (id == ActionResultWithStringParameter)
{
return Conflict("Something went wrong.");
}
if (id == ObjectResultWithErrorObjectId)
{
return Error(new ErrorObject(HttpStatusCode.BadGateway));
}
if (id == ObjectResultWithErrorCollectionId)
{
var errors = new[]
{
new ErrorObject(HttpStatusCode.PreconditionFailed),
new ErrorObject(HttpStatusCode.Unauthorized),
new ErrorObject(HttpStatusCode.ExpectationFailed)
{
Title = "This is not a very great request."
}
};
return Error(errors);
}
return await base.GetAsync(id, cancellationToken);
}
}