-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiEncodingTests.cs
More file actions
76 lines (67 loc) · 2.75 KB
/
OpenApiEncodingTests.cs
File metadata and controls
76 lines (67 loc) · 2.75 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.OpenApi.Reader;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
{
[Collection("DefaultSettings")]
public class OpenApiEncodingTests
{
private const string SampleFolderPath = "V3Tests/Samples/OpenApiEncoding/";
[Fact]
public async Task ParseBasicEncodingShouldSucceed()
{
// Act
var encoding = await OpenApiModelFactory.LoadAsync<OpenApiEncoding>(Path.Combine(SampleFolderPath, "basicEncoding.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings);
// Assert
Assert.Equivalent(
new OpenApiEncoding
{
ContentType = "application/xml; charset=utf-8"
}, encoding);
}
[Fact]
public async Task ParseAdvancedEncodingShouldSucceed()
{
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "advancedEncoding.yaml"));
// Act
var encoding = await OpenApiModelFactory.LoadAsync<OpenApiEncoding>(stream, OpenApiSpecVersion.OpenApi3_0, new(), settings: SettingsFixture.ReaderSettings);
// Assert
Assert.Equivalent(
new OpenApiEncoding
{
ContentType = "image/png, image/jpeg",
Headers = new Dictionary<string, IOpenApiHeader>
{
["X-Rate-Limit-Limit"] =
new OpenApiHeader()
{
Description = "The number of allowed requests in the current period",
Schema = new OpenApiSchema()
{
Type = JsonSchemaType.Integer
}
}
}
}, encoding);
}
[Fact]
public async Task ParseEncodingWithAllowReservedShouldSucceed()
{
// Act
var encoding = await OpenApiModelFactory.LoadAsync<OpenApiEncoding>(Path.Combine(SampleFolderPath, "encodingWithAllowReserved.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings);
// Assert
Assert.Equivalent(
new OpenApiEncoding
{
ContentType = "application/x-www-form-urlencoded",
Style = ParameterStyle.Form,
Explode = true,
AllowReserved = true
}, encoding);
}
}
}