-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MethodInfo discovery for Minimal API
- Loading branch information
1 parent
c7d580a
commit b36b178
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
...ckle.AspNetCore.SwaggerGen.Test/ApiDescriptionExtensions/ApiDescriptionExtensionsTests.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,47 @@ | ||
using Microsoft.AspNetCore.Mvc.Abstractions; | ||
using Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures; | ||
using Swashbuckle.AspNetCore.TestSupport; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Swashbuckle.AspNetCore.SwaggerGen.Test.ApiDescriptionExtensions | ||
{ | ||
public class ApiDescriptionExtensionsTests | ||
{ | ||
[Fact] | ||
public void TryGetMethodInfo_GetsMethodInfo_IfControllerActionDescriptor() | ||
{ | ||
var apiDescription = ApiDescriptionFactory.Create<FakeController>(c => nameof(c.ActionWithNoParameters), groupName: "v1", httpMethod: "POST", relativePath: "/"); | ||
|
||
var result = apiDescription.TryGetMethodInfo(out var methodInfo); | ||
|
||
Assert.True(result); | ||
Assert.NotNull(methodInfo); | ||
} | ||
|
||
[Fact] | ||
public void TryGetMethodInfo_GetsMethodInfo_IfEndpointActionDescriptor() | ||
{ | ||
var testMethodInfo = typeof(TestMinimalApiMethod).GetMethod("RequestDelegate"); | ||
|
||
var actionDescriptor = new ActionDescriptor(); | ||
actionDescriptor.EndpointMetadata = new List<object> { testMethodInfo }; | ||
actionDescriptor.Parameters = testMethodInfo | ||
.GetParameters() | ||
.Select(p => new ParameterDescriptor | ||
{ | ||
Name = p.Name, | ||
ParameterType = p.ParameterType | ||
}) | ||
.ToList(); | ||
|
||
var apiDescription = ApiDescriptionFactory.Create(actionDescriptor, testMethodInfo, groupName: "v1", httpMethod: "POST", relativePath: "/"); | ||
|
||
var result = apiDescription.TryGetMethodInfo(out var methodInfo); | ||
|
||
Assert.True(result); | ||
Assert.NotNull(methodInfo); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/TestMinimalApiMethod.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures | ||
{ | ||
public class TestMinimalApiMethod | ||
{ | ||
public static Task RequestDelegate(long id) | ||
{ | ||
return Task.FromResult(id); | ||
} | ||
} | ||
} |