public void TestInitialize() { _validator = new BookFormValidator(); var userAvailability = new UserAvailabilityViewModel() { DateTime = DateTime.Parse("21/09/2018 15:50"), TimeSpan = new TimeSpan(2, 0, 0) }; _viewModel = new BookFormViewModel() { Subject = "Test", Availability = userAvailability, StartTime = userAvailability.DateTime.TimeOfDay, EndTime = userAvailability.DateTime.TimeOfDay.Add(new TimeSpan(1, 0, 0)) }; }
public void Book__ServiceFailuare_ServiceErrorAddedToModel() { //Arrange var userAvailability = new UserAvailabilityViewModel() { Id = 113, DateTime = DateTime.Parse("21/09/2018 15:50"), TimeSpan = new TimeSpan(2, 0, 0) }; var viewModel = new BookFormViewModel() { Subject = "Test", Availability = userAvailability, StartTime = userAvailability.DateTime.TimeOfDay, EndTime = userAvailability.DateTime.TimeOfDay.Add(new TimeSpan(1, 0, 0)), Type = new AppointmentTypeViewModel() { Id = 132 } }; var expectedResult = new ServiceResult(false, "error message"); _mockAppointmentService.Setup(m => m.BookAppointment(viewModel.Subject, viewModel.DateTime, viewModel.TimeSpan, _userId, viewModel.Type.Id, viewModel.Availability.Id)) .Returns(expectedResult); //Act var result = _controller.Book(viewModel) as ViewResult; //Assert result.Should().NotBeNull(); var serviceError = _controller.ModelState["Appointment"]; serviceError.Errors.Should().HaveCount(1); serviceError.Errors[0].ErrorMessage.Should().Be(expectedResult.ErrorMessage); }
public void Book__ValidRequest_ShouldRedirectIndex() { //Arrange var userAvailability = new UserAvailabilityViewModel() { Id = 113, DateTime = DateTime.Parse("21/09/2018 15:50"), TimeSpan = new TimeSpan(2, 0, 0) }; var viewModel = new BookFormViewModel() { Subject = "Test", Availability = userAvailability, StartTime = userAvailability.DateTime.TimeOfDay, EndTime = userAvailability.DateTime.TimeOfDay.Add(new TimeSpan(1, 0, 0)), Type = new AppointmentTypeViewModel() { Id = 132 } }; var expectedResult = new ServiceResult(true); _mockAppointmentService.Setup(m => m.BookAppointment(viewModel.Subject, viewModel.DateTime, viewModel.TimeSpan, _userId, viewModel.Type.Id, viewModel.Availability.Id)) .Returns(expectedResult); //Act var result = _controller.Book(viewModel) as RedirectToRouteResult; //Assert result.Should().NotBeNull(); result.RouteValues.Should().HaveCount(1); var routeValue = result.RouteValues["action"]; routeValue.Should().Be("Index"); }
/// <summary> /// Checking the time is inclusive between availability /// start and end time /// </summary> /// <param name="time"></param> /// <param name="availability"></param> /// <returns></returns> private bool ValidAppointmentStartTime(TimeSpan StartTime, UserAvailabilityViewModel availability) { return(StartTime >= availability.DateTime.TimeOfDay && StartTime <= availability.DateTime.TimeOfDay.Add(availability.TimeSpan)); }