Posts

Showing posts with the label HTTPClient

Automate HTTP POSTing JSON data using HTTPClient

As part of automating Integration Tests for WebAPI calls ,I used  HTTPClient, Nunit and  Json.NET . In this example i will demonstrate  automating POST WebAPI call ( http://google:6789/api/appointment/book)   and JSON data is posted to the WebAPI call. lets say appointmentId is returned as a response.         [ Test ]         public async Task BookAppointmentsWithValidTimeSlotTest()         {             int sampleLeadTime = 5;                          DateTime currentDateTime = DateTime .Today;             int appointmentMonth = currentDateTime.Month;             int appointmentYear = currentDateTime.Year;             int appointmentDay = currentDateTime.Day + sampleLeadTime ; ...

Automate HTTP Get with query parameters using HTTPClient

As part of automating Integration Tests for WebAPI calls ,I used  HTTPClient, Nunit and Json.NET . In this example  i will demonstrate  automating  GET WebAPI with query parameters like  http://www.google.com/calendar?zip=98007&service=1 and lets say the response is returned in a result JSON objects. Brief explanation of code : Query Parameters are built using  HttpUtility .ParseQueryString () and URI is built using UriBuilder(). The object (say  Calendar class) which we want to verify after de-serialization is inside   result  JSON objects (result : {} )   which is a key,value pair . To access value of the result JSON object we need to do something like data[result] as shown in below code. using System.Net.Http; using System.Web; using NUnit.Framework; using System.Net.Http.Headers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; [ Test ]   public async Task GetCalend...