-
Notifications
You must be signed in to change notification settings - Fork 11
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 #299 from ServiceComposer/di-registration-bug
Fix: Application startup fails if ASPNETCORE_ENVIRONMENT is set to Development
- Loading branch information
Showing
4 changed files
with
98 additions
and
17 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
73 changes: 73 additions & 0 deletions
73
src/ServiceComposer.AspNetCore.Endpoints.Tests/When_validating_container_configuration.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,73 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Newtonsoft.Json.Linq; | ||
using ServiceComposer.AspNetCore.Testing; | ||
using Xunit; | ||
|
||
namespace ServiceComposer.AspNetCore.Endpoints.Tests | ||
{ | ||
public class When_validating_container_configuration | ||
{ | ||
class EmptyResponseHandler : ICompositionRequestsHandler | ||
{ | ||
[HttpGet("/empty-response/{id}")] | ||
public Task Handle(HttpRequest request) | ||
{ | ||
var vm = request.GetComposedResponseModel(); | ||
var ctx = request.GetCompositionContext(); | ||
vm.RequestId = ctx.RequestId; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Startup_should_not_fail() | ||
{ | ||
// Arrange | ||
using var webApp = new SelfContainedWebApplicationFactoryWithHost<Dummy> | ||
( | ||
configureServices: services => | ||
{ | ||
services.AddViewModelComposition(options => | ||
{ | ||
options.AssemblyScanner.Disable(); | ||
options.RegisterCompositionHandler<EmptyResponseHandler>(); | ||
}); | ||
services.AddRouting(); | ||
}, | ||
configure: app => | ||
{ | ||
app.UseRouting(); | ||
app.UseEndpoints(builder => builder.MapCompositionHandlers()); | ||
} | ||
) | ||
{ | ||
HostBuilderCustomization = builder => | ||
{ | ||
builder.UseDefaultServiceProvider(options => | ||
{ | ||
options.ValidateScopes = true; | ||
options.ValidateOnBuild = true; | ||
}); | ||
} | ||
}; | ||
|
||
var client = webApp.CreateClient(); | ||
|
||
// Act | ||
var response = await client.GetAsync("/empty-response/1"); | ||
|
||
// Assert | ||
Assert.True(response.IsSuccessStatusCode); | ||
|
||
var contentString = await response.Content.ReadAsStringAsync(); | ||
dynamic body = JObject.Parse(contentString); | ||
Assert.NotNull(body.requestId); | ||
} | ||
} | ||
} |
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