public ActionResult <string[]> GetAvailableDays(int id, [FromQuery] DateTime?date = null, [FromQuery] int daysForward = 14) { var actualDate = date ?? DateTime.Now; return(Ok(doctorService.GetAvailableDays(doctorService.FindDoctor(id), actualDate, daysForward))); }
public void GetAvailableDays_Should_Return_Two_Days_When_One_Day_Is_Full() { // Arrange ApplicationDbContext dbContext = Shared.GetDatabaseContext(); DoctorService doctorService = new DoctorService(dbContext); Doctor doctor = new Doctor { Id = 1, }; var appointments = new[] { new Appointment // 3:45-4:30 appointment on 2019-11-26 { Id = 1, Date = new DateTime(2019, 11, 26), StartSlot = 15, EndSlot = 17, Doctor = doctor, }, new Appointment // 2:30-3:00 appointment on 2019-11-27 { Id = 2, Date = new DateTime(2019, 11, 27), StartSlot = 10, EndSlot = 11, Doctor = doctor, }, new Appointment // 3:00-3:30 appointment on 2019-11-27 { Id = 3, Date = new DateTime(2019, 11, 27), StartSlot = 12, EndSlot = 13, Doctor = doctor, }, new Appointment // 3:45-4:15 appointment on 2019-11-28 { Id = 4, Date = new DateTime(2019, 11, 28), StartSlot = 15, EndSlot = 17, Doctor = doctor, } }; var workingHours = new[] { new WorkingHours // 2019-11-26, 2:30-12:30 working hours, single appointment { Id = 1, Date = new DateTime(2019, 11, 26), StartSlot = 10, EndSlot = 50, Doctor = doctor, }, new WorkingHours // 2019-11-27, 2:30-3:30 working hours, appointments full { Id = 2, Date = new DateTime(2019, 11, 27), StartSlot = 10, EndSlot = 13, Doctor = doctor, }, new WorkingHours // 2019-11-28, 2:30-3:30 working hours, no appointments { Id = 3, Date = new DateTime(2019, 11, 28), StartSlot = 10, EndSlot = 50, Doctor = doctor, } }; dbContext.Doctors.Add(doctor); dbContext.Appointments.AddRange(appointments); dbContext.WorkingHours.AddRange(workingHours); dbContext.SaveChanges(); // Act string[] availableDays = doctorService.GetAvailableDays(doctor, new DateTime(2019, 11, 26), 14); // Assert Assert.NotNull(availableDays); Assert.Collection(availableDays, i => Assert.Equal("2019-11-26", i), i => Assert.Equal("2019-11-28", i), i => Assert.Equal("2019-12-03", i), i => Assert.Equal("2019-12-04", i), i => Assert.Equal("2019-12-05", i) ); }