1
1
using System . IO ;
2
+ using System . Text . Json . Nodes ;
2
3
using Microsoft . OpenApi . MicrosoftExtensions ;
3
4
using Microsoft . OpenApi . Writers ;
4
5
using Xunit ;
@@ -22,7 +23,7 @@ public void WritesNothingWhenNoValues()
22
23
{
23
24
// Arrange
24
25
OpenApiEnumValuesDescriptionExtension extension = new ( ) ;
25
- using TextWriter sWriter = new StringWriter ( ) ;
26
+ using var sWriter = new StringWriter ( ) ;
26
27
OpenApiJsonWriter writer = new ( sWriter ) ;
27
28
28
29
// Act
@@ -41,16 +42,16 @@ public void WritesEnumDescription()
41
42
OpenApiEnumValuesDescriptionExtension extension = new ( )
42
43
{
43
44
EnumName = "TestEnum" ,
44
- ValuesDescriptions = new ( )
45
- {
45
+ ValuesDescriptions =
46
+ [
46
47
new ( ) {
47
48
Description = "TestDescription" ,
48
49
Value = "TestValue" ,
49
50
Name = "TestName"
50
51
}
51
- }
52
+ ]
52
53
} ;
53
- using TextWriter sWriter = new StringWriter ( ) ;
54
+ using var sWriter = new StringWriter ( ) ;
54
55
OpenApiJsonWriter writer = new ( sWriter ) ;
55
56
56
57
// Act
@@ -65,5 +66,49 @@ public void WritesEnumDescription()
65
66
Assert . Contains ( "value\" : \" TestValue" , result ) ;
66
67
Assert . Contains ( "name\" : \" TestName" , result ) ;
67
68
}
69
+ [ Fact ]
70
+ public void ParsesEnumDescription ( )
71
+ {
72
+ var extensionValue =
73
+ """
74
+ {
75
+ "value": "Standard_LRS",
76
+ "description": "Locally redundant storage.",
77
+ "name": "StandardLocalRedundancy"
78
+ }
79
+ """ ;
80
+ var source = JsonNode . Parse ( extensionValue ) ;
81
+ Assert . NotNull ( source ) ;
82
+ var sourceAsObject = source . AsObject ( ) ;
83
+ Assert . NotNull ( sourceAsObject ) ;
84
+
85
+ var descriptionItem = new EnumDescription ( sourceAsObject ) ;
86
+ Assert . NotNull ( descriptionItem ) ;
87
+ Assert . Equal ( "Standard_LRS" , descriptionItem . Value ) ;
88
+ Assert . Equal ( "Locally redundant storage." , descriptionItem . Description ) ;
89
+ Assert . Equal ( "StandardLocalRedundancy" , descriptionItem . Name ) ;
90
+ }
91
+ [ Fact ]
92
+ public void ParsesEnumDescriptionWithDecimalValue ( )
93
+ {
94
+ var extensionValue =
95
+ """
96
+ {
97
+ "value": -1,
98
+ "description": "Locally redundant storage.",
99
+ "name": "StandardLocalRedundancy"
100
+ }
101
+ """ ;
102
+ var source = JsonNode . Parse ( extensionValue ) ;
103
+ Assert . NotNull ( source ) ;
104
+ var sourceAsObject = source . AsObject ( ) ;
105
+ Assert . NotNull ( sourceAsObject ) ;
106
+
107
+ var descriptionItem = new EnumDescription ( sourceAsObject ) ;
108
+ Assert . NotNull ( descriptionItem ) ;
109
+ Assert . Equal ( "-1" , descriptionItem . Value ) ;
110
+ Assert . Equal ( "Locally redundant storage." , descriptionItem . Description ) ;
111
+ Assert . Equal ( "StandardLocalRedundancy" , descriptionItem . Name ) ;
112
+ }
68
113
}
69
114
0 commit comments