public ReservationResultModel AddReservation(int userId, string userMail, DateTime dateTime) { ReservationResultModel model = new ReservationResultModel(); var reservationTemp = GetReservationsByDate(dateTime).Find(x => x.ReservationStartDate == dateTime); if (dateTime < DateTime.Today) { model.ResultText = "Reservation Date Is Outdated"; model.Result = false; } else if (reservationTemp == null) { Reservation reservation = new Reservation(); reservation.UserId = userId; reservation.ReservationStartDate = dateTime; reservation.IsDeleted = false; reservation.UserMail = userMail; int i = _genericRepository.Add(reservation); model.Result = true; model.ResultText = "Reservation Created Successfully"; } else { model.ResultText = "Selected Reservation Time Is Not Enabled"; model.Result = false; } return(model); }
public void MakeReservation_Reservation_Not_Created_Return_BadRequest() { //Arrange int expectedStatusCode = 400; CreateReservationModel createReservationModel = new CreateReservationModel { UserId = Guid.NewGuid(), ProjectionId = Guid.NewGuid(), SeatIds = new List <SeatDomainModel>() }; ReservationResultModel reservationResultModel = new ReservationResultModel { ErrorMessage = null, IsSuccessful = false }; _reservationService = new Mock <IReservationService>(); _reservationService.Setup(x => x .CreateReservation(It.IsAny <CreateReservationModel>())).Returns(reservationResultModel); ReservationsController reservationsController = new ReservationsController(_reservationService.Object); //Act var result = reservationsController.MakeReservation(createReservationModel).Result; var createdResult = ((BadRequestObjectResult)result).Value; var reservationResultDomainModel = (ErrorResponseModel)createdResult; //Assert Assert.IsNotNull(createdResult); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode); }
public ActionResult AddReservation(string date, string time) { DateTime dateTime = string.IsNullOrEmpty(date) ? DateTime.Today : Convert.ToDateTime(date).Date; dateTime = dateTime.AddHours(Convert.ToDouble(time)); ReservationResultModel result = _reservationService.AddReservation(Convert.ToInt32(User.Identity.GetUserId()), User.Identity.GetUserName(), dateTime); TempData["result"] = result.ResultText; return(PartialView("_ReservationList", GetReservationModel(date))); }
public void MakeReservation_Throw_DbUpdateException() { //Arrange int expectedStatusCode = 400; string expectedMessage = "Inner exception error message."; CreateReservationModel createReservationModel = new CreateReservationModel { UserId = Guid.NewGuid(), ProjectionId = Guid.NewGuid(), SeatIds = new List <SeatDomainModel>() }; ReservationResultModel reservationResultModel = new ReservationResultModel { Reservation = new ReservationDomainModel { Id = Guid.NewGuid(), ProjectionId = Guid.NewGuid(), UserId = createReservationModel.UserId }, ErrorMessage = null, IsSuccessful = true }; Exception exception = new Exception("Inner exception error message."); DbUpdateException dbUpdateException = new DbUpdateException("Error.", exception); _reservationService = new Mock <IReservationService>(); _reservationService.Setup(x => x .CreateReservation(It.IsAny <CreateReservationModel>())).Throws(dbUpdateException); ReservationsController reservationsController = new ReservationsController(_reservationService.Object); //Act var result = reservationsController.MakeReservation(createReservationModel).Result; var badRequestResultValue = ((BadRequestObjectResult)result).Value; var errorResponse = (ErrorResponseModel)badRequestResultValue; //Assert Assert.IsNotNull(badRequestResultValue); Assert.AreEqual(expectedMessage, errorResponse.ErrorMessage); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode); }
public void MakeReservation_ReservationCreatedSuccesful_ReturnCreated() { //Arrange int expectedStatusCode = 201; CreateReservationModel createReservationModel = new CreateReservationModel { UserId = Guid.NewGuid(), ProjectionId = Guid.NewGuid(), SeatIds = new List <SeatDomainModel>() }; ReservationResultModel reservationResultModel = new ReservationResultModel { Reservation = new ReservationDomainModel { Id = Guid.NewGuid(), ProjectionId = Guid.NewGuid(), UserId = createReservationModel.UserId }, ErrorMessage = null, IsSuccessful = true }; _reservationService = new Mock <IReservationService>(); _reservationService.Setup(x => x .CreateReservation(It.IsAny <CreateReservationModel>())).Returns(reservationResultModel); ReservationsController reservationsController = new ReservationsController(_reservationService.Object); //Act var result = reservationsController.MakeReservation(createReservationModel).Result; var createdResult = ((CreatedResult)result).Value; var reservationResultDomainModel = (ReservationResultModel)createdResult; //Assert Assert.IsNotNull(createdResult); Assert.AreEqual(createReservationModel.UserId, reservationResultDomainModel.Reservation.UserId); Assert.IsInstanceOfType(result, typeof(CreatedResult)); Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode); }