public void DeleteBookingReturns201() { BookingPayload payload = new BookingPayload(); payload.SetFirstname("Mary"); payload.SetLastname("White"); payload.SetTotalPrice(200); payload.SetDepositPaid(true); payload.SetBookingDates(new BookingDatesPayload(new DateTime(2017, 3, 31), new DateTime(2017, 4, 3))); payload.SetAdditionalNeeds("None"); var response = Booking.PostBooking(payload); string responsePayload = response.Content.ReadAsStringAsync().Result; BookingResponsePayload bookingResponse = JsonConvert.DeserializeObject <BookingResponsePayload>(responsePayload); AuthPayload authPayload = new AuthPayload(); authPayload.SetUsername("admin"); authPayload.SetPassword("password123"); AuthResponsePayload authResponse = Auth.PostAuth(authPayload); var deleteResponse = Booking.DeleteBooking(bookingResponse.bookingid, authResponse.token); Assert.IsTrue(deleteResponse.StatusCode == HttpStatusCode.Created, "Http Status Code is not 201"); }
public void PostAPICall() { //Think of a client like a browser, and the URL we are interested in var client = new RestClient("https://automationintesting.online"); //Here we build up our request with the required information. //In this instance we are just providded the route and stating we expect JSON back var request = new RestRequest("auth/login", DataFormat.Json); //I've created a basic object and set the values with need. //These directly map to the JSON we have to send - https://automationintesting.online/auth/swagger-ui.html AuthPayload payload = new AuthPayload(); payload.username = "******"; payload.password = "******"; //Provide the object we've created to RESTSharp request.AddJsonBody(payload); //Instruct RESTSharp to send our request using the POST method var response = client.Post(request); // //Asserting that the status is "OK" Assert.That(response.StatusCode.ToString(), Is.EqualTo("OK")); //Asserting that the status code is 200 Assert.That((int)response.StatusCode, Is.EqualTo(200)); //This request return JSON, so we have to parse/deserialise it to an object we can use in C# //I've created the AuthResponse below and told JSONConert to use that object //It will try to match properties like for like. AuthResponse dave = JsonConvert.DeserializeObject <AuthResponse>(response.Content); //I'm expecting a token, and I know it's length should be 16 characters. Assert.That(dave.token.Length, Is.EqualTo(16)); }