|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Text.Json; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.AspNetCore.Authentication; |
| 7 | +using Microsoft.AspNetCore.Http; |
5 | 8 | using Microsoft.AspNetCore.Mvc.Abstractions; |
6 | 9 | using Microsoft.AspNetCore.Mvc.ApiExplorer; |
7 | 10 | using Microsoft.AspNetCore.Mvc.ModelBinding; |
8 | | -using Microsoft.AspNetCore.Http; |
9 | 11 | using Microsoft.AspNetCore.Routing; |
10 | 12 | using Microsoft.OpenApi.Any; |
11 | 13 | using Microsoft.OpenApi.Models; |
12 | 14 | using Swashbuckle.AspNetCore.Swagger; |
13 | 15 | using Swashbuckle.AspNetCore.TestSupport; |
14 | 16 | using Xunit; |
15 | | -using System.Threading.Tasks; |
16 | | -using Microsoft.AspNetCore.Server.HttpSys; |
17 | | -using Microsoft.AspNetCore.Authentication; |
18 | 17 |
|
19 | 18 | namespace Swashbuckle.AspNetCore.SwaggerGen.Test |
20 | 19 | { |
@@ -1409,6 +1408,31 @@ public void GetSwagger_SupportsOption_DocumentFilters() |
1409 | 1408 | Assert.Contains("ComplexType", document.Components.Schemas.Keys); |
1410 | 1409 | } |
1411 | 1410 |
|
| 1411 | + [Theory] |
| 1412 | + [InlineData("connect")] |
| 1413 | + [InlineData("CONNECT")] |
| 1414 | + [InlineData("FOO")] |
| 1415 | + public void GetSwagger_GeneratesSwaggerDocument_ThrowsIfHttpMethodNotSupported(string httpMethod) |
| 1416 | + { |
| 1417 | + var subject = Subject( |
| 1418 | + apiDescriptions: new[] |
| 1419 | + { |
| 1420 | + ApiDescriptionFactory.Create<FakeController>( |
| 1421 | + c => nameof(c.ActionWithNoParameters), groupName: "v1", httpMethod: httpMethod, relativePath: "resource"), |
| 1422 | + }, |
| 1423 | + options: new SwaggerGeneratorOptions |
| 1424 | + { |
| 1425 | + SwaggerDocs = new Dictionary<string, OpenApiInfo> |
| 1426 | + { |
| 1427 | + ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } |
| 1428 | + } |
| 1429 | + } |
| 1430 | + ); |
| 1431 | + |
| 1432 | + var exception = Assert.Throws<SwaggerGeneratorException>(() => subject.GetSwagger("v1")); |
| 1433 | + Assert.Equal($"The \"{httpMethod}\" HTTP method is not supported.", exception.Message); |
| 1434 | + } |
| 1435 | + |
1412 | 1436 | private static SwaggerGenerator Subject( |
1413 | 1437 | IEnumerable<ApiDescription> apiDescriptions, |
1414 | 1438 | SwaggerGeneratorOptions options = null, |
|
0 commit comments