Skip to content

Commit 115703f

Browse files
Bart Koelmanmaurei
Bart Koelman
andauthored
Refactor tests (#941)
* Refactored tests for HttpReadOnly/NoHttpPost/Patch/Delete controller attributes * Refactored tests for casing convention * Refactored tests for custom exception handler * Refactored tests for nulls/default query string parameters; removed some duplication and fixed an equality bug. * Refactored tests for DisableQueryStringAttribute * Refactored tests for resource injection * Fixed assertions on DateTime/DateTimeOffset in tests * Refactored tests for non-json:api controllers * Refactored tests for ActionResult usage * Refactored tests for custom routes * Refactored tests for links rendering * Refactored tests for exception handling in serializer * Refactored tests for serialization * Refactored tests for resource hooks * General cleanup * Extracted test building blocks in shared project * Auto-adjust namespaces * Refactored tests for service discovery * Refactored tests for no EF Core * Renamed IntegrationTestContext to ExampleIntegrationTestContext because it has a strong dependency on EmptyStartup from JsonApiDotNetCoreExamples project. * Adjusted test names for ModelStateValidationTests * Adjusted test names for pagination * Adjusted test names for meta * Fixed broken tests; simpler bootstrap setup * Adjusted test names for hooks * Enable concurrent testruns (makes running all tests 60% faster) * Removed unused using * Cleanup tests for hooks * Cleanup example models * Revert "Enable concurrent testruns (makes running all tests 60% faster)" to investigate why cibuild hangs This reverts commit d3ff09a. * fixed failing testrunner * Enable running integration tests in parallel * test * Disable duplicate builds * Revert "Disable duplicate builds" This reverts commit 38c127a. * Addressed review feedback * Moved integration tests for filter/include/page/sort/fields into QueryStrings subfolder and auto-adjusted namespaces. * Move types into separate files * Moved unit tests for query string parameters into ExampleTests project, so they can share private models with integration tests for query strings. They are likely to evolve simultaneously, so I prefer not to make a copy of them. Renamed Blog to LegacyBlog in preparation for refactoring to make query string tests run against private models. LegacyBlog is going away at the end. * Refactored query string integration tests to use private models. Changes: LegacyBlog -> Blog Title -> Title CompanyName -> PlatformName HasMany Articles -> Posts HasOne Owner -> Owner Article -> BlogPost Caption -> Caption Url -> Url HasOne Author -> Author + HasOne Reviewer HasManyThrough Tags -> Labels HasMany Revisions -> Comments HasOne Blog -> Parent Tag -> Label Name -> Name Color -> Color HasManyThrough Articles -> Posts Revision -> Comment + Text PublishTime -> CreatedAt HasOne Author -> Author HasOne Article -> Parent Author -> WebAccount FirstName/LastName -> UserName/DisplayName + Password DateOfBirth -> DateOfBirth BusinessEmail -> EmailAddress LivingAddress -> Preferences HasMany Articles -> Posts Address -> AccountPreferences + UseDarkTheme * Refactored query string unit tests to use private models. * Cleanup models in example project * Addressed review feedback * Rename * Refactored tests for logging * Refactored tests for meta * renamed ResourceHook tests and fixed a few wrong assertions Co-authored-by: maurei <[email protected]>
1 parent 569eebd commit 115703f

File tree

281 files changed

+9170
-7939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+9170
-7939
lines changed

JsonApiDotNetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiDbContextExample", "sr
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiDbContextTests", "test\MultiDbContextTests\MultiDbContextTests.csproj", "{EC3202C6-1D4C-4B14-A599-B9D3F27FE3BA}"
4747
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestBuildingBlocks", "test\TestBuildingBlocks\TestBuildingBlocks.csproj", "{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}"
49+
EndProject
4850
Global
4951
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5052
Debug|Any CPU = Debug|Any CPU
@@ -199,6 +201,18 @@ Global
199201
{EC3202C6-1D4C-4B14-A599-B9D3F27FE3BA}.Release|x64.Build.0 = Release|Any CPU
200202
{EC3202C6-1D4C-4B14-A599-B9D3F27FE3BA}.Release|x86.ActiveCfg = Release|Any CPU
201203
{EC3202C6-1D4C-4B14-A599-B9D3F27FE3BA}.Release|x86.Build.0 = Release|Any CPU
204+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
205+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|Any CPU.Build.0 = Debug|Any CPU
206+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|x64.ActiveCfg = Debug|Any CPU
207+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|x64.Build.0 = Debug|Any CPU
208+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|x86.ActiveCfg = Debug|Any CPU
209+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Debug|x86.Build.0 = Debug|Any CPU
210+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|Any CPU.ActiveCfg = Release|Any CPU
211+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|Any CPU.Build.0 = Release|Any CPU
212+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|x64.ActiveCfg = Release|Any CPU
213+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|x64.Build.0 = Release|Any CPU
214+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|x86.ActiveCfg = Release|Any CPU
215+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21}.Release|x86.Build.0 = Release|Any CPU
202216
EndGlobalSection
203217
GlobalSection(SolutionProperties) = preSolution
204218
HideSolutionNode = FALSE
@@ -216,6 +230,7 @@ Global
216230
{21D27239-138D-4604-8E49-DCBE41BCE4C8} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
217231
{6CAFDDBE-00AB-4784-801B-AB419C3C3A26} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
218232
{EC3202C6-1D4C-4B14-A599-B9D3F27FE3BA} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
233+
{210FD61E-FF5D-4CEE-8E0D-C739ECCCBA21} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
219234
EndGlobalSection
220235
GlobalSection(ExtensibilityGlobals) = postSolution
221236
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

docs/usage/extensibility/controllers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The next option is to use the ActionFilter attributes that ship with the library
7474
- `HttpReadOnly`: all of the above
7575

7676
Not only does this reduce boilerplate, but it also provides a more meaningful HTTP response code.
77-
An attempt to use one blacklisted methods will result in a HTTP 405 Method Not Allowed response.
77+
An attempt to use one of the blacklisted methods will result in a HTTP 405 Method Not Allowed response.
7878

7979
```c#
8080
[HttpReadOnly]

src/Examples/GettingStarted/Data/SampleDbContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public SampleDbContext(DbContextOptions<SampleDbContext> options)
1212
{
1313
}
1414

15-
protected override void OnModelCreating(ModelBuilder modelBuilder)
15+
protected override void OnModelCreating(ModelBuilder builder)
1616
{
17-
modelBuilder.Entity<Person>();
17+
builder.Entity<Person>();
1818
}
1919
}
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace JsonApiDotNetCoreExample.Controllers
6+
{
7+
[Route("[controller]")]
8+
public sealed class NonJsonApiController : ControllerBase
9+
{
10+
[HttpGet]
11+
public IActionResult Get()
12+
{
13+
var result = new[] {"Welcome!"};
14+
return Ok(result);
15+
}
16+
17+
[HttpPost]
18+
public async Task<IActionResult> PostAsync()
19+
{
20+
string name = await new StreamReader(Request.Body).ReadToEndAsync();
21+
22+
if (string.IsNullOrEmpty(name))
23+
{
24+
return BadRequest("Please send your name.");
25+
}
26+
27+
var result = "Hello, " + name;
28+
return Ok(result);
29+
}
30+
31+
[HttpPut]
32+
public IActionResult Put([FromBody] string name)
33+
{
34+
var result = "Hi, " + name;
35+
return Ok(result);
36+
}
37+
38+
[HttpPatch]
39+
public IActionResult Patch(string name)
40+
{
41+
var result = "Good day, " + name;
42+
return Ok(result);
43+
}
44+
45+
[HttpDelete]
46+
public IActionResult Delete()
47+
{
48+
return Ok("Bye.");
49+
}
50+
}
51+
}

src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JsonApiDotNetCoreExample.Controllers
88
{
99
public sealed class PassportsController : JsonApiController<Passport>
1010
{
11-
public PassportsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Passport, int> resourceService)
11+
public PassportsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Passport> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs

-18
This file was deleted.

src/Examples/JsonApiDotNetCoreExample/Controllers/Restricted/ReadOnlyController.cs

-106
This file was deleted.

src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs

-20
This file was deleted.

src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs

-35
This file was deleted.

src/Examples/JsonApiDotNetCoreExample/Controllers/ThrowingResourcesController.cs

-18
This file was deleted.

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs

-44
This file was deleted.

0 commit comments

Comments
 (0)