private AppointmentServiceType CreateAppointmentService()
        {
            IAppointmentRepository <IdType> appointmentRepository = new InMemoryAppointmentRepository <IdType>();
            ICalendar SimpleCalendar = new StandardWorkingCalendar();
            AppointmentServiceType appointmentService = new AppointmentService <IdType>(appointmentRepository, SimpleCalendar);

            return(appointmentService);
        }
        public void Index_returns_a_list_of_the_existing_appointments()
        {
            var repository = new InMemoryAppointmentRepository();

            repository.Create(MakeAppointment(1, "John"));
            repository.Create(MakeAppointment(2, "Jane"));
            var controller = GetAppointmentsController(repository);
            var result     = controller.Index() as ViewResult;

            Assert.That(result.ViewData.Model, Is.EqualTo(repository.FindAll()));
        }
        public void Update_Appointment_updates_an_appointment_on_repository()
        {
            var repository = new InMemoryAppointmentRepository();

            repository.Create(MakeAppointment(1, "John"));

            var controller = GetAppointmentsController(repository);

            controller.Edit(MakeAppointment(1, "Charles"));

            Assert.That(repository.FindById(1).Name, Is.EqualTo("Charles"));
        }
        public void Create_Appointment_creates_an_appointment_when_the_model_is_valid()
        {
            var repository = new InMemoryAppointmentRepository();
            var controller = GetAppointmentsController(repository);

            var appointment = MakeAppointment();

            controller.Create(appointment);

            var appointments = repository.FindAll();

            Assert.That(appointments, Contains.Item(appointment));
        }
        public void Delete_Appointment_redirects_to_index_view_on_success()
        {
            var appointment = MakeAppointment();

            var repository = new InMemoryAppointmentRepository();

            repository.Create(appointment);

            var controller = GetAppointmentsController(new InMemoryAppointmentRepository());
            var result     = (RedirectToRouteResult)controller.Delete(appointment.Id);

            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
        }
        public void Delete_Appointment_removes_an_appointment_from_repository()
        {
            var appointment = MakeAppointment();

            var repository = new InMemoryAppointmentRepository();

            repository.Create(appointment);

            var controller = GetAppointmentsController(repository);

            controller.Delete(appointment.Id);

            Assert.That(repository.FindAll(), !Contains.Item(appointment));
        }
        public void FindAvailableAppointments_returns_an_empty_list_if_there_are_not_available_appointments()
        {
            var repository = new InMemoryAppointmentRepository();

            var appointment = new Appointment();

            repository.Create(appointment);

            var mockTimeConverter = new Mock <ITimeConverter>();

            // For test purposes lets assume the local timezone is Pacific Standard Time.
            mockTimeConverter.Setup(x => x.ToLocalTime(It.IsAny <DateTime>(), It.IsAny <String>()))
            .Returns(new DateTime(2015, 07, 15, 12, 01, 00));

            var appointmentsFinder = new AppointmentsFinder(repository, mockTimeConverter.Object);

            var currentTime           = new DateTime(2015, 7, 15, 11, 30, 00);
            var availableAppointments = appointmentsFinder.FindAvailableAppointments(currentTime);

            Assert.That(availableAppointments, Is.Empty);
        }