Skip to content

Commit eb9ba94

Browse files
committed
Add unit tests
1 parent e41b927 commit eb9ba94

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.OpenApi.Models;
1212
using Microsoft.OpenApi.Readers.ParseNodes;
1313
using Microsoft.OpenApi.Readers.V2;
14+
using Microsoft.OpenApi.Readers.V3;
1415
using Microsoft.OpenApi.Tests;
1516
using Xunit;
1617

@@ -484,7 +485,56 @@ public void ParseV2ResponseWithExamplesExtensionWorks()
484485
actual = actual.MakeLineBreaksEnvironmentNeutral();
485486
expected = expected.MakeLineBreaksEnvironmentNeutral();
486487
actual.Should().Be(expected);
487-
//Assert.Equal(expected, actual);
488+
}
489+
490+
[Fact]
491+
public void LoadV3ExamplesInResponseAsExtensionsWorks()
492+
{
493+
// Arrange
494+
MapNode node;
495+
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "v3OperationWithResponseExamples.yaml")))
496+
{
497+
node = TestHelper.CreateYamlMapNode(stream);
498+
}
499+
500+
// Act
501+
var operation = OpenApiV3Deserializer.LoadOperation(node);
502+
var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
503+
504+
// Assert
505+
var expected = @"summary: Get all pets
506+
produces:
507+
- application/json
508+
responses:
509+
'200':
510+
description: Successful response
511+
schema:
512+
type: array
513+
items:
514+
type: object
515+
properties:
516+
name:
517+
type: string
518+
age:
519+
type: integer
520+
x-examples:
521+
example1:
522+
summary: Example - List of Pets
523+
value:
524+
- name: Buddy
525+
age: 2
526+
- name: Whiskers
527+
age: 1
528+
example2:
529+
summary: Example - Playful Cat
530+
value:
531+
name: Whiskers
532+
age: 1";
533+
534+
// Assert
535+
actual = actual.MakeLineBreaksEnvironmentNeutral();
536+
expected = expected.MakeLineBreaksEnvironmentNeutral();
537+
actual.Should().Be(expected);
488538
}
489539
}
490540
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
summary: Get all pets
2+
responses:
3+
'200':
4+
description: Successful response
5+
content:
6+
application/json:
7+
schema:
8+
type: array
9+
items:
10+
type: object
11+
properties:
12+
name:
13+
type: string
14+
age:
15+
type: integer
16+
examples:
17+
example1:
18+
summary: Example - List of Pets
19+
value:
20+
- name: "Buddy"
21+
age: 2
22+
- name: "Whiskers"
23+
age: 1
24+
example2:
25+
summary: Example - Playful Cat
26+
value:
27+
name: "Whiskers"
28+
age: 1

0 commit comments

Comments
 (0)