Skip to content

Commit

Permalink
Add failing test for #297
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroservienti committed Apr 1, 2021
1 parent 141d972 commit 614d889
Showing 1 changed file with 71 additions and 0 deletions.
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);
}
}
}

0 comments on commit 614d889

Please sign in to comment.