-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor OpenApiReaderTests and OpenApiDocumentExtensions
- Loading branch information
1 parent
fd4e270
commit 403f148
Showing
4 changed files
with
114 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
|
||
namespace OasReader.Tests; | ||
|
||
internal class EmbeddedResources | ||
{ | ||
public static string GetStream(string name) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resourceName = $"OasReader.Tests.Resources.{name}"; | ||
|
||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
using var reader = new StreamReader(stream ?? throw new InvalidOperationException($"Could not find the embedded resource {name}")); | ||
|
||
return reader.ReadToEnd(); | ||
} | ||
} |
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,35 @@ | ||
using FluentAssertions; | ||
using Microsoft.OpenApi.Models; | ||
using Microsoft.OpenApi.Readers; | ||
using Xunit; | ||
|
||
namespace OasReader.Tests; | ||
|
||
public class OpenApiDocumentExtensionsTests | ||
{ | ||
[Theory] | ||
[InlineData("bot.yaml", "bot.components.yaml")] | ||
[InlineData("petstore.yaml", "petstore.components.yaml")] | ||
public async Task Returns_NotNull(string apiFile, string componentsFile) | ||
{ | ||
var folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); | ||
Directory.CreateDirectory(folder); | ||
|
||
var componentsFilename = Path.Combine(folder, componentsFile); | ||
var openapiFilename = Path.Combine(folder, apiFile); | ||
|
||
var componentContents = EmbeddedResources.GetStream(componentsFile); | ||
var apiContents = EmbeddedResources.GetStream(apiFile); | ||
|
||
await File.WriteAllTextAsync(componentsFilename, componentContents); | ||
await File.WriteAllTextAsync(openapiFilename, apiContents); | ||
|
||
var file = File.OpenRead(openapiFilename); | ||
var textReader = new StreamReader(file); | ||
var reader = new OpenApiTextReaderReader(); | ||
var result = await reader.ReadAsync(textReader, CancellationToken.None); | ||
OpenApiDocument sut = result.OpenApiDocument; | ||
|
||
sut.ContainsExternalReferences().Should().BeTrue(); | ||
} | ||
} |
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
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