0

I'm testing an API and I'm looking to define my payload using classes so that my program can then deserialize/serialize into any format(namely XML in my case). Below is an example of the payload

 <Order>
   <BillingAddress>
     <AddressLine1></AddressLine1>
     <AddressLine2></AddressLine2>
     <City></City>
   </BillingAddress>
   <Items>
     <Item IsKit="false">
     <CountryVATRate></CountryVATRate>
     <Group></Group>
     <Reference></Reference>
   </Item>
   <Item IsKit="false">
    <CountryVATRate>0.25</CountryVATRate>
    <Group>5360693120</Group>
    <Reference>5360693120</Reference>
   </Item>
 </Items>
 <OrderAmount>35</OrderAmount>
 <TimeStamp>2017-03-30 00:00:00.102</TimeStamp>
</Order>

So my thinking is that I would have an overall Order class which looks something like the below

public class Order()
{
  BillingAddress bAddr; //another class
  List Items;
  double OrderAmount;
  DateTime TimeStamp;
 }

What I am trying to work out is the best way of setting up my framework so that in the example of the BillingAddress class I can set up a series of properties e.g. AddressLine1/AddressLine1 etc which can then be called when I run the test

Any advice on how to structure the test framework would be most appreciated

0

I’m not sure how it works in C# but you may use the optional arguments. Also I would recommend to create a models of your payloads. - models -> - xml - xml then pass this file as your payload. In your case it’s XML and for example interface.

  • Thanks Jack. Can you explain further on what you mean by creating a model of the payloads? – Andy Tilston Oct 5 '18 at 8:14
0

You are on the right track here, but do not reinvent the wheel. Simply serializing the xml with any of the available c# serializers will get You started. I did the exact same thing for a rest API in java. It might even be possible to generate the xsl files and then create classes from them (it was in my case, thanks to the IDE). I am no expert in Visual Studio, but it should be capable of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.