Skip to content

Commit 0781a89

Browse files
committed
chore: moves tests definitions to the right location
Signed-off-by: Vincent Biret <[email protected]>
1 parent fefec09 commit 0781a89

File tree

2 files changed

+150
-150
lines changed

2 files changed

+150
-150
lines changed

test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiPathItemDeserializerTests.cs

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -49,149 +49,4 @@ public async Task ParsePathItemWithQueryAndAdditionalOperationsV32Works()
4949
Assert.Single(subscribeOp.Parameters);
5050
Assert.Equal("events", subscribeOp.Parameters[0].Name);
5151
}
52-
53-
[Fact]
54-
public async Task SerializeV32PathItemToV31ProducesExtensions()
55-
{
56-
// Arrange
57-
var pathItem = new OpenApiPathItem
58-
{
59-
Summary = "Test path",
60-
Operations = new Dictionary<HttpMethod, OpenApiOperation>
61-
{
62-
[HttpMethod.Get] = new OpenApiOperation
63-
{
64-
Summary = "Get operation",
65-
OperationId = "getOp",
66-
Responses = new OpenApiResponses
67-
{
68-
["200"] = new OpenApiResponse { Description = "Success" }
69-
}
70-
},
71-
[new HttpMethod("Query")] = new OpenApiOperation
72-
{
73-
Summary = "Query operation",
74-
OperationId = "queryOp",
75-
Responses = new OpenApiResponses
76-
{
77-
["200"] = new OpenApiResponse { Description = "Success" }
78-
}
79-
},
80-
[new HttpMethod("notify")] = new OpenApiOperation
81-
{
82-
Summary = "Notify operation",
83-
OperationId = "notifyOp",
84-
Responses = new OpenApiResponses
85-
{
86-
["200"] = new OpenApiResponse { Description = "Success" }
87-
}
88-
}
89-
}
90-
};
91-
92-
// Act
93-
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
94-
95-
// Assert
96-
Assert.Contains("Query:", yaml);
97-
Assert.Contains("x-oai-additionalOperations:", yaml);
98-
Assert.Contains("queryOp", yaml);
99-
Assert.Contains("notifyOp", yaml);
100-
}
101-
102-
[Fact]
103-
public async Task SerializeV32PathItemToV3ProducesExtensions()
104-
{
105-
// Arrange
106-
var pathItem = new OpenApiPathItem
107-
{
108-
Summary = "Test path",
109-
Operations = new Dictionary<HttpMethod, OpenApiOperation>
110-
{
111-
[HttpMethod.Get] = new OpenApiOperation
112-
{
113-
Summary = "Get operation",
114-
OperationId = "getOp",
115-
Responses = new OpenApiResponses
116-
{
117-
["200"] = new OpenApiResponse { Description = "Success" }
118-
}
119-
},
120-
[new HttpMethod("Query")] = new OpenApiOperation
121-
{
122-
Summary = "Query operation",
123-
OperationId = "queryOp",
124-
Responses = new OpenApiResponses
125-
{
126-
["200"] = new OpenApiResponse { Description = "Success" }
127-
}
128-
},
129-
[new HttpMethod("notify")] = new OpenApiOperation
130-
{
131-
Summary = "Notify operation",
132-
OperationId = "notifyOp",
133-
Responses = new OpenApiResponses
134-
{
135-
["200"] = new OpenApiResponse { Description = "Success" }
136-
}
137-
}
138-
}
139-
};
140-
141-
// Act
142-
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
143-
144-
// Assert
145-
Assert.Contains("Query:", yaml);
146-
Assert.Contains("x-oai-additionalOperations:", yaml);
147-
Assert.Contains("queryOp", yaml);
148-
Assert.Contains("notifyOp", yaml);
149-
}
150-
151-
[Fact]
152-
public void PathItemShallowCopyIncludesV32Fields()
153-
{
154-
// Arrange
155-
var original = new OpenApiPathItem
156-
{
157-
Summary = "Original",
158-
Operations = new Dictionary<HttpMethod, OpenApiOperation>
159-
{
160-
[HttpMethod.Get] = new OpenApiOperation
161-
{
162-
Summary = "Get operation",
163-
OperationId = "getOp",
164-
Responses = new OpenApiResponses()
165-
},
166-
[new HttpMethod("Query")] = new OpenApiOperation
167-
{
168-
Summary = "Query operation",
169-
OperationId = "queryOp"
170-
},
171-
[new HttpMethod("notify")] = new OpenApiOperation
172-
{
173-
Summary = "Notify operation",
174-
OperationId = "notifyOp"
175-
}
176-
}
177-
};
178-
179-
// Act
180-
var copy = original.CreateShallowCopy();
181-
182-
// Assert
183-
Assert.NotNull(original.Operations);
184-
Assert.NotNull(copy.Operations);
185-
Assert.Contains(HttpMethod.Get, original.Operations);
186-
Assert.Contains(HttpMethod.Get, copy.Operations);
187-
188-
var copyQueryOp = Assert.Contains(new HttpMethod("Query"), copy.Operations);
189-
Assert.Contains(new HttpMethod("Query"), original.Operations);
190-
Assert.Equal("Query operation", copyQueryOp.Summary);
191-
Assert.Equal("queryOp", copyQueryOp.OperationId);
192-
Assert.Contains(new HttpMethod("notify"), original.Operations);
193-
var copyNotifyOp = Assert.Contains(new HttpMethod("notify"), copy.Operations);
194-
Assert.Equal("Notify operation", copyNotifyOp.Summary);
195-
Assert.Equal("notifyOp", copyNotifyOp.OperationId);
196-
}
19752
}

test/Microsoft.OpenApi.Tests/Models/OpenApiPathItemTests.cs

Lines changed: 150 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public async Task SerializeAsV32JsonWithQueryAndAdditionalOperationsWorks()
426426
[new HttpMethod("Query")] = new OpenApiOperation
427427
{
428428
Summary = "query operation",
429-
Description = "query description",
429+
Description = "query description",
430430
OperationId = "queryOperation",
431431
Responses = new OpenApiResponses
432432
{
@@ -440,7 +440,7 @@ public async Task SerializeAsV32JsonWithQueryAndAdditionalOperationsWorks()
440440
{
441441
Summary = "notify operation",
442442
Description = "notify description",
443-
OperationId = "notifyOperation",
443+
OperationId = "notifyOperation",
444444
Responses = new OpenApiResponses
445445
{
446446
["200"] = new OpenApiResponse
@@ -530,7 +530,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV31Works()
530530
var pathItem = new OpenApiPathItem
531531
{
532532
Summary = "summary",
533-
Description = "description",
533+
Description = "description",
534534
Operations = new Dictionary<HttpMethod, OpenApiOperation>
535535
{
536536
[HttpMethod.Get] = new OpenApiOperation
@@ -569,7 +569,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV31Works()
569569
}
570570
}
571571
},
572-
572+
573573
}
574574
};
575575

@@ -589,7 +589,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV3Works()
589589
{
590590
var pathItem = new OpenApiPathItem
591591
{
592-
Summary = "summary",
592+
Summary = "summary",
593593
Description = "description",
594594
Operations = new Dictionary<HttpMethod, OpenApiOperation>
595595
{
@@ -749,4 +749,149 @@ public void CopyConstructorCopiesQueryAndAdditionalOperations()
749749

750750
Assert.Equal(originalNotifyOp.Summary, copyNotifyOp.Summary);
751751
}
752+
753+
[Fact]
754+
public async Task SerializeV32PathItemToV31ProducesExtensions()
755+
{
756+
// Arrange
757+
var pathItem = new OpenApiPathItem
758+
{
759+
Summary = "Test path",
760+
Operations = new Dictionary<HttpMethod, OpenApiOperation>
761+
{
762+
[HttpMethod.Get] = new OpenApiOperation
763+
{
764+
Summary = "Get operation",
765+
OperationId = "getOp",
766+
Responses = new OpenApiResponses
767+
{
768+
["200"] = new OpenApiResponse { Description = "Success" }
769+
}
770+
},
771+
[new HttpMethod("Query")] = new OpenApiOperation
772+
{
773+
Summary = "Query operation",
774+
OperationId = "queryOp",
775+
Responses = new OpenApiResponses
776+
{
777+
["200"] = new OpenApiResponse { Description = "Success" }
778+
}
779+
},
780+
[new HttpMethod("notify")] = new OpenApiOperation
781+
{
782+
Summary = "Notify operation",
783+
OperationId = "notifyOp",
784+
Responses = new OpenApiResponses
785+
{
786+
["200"] = new OpenApiResponse { Description = "Success" }
787+
}
788+
}
789+
}
790+
};
791+
792+
// Act
793+
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
794+
795+
// Assert
796+
Assert.Contains("Query:", yaml);
797+
Assert.Contains("x-oai-additionalOperations:", yaml);
798+
Assert.Contains("queryOp", yaml);
799+
Assert.Contains("notifyOp", yaml);
800+
}
801+
802+
[Fact]
803+
public async Task SerializeV32PathItemToV3ProducesExtensions()
804+
{
805+
// Arrange
806+
var pathItem = new OpenApiPathItem
807+
{
808+
Summary = "Test path",
809+
Operations = new Dictionary<HttpMethod, OpenApiOperation>
810+
{
811+
[HttpMethod.Get] = new OpenApiOperation
812+
{
813+
Summary = "Get operation",
814+
OperationId = "getOp",
815+
Responses = new OpenApiResponses
816+
{
817+
["200"] = new OpenApiResponse { Description = "Success" }
818+
}
819+
},
820+
[new HttpMethod("Query")] = new OpenApiOperation
821+
{
822+
Summary = "Query operation",
823+
OperationId = "queryOp",
824+
Responses = new OpenApiResponses
825+
{
826+
["200"] = new OpenApiResponse { Description = "Success" }
827+
}
828+
},
829+
[new HttpMethod("notify")] = new OpenApiOperation
830+
{
831+
Summary = "Notify operation",
832+
OperationId = "notifyOp",
833+
Responses = new OpenApiResponses
834+
{
835+
["200"] = new OpenApiResponse { Description = "Success" }
836+
}
837+
}
838+
}
839+
};
840+
841+
// Act
842+
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
843+
844+
// Assert
845+
Assert.Contains("Query:", yaml);
846+
Assert.Contains("x-oai-additionalOperations:", yaml);
847+
Assert.Contains("queryOp", yaml);
848+
Assert.Contains("notifyOp", yaml);
849+
}
850+
851+
[Fact]
852+
public void PathItemShallowCopyIncludesV32Fields()
853+
{
854+
// Arrange
855+
var original = new OpenApiPathItem
856+
{
857+
Summary = "Original",
858+
Operations = new Dictionary<HttpMethod, OpenApiOperation>
859+
{
860+
[HttpMethod.Get] = new OpenApiOperation
861+
{
862+
Summary = "Get operation",
863+
OperationId = "getOp",
864+
Responses = new OpenApiResponses()
865+
},
866+
[new HttpMethod("Query")] = new OpenApiOperation
867+
{
868+
Summary = "Query operation",
869+
OperationId = "queryOp"
870+
},
871+
[new HttpMethod("notify")] = new OpenApiOperation
872+
{
873+
Summary = "Notify operation",
874+
OperationId = "notifyOp"
875+
}
876+
}
877+
};
878+
879+
// Act
880+
var copy = original.CreateShallowCopy();
881+
882+
// Assert
883+
Assert.NotNull(original.Operations);
884+
Assert.NotNull(copy.Operations);
885+
Assert.Contains(HttpMethod.Get, original.Operations);
886+
Assert.Contains(HttpMethod.Get, copy.Operations);
887+
888+
var copyQueryOp = Assert.Contains(new HttpMethod("Query"), copy.Operations);
889+
Assert.Contains(new HttpMethod("Query"), original.Operations);
890+
Assert.Equal("Query operation", copyQueryOp.Summary);
891+
Assert.Equal("queryOp", copyQueryOp.OperationId);
892+
Assert.Contains(new HttpMethod("notify"), original.Operations);
893+
var copyNotifyOp = Assert.Contains(new HttpMethod("notify"), copy.Operations);
894+
Assert.Equal("Notify operation", copyNotifyOp.Summary);
895+
Assert.Equal("notifyOp", copyNotifyOp.OperationId);
896+
}
752897
}

0 commit comments

Comments
 (0)