-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathResponseMetaTests.cs
65 lines (54 loc) · 2.12 KB
/
ResponseMetaTests.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
59
60
61
62
63
64
65
using System.Net;
using FluentAssertions;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Serialization.Response;
using Microsoft.Extensions.DependencyInjection;
using TestBuildingBlocks;
using Xunit;
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;
public sealed class ResponseMetaTests : IClassFixture<IntegrationTestContext<TestableStartup<MetaDbContext>, MetaDbContext>>
{
private readonly IntegrationTestContext<TestableStartup<MetaDbContext>, MetaDbContext> _testContext;
public ResponseMetaTests(IntegrationTestContext<TestableStartup<MetaDbContext>, MetaDbContext> testContext)
{
_testContext = testContext;
testContext.UseController<ProductFamiliesController>();
testContext.UseController<SupportTicketsController>();
testContext.ConfigureServices(services => services.AddSingleton<IResponseMeta, SupportResponseMeta>());
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
options.IncludeTotalResourceCount = false;
}
[Fact]
public async Task Returns_top_level_meta()
{
// Arrange
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<SupportTicket>();
});
const string route = "/supportTickets";
// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecuteGetAsync<string>(route);
// Assert
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
responseDocument.Should().BeJson("""
{
"links": {
"self": "http://localhost/supportTickets",
"first": "http://localhost/supportTickets"
},
"data": [],
"meta": {
"license": "MIT",
"projectUrl": "https://github.com/json-api-dotnet/JsonApiDotNetCore/",
"versions": [
"v4.0.0",
"v3.1.0",
"v2.5.2",
"v1.3.1"
]
}
}
""");
}
}