public void MovieTagsController_GetAllReservations_ReservationsReturnsNull_ReturnError() { //Arrange IEnumerable <ReservationDomainModel> nullDomainModel = null; Task <IEnumerable <ReservationDomainModel> > nullTask = Task.FromResult(nullDomainModel); string expectedMessage = Messages.RESERVATION_GET_ALL_ERROR; int expectedStatusCode = 500; ErrorResponseModel errorResponseModel = new ErrorResponseModel(); errorResponseModel.ErrorMessage = expectedMessage; errorResponseModel.StatusCode = System.Net.HttpStatusCode.InternalServerError; ReservationsController reservationsController = new ReservationsController(_mockReservationService.Object, _mockUserService.Object, _mockProjectionService.Object); _mockReservationService.Setup(x => x.GetAllReservations()).Returns(nullTask); //Act var result = reservationsController.GetAllReservations().ConfigureAwait(false).GetAwaiter().GetResult().Result; ObjectResult viewResult = (ObjectResult)result; var viewMessage = (ErrorResponseModel)viewResult.Value; //Assert Assert.IsNotNull(result); Assert.AreEqual(viewResult.Value.ToString(), errorResponseModel.ToString()); Assert.AreEqual(errorResponseModel.ErrorMessage, viewMessage.ErrorMessage); Assert.AreEqual(viewResult.StatusCode, expectedStatusCode); }
public void ReservationsController_GetAllReservations_ReturnsListOfReservations() { //Arrange List <ReservationDomainModel> reservationList = new List <ReservationDomainModel>(); reservationList.Add(_reservationDomainModel); IEnumerable <ReservationDomainModel> reservations = reservationList; Task <IEnumerable <ReservationDomainModel> > responseTask = Task.FromResult(reservations); int expectedCount = 1; int expectedStatusCode = 200; ReservationsController reservationsController = new ReservationsController(_mockReservationService.Object, _mockUserService.Object, _mockProjectionService.Object); _mockReservationService.Setup(x => x.GetAllReservations()).Returns(responseTask); //Act var result = reservationsController.GetAllReservations().ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var reservationDomainModelResultList = (List <ReservationDomainModel>)resultList; //Assert Assert.IsNotNull(resultList); Assert.AreEqual(reservationDomainModelResultList.Count, expectedCount); Assert.IsInstanceOfType(reservationDomainModelResultList[0], typeof(ReservationDomainModel)); Assert.AreEqual(reservationDomainModelResultList[0].ProjectionId, _reservationDomainModel.ProjectionId); Assert.AreEqual(reservationDomainModelResultList[0].SeatId, _reservationDomainModel.SeatId); Assert.AreEqual(reservationDomainModelResultList[0].UserId, _reservationDomainModel.UserId); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void GetAllReservations_ShouldReturnAllReservations() { ActionResult <IEnumerable <ReservationReadDto> > reservations = _controller.GetAllReservations(); Assert.IsTrue(reservations.Result is OkObjectResult); }