public void Should_get_appointments_by_date() { var dto = new AppointmentGetByDateDto() { StartDate = DateTime.Now, EndDate = DateTime.Now.AddMonths(1) }; var item1 = new AppointmentItem { Id = 1, AppointmentDate = DateTime.Now.AddDays(5), CustomerName = "test1" }; var item2 = new AppointmentItem { Id = 2, AppointmentDate = DateTime.Now.AddDays(15), CustomerName = "test2" }; var itemList = Enumerable.Empty <AppointmentItem>().AsQueryable(); itemList.Append(item1); itemList.Append(item2); _repository.Setup(x => x.GetByDate(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(itemList); var result = _controller.GetAppointmentsByDate(dto) as OkObjectResult; _repository.Verify(x => x.GetByDate(dto.StartDate, dto.EndDate), Times.Once); Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); }
public void Should_not_get_appointments_out_of_given_range() { var dto = new AppointmentGetByDateDto() { StartDate = DateTime.Now, EndDate = DateTime.Now }; var result = _controller.GetAppointmentsByDate(dto); _repository.Verify(x => x.GetByDate(dto.StartDate, dto.EndDate), Times.Once); Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); }
public ActionResult GetAppointmentsByDate([FromBody] AppointmentGetByDateDto appointmentByDateDto) { var appointmentItems = _appointmentRepository.GetByDate(appointmentByDateDto.StartDate, appointmentByDateDto.EndDate); if (appointmentItems == null) { return(NotFound()); } foreach (var item in appointmentItems) { _mapper.Map <AppointmentItemDto>(item); } return(Ok(appointmentItems)); }