@@ -41,9 +41,10 @@ private IEnumerable<string> ConvertXml(string name, string xsd, Generator genera
41
41
DataAnnotationMode = generatorPrototype . DataAnnotationMode ,
42
42
GenerateDesignerCategoryAttribute = generatorPrototype . GenerateDesignerCategoryAttribute ,
43
43
EntityFramework = generatorPrototype . EntityFramework ,
44
+ AssemblyVisible = generatorPrototype . AssemblyVisible ,
44
45
GenerateInterfaces = generatorPrototype . GenerateInterfaces ,
45
46
MemberVisitor = generatorPrototype . MemberVisitor ,
46
- CodeTypeReferenceOptions = generatorPrototype . CodeTypeReferenceOptions
47
+ CodeTypeReferenceOptions = generatorPrototype . CodeTypeReferenceOptions
47
48
} ;
48
49
49
50
var set = new XmlSchemaSet ( ) ;
@@ -389,12 +390,12 @@ public void DontGenerateElementForEmptyCollectionInChoice()
389
390
}
390
391
391
392
392
- [ Theory ]
393
- [ InlineData ( CodeTypeReferenceOptions . GlobalReference , "[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]" ) ]
394
- [ InlineData ( ( CodeTypeReferenceOptions ) 0 , "[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]" ) ]
395
- public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions ( CodeTypeReferenceOptions codeTypeReferenceOptions , string expectedLine )
396
- {
397
- const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
393
+ [ Theory ]
394
+ [ InlineData ( CodeTypeReferenceOptions . GlobalReference , "[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]" ) ]
395
+ [ InlineData ( ( CodeTypeReferenceOptions ) 0 , "[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]" ) ]
396
+ public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions ( CodeTypeReferenceOptions codeTypeReferenceOptions , string expectedLine )
397
+ {
398
+ const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
398
399
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
399
400
<xs:complexType name=""document"">
400
401
<xs:attribute name=""some-value"">
@@ -409,26 +410,26 @@ public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions(CodeTypeRef
409
410
</xs:complexType>
410
411
</xs:schema>" ;
411
412
412
- var generatedType = ConvertXml ( nameof ( EditorBrowsableAttributeRespectsCodeTypeReferenceOptions ) , xsd , new Generator
413
- {
414
- CodeTypeReferenceOptions = codeTypeReferenceOptions ,
415
- GenerateNullables = true ,
416
- GenerateInterfaces = false ,
417
- NamespaceProvider = new NamespaceProvider
418
- {
419
- GenerateNamespace = key => "Test"
420
- }
421
- } ) ;
422
-
423
- Assert . Contains (
424
- expectedLine ,
425
- generatedType . First ( ) ) ;
426
- }
427
-
428
- [ Fact ]
429
- public void MixedTypeMustNotCollideWithExistingMembers ( )
430
- {
431
- const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
413
+ var generatedType = ConvertXml ( nameof ( EditorBrowsableAttributeRespectsCodeTypeReferenceOptions ) , xsd , new Generator
414
+ {
415
+ CodeTypeReferenceOptions = codeTypeReferenceOptions ,
416
+ GenerateNullables = true ,
417
+ GenerateInterfaces = false ,
418
+ NamespaceProvider = new NamespaceProvider
419
+ {
420
+ GenerateNamespace = key => "Test"
421
+ }
422
+ } ) ;
423
+
424
+ Assert . Contains (
425
+ expectedLine ,
426
+ generatedType . First ( ) ) ;
427
+ }
428
+
429
+ [ Fact ]
430
+ public void MixedTypeMustNotCollideWithExistingMembers ( )
431
+ {
432
+ const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
432
433
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" targetNamespace=""http://local.none"" xmlns:l=""http://local.none"">
433
434
<xs:element name=""document"" type=""l:elem"">
434
435
</xs:element>
@@ -437,54 +438,54 @@ public void MixedTypeMustNotCollideWithExistingMembers()
437
438
</xs:complexType>
438
439
</xs:schema>" ;
439
440
440
- var generatedType = ConvertXml ( nameof ( MixedTypeMustNotCollideWithExistingMembers ) , xsd , new Generator
441
- {
442
- NamespaceProvider = new NamespaceProvider
443
- {
444
- GenerateNamespace = key => "Test"
445
- }
446
- } ) ;
447
-
448
- Assert . Contains (
449
- @"public string[] Text_1 { get; set; }" ,
450
- generatedType . First ( ) ) ;
451
- }
452
-
453
- [ Fact ]
454
- public void MixedTypeMustNotCollideWithContainingTypeName ( )
455
- {
456
- const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
441
+ var generatedType = ConvertXml ( nameof ( MixedTypeMustNotCollideWithExistingMembers ) , xsd , new Generator
442
+ {
443
+ NamespaceProvider = new NamespaceProvider
444
+ {
445
+ GenerateNamespace = key => "Test"
446
+ }
447
+ } ) ;
448
+
449
+ Assert . Contains (
450
+ @"public string[] Text_1 { get; set; }" ,
451
+ generatedType . First ( ) ) ;
452
+ }
453
+
454
+ [ Fact ]
455
+ public void MixedTypeMustNotCollideWithContainingTypeName ( )
456
+ {
457
+ const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
457
458
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" targetNamespace=""http://local.none"" xmlns:l=""http://local.none"">
458
459
<xs:element name=""document"" type=""l:Text"">
459
460
</xs:element>
460
461
<xs:complexType name=""Text"" mixed=""true"">
461
462
</xs:complexType>
462
463
</xs:schema>" ;
463
464
464
- var generatedType = ConvertXml ( nameof ( MixedTypeMustNotCollideWithExistingMembers ) , xsd , new Generator
465
- {
466
- NamespaceProvider = new NamespaceProvider
467
- {
468
- GenerateNamespace = key => "Test"
469
- }
470
- } ) ;
471
-
472
- Assert . Contains (
473
- @"public string[] Text_1 { get; set; }" ,
474
- generatedType . First ( ) ) ;
475
- }
476
-
477
- [ Theory ]
478
- [ InlineData ( @"xml/sameattributenames.xsd" , @"xml/sameattributenames_import.xsd" ) ]
479
- public void CollidingAttributeAndPropertyNamesCanBeResolved ( params string [ ] files )
480
- {
481
- // Compilation would previously throw due to duplicate type name within type
482
- var assembly = Compiler . GenerateFiles ( "AttributesWithSameName" , files ) ;
483
-
484
- Assert . NotNull ( assembly ) ;
485
- }
486
-
487
- [ Fact ]
465
+ var generatedType = ConvertXml ( nameof ( MixedTypeMustNotCollideWithExistingMembers ) , xsd , new Generator
466
+ {
467
+ NamespaceProvider = new NamespaceProvider
468
+ {
469
+ GenerateNamespace = key => "Test"
470
+ }
471
+ } ) ;
472
+
473
+ Assert . Contains (
474
+ @"public string[] Text_1 { get; set; }" ,
475
+ generatedType . First ( ) ) ;
476
+ }
477
+
478
+ [ Theory ]
479
+ [ InlineData ( @"xml/sameattributenames.xsd" , @"xml/sameattributenames_import.xsd" ) ]
480
+ public void CollidingAttributeAndPropertyNamesCanBeResolved ( params string [ ] files )
481
+ {
482
+ // Compilation would previously throw due to duplicate type name within type
483
+ var assembly = Compiler . GenerateFiles ( "AttributesWithSameName" , files ) ;
484
+
485
+ Assert . NotNull ( assembly ) ;
486
+ }
487
+
488
+ [ Fact ]
488
489
public void ComplexTypeWithAttributeGroupExtension ( )
489
490
{
490
491
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
@@ -630,6 +631,50 @@ public void ChoiceMembersAreNullable()
630
631
Assert . Contains ( "Opt4Specified" , content ) ;
631
632
}
632
633
634
+ [ Fact ]
635
+ public void AssemblyVisibleIsInternal ( )
636
+ {
637
+ // We test to see whether choices which are part of a larger ComplexType are marked as nullable.
638
+ // Because nullability isn't directly exposed in the generated C#, we use "XXXSpecified" on a value type
639
+ // as a proxy.
640
+
641
+ const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
642
+ <xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:xlink=""http://www.w3.org/1999/xlink"" elementFormDefault=""qualified"" attributeFormDefault=""unqualified"">
643
+ <xs:complexType name=""Root"">
644
+ <xs:sequence>
645
+ <!-- Choice directly inside a complex type -->
646
+ <xs:element name=""Sub"">
647
+ <xs:complexType>
648
+ <xs:choice>
649
+ <xs:element name=""Opt1"" type=""xs:int""/>
650
+ <xs:element name=""Opt2"" type=""xs:int""/>
651
+ </xs:choice>
652
+ </xs:complexType>
653
+ </xs:element>
654
+ <!-- Choice as part of a larger sequence -->
655
+ <xs:choice>
656
+ <xs:element name=""Opt3"" type=""xs:int""/>
657
+ <xs:element name=""Opt4"" type=""xs:int""/>
658
+ </xs:choice>
659
+ </xs:sequence>
660
+ </xs:complexType>
661
+ </xs:schema>" ;
662
+
663
+ var generator = new Generator
664
+ {
665
+ NamespaceProvider = new NamespaceProvider
666
+ {
667
+ GenerateNamespace = key => "Test"
668
+ } ,
669
+ AssemblyVisible = true
670
+ } ;
671
+ var contents = ConvertXml ( nameof ( ComplexTypeWithAttributeGroupExtension ) , xsd , generator ) ;
672
+ var content = Assert . Single ( contents ) ;
673
+
674
+ Assert . Contains ( "internal partial class RootSub" , content ) ;
675
+ Assert . Contains ( "internal partial class Root" , content ) ;
676
+ }
677
+
633
678
private static void CompareOutput ( string expected , string actual )
634
679
{
635
680
string Normalize ( string input ) => Regex . Replace ( input , @"[ \t]*\r\n" , "\n " ) ;
0 commit comments