public void SecurePostUsingHTTPClientHelper() { 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>"; string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" }, { "Authorization", authheader } }; restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent); Console.WriteLine(xmlresponsedata.ToString()); Assert.AreEqual("Alienware", xmlresponsedata.BrandName); }
public void testSecureHTTPClientHelper_xml() { 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>"; string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" }, { "Authorization", authheader } }; restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header); 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 = HttpClientHelper.PerformPutRequest(secureputurl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header); 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"); }
public void TestSecureDeletehttpclienthelper() { int idno = this.id; postdata(idno); string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; Dictionary <string, string> header = new Dictionary <string, string> { { "Authorization", authheader } }; restResponse = HttpClientHelper.PerformDeleteRequest(securedelurl + idno, header); Assert.AreEqual(200, restResponse.StatusCode, "The data is deleted"); restResponse = HttpClientHelper.PerformDeleteRequest(securedelurl + idno, header); Assert.AreEqual(404, restResponse.StatusCode, "The data is deleted"); }
public void TestSecureGetUsingHelperMethod() { Dictionary <string, string> httpheader = new Dictionary <string, string>(); httpheader.Add("Accept", "application/json"); //httpheader.Add("Authorization", "Basic YWRtaW46d2VsY29tZQ=="); string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; httpheader.Add("Authorization", authheader); RestResponse restResponse = HttpClientHelper.PerformGetRequest(secureurl, httpheader); Assert.AreEqual(200, restResponse.StatusCode, "Status code is not connected"); //List<JsonRootObject> jsonroot = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent); //Console.WriteLine(jsonroot[0].BrandName.ToString()); List <JsonRootObject> jsondata = ResponseDataHelper.DeserializeJSONResponse <List <JsonRootObject> >(restResponse.ResponseContent); Console.WriteLine(jsondata[1].ToString()); }