From 2b82a74b805be0a4a9971b3fc0cbc6cd11fa2518 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Mon, 16 Jan 2023 14:47:07 -0500 Subject: [PATCH] Added more tests to meet the coverage gods --- .../Services/OpenApiServiceTests.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index be1ca18e8..dbfbce221 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -131,6 +131,30 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram() Assert.Contains("graph LR", output); } + [Fact] + public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiagram() + { + var fileinfo = new FileInfo("sample.md"); + // create a dummy ILogger instance for testing + await OpenApiService.ShowOpenApiDocument(null, "UtilityFiles\\Todo.xml", "todos", fileinfo, new Logger(new LoggerFactory()), new CancellationToken()); + + var output = File.ReadAllText(fileinfo.FullName); + Assert.Contains("graph LR", output); + } + + [Fact] + public async Task ThrowIfURLIsNotResolvableWhenValidating() + { + var message = Assert.ThrowsAsync(async () => + await OpenApiService.ValidateOpenApiDocument("https://example.org/itdoesnmatter", new Logger(new LoggerFactory()), new CancellationToken())); + } + + [Fact] + public async Task ThrowIfFileDoesNotExistWhenValidating() + { + var message = Assert.ThrowsAsync(async () => + await OpenApiService.ValidateOpenApiDocument("aFileThatBetterNotExist.fake", new Logger(new LoggerFactory()), new CancellationToken())); + } [Fact] public async Task TransformCommandConvertsOpenApi() @@ -175,8 +199,6 @@ public void InvokeShowCommand() } - - // Relatively useless test to keep the code coverage metrics happy [Fact] public void CreateRootCommand()