mardi 26 avril 2016

Generate mock XML file from C# class hierachy

In order to generate UBL-order documents in XML, I have created 44 classes in C# using Xml.Serialization. The class consist of a root class "OrderType" which contains a lot of properties (classes), which again contains more properties.

In order to test that the classes always will build a XML document that will pass a validation. I want a XML file containing all the possible nodes (at least once) the hierarchy of Classes/Properties can build.

A very reduced code example:

[XmlRootAttribute]
[XmlTypeAttribute]
public class OrderType
{
     public DeliveryType Delivery { get; set; }
     //+ 50 more properties
     public OrderType(){}
}

[XmlTypeAttribute]
public class DeliveryType 
{
     public QuantityType Quantity { get; set; }
     //+ 10 more properties
     public DeliveryType (){}
}

I have already tried to initialise some properties in some of the constructors and it works fine, but this method would take a whole week to finish.

So! Is there a smart an quick method to generate a Mock XML document with all properties initialized?

It's ok that the outer nodes just are defined e.g.: < Code />





Aucun commentaire:

Enregistrer un commentaire