Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Apply(HttpChain chain, IServiceContainer container)

if (registered.Count() == 1)
{
chain.Metadata.ProducesProblem(400);
chain.Metadata.ProducesValidationProblem(400);

var method =
typeof(FluentValidationHttpExecutor).GetMethod(nameof(FluentValidationHttpExecutor.ExecuteOne))!
Expand All @@ -41,7 +41,7 @@ public void Apply(HttpChain chain, IServiceContainer container)
}
else if (registered.Count() > 1)
{
chain.Metadata.ProducesProblem(400);
chain.Metadata.ProducesValidationProblem(400);

var method =
typeof(FluentValidationHttpExecutor).GetMethod(nameof(FluentValidationHttpExecutor.ExecuteMany))!
Expand Down
30 changes: 24 additions & 6 deletions src/Http/Wolverine.Http.Tests/fluent_validation_middleware.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using Alba;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Wolverine.Http.Tests.DifferentAssembly.Validation;
using WolverineWebApi.Validation;

Expand All @@ -11,6 +16,19 @@ public fluent_validation_middleware(AppFixture fixture) : base(fixture)
{
}

[Fact]
public void adds_problem_validation_to_open_api_metadata()
{
var endpoints = Host.Services.GetServices<EndpointDataSource>().SelectMany(x => x.Endpoints).OfType<RouteEndpoint>()
.ToList();

var endpoint = endpoints.Single(x => x.RoutePattern.RawText == "/validate/customer");

var produces = endpoint.Metadata.OfType<IProducesResponseTypeMetadata>().Single(x => x.Type == typeof(HttpValidationProblemDetails));
produces.StatusCode.ShouldBe(400);
produces.ContentTypes.Single().ShouldBe("application/problem+json");
}

[Fact]
public async Task one_validator_happy_path()
{
Expand All @@ -36,9 +54,9 @@ public async Task one_validator_sad_path()
x.StatusCodeShouldBe(400);
});

// Just proving that we have ProblemDetails content
// Just proving that we have HttpValidationProblemDetails content
// in the request
var problems = results.ReadAsJson<ProblemDetails>();
var problems = results.ReadAsJson<HttpValidationProblemDetails>();
}
[Fact]
public async Task one_validator_sad_path_in_different_assembly()
Expand All @@ -52,9 +70,9 @@ public async Task one_validator_sad_path_in_different_assembly()
x.StatusCodeShouldBe(400);
});

// Just proving that we have ProblemDetails content
// Just proving that we have HttpValidationProblemDetails content
// in the request
var problems = results.ReadAsJson<ProblemDetails>();
var problems = results.ReadAsJson<HttpValidationProblemDetails>();
}

[Fact]
Expand Down Expand Up @@ -82,7 +100,7 @@ public async Task two_validator_sad_path()
x.StatusCodeShouldBe(400);
});

var problems = results.ReadAsJson<ProblemDetails>();
var problems = results.ReadAsJson<HttpValidationProblemDetails>();
}

[Fact]
Expand All @@ -97,6 +115,6 @@ public async Task when_using_compound_handler_validation_is_called_before_load()
x.StatusCodeShouldBe(400);
});

var problems = results.ReadAsJson<ProblemDetails>();
var problems = results.ReadAsJson<HttpValidationProblemDetails>();
}
}
Loading