Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mganss/XmlSchemaClassGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed May 31, 2022
2 parents 7e3654f + f18798b commit 825af3e
Show file tree
Hide file tree
Showing 3 changed files with 470 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Glob.cs" Version="5.1.766" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="System.CodeDom" Version="6.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.4">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
86 changes: 86 additions & 0 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2578,5 +2578,91 @@ public void TestArrayItemAttribute()
var optionList = applicationType.GetProperty("OptionList");
Assert.Equal("Test_Generation_Namespace.T_OptionList", optionList.PropertyType.FullName);
}

[Fact]
public void CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate()
{
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:element name=""Element"">
<xs:complexType>
<xs:attributeGroup ref=""AttrGroup""/>
</xs:complexType>
</xs:element>
<xs:attributeGroup name=""AttrGroup"">
<xs:attribute name=""Attr"">
<xs:simpleType>
<xs:list itemType=""xs:int""/>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
</xs:schema>";

var generator = new Generator
{
NamespaceProvider = new NamespaceProvider
{
GenerateNamespace = key => "Test",
},
GenerateInterfaces = true,
CollectionSettersMode = CollectionSettersMode.Private
};
var contents = ConvertXml(nameof(CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate), xsd, generator).ToArray();
var assembly = Compiler.Compile(nameof(CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate), contents);

var interfaceProperty = assembly.GetType("Test.IAttrGroup")?.GetProperty("Attr");
var implementerProperty = assembly.GetType("Test.Element")?.GetProperty("Attr");
Assert.NotNull(interfaceProperty);
Assert.NotNull(implementerProperty);

var interfaceHasPublicSetter = interfaceProperty.GetSetMethod() != null;
var implementerHasPublicSetter = implementerProperty.GetSetMethod() != null;
Assert.False(interfaceHasPublicSetter);
Assert.False(implementerHasPublicSetter);
}

[Fact]
public void CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic()
{
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:element name=""Element"">
<xs:complexType>
<xs:attributeGroup ref=""AttrGroup""/>
</xs:complexType>
</xs:element>
<xs:attributeGroup name=""AttrGroup"">
<xs:attribute name=""Attr"">
<xs:simpleType>
<xs:list itemType=""xs:int""/>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
</xs:schema>";

var generator = new Generator
{
NamespaceProvider = new NamespaceProvider
{
GenerateNamespace = key => "Test",
},
GenerateInterfaces = true,
CollectionSettersMode = CollectionSettersMode.Public
};
var contents = ConvertXml(nameof(CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic), xsd, generator).ToArray();
var assembly = Compiler.Compile(nameof(CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic), contents);

var interfaceProperty = assembly.GetType("Test.IAttrGroup")?.GetProperty("Attr");
var implementerProperty = assembly.GetType("Test.Element")?.GetProperty("Attr");
Assert.NotNull(interfaceProperty);
Assert.NotNull(implementerProperty);

var interfaceHasPublicSetter = interfaceProperty.GetSetMethod() != null;
var implementerHasPublicSetter = implementerProperty.GetSetMethod() != null;
Assert.True(interfaceHasPublicSetter);
Assert.True(implementerHasPublicSetter);
}
}
}
Loading

0 comments on commit 825af3e

Please sign in to comment.