Esempio n. 1
0
        public void DeleteBookingUsingBasicAuth()
        {
            //Make a post request to add new booking and save its bookingid
            Dictionary <string, string> header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" }
            };
            Booking          booking                     = new Booking("Manisha", "Chanda", 200, true, new Bookingdates(new DateTime(2011, 12, 28), new DateTime(2012, 3, 1)), "Vacation so do not disturb");
            RestClientHelper restClientHelper            = new RestClientHelper();
            IRestResponse <BookingResponse> restresponse = restClientHelper.PerformPostRequest <BookingResponse>(URLEndPoint.bookingurl, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse.StatusCode);
            Assert.IsNotNull(restresponse.Data, "Rest response is null");
            int bookingid = restresponse.Data.bookingid;

            //Use basic authentication and perfrom delete request using bookingid
            header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Authorization", AuthenticationValues.Base64EncodedBaiscAuth() }
            };
            RestClientHelper restClientHelper1 = new RestClientHelper();
            IRestResponse    restResponse1     = restClientHelper1.PerformDeleteRequest(URLEndPoint.bookingurl + bookingid, header, null);

            Assert.AreEqual(201, (int)restResponse1.StatusCode);

            //Verify the booking id and its values does not exist
            restResponse1 = restClientHelper.PerformDeleteRequest(URLEndPoint.bookingurl + bookingid, header, null);
            Assert.AreEqual(405, (int)restResponse1.StatusCode);
        }
Esempio n. 2
0
        public void UpdateBooking_JsonRequest_JsonResponse_BaiscAuth()
        {
            //Make a post request to add new booking and save its bookingid
            Dictionary <string, string> header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" }
            };
            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();
            IRestResponse <BookingResponse> restresponse = restClientHelper.PerformPostRequest <BookingResponse>(URLEndPoint.bookingurl, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse.StatusCode);
            int bookingid = restresponse.Data.bookingid;

            //Make a put request and update booking using bookingid
            header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" },
                { "Authorization", AuthenticationValues.Base64EncodedBaiscAuth() }
            };
            checkin  = new DateTime(2016, 02, 09);
            checkout = new DateTime(2017, 02, 20);
            Booking                 booking1          = new Booking("Manu", "Chandu", 150, true, new Bookingdates(checkin, checkout), "Towel not needed");
            RestClientHelper        restClientHelper1 = new RestClientHelper();
            IRestResponse <Booking> restresponse1     = restClientHelper1.PerformPutRequest <Booking>(URLEndPoint.bookingurl + bookingid, header, null, booking1, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse1.StatusCode);

            //Make a get response and verify the booking has been updated
            header = new Dictionary <string, string>()
            {
                { "Accept", "application/json" }
            };
            RestClientHelper        restClientHelper2 = new RestClientHelper();
            IRestResponse <Booking> restresponse2     = restClientHelper2.PerformGetRequest <Booking>(URLEndPoint.bookingurl + bookingid, header);

            Assert.AreEqual(200, (int)restresponse2.StatusCode);
            Assert.IsNotNull(restresponse2.Content, "Rest response is null");
            Assert.IsTrue(restresponse2.Data.firstname.Contains("Manu"), "Firstname is not updated ");
            Assert.IsTrue(restresponse2.Data.lastname.Contains("Chandu"), "Lastname is not updated");
            Assert.AreEqual(150, restresponse2.Data.totalprice, "Total price is not updated");
            Assert.AreEqual(Booking.convertdateinstring(checkin), Booking.convertdateinstring(restresponse2.Data.bookingdates.checkin), "Checkin date is not updated");
            Assert.AreEqual(Booking.convertdateinstring(checkout), Booking.convertdateinstring(restresponse2.Data.bookingdates.checkout), "Checkout date is not updated");
            Assert.IsTrue(restresponse2.Data.additionalneeds.Contains("Towel not needed"), "Additional needs is not updated");
        }
Esempio n. 3
0
        public void UpdatePartialBooking_JsonRequest_XmlResponse_BasicAuth()
        {
            //Make a post request to add new booking and save its bookingid
            Dictionary <string, string> header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/xml" }
            };
            Booking          booking          = new Booking("Mikk", "Poom", 2120, false, new Bookingdates(new DateTime(2017, 01, 21), new DateTime(2017, 02, 21)), "Towel needed");
            RestClientHelper restClientHelper = new RestClientHelper();
            IRestResponse <CreatedbookingXML> restresponse = restClientHelper.PerformPostRequest <CreatedbookingXML>(URLEndPoint.bookingurl, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse.StatusCode);
            int bookingid = int.Parse(restresponse.Data.Bookingid);

            //Make a patch request and update booking using bookingid
            header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/xml" },
                { "Authorization", AuthenticationValues.Base64EncodedBaiscAuth() }
            };
            DateTime checkin  = new DateTime(2016, 02, 09);
            DateTime checkout = new DateTime(2017, 02, 20);

            booking.SetAdditionalNeeds("Nothing required");
            booking.SetBookingDates(new Bookingdates(checkin, checkout));
            RestClientHelper           restClientHelper1 = new RestClientHelper();
            IRestResponse <BookingXML> restresponse1     = restClientHelper1.PerformPatchRequest <BookingXML>(URLEndPoint.bookingurl + bookingid, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse1.StatusCode);

            // Make a get response and verify the booking has been updated
            header = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };
            RestClientHelper           restClientHelper2 = new RestClientHelper();
            IRestResponse <BookingXML> restresponse2     = restClientHelper2.PerformGetRequest <BookingXML>(URLEndPoint.bookingurl + bookingid, header);

            Assert.AreEqual(200, (int)restresponse2.StatusCode);
            Assert.IsNotNull(restresponse2.Content, "Rest response is null");
            Assert.AreEqual(Booking.convertdateinstring(checkin), restresponse2.Data.Bookingdates.Checkin, "Checkin date is not updated");
            Assert.AreEqual(Booking.convertdateinstring(checkout), restresponse2.Data.Bookingdates.Checkout, "Checkout date is not updated");
            Assert.IsTrue(restresponse2.Data.Additionalneeds.Contains("Nothing required"), "Additional needs is not updated");
        }