Skip to content

Commit

Permalink
Fix duplicate order (fixes #246)
Browse files Browse the repository at this point in the history
Add wfs tests
  • Loading branch information
Michael Ganss committed Jan 14, 2021
1 parent b918fa9 commit f981af5
Show file tree
Hide file tree
Showing 26 changed files with 3,730 additions and 19 deletions.
31 changes: 28 additions & 3 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static IEnumerable<string> ConvertXml(string name, string xsd, Generator

const string IS24Pattern = @"xsd\is24\*\*.xsd";
const string IS24ImmoTransferPattern = @"xsd\is24immotransfer\is24immotransfer.xsd";
const string WadlPattern = @"xsd\wadl\*.xsd";
const string WadlPattern = @"xsd\wadl\wadl.xsd";
const string ListPattern = @"xsd\list\list.xsd";
const string SimplePattern = @"xsd\simple\*.xsd";
const string ArrayOrderPattern = @"xsd\array-order\array-order.xsd";
Expand All @@ -96,6 +96,7 @@ private static IEnumerable<string> ConvertXml(string name, string xsd, Generator
const string VSTstPattern = @"xsd\vstst\vstst.xsd";
const string BpmnPattern = @"xsd\bpmn\*.xsd";
const string DtsxPattern = @"xsd\dtsx\dtsx2.xsd";
const string WfsPattern = @"xsd\wfs\schemas.opengis.net\wfs\2.0\wfs.xsd";

// IATA test takes too long to perform every time

Expand Down Expand Up @@ -447,6 +448,21 @@ public void TestVSTst()
TestSamples("VSTst", VSTstPattern);
}

[Fact, TestPriority(1)]
[UseCulture("en-US")]
public void TestWfs()
{
var output = new FileWatcherOutputWriter(Path.Combine("output", "wfs"));
Compiler.Generate("wfs", WfsPattern,
new Generator
{
OutputWriter = output,
EmitOrder = true,
GenerateInterfaces = false
});
TestSamples("wfs", WfsPattern);
}

private void TestSamples(string name, string pattern)
{
var assembly = Compiler.GetAssembly(name);
Expand All @@ -464,13 +480,18 @@ private bool HandleValidationError(string[] xmlLines, ValidationEventArgs e)
&& !e.Message.Contains("The Pattern constraint failed")); // generator doesn't generate valid values where pattern restrictions exist, e.g. email
}

private static readonly XmlQualifiedName AnyType = new XmlQualifiedName("anyType", XmlSchema.Namespace);

private void DeserializeSampleXml(string pattern, Assembly assembly)
{
var files = Glob.ExpandNames(pattern);

var set = new XmlSchemaSet();
var xmlSchemaReaderSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };

set.XmlResolver = new XmlUrlResolver();

var schemas = files.Select(f => XmlSchema.Read(XmlReader.Create(f), (s, e) =>
var schemas = files.Select(f => XmlSchema.Read(XmlReader.Create(f, xmlSchemaReaderSettings), (s, e) =>
{
Assert.True(false, e.Message);
}));
Expand All @@ -484,7 +505,11 @@ private void DeserializeSampleXml(string pattern, Assembly assembly)

var anyValidXml = false;
var sb = new StringBuilder();
foreach (var rootElement in set.GlobalElements.Values.Cast<XmlSchemaElement>().Where(e => !e.IsAbstract && !(e.ElementSchemaType is XmlSchemaSimpleType)))

foreach (var rootElement in set.GlobalElements.Values.Cast<XmlSchemaElement>().Where(e =>
!e.IsAbstract
&& !(e.ElementSchemaType is XmlSchemaSimpleType)
&& e.ElementSchemaType.QualifiedName != AnyType))
{
var type = FindType(assembly, rootElement.QualifiedName);
var serializer = new XmlSerializer(type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<xsd:schema xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.opengis.net/fes/2.0" elementFormDefault="qualified" version="2.0.3">

<xsd:annotation>
<xsd:documentation>
Filter Encoding is an OGC Standard.
Copyright (c) 2010, 2014 Open Geospatial Consortium.
To obtain additional rights of use, visit http://www.opengeospatial.org/legal/ .
</xsd:documentation>
</xsd:annotation>

<xsd:include schemaLocation="filterAll.xsd"/>

<xsd:element name="expression" abstract="true"/>

<xsd:element name="ValueReference" type="xsd:string" substitutionGroup="fes:expression"/>

<xsd:element name="Function" type="fes:FunctionType" substitutionGroup="fes:expression"/>
<xsd:complexType name="FunctionType">
<xsd:sequence>
<xsd:element ref="fes:expression" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>

<xsd:element name="Literal" type="fes:LiteralType" substitutionGroup="fes:expression"/>
<xsd:complexType name="LiteralType" mixed="true">
<xsd:sequence>
<xsd:any minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="type" type="xsd:QName"/>
</xsd:complexType>

</xsd:schema>
Loading

0 comments on commit f981af5

Please sign in to comment.