public async Task SearchAppointmentsByYearMonthAsync_should_return_aggregate_given_no_slots() { var config = new AppointmentConfig() { AvailableIntervalStart = new LocalDate(2021, 5, 5), AvailableIntervalEnd = new LocalDate(2021, 5, 5), }; await configManager !.SaveConfigAsync(config); var aggregatesForMonth = await sut !.SearchAppointmentsByYearMonthAsync(new YearMonth(2021, 5)); Assert.AreEqual(new YearMonth(2021, 5), aggregatesForMonth.Month); Assert.IsFalse(aggregatesForMonth.PrevMonthAvailable); Assert.IsFalse(aggregatesForMonth.NextMonthAvailable); Assert.IsTrue(aggregatesForMonth.Appointments.Any()); foreach (var daily in aggregatesForMonth.Appointments) { Assert.AreEqual(new YearMonth(2021, 5), daily.Date.ToYearMonth()); if (daily.Date <= new LocalDate(2021, 5, 4)) { Assert.IsFalse(daily.PrevDateAvailable); Assert.IsTrue(daily.NextDateAvailable); } else if (daily.Date >= new LocalDate(2021, 5, 6)) { Assert.IsTrue(daily.PrevDateAvailable); Assert.IsFalse(daily.NextDateAvailable); } else { Assert.IsFalse(daily.PrevDateAvailable); Assert.IsFalse(daily.NextDateAvailable); } } }
public async Task SearchAppointmentsByDateAsync_should_return_aggregate_given_appointment_exists() { var config = new AppointmentConfig() { AvailableIntervalStart = new LocalDate(2021, 5, 5), AvailableIntervalEnd = new LocalDate(2021, 5, 5), }; await configManager !.SaveConfigAsync(config); var slot = new AppointmentSlot() { From = new LocalDateTime(2021, 5, 5, 10, 0), Duration = Period.FromHours(1), CountOfSlot = 1, }; db !.Slots.Add(slot); var appointment = new Appointment() { From = new LocalDateTime(2021, 5, 5, 10, 0), Duration = Period.FromHours(1), }; db !.Appointments.Add(appointment); await db !.SaveChangesAsync(); var aggregatesForDay = await sut !.SearchAppointmentsByDateAsync(new LocalDate(2021, 5, 5)); Assert.IsTrue(aggregatesForDay.AllSlots.First().Appointments.Any()); }
public async Task <IActionResult> OnPostAppointmentConfig() { var appointmentConfig = new AppointmentConfig(); appointmentConfig.AvailableIntervalStart = ParseDate(AvailableIntervalStart); appointmentConfig.AvailableIntervalEnd = ParseDate(AvailableIntervalEnd); await _appointmentConfigManager.SaveConfigAsync(appointmentConfig); return(RedirectToPage()); }
public async Task SearchAppointmentsByYearMonthAsync_should_return_aggregate_given_next_month_available() { var config = new AppointmentConfig() { AvailableIntervalStart = new LocalDate(2021, 5, 1), AvailableIntervalEnd = new LocalDate(2021, 6, 1), }; await configManager !.SaveConfigAsync(config); var aggregatesForMonth = await sut !.SearchAppointmentsByYearMonthAsync(new YearMonth(2021, 5)); Assert.AreEqual(new YearMonth(2021, 5), aggregatesForMonth.Month); Assert.IsFalse(aggregatesForMonth.PrevMonthAvailable); Assert.IsTrue(aggregatesForMonth.NextMonthAvailable); }
public AppointmentsForDay(LocalDate date, AppointmentConfig config, List <AppointmentAggregate> slots) { PrevDateAvailable = config.AvailableIntervalStart == null || config.AvailableIntervalStart < date; NextDateAvailable = config.AvailableIntervalEnd == null || date < config.AvailableIntervalEnd; Date = date; AllSlots = slots.OrderBy(a => a.From).ToList(); if (((config.AvailableIntervalStart == null || config.AvailableIntervalStart <= date) && (config.AvailableIntervalEnd == null || date <= config.AvailableIntervalEnd))) { AvailableSlots = AllSlots.Where(a => a.CanCreateAppointment).ToList(); } else { AvailableSlots = new List <AppointmentAggregate>(); } }
public async Task SearchAppointmentsByDateAsync_should_return_aggregate_given_no_slot() { var config = new AppointmentConfig() { AvailableIntervalStart = new LocalDate(2021, 5, 5), AvailableIntervalEnd = new LocalDate(2021, 5, 5), }; await configManager !.SaveConfigAsync(config); var aggregatesForDay = await sut !.SearchAppointmentsByDateAsync(new LocalDate(2021, 5, 5)); Assert.AreEqual(new LocalDate(2021, 5, 5), aggregatesForDay.Date); Assert.IsFalse(aggregatesForDay.PrevDateAvailable); Assert.IsFalse(aggregatesForDay.NextDateAvailable); Assert.IsFalse(aggregatesForDay.AllSlots.Any()); }
public Task SaveConfigAsync(AppointmentConfig config) { return(SaveConfigAsync <AppointmentConfig>(config)); }
public AppointmentsForMonth(YearMonth month, AppointmentConfig config) { PrevMonthAvailable = config.AvailableIntervalStart == null || config.AvailableIntervalStart.Value.ToYearMonth() < month; NextMonthAvailable = config.AvailableIntervalEnd == null || month < config.AvailableIntervalEnd.Value.ToYearMonth(); Month = month; }