1
+ // ------------------------------------------------------------
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
4
+ // ------------------------------------------------------------
5
+
6
+ using System . IO ;
7
+ using System . Linq ;
8
+ using FluentAssertions ;
9
+ using Microsoft . OpenApi . Models ;
10
+ using Microsoft . OpenApi . Readers . ParseNodes ;
11
+ using Microsoft . OpenApi . Readers . V3 ;
12
+ using SharpYaml . Serialization ;
13
+ using Xunit ;
14
+
15
+ namespace Microsoft . OpenApi . Readers . Tests . V3Tests
16
+ {
17
+ [ Collection ( "DefaultSettings" ) ]
18
+ public class OpenApiEncodingTests
19
+ {
20
+ private const string SampleFolderPath = "V3Tests/Samples/OpenApiEncoding" ;
21
+
22
+ [ Fact ]
23
+ public void ParseBasicEncodingShouldSucceed ( )
24
+ {
25
+ using ( var stream = File . OpenRead ( Path . Combine ( SampleFolderPath , "basicEncoding.yaml" ) ) )
26
+ {
27
+ var yamlStream = new YamlStream ( ) ;
28
+ yamlStream . Load ( new StreamReader ( stream ) ) ;
29
+ var yamlNode = yamlStream . Documents . First ( ) . RootNode ;
30
+
31
+ var context = new ParsingContext ( ) ;
32
+ var diagnostic = new OpenApiDiagnostic ( ) ;
33
+
34
+ var node = new MapNode ( context , diagnostic , ( YamlMappingNode ) yamlNode ) ;
35
+
36
+ // Act
37
+ var encoding = OpenApiV3Deserializer . LoadEncoding ( node ) ;
38
+
39
+ // Assert
40
+ encoding . ShouldBeEquivalentTo (
41
+ new OpenApiEncoding
42
+ {
43
+ ContentType = "application/xml; charset=utf-8"
44
+ } ) ;
45
+ }
46
+ }
47
+
48
+ [ Fact ]
49
+ public void ParseAdvancedEncodingShouldSucceed ( )
50
+ {
51
+ using ( var stream = File . OpenRead ( Path . Combine ( SampleFolderPath , "advancedEncoding.yaml" ) ) )
52
+ {
53
+ var yamlStream = new YamlStream ( ) ;
54
+ yamlStream . Load ( new StreamReader ( stream ) ) ;
55
+ var yamlNode = yamlStream . Documents . First ( ) . RootNode ;
56
+
57
+ var context = new ParsingContext ( ) ;
58
+ var diagnostic = new OpenApiDiagnostic ( ) ;
59
+
60
+ var node = new MapNode ( context , diagnostic , ( YamlMappingNode ) yamlNode ) ;
61
+
62
+ // Act
63
+ var encoding = OpenApiV3Deserializer . LoadEncoding ( node ) ;
64
+
65
+ // Assert
66
+ encoding . ShouldBeEquivalentTo (
67
+ new OpenApiEncoding
68
+ {
69
+ ContentType = "image/png, image/jpeg" ,
70
+ Headers =
71
+ {
72
+ [ "X-Rate-Limit-Limit" ] =
73
+ new OpenApiHeader
74
+ {
75
+ Description = "The number of allowed requests in the current period" ,
76
+ Schema = new OpenApiSchema
77
+ {
78
+ Type = "integer"
79
+ }
80
+ }
81
+ }
82
+ } ) ;
83
+ }
84
+ }
85
+ }
86
+ }
0 commit comments