Skip to content

Commit 93ebc95

Browse files
nyang-codeDerich367
authored andcommitted
add DocumentTests (Azure#442)
1 parent 2999e2f commit 93ebc95

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,5 +558,36 @@ public async Task Given_ServerDetails_WithEmptyRoutePrefix_When_RenderAsync_Invo
558558
((string)json?.basePath).Should().BeEquivalentTo(null);
559559
((string)json?.schemes[0]).Should().BeEquivalentTo(scheme);
560560
}
561+
562+
[DataTestMethod]
563+
[DataRow("https", "localhost", "api")]
564+
[DataRow("https", "localhost", "")]
565+
[DataRow("https", "localhost", null)]
566+
public async Task Given_ServerDetails_When_RenderAsync_Invoked_Then_It_Should_Return_Result(string scheme, string host, string routePrefix)
567+
{
568+
var helper = new Mock<IDocumentHelper>();
569+
570+
var url = $"{scheme}://{host}/{routePrefix}";
571+
var uri = new Uri(url);
572+
var req = new Mock<IHttpRequestDataObject>();
573+
req.SetupGet(p => p.Scheme).Returns(scheme);
574+
575+
req.SetupGet(p => p.Host).Returns(new HostString(host));
576+
577+
578+
var doc = new Document(helper.Object);
579+
580+
var result = await doc.InitialiseDocument()
581+
.AddServer(req.Object, routePrefix)
582+
.RenderAsync(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json);
583+
584+
dynamic json = JObject.Parse(result);
585+
586+
((string)json?.host).Should().BeEquivalentTo(null);
587+
((string)json?.basePath).Should().BeEquivalentTo(null);
588+
((string)json?.schemes).Should().BeEquivalentTo(null);
589+
((string)json?.servers[0].url).Should().BeEquivalentTo(uri.AbsoluteUri);
590+
}
561591
}
562592
}
593+

0 commit comments

Comments
 (0)