private void sendputrequest() { string contentxml = "<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.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" } }; restResponse = httpClientAsyncHelper.PerformPostRequest(postdelayurl, contentxml, xmldataformat, header).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); contentxml = "<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>" + "<Feature>1 TB is added</Feature>" + "</Features>" + "<Id>" + id.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; //using (HttpClient httpClient = new HttpClient()) //{ // HttpContent httpContent = new StringContent(contentxml, Encoding.UTF8, xmldataformat); // Task<HttpResponseMessage> httpResponseMessage = httpClient.PutAsync(puturl, httpContent); // restResponse = new RestResponse((int)httpResponseMessage.Result.StatusCode, httpResponseMessage.Result.Content.ReadAsStringAsync().Result); // Assert.AreEqual(200, restResponse.StatusCode); //} restResponse = httpClientAsyncHelper.PerformPutRequest(putdelayurl, contentxml, xmldataformat, header).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); restResponse = httpClientAsyncHelper.PerformGetRequest(getdelayurl + id, header).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent); //Console.WriteLine(xmlresponsedata.Features.Feature.ToString()); Assert.IsTrue(xmlresponsedata.Features.Feature.Contains("1 TB is added"), "Failed to add data"); }
private void SendPutRequest() { 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> headers = new Dictionary <string, string>() { { "Accept", "application/xml" } }; RestResponse restResponse = httpClientAsyncHelper.PerformPostRequest(delayPostUrl, xmlData, xmlMediaType, headers).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); 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>" + "<Feature>1 TB of SSD</Feature>" + "</Features>" + "<Id> " + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; restResponse = httpClientAsyncHelper.PerformPutRequest(delayPutUrl, xmlData, xmlMediaType, headers).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); restResponse = httpClientAsyncHelper.PerformGetRequest(delayGetWithId + id, headers).GetAwaiter().GetResult(); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent); Assert.IsTrue(xmlObj.Features.Feature.Contains("1 TB of SSD"), "Item Not found"); }