-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1246 from json-api-dotnet/api-controller-attribute
Better handling of [ApiController] usage
- Loading branch information
Showing
5 changed files
with
162 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/JsonApiDotNetCoreTests/IntegrationTests/CustomRoutes/ApiControllerAttributeLogTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using TestBuildingBlocks; | ||
using Xunit; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.CustomRoutes; | ||
|
||
public sealed class ApiControllerAttributeLogTests : IntegrationTestContext<TestableStartup<CustomRouteDbContext>, CustomRouteDbContext> | ||
{ | ||
private readonly FakeLoggerFactory _loggerFactory; | ||
|
||
public ApiControllerAttributeLogTests() | ||
{ | ||
UseController<CiviliansController>(); | ||
|
||
_loggerFactory = new FakeLoggerFactory(LogLevel.Warning); | ||
|
||
ConfigureLogging(options => | ||
{ | ||
options.ClearProviders(); | ||
options.AddProvider(_loggerFactory); | ||
}); | ||
|
||
ConfigureServicesBeforeStartup(services => | ||
{ | ||
services.AddSingleton(_loggerFactory); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Logs_warning_at_startup_when_ApiControllerAttribute_found() | ||
{ | ||
// Arrange | ||
_loggerFactory.Logger.Clear(); | ||
|
||
// Act | ||
_ = Factory; | ||
|
||
// Assert | ||
_loggerFactory.Logger.Messages.ShouldHaveCount(1); | ||
_loggerFactory.Logger.Messages.Single().LogLevel.Should().Be(LogLevel.Warning); | ||
|
||
_loggerFactory.Logger.Messages.Single().Text.Should().Be( | ||
$"Found JSON:API controller '{typeof(CiviliansController)}' with [ApiController]. Please remove this attribute for optimal JSON:API compliance."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters