Пример #1
0
        public void Should_return_JSON_string_when_person_is_created_for_put()
        {
            dynamic actual = null;

            try
            {
                // Given
                IPersonForResponse model    = CreateModelForPutTest();
                dynamic            expected = CreateExpectedResponseForPutTest();
                Browser            browser  = CreateBrowser();

                // When
                BrowserResponse result = browser.Put("/person/",
                                                     with =>
                {
                    with.JsonBody(model);
                });

                actual = XUnitPersonsHelper.ToDynamic(result.Body.AsString());

                // Then
                XUnitPersonsHelper.AssertPersonIgnoreId(expected,
                                                        actual);
            }
            finally
            {
                if (actual != null)
                {
                    int id = Convert.ToInt32(actual ["Id"].Value);

                    DeleteDoctorById(id);
                }
            }
        }
Пример #2
0
        public void Should_return_JSON_string_when_person_is_created()
        {
            dynamic actual = null;

            try
            {
                // Given
                dynamic expected = CreateExpectedResponseForCreate();
                Browser browser  = CreateBrowser();

                // When
                BrowserResponse result = browser.Post("/person/",
                                                      with =>
                {
                    with.HttpRequest();
                });

                actual = XUnitPersonsHelper.ToDynamic(result.Body.AsString());

                // Then
                XUnitPersonsHelper.AssertPersonIgnoreId(expected,
                                                        actual);
            }
            finally
            {
                if (actual != null)
                {
                    var id = ( long )actual ["Id"].Value;

                    DeleteDoctorById(id);
                }
            }
        }
Пример #3
0
        public void Should_return_JSON_string_when_person_is_updated()
        {
            IPersonForResponse model = null;

            try
            {
                // Given
                Browser browser = CreateBrowser();
                dynamic person  = CreateDoctorToBeDeleted(browser);
                model = CreateModelForUpdate(person);

                dynamic expected = CreatedExpectedDoctorForUpdate(model.Id);

                // When
                BrowserResponse result = browser.Put("/person/",
                                                     with =>
                {
                    with.JsonBody(model);
                });

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

                // Then
                XUnitPersonsHelper.AssertPerson(expected,
                                                actual);
            }
            finally
            {
                if (model != null)
                {
                    DeleteDoctorById(model.Id);
                }
            }
        }
Пример #4
0
        private dynamic CreateExpectedJsonStringForList()
        {
            const string json = "[" +
                                "{\"Id\":1,\"FirstName\":\"Peter\",\"Surname\":\"Smith\",\"DateOfBirth\":\"30/06/2010\",\"Sex\":\"m\",\"Email\":\"[email protected]\"}," +
                                "{\"Id\":2,\"FirstName\":\"Tim\",\"Surname\":\"Mayer\",\"DateOfBirth\":\"30/06/2000\",\"Sex\":\"m\",\"Email\":\"[email protected]\"}" +
                                "]";

            return(XUnitPersonsHelper.ToDynamic(json));
        }
Пример #5
0
        private dynamic CreateDoctorToBeDeleted(Browser browser)
        {
            BrowserResponse result = browser.Post("/person/",
                                                  with =>
            {
                with.HttpRequest();
            });

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

            return(actual);
        }
Пример #6
0
        private dynamic CreateExpectedResponseForPutTest()
        {
            const string json = "{" +
                                "\"FirstName\":\"Create\"," +
                                "\"Surname\":\"Test\"," +
                                "\"Id\":-1," +
                                "\"DateOfBirth\" : \"1/01/2001\"," +
                                "\"Sex\" : \"M\"," +
                                "\"Email\" : \"Email\"" +
                                "}";

            return(XUnitPersonsHelper.ToDynamic(json));
        }
Пример #7
0
        private static dynamic CreateExpectedResponseForMiller()
        {
            const string json = "{" +
                                "\"Id\":1," +
                                "\"FirstName\":\"Peter\"," +
                                "\"Surname\":\"Smith\"," +
                                "\"DateOfBirth\":\"30/06/2010\"," +
                                "\"Sex\":\"m\"," +
                                "\"Email\":\"[email protected]\"" +
                                "}";

            return(XUnitPersonsHelper.ToDynamic(json));
        }
Пример #8
0
        private dynamic CreatedExpectedDoctorForUpdate(int personId)
        {
            string json = "{" +
                          "\"Id\": " + personId + "," +
                          "\"FirstName\": \"FirstName Update\"," +
                          "\"Surname\": \"Surname Update\"," +
                          "\"Sex\": \"F\"," +
                          "\"Email\": \"Email Updated\"," +
                          "\"DateOfBirth\" : \"11/11/2011\"" +
                          "}";

            string together = json;

            return(XUnitPersonsHelper.ToDynamic(together));
        }
Пример #9
0
        public void Should_update_database_when_person_is_updated()
        {
            IPersonForResponse model = null;

            try
            {
                // Given
                Browser browser = CreateBrowser();
                dynamic person  = CreateDoctorToBeDeleted(browser);
                model = CreateModelForUpdate(person);

                // When
                BrowserResponse result = browser.Put("/person/",
                                                     with =>
                {
                    with.JsonBody(model);
                });

                // Then
                Assert.Equal(HttpStatusCode.OK,
                             result.StatusCode);

                // *** Post-conditions ***
                // Given
                dynamic expected = CreatedExpectedDoctorForUpdate(model.Id);

                // When
                result = browser.Get("/person/" + model.Id,
                                     with =>
                {
                    with.HttpRequest();
                });

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

                // Then
                XUnitPersonsHelper.AssertPerson(expected,
                                                actual);
            }
            finally
            {
                if (model != null)
                {
                    DeleteDoctorById(model.Id);
                }
            }
        }
Пример #10
0
        private dynamic CreatedExpectedDoctorFor(int id)
        {
            string dateString = DateTime.Now.ToShortDateString();

            string jsonOne = "{" +
                             "\"Id\": " + id + "," +
                             "\"FirstName\": \"FirstName\"," +
                             "\"Surname\": null," +
                             "\"Sex\": null," +
                             "\"Email\": null,";

            string jsonTwo = "\"DateOfBirth\" : \"" + dateString + "\"}";

            string together = jsonOne + jsonTwo;

            return(XUnitPersonsHelper.ToDynamic(together));
        }
Пример #11
0
        public void Should_return_JSON_string_when_list_requested()
        {
            // Given
            dynamic expected = CreateExpectedJsonStringForList();
            Browser browser  = CreateBrowser();

            // When
            BrowserResponse result = browser.Get("/person/",
                                                 with =>
            {
                with.HttpRequest();
            });

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

            // Then
            XUnitPersonsHelper.AssertDoctors(expected,
                                             actual);
        }
Пример #12
0
        public void Should_return_JSON_string_when_person_with_id_exists()
        {
            // Given
            dynamic expected = CreateExpectedResponseForMiller();
            Browser browser  = CreateBrowser();

            // When
            BrowserResponse result = browser.Get("/person/1",
                                                 with =>
            {
                with.HttpRequest();
            });

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

            // Then
            XUnitPersonsHelper.AssertPerson(expected,
                                            actual);
        }
Пример #13
0
        public void Should_return_JSON_string_when_person_is_deleted()
        {
            // Given
            Browser browser  = CreateBrowser();
            dynamic person   = CreateDoctorToBeDeleted(browser);
            int     personId = Convert.ToInt32(person ["Id"].Value);
            dynamic expected = CreatedExpectedDoctorFor(personId);

            // When
            BrowserResponse result = browser.Delete("/person/" + personId,
                                                    with =>
            {
                with.HttpRequest();
            });

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

            // Then
            XUnitPersonsHelper.AssertPerson(expected,
                                            actual);
        }