From 614d88938ff4b72071cb037e365f7b7847905046 Mon Sep 17 00:00:00 2001 From: mauroservienti Date: Thu, 1 Apr 2021 10:44:39 +0200 Subject: [PATCH] Add failing test for #297 --- ...When_validating_container_configuration.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/ServiceComposer.AspNetCore.Endpoints.Tests/When_validating_container_configuration.cs diff --git a/src/ServiceComposer.AspNetCore.Endpoints.Tests/When_validating_container_configuration.cs b/src/ServiceComposer.AspNetCore.Endpoints.Tests/When_validating_container_configuration.cs new file mode 100644 index 00000000..ce71933d --- /dev/null +++ b/src/ServiceComposer.AspNetCore.Endpoints.Tests/When_validating_container_configuration.cs @@ -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 + ( + configureServices: services => + { + services.AddViewModelComposition(options => + { + options.AssemblyScanner.Disable(); + options.RegisterCompositionHandler(); + }); + 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); + } + } +} \ No newline at end of file