Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        public IDoctorForResponse Save(IDoctorForResponse doctor)
        {
            IDoctor toBeUpdated = ToDoctor(doctor);

            m_Repository.Save(toBeUpdated);

            return(new DoctorForResponse(toBeUpdated));
        }
        public IDoctorForResponse Save(IDoctorForResponse doctor)
        {
            IDoctor toBeUpdated = ToDoctor(doctor);

            m_Repository.Save(toBeUpdated);

            return new DoctorForResponse(toBeUpdated);
        }
Ejemplo n.º 5
0
        private IEnumerable <IDoctorForResponse> CreateListOneDoctor(IDoctorForResponse doctor)
        {
            var list = new Collection <IDoctorForResponse>
            {
                doctor
            };


            return(list.AsQueryable());
        }
Ejemplo n.º 6
0
        public Response DeleteById(int id)
        {
            IDoctorForResponse doctor = m_InformationFinder.Delete(id);

            if (doctor == null)
            {
                return(HttpStatusCode.NotFound);
            }

            return(AsJson(doctor));
        }
        public void Delete_ReturnsNull_ForCanNotAdd()
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.Delete(Arg.Any <int>()).Returns(( IDoctor )null);
            InformationFinder sut = CreateSut(repository);

            // Act
            IDoctorForResponse actual = sut.Delete(DoesNotMatter);

            // Assert
            Assert.Null(actual);
        }
        public void FindById_ReturnsNull_ForNotExistingId()
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.FindById(DoesNotMatter).Returns(( IDoctor )null);
            InformationFinder sut = CreateSut(repository);

            // Act
            IDoctorForResponse actual = sut.FindById(DoesNotMatter);

            // Assert
            Assert.Null(actual);
        }
Ejemplo n.º 9
0
        public void FindById_ReturnsResponse_ForKnownId([NotNull] IDoctorForResponse doctor)
        {
            // Arrange
            var finder = Substitute.For <IInformationFinder>();

            finder.FindById(doctor.Id).Returns(doctor);
            RequestHandler sut = CreateSut(finder);

            // Act
            Response actual = sut.FindById(doctor.Id);

            // Assert
            Assert.Equal(HttpStatusCode.OK,
                         actual.StatusCode);
        }
        public void Delete_ReturnsNewDoctor_WhenCalled([NotNull] IDoctor doctor)
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.Delete(Arg.Any <int>()).Returns(doctor);
            InformationFinder sut = CreateSut(repository);

            // Act
            IDoctorForResponse actual = sut.Delete(DoesNotMatter);

            // Assert
            Assert.Equal(doctor.Id,
                         actual.Id);
        }
        public void FindById_ReturnsDoctor_ForExistingId([NotNull] IDoctor doctor)
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.FindById(doctor.Id).Returns(doctor);
            InformationFinder sut = CreateSut(repository);

            // Act
            IDoctorForResponse actual = sut.FindById(doctor.Id);

            // Assert
            Assert.Equal(doctor.Id,
                         actual.Id);
        }
        public void Save_CallsSave_WhenCalled([NotNull] IDoctorForResponse toBeUpdated,
                                              [NotNull] IDoctor doctor)
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.Save(Arg.Any <IDoctor>());
            InformationFinder sut = CreateSut(repository);

            // Act
            sut.Save(toBeUpdated);

            // Assert
            repository.Received().Save(Arg.Is <IDoctor>(x => x.Id == toBeUpdated.Id));
        }
Ejemplo n.º 13
0
        private static IDoctor ToDoctor(IDoctorForResponse doctor)
        {
            string firstName = DefaultText(doctor.FirstName,
                                           "FirstName");
            string lastName = DefaultText(doctor.LastName,
                                          "LastName");

            IDoctor instance = new Doctor
            {
                Id        = doctor.Id,
                FirstName = firstName,
                LastName  = lastName
            };

            return(instance);
        }
        public void Save_ReturnsUpdatedDoctor_ForExisting([NotNull] IDoctorForResponse toBeUpdated,
                                                          [NotNull] IDoctor doctor)
        {
            // Arrange
            var repository = Substitute.For <IDoctorsRepository>();

            repository.Save(Arg.Any <IDoctor>());
            InformationFinder sut = CreateSut(repository);

            // Act
            IDoctorForResponse actual = sut.Save(toBeUpdated);

            // Assert
            Assert.Equal(toBeUpdated.Id,
                         actual.Id);
        }
Ejemplo n.º 15
0
        public void FindByLastName_ReturnsResponseOK_ForMoreThanOneDoctor([NotNull] IDoctorForResponse doctor)
        {
            // Arrange
            IEnumerable <IDoctorForResponse> list = CreateListOneDoctor(doctor);
            var finder = Substitute.For <IInformationFinder>();

            finder.FindByLastName(doctor.LastName).Returns(list);
            RequestHandler sut = CreateSut(finder);

            // Act
            Response actual = sut.FindByLastName(doctor.LastName);

            // Assert
            Assert.Equal(HttpStatusCode.OK,
                         actual.StatusCode);
        }
Ejemplo n.º 16
0
        public void Save_ReturnsStatusOK_WhenCalled([NotNull] IDoctorForResponse toBeCreated,
                                                    [NotNull] IDoctorForResponse created)
        {
            // Arrange
            var finder = Substitute.For <IInformationFinder>();

            finder.Save(toBeCreated).Returns(created);
            RequestHandler sut = CreateSut(finder);

            // Act
            Response actual = sut.Save(toBeCreated);

            // Assert
            Assert.Equal(HttpStatusCode.OK,
                         actual.StatusCode);
        }
Ejemplo n.º 17
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);
                }
            }
        }
Ejemplo n.º 18
0
        public Response Save(IDoctorForResponse doctor)
        {
            IDoctorForResponse saved = m_InformationFinder.Save(doctor);

            return(AsJson(saved));
        }
        public Response Save(IDoctorForResponse doctor)
        {
            IDoctorForResponse saved = m_InformationFinder.Save(doctor);

            return AsJson(saved);
        }
        private static IDoctor ToDoctor(IDoctorForResponse doctor)
        {
            string firstName = DefaultText(doctor.FirstName,
                                           "FirstName");
            string lastName = DefaultText(doctor.LastName,
                                          "LastName");

            IDoctor instance = new Doctor
                               {
                                   Id = doctor.Id,
                                   FirstName = firstName,
                                   LastName = lastName
                               };

            return instance;
        }
        private IEnumerable<IDoctorForResponse> CreateListOneDoctor(IDoctorForResponse doctor)
        {
            var list = new Collection <IDoctorForResponse>
                       {
                           doctor
                       };

            return list.AsQueryable();
        }