@@ -186,40 +186,102 @@ public void TestGuid()
186186
187187 [ Fact , TestPriority ( 1 ) ]
188188 [ UseCulture ( "en-US" ) ]
189- public void TestUnion ( )
189+ public void TestUnion ( )
190+ {
191+ var assembly = Compiler . Generate ( "Union" , UnionPattern , new Generator
192+ {
193+ NamespacePrefix = "Union" ,
194+ IntegerDataType = typeof ( int ) ,
195+ MapUnionToWidestCommonType = true
196+ } ) ;
197+
198+ Assert . NotNull ( assembly ) ;
199+
200+ SharedTestFunctions . TestSamples ( Output , "Union" , UnionPattern ) ;
201+
202+ var snapshotType = assembly . GetType ( "Union.Snapshot" ) ;
203+ Assert . NotNull ( snapshotType ) ;
204+
205+ var date = snapshotType . GetProperty ( "Date" ) ;
206+ Assert . NotNull ( date ) ;
207+ Assert . Equal ( typeof ( DateTime ) , date . PropertyType ) ;
208+
209+ var count = snapshotType . GetProperty ( "Count" ) ;
210+ Assert . NotNull ( count ) ;
211+ Assert . Equal ( typeof ( int ) , count . PropertyType ) ;
212+
213+ var num = snapshotType . GetProperty ( "Num" ) ;
214+ Assert . NotNull ( num ) ;
215+ Assert . Equal ( typeof ( decimal ) , num . PropertyType ) ;
216+ }
217+
218+ [ Fact , TestPriority ( 1 ) ]
219+ [ UseCulture ( "en-US" ) ]
220+ public void TestSimpleContentEnum ( )
190221 {
191- var assembly = Compiler . Generate ( "Union" , UnionPattern , new Generator
192- {
193- NamespacePrefix = "Union" ,
194- IntegerDataType = typeof ( int ) ,
195- MapUnionToWidestCommonType = true
196- } ) ;
197-
198- Assert . NotNull ( assembly ) ;
199-
200- SharedTestFunctions . TestSamples ( Output , "Union" , UnionPattern ) ;
222+ var assembly = Compiler . Generate ( "SimpleContentEnum" , "xsd/simple/simplecontent-enum.xsd" ) ;
201223
202- var snapshotType = assembly . GetType ( "Union.Snapshot" ) ;
203- Assert . NotNull ( snapshotType ) ;
224+ const string ns = "SimpleContentEnum.Simplecontent" ;
204225
205- var date = snapshotType . GetProperty ( "Date" ) ;
206- Assert . NotNull ( date ) ;
207- Assert . Equal ( typeof ( DateTime ) , date . PropertyType ) ;
226+ // The enum type should be generated
227+ var enumType = assembly . GetType ( $ "{ ns } .TransConfirmationCodeTypeEnum") ;
228+ if ( enumType == null )
229+ {
230+ var names = string . Join ( ", " , assembly . GetTypes ( ) . Select ( t => t . FullName ) ) ;
231+ Assert . Fail ( $ "Enum type not found. Available types: { names } ") ;
232+ }
208233
209- var count = snapshotType . GetProperty ( "Count" ) ;
210- Assert . NotNull ( count ) ;
211- Assert . Equal ( typeof ( int ) , count . PropertyType ) ;
234+ // Verify it's an enum with the expected values
235+ Assert . True ( enumType . IsEnum ) ;
236+ var enumValues = Enum . GetNames ( enumType ) ;
237+ Assert . Contains ( "Always" , enumValues ) ;
238+ Assert . Contains ( "Never" , enumValues ) ;
239+ Assert . Contains ( "OnError" , enumValues ) ;
212240
213- var num = snapshotType . GetProperty ( "Num" ) ;
214- Assert . NotNull ( num ) ;
215- Assert . Equal ( typeof ( decimal ) , num . PropertyType ) ;
216- }
241+ // The derived class should exist and inherit from the base
242+ var type = assembly . GetType ( $ "{ ns } .TransConfirmationCodeType") ;
243+ Assert . NotNull ( type ) ;
217244
218- [ Fact , TestPriority ( 1 ) ]
219- [ UseCulture ( "en-US" ) ]
220- public void TestList ( )
221- {
222- Compiler . Generate ( "List" , ListPattern ) ;
245+ var baseType = assembly . GetType ( $ "{ ns } .CodeType") ;
246+ Assert . Equal ( baseType , type . BaseType ) ;
247+
248+ // The derived class inherits the string Value property from the base class
249+ var valueProperty = type . GetProperty ( "Value" ) ;
250+ Assert . NotNull ( valueProperty ) ;
251+ Assert . Equal ( typeof ( string ) , valueProperty . PropertyType ) ;
252+
253+ // The derived class should have an EnumValue adapter property
254+ var enumValueProperty = type . GetProperty ( "EnumValue" ) ;
255+ Assert . NotNull ( enumValueProperty ) ;
256+ Assert . Equal ( typeof ( Nullable < > ) . MakeGenericType ( enumType ) , enumValueProperty . PropertyType ) ;
257+
258+ // Test that the EnumValue property works correctly
259+ var instance = Activator . CreateInstance ( type ) ;
260+ Assert . NotNull ( instance ) ;
261+
262+ // Set Value to a string and verify EnumValue returns the correct enum
263+ valueProperty . SetValue ( instance , "Always" ) ;
264+ var enumValue = enumValueProperty . GetValue ( instance ) ;
265+ Assert . NotNull ( enumValue ) ;
266+ Assert . Equal ( "Always" , enumValue . ToString ( ) ) ;
267+
268+ // Set EnumValue and verify Value is updated
269+ var alwaysValue = Enum . Parse ( enumType , "Never" ) ;
270+ enumValueProperty . SetValue ( instance , alwaysValue ) ;
271+ var stringValue = valueProperty . GetValue ( instance ) ;
272+ Assert . Equal ( "Never" , stringValue ) ;
273+
274+ // Set EnumValue to null and verify Value is null
275+ enumValueProperty . SetValue ( instance , null ) ;
276+ stringValue = valueProperty . GetValue ( instance ) ;
277+ Assert . Null ( stringValue ) ;
278+ }
279+
280+ [ Fact , TestPriority ( 1 ) ]
281+ [ UseCulture ( "en-US" ) ]
282+ public void TestList ( )
283+ {
284+ Compiler . Generate ( "List" , ListPattern ) ;
223285 SharedTestFunctions . TestSamples ( Output , "List" , ListPattern ) ;
224286 }
225287
0 commit comments