I'm creating an API testing framework, and to avoid having a test class containing 1000's of lines of code I'm looking at creating separate classes which will hold the xml data, which I'll then call in my test.
My initial thoughts were to create a payload class which would contain the XML elements for my test(an example is below)
public class CreateOrderPayload
{
public static string OrderPayload()
{
XDocument OrderData = new XDocument();
XElement root = new XElement("Order");
DateTime now = DateTime.Now;
root.Add(new XElement("BillingAddress",
new XElement("AddressLine1", "Canada adress 17"),
new XElement("AddressLine2", "ccc"),
root.Add(new XElement("Customer",
new XElement("ContactNumber", "ContactNum"),
new XElement("EmailAddress", "[email protected]"),
root.Add(new XElement("OriginalOrderId", "2315923148"));
root.Add(new XElement("Source", "fffff"));
OrderData.Add(root);
return OrderData.ToString();
}
}
In my actual test I'd then look to call the above class so that I can grab the payload to use for my test. I'm using RestSharp to do this so would initialise my test with something like the below:
restClient = new RestClient(Constants.CRCOrderApi);
restRequest = new RestRequest(Method.POST);
What I'm trying to work out is how I would grab the XML from my CreateOrderPayload class to pass across into my test?