This repository was archived by the owner on Nov 11, 2025. It is now read-only.
forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryLoadReferenceV2Tests.cs
More file actions
105 lines (91 loc) · 3.66 KB
/
TryLoadReferenceV2Tests.cs
File metadata and controls
105 lines (91 loc) · 3.66 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.ReferenceService
{
[Collection("DefaultSettings")]
public class TryLoadReferenceV2Tests
{
private const string SampleFolderPath = "ReferenceService/Samples/";
[Fact]
public async Task LoadParameterReference()
{
// Arrange
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
var reference = new OpenApiParameterReference("skipParam", result.Document);
// Assert
Assert.Equivalent(
new OpenApiParameter
{
Name = "skip",
In = ParameterLocation.Query,
Description = "number of items to skip",
Required = true,
Schema = new OpenApiSchema()
{
Type = JsonSchemaType.Integer,
Format = "int32"
}
},
reference
);
}
[Fact]
public async Task LoadSecuritySchemeReference()
{
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
var reference = new OpenApiSecuritySchemeReference("api_key_sample", result.Document);
// Assert
Assert.Equivalent(
new OpenApiSecurityScheme
{
Type = SecuritySchemeType.ApiKey,
Name = "api_key",
In = ParameterLocation.Header
}, reference
);
}
[Fact]
public async Task LoadResponseReference()
{
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
var reference = new OpenApiResponseReference("NotFound", result.Document);
// Assert
Assert.Equivalent(
new OpenApiResponse
{
Summary = null,
Description = "Entity not found.",
Content = new Dictionary<string, OpenApiMediaType>()
{
["application/json"] = new()
}
}, reference
);
}
[Fact]
public async Task LoadResponseAndSchemaReference()
{
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
var reference = new OpenApiResponseReference("GeneralError", result.Document);
var expected = new OpenApiResponse
{
Description = "General Error",
Content = new Dictionary<string, OpenApiMediaType>()
{
["application/json"] = new()
{
Schema = new OpenApiSchemaReference("SampleObject2")
}
}
};
((OpenApiSchemaReference)expected.Content["application/json"].Schema).Reference.EnsureHostDocumentIsSet(result.Document);
var actual = reference.Target;
// Assert
Assert.Equivalent(expected, actual);
}
}
}