public IActionResult View(int id, [FromQuery(Name = "date")] DateTime date, [FromQuery(Name = "patient")] int?patientId ) { Doctor doctor = doctorService.FindDoctor(id); if (doctor == null) { logger.LogError("There was en error while trying to find doctor"); Response.StatusCode = 404; return(View("NotFound")); } DoctorViewModel viewModel = new DoctorViewModel(doctor, doctorService); ViewBag.doctorView = viewModel; ViewBag.freeHours = doctorService.ComputeFreeSlots(doctor, date); ViewBag.date = date; ViewBag.patientId = patientId; return(View()); }
public void ComputeFreeSlots_Should_Return_Not_Empty_Array_Of_Hours_When_Given_Working_Hours_And_Appointment() { // Arrange ApplicationDbContext dbContext = Shared.GetDatabaseContext(); DoctorService doctorService = new DoctorService(dbContext); Doctor doctor = new Doctor { Id = 1, }; Appointment appointment = new Appointment // 3:45-4:30 appointment { Id = 1, Date = new DateTime(2019, 11, 26), StartSlot = 15, EndSlot = 17, Doctor = doctor, }; WorkingHours workingHours = new WorkingHours // 2:30-12:30 working hours { Id = 1, Date = new DateTime(2019, 11, 26), StartSlot = 10, EndSlot = 50, Doctor = doctor, }; dbContext.Doctors.Add(doctor); dbContext.Appointments.Add(appointment); dbContext.WorkingHours.Add(workingHours); dbContext.SaveChanges(); // Act string[] freeSlots = doctorService.ComputeFreeSlots(doctor, new DateTime(2019, 11, 26)); // Assert Assert.NotNull(freeSlots); Assert.NotEmpty(freeSlots); string[] invalidSlots = new string[] { "3:45", "4:00", "4:15" }; bool contains = invalidSlots.Any(c => freeSlots.Contains(c)); Assert.False(contains); }