-
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.
- Loading branch information
1 parent
141d972
commit 614d889
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
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 | ||
var client = 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; | ||
}); | ||
} | ||
}.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); | ||
} | ||
} | ||
} |