Skip to content

Commit 2999e2f

Browse files
GEONheongDerich367
authored andcommitted
Adds new function for OpenApi v3 (Azure#441)
1 parent a90ccd7 commit 2999e2f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Tests/DocumentTests.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public async Task Given_ServerDetails_With_ConfigurationOptions_When_RenderAsync
474474
}
475475

476476
[TestMethod]
477-
public async Task Given_ServerDetails_WithNullRoutePrefix_When_RenderAsync_Invoked_Then_It_Should_Return_Result()
477+
public async Task Given_ServerDetails_WithNullRoutePrefix_When_RenderAsync_Invoked_Then_It_Should_Return_Result_OpenApiV2()
478478
{
479479
var helper = new Mock<IDocumentHelper>();
480480

@@ -500,6 +500,38 @@ public async Task Given_ServerDetails_WithNullRoutePrefix_When_RenderAsync_Invok
500500
((string)json?.schemes[0]).Should().BeEquivalentTo(scheme);
501501
}
502502

503+
[TestMethod]
504+
public async Task Given_ServerDetails_WithNullRoutePrefix_When_RenderAsync_Invoked_Then_It_Should_Return_Result_OpenApiV3()
505+
{
506+
var helper = new Mock<IDocumentHelper>();
507+
508+
var scheme = "https";
509+
var host = "localhost";
510+
string routePrefix = null;
511+
512+
var url = $"{scheme}://{host}";
513+
var req = new Mock<IHttpRequestDataObject>();
514+
req.SetupGet(p => p.Scheme).Returns(scheme);
515+
req.SetupGet(p => p.Host).Returns(new HostString(host));
516+
517+
var doc = new Document(helper.Object);
518+
519+
var result = await doc.InitialiseDocument()
520+
.AddServer(req.Object, routePrefix)
521+
.RenderAsync(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json);
522+
523+
dynamic json = JObject.Parse(result);
524+
525+
526+
((object)json?.servers).Should().NotBeNull();
527+
((int)json?.servers.Count).Should().BeGreaterThan(0);
528+
529+
var uri = new Uri((string)json?.servers[0].url);
530+
531+
uri.Scheme.Should().BeEquivalentTo(scheme);
532+
uri.Host.Should().BeEquivalentTo(host);
533+
}
534+
503535
[TestMethod]
504536
public async Task Given_ServerDetails_WithEmptyRoutePrefix_When_RenderAsync_Invoked_Then_It_Should_Return_Result()
505537
{

0 commit comments

Comments
 (0)