示例#1
0
        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);
                }
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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);
                }
            }
        }
示例#4
0
        private dynamic CreateExpectedJsonStringForSearchForSmith()
        {
            const string json = "[" +
                                "{\"LastName\":\"Smith\",\"FirstName\":\"Will\",\"Id\":2}," +
                                "{\"LastName\":\"Smith\",\"FirstName\":\"Jane\",\"Id\":3}" +
                                "]";

            return(XUnitDoctorsHelper.ToDynamic(json));
        }
示例#5
0
        private dynamic CreatedExpectedDoctorFor(int doctorId)
        {
            string json = "{" +
                          "\"FirstName\":\"FirstName\"," +
                          "\"LastName\":\"LastName\"," +
                          "\"Id\":" + doctorId +
                          "}";

            return(XUnitDoctorsHelper.ToDynamic(json));
        }
示例#6
0
        private dynamic CreateExpectedResponseForPutTest()
        {
            const string json = "{" +
                                "\"FirstName\":\"Create\"," +
                                "\"LastName\":\"Test\"," +
                                "\"Id\":-1" +
                                "}";

            return(XUnitDoctorsHelper.ToDynamic(json));
        }
示例#7
0
        private dynamic CreateDoctorToBeDeleted(Browser browser)
        {
            BrowserResponse result = browser.Post("/doctors/",
                                                  with =>
            {
                with.HttpRequest();
            });

            dynamic actual = XUnitDoctorsHelper.ToDynamic(result.Body.AsString());

            return(actual);
        }
示例#8
0
        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);
                }
            }
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        private dynamic CreateExpectedResponseForCreate()
        {
            const string json = "{\"LastName\":\"LastName\",\"FirstName\":\"FirstName\",\"Id\":3}";

            return(XUnitDoctorsHelper.ToDynamic(json));
        }
示例#14
0
        private static dynamic CreateExpectedResponseForMiller()
        {
            const string json = "{\"LastName\":\"Miller\",\"FirstName\":\"Mary\",\"Id\":1}";

            return(XUnitDoctorsHelper.ToDynamic(json));
        }