public void UpdateBooking_UrlEncodedRequest_UrlEncodedResponse() { string tokenvalue = restResponse.Data.token; //Make a post request to add new booking and save its bookingid Dictionary <string, string> header = new Dictionary <string, string>() { { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/xml" } }; DateTime checkin = new DateTime(2016, 02, 18); DateTime checkout = new DateTime(2017, 02, 21); Booking booking = new Booking("Manisha", "Chanda", 200, true, new Bookingdates(checkin, checkout), "Towel"); RestClientHelper restClientHelper = new RestClientHelper(); object urlencodedbody = URLformat.SerializeURLformat(booking.firstname, booking.lastname, booking.totalprice, booking.depositpaid, booking.bookingdates); IRestResponse <CreatedbookingXML> restresponse = restClientHelper.PerformPostRequest <CreatedbookingXML>(URLEndPoint.bookingurl, header, null, urlencodedbody, true); Assert.AreEqual(200, (int)restresponse.StatusCode); int bookingid = int.Parse(restresponse.Data.Bookingid); // Make a put request and update booking using bookingid header = new Dictionary <string, string>() { { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/x-www-form-urlencoded" } }; checkin = new DateTime(2016, 12, 16); checkout = new DateTime(2017, 12, 29); urlencodedbody = URLformat.SerializeURLformat("Manu", "Chandu", 150, false, new Bookingdates(checkin, checkout)); RestClientHelper restClientHelper1 = new RestClientHelper(); IRestResponse restresponse1 = restClientHelper1.PerformPutRequest(URLEndPoint.bookingurl + bookingid, header, tokenvalue, urlencodedbody, true); Assert.AreEqual(200, (int)restresponse1.StatusCode); //Make a get response and verify the booking has been updated header = new Dictionary <string, string>() { { "Accept", "application/x-www-form-urlencoded" } }; RestClientHelper restClientHelper2 = new RestClientHelper(); IRestResponse restresponse2 = restClientHelper2.PerformGetRequest(URLEndPoint.bookingurl + bookingid, header); Assert.AreEqual(200, (int)restresponse2.StatusCode); Assert.IsNotNull(restresponse2.Content, "Rest response is null"); Assert.IsTrue(restresponse2.Content.Contains("Manu"), "Firstname is not updated "); Assert.IsTrue(restresponse2.Content.Contains("Chandu"), "Lastname is not updated"); Assert.IsTrue(restresponse2.Content.Contains("150"), "Total price is not updated"); Assert.IsTrue(restresponse2.Content.Contains(Booking.convertdateinstring(checkin)), "Checkin Date is not updated"); Assert.IsTrue(restresponse2.Content.Contains(Booking.convertdateinstring(checkout)), "Check out date is not updated"); Assert.IsTrue(restresponse2.Content.Contains("true"), "Deposit paid should not be updated."); }
public void CreateBooking_URLencodedRequest_URLencodedResponse() { Dictionary <string, string> header = new Dictionary <string, string>() { { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/x-www-form-urlencoded" } }; Booking booking = new Booking("Manoj", "Kumar", 1240, false, new Bookingdates(new DateTime(2019, 11, 12), new DateTime(2019, 12, 1)), "Towel"); RestClientHelper restClientHelper = new RestClientHelper(); object urlencodedbody = URLformat.SerializeURLformat(booking.firstname, booking.lastname, booking.totalprice, booking.depositpaid, booking.bookingdates); IRestResponse restResponse = restClientHelper.PerformPostRequest(URLEndPoint.bookingurl, header, null, urlencodedbody, true); Assert.AreEqual(200, (int)restResponse.StatusCode); Assert.IsNotNull(restResponse.Content, "Rest response is null"); Assert.IsTrue(restResponse.Content.Contains("&booking%5Btotalprice%5D"), "Data has not been added"); }
public void CreateBooking_URLencodedRequest_XmlResponse() { Dictionary <string, string> header = new Dictionary <string, string>() { { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/xml" } }; Booking booking = new Booking("Mahesh", "Thakur", 2000, true, new Bookingdates(new DateTime(2016, 2, 12), new DateTime(2017, 3, 1)), "Towel might be required"); RestClientHelper restClientHelper = new RestClientHelper(); object urlencodedbody = URLformat.SerializeURLformat(booking.firstname, booking.lastname, booking.totalprice, booking.depositpaid, booking.bookingdates); IRestResponse <CreatedbookingXML> restResponse = restClientHelper.PerformPostRequest <CreatedbookingXML>(URLEndPoint.bookingurl, header, null, urlencodedbody, true); Assert.AreEqual(200, (int)restResponse.StatusCode); Assert.IsNotNull(restResponse.Data, "Rest response is null"); Assert.IsTrue(restResponse.Data.Booking.Firstname.Contains("Mahesh"), "Data has not been added"); }