public void PostEndPointusingXmlData() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature> 8th Generation Intel® Core™ i5 - 8300H </Feature>" + "<Feature> Windows 10 Home 64 - bit English </Feature>" + "<Feature> NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature> 8GB, 2x4GB, DDR4, 2666MHz </Feature>" + " </Features>" + "<Id>" + id + "</Id>" + "<LaptopName> Alienware M17 </LaptopName>" + "</Laptop>"; Dictionary <string, string> requestHeaders = new Dictionary <string, string>() { { "Accept", "application/xml" }, { "Content-Type", "application/xml" } }; IRestResponse <Laptop> restResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, xmlData, DataFormat.Xml); // if (restResponse.IsSuccessful) { Console.WriteLine((int)restResponse.StatusCode); Console.WriteLine(restResponse.Content); Assert.AreEqual(200, (int)restResponse.StatusCode); Assert.AreEqual("AlienWare", restResponse.Data.BrandName); } }
public void TestDeleteEndPoint() { int id = random.Next(100); string jsonData = "{" + "\"BrandName\": \"AnimalWare\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\":" + id + "," + "\"LaptopName\": \"LionWare M17\"" + "}"; Dictionary <string, string> requestHeaders = new Dictionary <string, string>() { { "Accept", "application/json" }, { "Content-Type", "application/json" } }; IRestResponse <Laptop> postResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, jsonData, DataFormat.Json); IRestResponse <Laptop> getResponseBeforeDelete = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + id, requestHeaders); Console.WriteLine("Brandname =>" + getResponseBeforeDelete.Data.BrandName); requestHeaders["Accept"] = "*/*"; //This Header is needed to receive the response from Delete request. IRestResponse deleteResponse = RestRequestHelper.PerformDeleteRequest(deleteUrl + id, requestHeaders); Assert.AreEqual(200, (int)deleteResponse.StatusCode); deleteResponse = RestRequestHelper.PerformDeleteRequest(deleteUrl + id, requestHeaders); Assert.AreEqual(404, (int)deleteResponse.StatusCode); }
public void PuttEndPointsWithJsonData() { int id = random.Next(100); string jsonData = "{" + "\"BrandName\": \"AnimalWare\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\":" + id + "," + "\"LaptopName\": \"LionWare M17\"" + "}"; string jsonDataForPut = "{" + "\"BrandName\": \"LionWare\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\":" + id + "," + "\"LaptopName\": \"AlienWare M17\"" + "}"; Dictionary <string, string> requestHeaders = new Dictionary <string, string>() { { "Accept", "application/json" }, { "Content-Type", "application/json" } }; IRestResponse <Laptop> postResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, jsonData, DataFormat.Json); IRestResponse <Laptop> getResponseBeforePut = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + postResponse.Data.Id, requestHeaders); Console.WriteLine("Brandname =>" + getResponseBeforePut.Data.BrandName); IRestResponse <Laptop> putResponse = RestRequestHelper.PerformPutRequest <Laptop>(putUrl, requestHeaders, jsonDataForPut, DataFormat.Json); Assert.AreEqual("LionWare", putResponse.Data.BrandName); IRestResponse <Laptop> getResponseafterPut = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + postResponse.Data.Id, requestHeaders); Console.WriteLine("LaptopName =>" + getResponseBeforePut.Data.LaptopName); }
public void PostEndPointsusingHelper() { Dictionary <string, string> requestHeaders = new Dictionary <string, string>() { { "Accept", "application/json" }, { "Content-Type", "application/json" } }; IRestResponse <Laptop> restResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, GetLaptopObject(), DataFormat.Json); if (restResponse.IsSuccessful) { Console.WriteLine((int)restResponse.StatusCode); Console.WriteLine(restResponse.Content); Assert.AreEqual(200, (int)restResponse.StatusCode); Assert.AreEqual("sample BrandName", restResponse.Data.BrandName); } }