public void Should_return_JSON_string_when_doctor_is_created() { dynamic actual = null; try { // Given dynamic expected = CreateExpectedResponseForCreate(); Browser browser = CreateBrowser(); // When BrowserResponse result = browser.Post("/doctors/", with => { with.HttpRequest(); }); actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctorIgnoreId(expected, actual); } finally { if (actual != null) { var doctorId = ( long )actual ["Id"].Value; DeleteDoctorById(doctorId); } } }
public void Should_return_JSON_string_when_doctor_is_created_for_put() { dynamic actual = null; try { // Given IDoctorForResponse model = CreateModelForPutTest(); dynamic expected = CreateExpectedResponseForPutTest(); Browser browser = CreateBrowser(); // When BrowserResponse result = browser.Put("/doctors/", with => { with.JsonBody(model); }); actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctorIgnoreId(expected, actual); } finally { if (actual != null) { int id = Convert.ToInt32(actual ["Id"].Value); DeleteDoctorById(id); } } }
public void Should_return_JSON_string_when_doctor_is_updated() { IDoctorForResponse model = null; try { // Given Browser browser = CreateBrowser(); dynamic doctor = CreateDoctorToBeDeleted(browser); model = CreateModelForUpdate(doctor); dynamic expected = CreatedExpectedDoctorForUpdate(model.Id); // When BrowserResponse result = browser.Put("/doctors/", with => { with.JsonBody(model); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctor(expected, actual); } finally { if (model != null) { DeleteDoctorById(model.Id); } } }
private dynamic CreateExpectedJsonStringForSearchForSmith() { const string json = "[" + "{\"LastName\":\"Smith\",\"FirstName\":\"Will\",\"Id\":2}," + "{\"LastName\":\"Smith\",\"FirstName\":\"Jane\",\"Id\":3}" + "]"; return(XUnitDoctorsHelper.ToDynamic(json)); }
private dynamic CreatedExpectedDoctorFor(int doctorId) { string json = "{" + "\"FirstName\":\"FirstName\"," + "\"LastName\":\"LastName\"," + "\"Id\":" + doctorId + "}"; return(XUnitDoctorsHelper.ToDynamic(json)); }
private dynamic CreateExpectedResponseForPutTest() { const string json = "{" + "\"FirstName\":\"Create\"," + "\"LastName\":\"Test\"," + "\"Id\":-1" + "}"; return(XUnitDoctorsHelper.ToDynamic(json)); }
private dynamic CreateDoctorToBeDeleted(Browser browser) { BrowserResponse result = browser.Post("/doctors/", with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); return(actual); }
public void Should_update_database_when_doctor_is_updated() { IDoctorForResponse model = null; try { // Given Browser browser = CreateBrowser(); dynamic doctor = CreateDoctorToBeDeleted(browser); model = CreateModelForUpdate(doctor); // When BrowserResponse result = browser.Put("/doctors/", with => { with.JsonBody(model); }); // Then Assert.Equal(HttpStatusCode.OK, result.StatusCode); // *** Post-conditions *** // Given dynamic expected = CreatedExpectedDoctorForUpdate(model.Id); // When result = browser.Get("/doctors/" + model.Id, with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctor(expected, actual); } finally { if (model != null) { DeleteDoctorById(model.Id); } } }
public void Should_return_JSON_string_when_search_by_last_name_returns_multiple() { // Given dynamic expected = CreateExpectedJsonStringForSearchForSmith(); Browser browser = CreateBrowser(); // When BrowserResponse result = browser.Get("/doctors/byLastName/Smith", with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctors(expected, actual); }
public void Should_return_JSON_string_when_list_requested() { // Given dynamic expected = CreateExpectedJsonStringForList(); Browser browser = CreateBrowser(); // When BrowserResponse result = browser.Get("/doctors/", with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctors(expected, actual); }
public void Should_return_JSON_string_when_doctor_with_id_exists() { // Given dynamic expected = CreateExpectedResponseForMiller(); Browser browser = CreateBrowser(); // When BrowserResponse result = browser.Get("/doctors/1", with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctor(expected, actual); }
public void Should_return_JSON_string_when_doctor_is_deleted() { // Given Browser browser = CreateBrowser(); dynamic doctor = CreateDoctorToBeDeleted(browser); int doctorId = Convert.ToInt32(doctor ["Id"].Value); dynamic expected = CreatedExpectedDoctorFor(doctorId); // When BrowserResponse result = browser.Delete("/doctors/" + doctorId, with => { with.HttpRequest(); }); dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString()); // Then XUnitDoctorsHelper.AssertDoctor(expected, actual); }
private dynamic CreateExpectedResponseForCreate() { const string json = "{\"LastName\":\"LastName\",\"FirstName\":\"FirstName\",\"Id\":3}"; return(XUnitDoctorsHelper.ToDynamic(json)); }
private static dynamic CreateExpectedResponseForMiller() { const string json = "{\"LastName\":\"Miller\",\"FirstName\":\"Mary\",\"Id\":1}"; return(XUnitDoctorsHelper.ToDynamic(json)); }