public void Should_return_JSON_string_when_post_requested()
        {
            dynamic actual = null;

            try
            {
                // Given
                ISlotForResponse model    = CreateModelForPutTest();
                dynamic          expected = CreatedExpectedSlotForPost(model);
                Browser          browser  = CreateBrowser();

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

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

                // Then
                AssertSlotIgnoringIds(expected,
                                      actual);
            }
            finally
            {
                if (actual != null)
                {
                    var slotId = ( int )actual ["Id"].Value;

                    DeleteSlotById(slotId);
                }
            }
        }
        public ISlotForResponse Save(ISlotForResponse slot)
        {
            ISlot toBeUpdated = ToSlot(slot);

            m_Repository.Save(toBeUpdated);

            return new SlotForResponse(toBeUpdated);
        }
        public ISlotForResponse Save(ISlotForResponse slot)
        {
            ISlot toBeUpdated = ToSlot(slot);

            m_Repository.Save(toBeUpdated);

            return(new SlotForResponse(toBeUpdated));
        }
 private ISlot ToSlot(ISlotForResponse slot)
 {
     return(new Slot
     {
         Id = slot.Id,
         DayId = slot.DayId,
         StartDateTime = slot.StartDateTime,
         EndDateTime = slot.EndDateTime,
         Status = slot.Status
     });
 }
        public Response DeleteById(int id)
        {
            ISlotForResponse slot = m_InformationFinder.Delete(id);

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

            return(AsJson(slot));
        }
        public void Save_ReturnsSlot_WhenCalled([NotNull] ISlotForResponse slot)
        {
            // Arrange
            var repository        = Substitute.For <ISlotsRepository>();
            InformationFinder sut = CreateSut(repository);

            // Act
            ISlotForResponse actual = sut.Save(slot);

            // Assert
            AssertSlotIgnoreId(slot,
                               actual);
        }
        private static void AssertSlotIgnoreId(ISlotForResponse expected,
                                               ISlotForResponse actual)
        {
            Console.WriteLine("Comparing days with id {0} and {1}...",
                              expected.Id,
                              actual.Id);

            Assert.True(expected.DayId == actual.DayId,
                        "DayId");
            Assert.True(expected.StartDateTime == actual.StartDateTime,
                        "StartDateTime");
            Assert.True(expected.EndDateTime == actual.EndDateTime,
                        "EndDateTime");
        }
        private dynamic CreateSlotToBeDeleted(Browser browser)
        {
            ISlotForResponse model = CreateModelForPutTest();

            BrowserResponse result = browser.Post("/slots/",
                                                  with =>
            {
                with.JsonBody(model);
            });

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

            return(actual);
        }
        public void FindById_ReturnsNull_ForNotExistingId()
        {
            // Arrange
            var repository = Substitute.For <ISlotsRepository>();

            repository.FindById(IdDoesNotMatter).Returns(( ISlot )null);
            InformationFinder sut = CreateSut(repository);

            // Act
            ISlotForResponse actual = sut.FindById(IdDoesNotMatter);

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

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

            // Act
            ISlotForResponse actual = sut.Delete(IdDoesNotMatter);

            // Assert
            Assert.Null(actual);
        }
        public void Save_ReturnsResponse_ForSlot([NotNull] ISlotForResponse slot)
        {
            // Arrange
            var finder = Substitute.For <IInformationFinder>();

            finder.FindById(Arg.Any <int>()).Returns(slot);
            RequestHandler sut = CreateSut(finder);

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

            // Assert
            Assert.Equal(HttpStatusCode.OK,
                         actual.StatusCode);
        }
        public void DeleteById_ReturnsResponse_WhenCalled([NotNull] ISlotForResponse slot)
        {
            // Arrange
            var finder = Substitute.For <IInformationFinder>();

            finder.Delete(slot.Id).Returns(slot);
            RequestHandler sut = CreateSut(finder);

            // Act
            Response actual = sut.DeleteById(slot.Id);

            // Assert
            Assert.Equal(HttpStatusCode.OK,
                         actual.StatusCode);
        }
        public void Save_CallsSave_WhenCalled([NotNull] ISlotForResponse slot)
        {
            // Arrange
            var repository        = Substitute.For <ISlotsRepository>();
            InformationFinder sut = CreateSut(repository);

            // Act
            sut.Save(slot);

            // Assert
            repository.Received().Save(Arg.Is <ISlot>(x => x.DayId == slot.DayId &&
                                                      x.StartDateTime == slot.StartDateTime &&
                                                      x.EndDateTime == slot.EndDateTime &&
                                                      x.Status == slot.Status));
        }
        public void FindById_ReturnsSlot_ForExistingId([NotNull] ISlot slot)
        {
            // Arrange
            var repository = Substitute.For <ISlotsRepository>();

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

            // Act
            ISlotForResponse actual = sut.FindById(slot.Id);

            // Assert
            Assert.Equal(slot.Id,
                         actual.Id);
        }
        public void Delete_ReturnsDeletedSlot_WhenCalled([NotNull] ISlot slot)
        {
            // Arrange
            var repository = Substitute.For <ISlotsRepository>();

            repository.FindById(Arg.Any <int>()).Returns(slot);
            InformationFinder sut = CreateSut(repository);

            // Act
            ISlotForResponse actual = sut.Delete(IdDoesNotMatter);

            // Assert
            Assert.Equal(slot.Id,
                         actual.Id);
        }
        private dynamic CreatedExpectedDoctorForUpdate(ISlotForResponse slot)
        {
            DateTime endDateTime   = slot.EndDateTime;
            DateTime startDateTime = slot.StartDateTime;

            string json = "{" +
                          "\"Id\":" + slot.Id + "," +
                          "\"DayId\":" + slot.DayId + "," +
                          "\"EndDateTime\":\"" + endDateTime.ToString(DateTimeFormat) + "\"," +
                          "\"StartDateTime\":\"" + startDateTime.ToString(DateTimeFormat) + "\"," +
                          "\"Status\":" + ( int )slot.Status +
                          "}";

            return(ToDynamic(json));
        }
        private dynamic CreatedExpectedSlotForPost(ISlotForResponse slot)
        {
            int      id    = slot.Id;
            DateTime start = slot.StartDateTime;
            DateTime end   = slot.EndDateTime;

            string json = "{" +
                          "\"Id\": " + id + "," +
                          "\"DayId\": 1," +
                          "\"EndDateTime\": \"" + end.ToString(DateTimeFormat) + "\"," +
                          "\"StartDateTime\": \"" + start.ToString(DateTimeFormat) + "\"," +
                          "\"Status\": 1" +
                          "}";

            return(ToDynamic(json));
        }
        public void Should_update_database_when_doctor_is_updated()
        {
            ISlotForResponse model = null;
            dynamic          actual;
            dynamic          expected;

            try
            {
                // Given
                Browser browser = CreateBrowser();
                dynamic slot    = CreateSlotToBeDeleted(browser);
                model    = CreateModelForUpdateTest(slot);
                expected = CreatedExpectedDoctorForUpdate(model);

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

                // Then
                actual = ToDynamic(result.Body.AsString());
            }
            finally
            {
                if (model != null)
                {
                    DeleteSlotById(model.Id);
                }
            }

            // Then
            Assert.NotNull(expected);
            Assert.NotNull(actual);

            AssertSlot(expected,
                       actual);
        }
        private static void AssertSlotIgnoreId(ISlotForResponse expected,
                                               ISlotForResponse actual)
        {
            Console.WriteLine("Comparing days with id {0} and {1}...",
                              expected.Id,
                              actual.Id);

            Assert.True(expected.DayId == actual.DayId,
                        "DayId");
            Assert.True(expected.StartDateTime == actual.StartDateTime,
                        "StartDateTime");
            Assert.True(expected.EndDateTime == actual.EndDateTime,
                        "EndDateTime");
        }
        public Response Save(ISlotForResponse slot)
        {
            ISlotForResponse saved = m_InformationFinder.Save(slot);

            return(AsJson(saved));
        }
        private dynamic CreatedExpectedDoctorForUpdate(ISlotForResponse slot)
        {
            DateTime endDateTime = slot.EndDateTime;
            DateTime startDateTime = slot.StartDateTime;

            string json = "{" +
                          "\"Id\":" + slot.Id + "," +
                          "\"DayId\":" + slot.DayId + "," +
                          "\"EndDateTime\":\"" + endDateTime.ToString(DateTimeFormat) + "\"," +
                          "\"StartDateTime\":\"" + startDateTime.ToString(DateTimeFormat) + "\"," +
                          "\"Status\":" + ( int ) slot.Status +
                          "}";

            return ToDynamic(json);
        }
 private ISlot ToSlot(ISlotForResponse slot)
 {
     return new Slot
            {
                Id = slot.Id,
                DayId = slot.DayId,
                StartDateTime = slot.StartDateTime,
                EndDateTime = slot.EndDateTime,
                Status = slot.Status
            };
 }
        public Response Save(ISlotForResponse slot)
        {
            ISlotForResponse saved = m_InformationFinder.Save(slot);

            return AsJson(saved);
        }
        private dynamic CreatedExpectedSlotForPost(ISlotForResponse slot)
        {
            int id = slot.Id;
            DateTime start = slot.StartDateTime;
            DateTime end = slot.EndDateTime;

            string json = "{" +
                          "\"Id\": " + id + "," +
                          "\"DayId\": 1," +
                          "\"EndDateTime\": \"" + end.ToString(DateTimeFormat) + "\"," +
                          "\"StartDateTime\": \"" + start.ToString(DateTimeFormat) + "\"," +
                          "\"Status\": 1" +
                          "}";

            return ToDynamic(json);
        }