File tree Expand file tree Collapse file tree 4 files changed +88
-1
lines changed
Microsoft.OpenApi.Readers.Tests
Microsoft.OpenApi.Tests/Models Expand file tree Collapse file tree 4 files changed +88
-1
lines changed Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
<PropertyGroup >
3
3
<TargetFrameworks >net6.0</TargetFrameworks >
4
4
<GeneratePackageOnBuild >false</GeneratePackageOnBuild >
164
164
<EmbeddedResource Include =" V3Tests\Samples\OpenApiInfo\basicInfo.yaml" >
165
165
<CopyToOutputDirectory >Never</CopyToOutputDirectory >
166
166
</EmbeddedResource >
167
+ <EmbeddedResource Include =" V3Tests\Samples\OpenApiLicense\licenseWithSpdxIdentifier.yaml" >
168
+ <CopyToOutputDirectory >Never</CopyToOutputDirectory >
169
+ </EmbeddedResource >
167
170
<EmbeddedResource Include =" V3Tests\Samples\OpenApiInfo\minimalInfo.yaml" >
168
171
<CopyToOutputDirectory >Never</CopyToOutputDirectory >
169
172
</EmbeddedResource >
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT license.
3
+
4
+ using Microsoft . OpenApi . Models ;
5
+ using Microsoft . OpenApi . Readers . ParseNodes ;
6
+ using Microsoft . OpenApi . Readers . V3 ;
7
+ using SharpYaml . Serialization ;
8
+ using System . IO ;
9
+ using Xunit ;
10
+ using System . Linq ;
11
+ using FluentAssertions ;
12
+
13
+ namespace Microsoft . OpenApi . Readers . Tests . V3Tests
14
+ {
15
+
16
+ public class OpenApiLicenseTests
17
+ {
18
+ private const string SampleFolderPath = "V3Tests/Samples/OpenApiLicense/" ;
19
+
20
+ [ Fact ]
21
+ public void ParseLicenseWithSpdxIdentifierShouldSucceed ( )
22
+ {
23
+ using var stream = Resources . GetStream ( Path . Combine ( SampleFolderPath , "licenseWithSpdxIdentifier.yaml" ) ) ;
24
+ var yamlStream = new YamlStream ( ) ;
25
+ yamlStream . Load ( new StreamReader ( stream ) ) ;
26
+ var yamlNode = yamlStream . Documents . First ( ) . RootNode ;
27
+
28
+ var diagnostic = new OpenApiDiagnostic ( ) ;
29
+ var context = new ParsingContext ( diagnostic ) ;
30
+
31
+ var node = new MapNode ( context , ( YamlMappingNode ) yamlNode ) ;
32
+
33
+ // Act
34
+ var license = OpenApiV3Deserializer . LoadLicense ( node ) ;
35
+
36
+ // Assert
37
+ license . Should ( ) . BeEquivalentTo (
38
+ new OpenApiLicense
39
+ {
40
+ Name = "Apache 2.0" ,
41
+ Identifier = "Apache-2.0"
42
+ } ) ;
43
+ }
44
+ }
45
+ }
Original file line number Diff line number Diff line change
1
+ name : Apache 2.0
2
+ identifier : Apache-2.0
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ public class OpenApiLicenseTests
30
30
}
31
31
} ;
32
32
33
+ public static OpenApiLicense LicenseWithIdentifier = new OpenApiLicense
34
+ {
35
+ Name = "Apache 2.0" ,
36
+ Identifier = "Apache-2.0"
37
+ } ;
38
+
33
39
[ Theory ]
34
40
[ InlineData ( OpenApiSpecVersion . OpenApi3_0 ) ]
35
41
[ InlineData ( OpenApiSpecVersion . OpenApi2_0 ) ]
@@ -123,5 +129,36 @@ public void ShouldCopyFromOriginalObjectWithoutMutating()
123
129
Assert . NotEqual ( AdvanceLicense . Name , licenseCopy . Name ) ;
124
130
Assert . NotEqual ( AdvanceLicense . Url , licenseCopy . Url ) ;
125
131
}
132
+
133
+ [ Fact ]
134
+ public void SerializeLicenseWithIdentifierAsJsonWorks ( )
135
+ {
136
+ // Arrange
137
+ var expected =
138
+ @"{
139
+ ""name"": ""Apache 2.0"",
140
+ ""identifier"": ""Apache-2.0""
141
+ }" ;
142
+
143
+ // Act
144
+ var actual = LicenseWithIdentifier . SerializeAsJson ( OpenApiSpecVersion . OpenApi3_0 ) ;
145
+
146
+ // Assert
147
+ Assert . Equal ( expected . MakeLineBreaksEnvironmentNeutral ( ) , actual . MakeLineBreaksEnvironmentNeutral ( ) ) ;
148
+ }
149
+
150
+ [ Fact ]
151
+ public void SerializeLicenseWithIdentifierAsYamlWorks ( )
152
+ {
153
+ // Arrange
154
+ var expected = @"name: Apache 2.0
155
+ identifier: Apache-2.0" ;
156
+
157
+ // Act
158
+ var actual = LicenseWithIdentifier . SerializeAsYaml ( OpenApiSpecVersion . OpenApi3_0 ) ;
159
+
160
+ // Assert
161
+ Assert . Equal ( expected . MakeLineBreaksEnvironmentNeutral ( ) , actual . MakeLineBreaksEnvironmentNeutral ( ) ) ;
162
+ }
126
163
}
127
164
}
You can’t perform that action at this time.
0 commit comments