Skip to content

Commit da1db37

Browse files
committed
Move OpenAPI client tests to dedicated test project, cleared up some unrequired internalsVisibleTo usage
1 parent 37a95b3 commit da1db37

File tree

12 files changed

+124
-62
lines changed

12 files changed

+124
-62
lines changed

JsonApiDotNetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonApiDotNetCore.OpenApi.C
5252
EndProject
5353
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonApiDotNetCoreExampleClient", "src\Examples\JsonApiDotNetCoreExampleClient\JsonApiDotNetCoreExampleClient.csproj", "{7FC5DFA3-6F66-4FD8-820D-81E93856F252}"
5454
EndProject
55+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiClientTests", "test\OpenApiClientTests\OpenApiClientTests.csproj", "{77F98215-3085-422E-B99D-4C404C2114CF}"
56+
EndProject
5557
Global
5658
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5759
Debug|Any CPU = Debug|Any CPU
@@ -266,6 +268,18 @@ Global
266268
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x64.Build.0 = Release|Any CPU
267269
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x86.ActiveCfg = Release|Any CPU
268270
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x86.Build.0 = Release|Any CPU
271+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
272+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
273+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|x64.ActiveCfg = Debug|Any CPU
274+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|x64.Build.0 = Debug|Any CPU
275+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|x86.ActiveCfg = Debug|Any CPU
276+
{77F98215-3085-422E-B99D-4C404C2114CF}.Debug|x86.Build.0 = Debug|Any CPU
277+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
278+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|Any CPU.Build.0 = Release|Any CPU
279+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|x64.ActiveCfg = Release|Any CPU
280+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|x64.Build.0 = Release|Any CPU
281+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|x86.ActiveCfg = Release|Any CPU
282+
{77F98215-3085-422E-B99D-4C404C2114CF}.Release|x86.Build.0 = Release|Any CPU
269283
EndGlobalSection
270284
GlobalSection(SolutionProperties) = preSolution
271285
HideSolutionNode = FALSE
@@ -288,6 +302,7 @@ Global
288302
{B693DE14-BB28-496F-AB39-B4E674ABCA80} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
289303
{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
290304
{7FC5DFA3-6F66-4FD8-820D-81E93856F252} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
305+
{77F98215-3085-422E-B99D-4C404C2114CF} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
291306
EndGlobalSection
292307
GlobalSection(ExtensibilityGlobals) = postSolution
293308
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

src/Examples/JsonApiDotNetCoreExampleClient/Program.cs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Threading.Tasks;
44
using JsonApiDotNetCoreExampleClient.GeneratedCode;
55

6-
#pragma warning disable AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException
7-
86
namespace JsonApiDotNetCoreExampleClient
97
{
108
// ReSharper disable once ClassNeverInstantiated.Global
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("OpenApiClientTests")]

src/JsonApiDotNetCore.OpenApi/AssemblyInfo.cs

-3
This file was deleted.

test/OpenApiTests/ClientLibrary/ApiResponse.cs renamed to test/OpenApiClientTests/LegacyClient/ApiResponse.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
22
using System.Threading.Tasks;
3-
using JsonApiDotNetCore;
4-
using OpenApiTests.ClientLibrary.GeneratedCode;
3+
using JsonApiDotNetCore.OpenApi.Client;
4+
using OpenApiClientTests.LegacyClient.GeneratedCode;
55

66
#pragma warning disable AV1008 // Class should not be static
77

8-
namespace OpenApiTests.ClientLibrary
8+
namespace OpenApiClientTests.LegacyClient
99
{
1010
internal static class ApiResponse
1111
{

test/OpenApiTests/ClientLibrary/ClientAttributeRegistrationLifeTimeTests.cs renamed to test/OpenApiClientTests/LegacyClient/ClientAttributeRegistrationLifeTimeTests.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
using FluentAssertions;
44
using FluentAssertions.Common;
55
using FluentAssertions.Extensions;
6-
using OpenApiTests.ClientLibrary.GeneratedCode;
6+
using OpenApiClientTests.LegacyClient.GeneratedCode;
77
using TestBuildingBlocks;
88
using Xunit;
99

1010
#pragma warning disable AV1704 // Don't include numbers in variables, parameters and type members
1111

12-
namespace OpenApiTests.ClientLibrary
12+
namespace OpenApiClientTests.LegacyClient
1313
{
1414
public sealed class ClientAttributeRegistrationLifetimeTests
1515
{
@@ -18,7 +18,7 @@ public async Task Disposed_attribute_registration_for_document_does_not_affect_r
1818
{
1919
// Arrange
2020
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
21-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
21+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
2222

2323
const string airplaneId = "XUuiP";
2424
var manufacturedAt = 1.January(2021).At(15, 23, 5, 33).ToDateTimeOffset(4.Hours());
@@ -64,7 +64,7 @@ public async Task Disposed_attribute_registration_for_document_does_not_affect_r
6464
public async Task Attribute_registration_can_be_used_for_multiple_requests()
6565
{
6666
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
67-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
67+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
6868

6969
// Arrange
7070
const string airplaneId = "XUuiP";
@@ -112,7 +112,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_
112112
{
113113
// Arrange
114114
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
115-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
115+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
116116

117117
const string airplaneId1 = "XUuiP";
118118
var manufacturedAt = 1.January(2021).At(15, 23, 5, 33).ToDateTimeOffset(4.Hours());
@@ -171,7 +171,7 @@ public async Task Request_is_unaffected_by_attribute_registration_for_different_
171171
public async Task Attribute_values_can_be_changed_after_attribute_registration()
172172
{
173173
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
174-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
174+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
175175

176176
// Arrange
177177
const string airplaneId = "XUuiP";
@@ -214,7 +214,7 @@ public async Task Attribute_values_can_be_changed_after_attribute_registration()
214214
public async Task Attribute_registration_is_unaffected_by_successive_attribute_registration_for_document_of_different_type()
215215
{
216216
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
217-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
217+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
218218

219219
// Arrange
220220
const string airplaneId1 = "XUuiP";
@@ -265,7 +265,7 @@ public async Task Attribute_registration_is_unaffected_by_successive_attribute_r
265265
public async Task Attribute_registration_is_unaffected_by_preceding_disposed_attribute_registration_for_different_document_of_same_type()
266266
{
267267
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
268-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
268+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
269269

270270
// Arrange
271271
const string airplaneId1 = "XUuiP";
@@ -327,7 +327,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att
327327
public async Task Attribute_registration_is_unaffected_by_preceding_disposed_attribute_registration_for_document_of_different_type()
328328
{
329329
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
330-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
330+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
331331

332332
// Arrange
333333
var requestDocument1 = new AirplanePostRequestDocument
@@ -386,7 +386,7 @@ public async Task Attribute_registration_is_unaffected_by_preceding_disposed_att
386386
public async Task Attribute_registration_is_unaffected_by_preceding_attribute_registration_for_different_document_of_same_type()
387387
{
388388
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
389-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
389+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
390390

391391
// Arrange
392392
const string airplaneId1 = "XUuiP";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using JsonApiDotNetCore.OpenApi.Client;
2+
3+
namespace OpenApiClientTests.LegacyClient.GeneratedCode
4+
{
5+
// ReSharper disable once MemberCanBeInternal
6+
partial interface ILegacyClient : IJsonApiClient
7+
{
8+
}
9+
}

test/OpenApiTests/ClientLibrary/GeneratedCode/OpenApiClient.cs renamed to test/OpenApiClientTests/LegacyClient/GeneratedCode/LegacyClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using JsonApiDotNetCore.OpenApi.Client;
22
using Newtonsoft.Json;
33

4-
namespace OpenApiTests.ClientLibrary.GeneratedCode
4+
namespace OpenApiClientTests.LegacyClient.GeneratedCode
55
{
6-
internal partial class OpenApiClient : JsonApiClient
6+
internal partial class LegacyClient : JsonApiClient
77
{
88
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
99
{

test/OpenApiTests/ClientLibrary/RequestTests.cs renamed to test/OpenApiClientTests/LegacyClient/RequestTests.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
using FluentAssertions.Extensions;
88
using JsonApiDotNetCore.Middleware;
99
using Microsoft.Net.Http.Headers;
10-
using OpenApiTests.ClientLibrary.GeneratedCode;
10+
using OpenApiClientTests.LegacyClient.GeneratedCode;
1111
using TestBuildingBlocks;
1212
using Xunit;
1313

1414
#pragma warning disable AV1500 // Member or local function contains too many statements
1515

16-
namespace OpenApiTests.ClientLibrary
16+
namespace OpenApiClientTests.LegacyClient
1717
{
1818
public sealed class RequestTests
1919
{
@@ -24,7 +24,7 @@ public async Task Getting_resource_collection_produces_expected_request()
2424
{
2525
// Arrange
2626
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
27-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
27+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
2828

2929
// Act
3030
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightCollectionAsync());
@@ -43,7 +43,7 @@ public async Task Getting_resource_produces_expected_request()
4343
const int flightId = 8712;
4444

4545
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
46-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
46+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
4747

4848
// Act
4949
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightAsync(flightId));
@@ -60,7 +60,7 @@ public async Task Partial_posting_resource_with_selected_relationships_produces_
6060
{
6161
// Arrange
6262
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
63-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
63+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
6464

6565
var requestDocument = new FlightPostRequestDocument
6666
{
@@ -102,7 +102,7 @@ public async Task Partial_posting_resource_produces_expected_request()
102102
{
103103
// Arrange
104104
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
105-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
105+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
106106

107107
const char euroSign = '\x20AC';
108108
const char checkMark = '\x2713';
@@ -165,7 +165,7 @@ public async Task Partial_patching_resource_produces_expected_request()
165165
var manufacturedAt = 1.January(2021).At(15, 23, 5, 33).ToDateTimeOffset(4.Hours());
166166

167167
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
168-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
168+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
169169

170170
var requestDocument = new AirplanePatchRequestDocument
171171
{
@@ -217,7 +217,7 @@ public async Task Deleting_resource_produces_expected_request()
217217
const int flightId = 8712;
218218

219219
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
220-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
220+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
221221

222222
// Act
223223
await apiClient.DeleteFlightAsync(flightId);
@@ -235,7 +235,7 @@ public async Task Getting_secondary_resource_produces_expected_request()
235235
const int flightId = 8712;
236236

237237
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
238-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
238+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
239239

240240
// Act
241241
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightOperatingAirplaneAsync(flightId));
@@ -254,7 +254,7 @@ public async Task Getting_secondary_resources_produces_expected_request()
254254
const int flightId = 8712;
255255

256256
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
257-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
257+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
258258

259259
// Act
260260
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightFlightAttendantsAsync(flightId));
@@ -273,7 +273,7 @@ public async Task Getting_ToOne_relationship_produces_expected_request()
273273
const int flightId = 8712;
274274

275275
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
276-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
276+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
277277

278278
// Act
279279
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightOperatingAirplaneRelationshipAsync(flightId));
@@ -292,7 +292,7 @@ public async Task Patching_ToOne_relationship_produces_expected_request()
292292
const int flightId = 8712;
293293

294294
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
295-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
295+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
296296

297297
var requestDocument = new ToOneAirplaneRequestData
298298
{
@@ -328,7 +328,7 @@ public async Task Getting_ToMany_relationship_produces_expected_request()
328328
const int flightId = 8712;
329329

330330
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
331-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
331+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
332332

333333
// Act
334334
_ = await ApiResponse.TranslateAsync(async () => await apiClient.GetFlightFlightAttendantsRelationshipAsync(flightId));
@@ -347,7 +347,7 @@ public async Task Posting_ToMany_relationship_produces_expected_request()
347347
const int flightId = 8712;
348348

349349
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
350-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
350+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
351351

352352
var requestDocument = new ToManyFlightAttendantRequestData
353353
{
@@ -397,7 +397,7 @@ public async Task Patching_ToMany_relationship_produces_expected_request()
397397
const int flightId = 8712;
398398

399399
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
400-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
400+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
401401

402402
var requestDocument = new ToManyFlightAttendantRequestData
403403
{
@@ -447,7 +447,7 @@ public async Task Deleting_ToMany_relationship_produces_expected_request()
447447
const int flightId = 8712;
448448

449449
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
450-
IOpenApiClient apiClient = new OpenApiClient(wrapper.HttpClient);
450+
ILegacyClient apiClient = new GeneratedCode.LegacyClient(wrapper.HttpClient);
451451

452452
var requestDocument = new ToManyFlightAttendantRequestData
453453
{

0 commit comments

Comments
 (0)