Skip to content

Commit

Permalink
I am confidence I have enough tests now
Browse files Browse the repository at this point in the history
  • Loading branch information
darrelmiller committed Jan 16, 2023
1 parent 96fae88 commit 7638805
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private static string GetInputPathExtension(string openapi = null, string csdl =
return extension;
}

internal static async Task ShowOpenApiDocument(string openapi, string csdl, string csdlFilter, FileInfo output, ILogger logger, CancellationToken cancellationToken)
internal static async Task<string> ShowOpenApiDocument(string openapi, string csdl, string csdlFilter, FileInfo output, ILogger logger, CancellationToken cancellationToken)
{
try
{
Expand Down Expand Up @@ -542,6 +542,8 @@ internal static async Task ShowOpenApiDocument(string openapi, string csdl, stri
process.StartInfo.FileName = output.FullName;
process.StartInfo.UseShellExecute = true;
process.Start();

return output.FullName;
}
else // Write diagram as Markdown document to output file
{
Expand All @@ -551,6 +553,7 @@ internal static async Task ShowOpenApiDocument(string openapi, string csdl, stri
WriteTreeDocumentAsMarkdown(openapi ?? csdl, document, writer);
}
logger.LogTrace("Created markdown document with diagram ");
return output.FullName;
}
}
}
Expand All @@ -562,6 +565,7 @@ internal static async Task ShowOpenApiDocument(string openapi, string csdl, stri
{
throw new InvalidOperationException($"Could not generate the document, reason: {ex.Message}", ex);
}
return null;
}

private static void LogErrors(ILogger logger, ReadResult result)
Expand Down
42 changes: 32 additions & 10 deletions test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ public void ReturnOpenApiConvertSettingsWhenSettingsFileIsProvided(string filePa
[Fact]
public void ShowCommandGeneratesMermaidDiagramAsMarkdown()
{
var openApiDoc = new OpenApiDocument();
openApiDoc.Info = new OpenApiInfo
var openApiDoc = new OpenApiDocument
{
Title = "Test",
Version = "1.0.0"
Info = new OpenApiInfo
{
Title = "Test",
Version = "1.0.0"
}
};
var stream = new MemoryStream();
using var writer = new StreamWriter(stream);
Expand All @@ -101,13 +103,15 @@ public void ShowCommandGeneratesMermaidDiagramAsMarkdown()
}

[Fact]
public void ShowCommandGeneratesMermaidDiagramAsHtml ()
public void ShowCommandGeneratesMermaidDiagramAsHtml()
{
var openApiDoc = new OpenApiDocument();
openApiDoc.Info = new OpenApiInfo
var openApiDoc = new OpenApiDocument
{
Title = "Test",
Version = "1.0.0"
Info = new OpenApiInfo
{
Title = "Test",
Version = "1.0.0"
}
};
var stream = new MemoryStream();
using var writer = new StreamWriter(stream);
Expand All @@ -118,7 +122,7 @@ public void ShowCommandGeneratesMermaidDiagramAsHtml ()
var output = reader.ReadToEnd();
Assert.Contains("graph LR", output);
}


[Fact]
public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram()
Expand All @@ -131,6 +135,13 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram()
Assert.Contains("graph LR", output);
}

[Fact]
public async Task ShowCommandGeneratesMermaidHtmlFileWithMermaidDiagram()
{
var filePath = await OpenApiService.ShowOpenApiDocument("UtilityFiles\\SampleOpenApi.yml", null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());
Assert.True(File.Exists(filePath));
}

[Fact]
public async Task ShowCommandGeneratesMermaidMarkdownFileFromCsdlWithMermaidDiagram()
{
Expand Down Expand Up @@ -185,6 +196,7 @@ public async Task TransformCommandConvertsOpenApi()
Assert.NotEmpty(output);
}


[Fact]
public async Task TransformCommandConvertsOpenApiWithDefaultOutputname()
{
Expand All @@ -195,6 +207,16 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputname()
Assert.NotEmpty(output);
}

[Fact]
public async Task TransformCommandConvertsCsdlWithDefaultOutputname()
{
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(null, "UtilityFiles\\Todo.xml", null, null, true, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());

var output = File.ReadAllText("output.yml");
Assert.NotEmpty(output);
}

[Fact]
public async Task TransformCommandConvertsOpenApiWithDefaultOutputnameAndSwitchFormat()
{
Expand Down

0 comments on commit 7638805

Please sign in to comment.