11using System . IO ;
2+ using System . Text . Json . Nodes ;
23using Microsoft . OpenApi . MicrosoftExtensions ;
34using Microsoft . OpenApi . Writers ;
45using Xunit ;
@@ -22,7 +23,7 @@ public void WritesNothingWhenNoValues()
2223 {
2324 // Arrange
2425 OpenApiEnumValuesDescriptionExtension extension = new ( ) ;
25- using TextWriter sWriter = new StringWriter ( ) ;
26+ using var sWriter = new StringWriter ( ) ;
2627 OpenApiJsonWriter writer = new ( sWriter ) ;
2728
2829 // Act
@@ -41,16 +42,16 @@ public void WritesEnumDescription()
4142 OpenApiEnumValuesDescriptionExtension extension = new ( )
4243 {
4344 EnumName = "TestEnum" ,
44- ValuesDescriptions = new ( )
45- {
45+ ValuesDescriptions =
46+ [
4647 new ( ) {
4748 Description = "TestDescription" ,
4849 Value = "TestValue" ,
4950 Name = "TestName"
5051 }
51- }
52+ ]
5253 } ;
53- using TextWriter sWriter = new StringWriter ( ) ;
54+ using var sWriter = new StringWriter ( ) ;
5455 OpenApiJsonWriter writer = new ( sWriter ) ;
5556
5657 // Act
@@ -65,5 +66,49 @@ public void WritesEnumDescription()
6566 Assert . Contains ( "value\" : \" TestValue" , result ) ;
6667 Assert . Contains ( "name\" : \" TestName" , result ) ;
6768 }
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+ }
68113}
69114
0 commit comments