-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathApiTestRunnerOptionsExtensions.cs
More file actions
31 lines (26 loc) · 1.03 KB
/
ApiTestRunnerOptionsExtensions.cs
File metadata and controls
31 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.IO;
using Microsoft.OpenApi.Models;
namespace Swashbuckle.AspNetCore.ApiTesting
{
public static class ApiTestRunnerOptionsExtensions
{
public static void AddOpenApiFile(this ApiTestRunnerOptions options, string documentName, string filePath)
{
using var fileStream = File.OpenRead(filePath);
using var memoryStream = new MemoryStream();
fileStream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
var result = OpenApiDocument.Load(memoryStream);
options.OpenApiDocs.Add(documentName, result.Document);
}
public static OpenApiDocument GetOpenApiDocument(this ApiTestRunnerOptions options, string documentName)
{
if (!options.OpenApiDocs.TryGetValue(documentName, out OpenApiDocument document))
{
throw new InvalidOperationException($"Document with name '{documentName}' not found");
}
return document;
}
}
}