TDD on C# with Auto-Fixture how to populate big objects with schema validations
-
08-10-2022 - |
문제
i m making some tests on my project and using Fixture to populate big objects. Those objects make part of an XML that has an schema.
//silly objects
Fixture fixture = new Fixture();
boleto = fixture.Create<Boleto>();
agencia = fixture.Create<Agencia>();
pasajero = fixture.Create<Pasajero>();
aerolinea = fixture.Create<Aerolinea>();
//xml build
XmlMySuite objXmlMySuite = new XmlMySuite();
string strXML = objXmlMySuite.buildXML(aerolinea, pasajero, agencia);
//xml validation
XmlSchemaSet xmlSchema = new XmlSchemaSet();
xmlSchema .Add("schema.xsd");
bool errors = false;
Console.WriteLine("Attempting to validate");
XDocument custOrdDoc = XDocument.Load(new XmlTextReader(new System.IO.StringReader(strXML)));
custOrdDoc.Validate(xmlSchema , (o, e) =>
{
Console.WriteLine("{0}", e.Message);
errors = true;
});
Console.WriteLine("custOrdDoc {0}", errors ? "did not validate" : "validated");
Console.WriteLine();
Assert.IsFalse(errors);
Is there any way to fill/populate the objects with Fixture validating that schema?
For example, one of the elements tag of the XML Schema is:
<xs:element name="Type">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="CCC"/>
<xs:enumeration value="AAA"/>
<xs:enumeration value="BBB"/>
<xs:enumeration value="QQQQ"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow