public void testPutUsingJSON() { string contentjson = "{" + "\"BrandName\": \"Alienware\"," + "\"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 M16\"" + "}"; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/json" } }; restResponse = HttpClientHelper.PerformPostRequest(posturl, contentjson, jsondataformat, header); Assert.AreEqual(200, restResponse.StatusCode); contentjson = "{" + "\"BrandName\": \"Alienware\"," + "\"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\"," + "\"1 TB SSD added\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M16\"" + "}"; using (HttpClient httpClient = new HttpClient()) { HttpContent httpContent = new StringContent(contentjson, Encoding.UTF8, jsondataformat); 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.PerformGetRequest(geturl + 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"); JsonRootObject JSONresponsedata = ResponseDataHelper.DeserializeJSONResponse <JsonRootObject>(restResponse.ResponseContent); Console.WriteLine(JSONresponsedata.Features.Feature); Assert.IsTrue(JSONresponsedata.Features.Feature.Contains("1 TB SSD added")); }
public void GetUsingHelperMethod() { Dictionary <string, string> httpheader = new Dictionary <string, string>(); httpheader.Add("Accept", "application/json"); RestResponse restResponse = HttpClientHelper.PerformGetRequest(url, httpheader); //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()); }
private void sendgetrequest() { Dictionary <string, string> httpheader = new Dictionary <string, string>(); httpheader.Add("Accept", "application/json"); restResponse = httpClientAsyncHelper.PerformGetRequest(delayurl, httpheader).GetAwaiter().GetResult(); //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()); }
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()); }