public void GetNumber_Of_Seats_Return_All() { //Arrange int expectedRow = 5; int expectedNumber = 6; int expectedStatusCode = 200; SeatAuditoriumDomainModel seatAuditoriumDomainModel = new SeatAuditoriumDomainModel { MaxNumber = 6, MaxRow = 5, Seats = new List <SeatDomainModel>() }; SeatAuditoriumDomainModel listOfSeatsIEn = seatAuditoriumDomainModel; Task <SeatAuditoriumDomainModel> responseTask = Task.FromResult(listOfSeatsIEn); _seatService = new Mock <ISeatService>(); _reservationService = new Mock <IReservationService>(); _seatService.Setup(x => x.GetAllSeatsForAuditorium(It.IsAny <int>())).Returns(responseTask); SeatsController seatsController = new SeatsController(_seatService.Object, _reservationService.Object); //Act var result = seatsController.GetNumberOfSeats(1).ConfigureAwait(false).GetAwaiter().GetResult().Result; var objectResult = ((OkObjectResult)result).Value; SeatAuditoriumDomainModel seatAuditoriumResult = (SeatAuditoriumDomainModel)objectResult; //Assert Assert.IsNotNull(objectResult); Assert.AreEqual(expectedRow, seatAuditoriumResult.MaxRow); Assert.AreEqual(expectedNumber, seatAuditoriumResult.MaxNumber); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void GetNumber_Of_Seats_Return_NotFound() { //Arrange int expectedStatusCode = 404; string expectedMessage = Messages.SEAT_AUDITORIUM_NOT_FOUND; SeatAuditoriumDomainModel seatAuditoriumDomainModel = null; Task <SeatAuditoriumDomainModel> responseTask = Task.FromResult(seatAuditoriumDomainModel); _seatService = new Mock <ISeatService>(); _reservationService = new Mock <IReservationService>(); _seatService.Setup(x => x.GetAllSeatsForAuditorium(It.IsAny <int>())).Returns(responseTask); SeatsController seatsController = new SeatsController(_seatService.Object, _reservationService.Object); //Act var result = seatsController.GetNumberOfSeats(1).ConfigureAwait(false).GetAwaiter().GetResult().Result; var objectResult = ((NotFoundObjectResult)result).Value; string seatAuditoriumResult = (string)objectResult; //Assert Assert.IsNotNull(objectResult); Assert.AreEqual(expectedMessage, seatAuditoriumResult); Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult)); Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode); }
public void SeatsController_GetNumberOfSeats_ReturnsNumberOfSeatsModel() { //Arrange Task <NumberOfSeatsModel> numberOfSeats = Task.FromResult(_numberOfSeats); SeatsController seatsController = new SeatsController(_mockSeatService.Object); int expectedStatusCode = 200; _mockSeatService.Setup(x => x.GetNumberOfSeats(It.IsAny <int>())).Returns(numberOfSeats); //Act var result = seatsController.GetNumberOfSeats(_seatDomainModel.AuditoriumId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var seatDomainModelResultList = (NumberOfSeatsModel)resultList; //Assert Assert.IsNotNull(seatDomainModelResultList); Assert.IsInstanceOfType(seatDomainModelResultList, typeof(NumberOfSeatsModel)); Assert.AreEqual(seatDomainModelResultList.MaxNumber, _numberOfSeats.MaxNumber); Assert.AreEqual(seatDomainModelResultList.MaxRow, _numberOfSeats.MaxRow); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void SeatsController_GetNumberOfSeats_SeatServiceReturnsNull_404() { //Arrange NumberOfSeatsModel nullNum = null; Task <NumberOfSeatsModel> numberOfSeats = Task.FromResult(nullNum); SeatsController seatsController = new SeatsController(_mockSeatService.Object); int expectedStatusCode = 404; string expectedMessage = Messages.AUDITORIUM_DOES_NOT_EXIST; _mockSeatService.Setup(x => x.GetNumberOfSeats(It.IsAny <int>())).Returns(numberOfSeats); //Act var result = seatsController.GetNumberOfSeats(_seatDomainModel.AuditoriumId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultResponse = ((NotFoundObjectResult)result); var badObjectResult = ((NotFoundObjectResult)result).Value; //Assert Assert.IsNotNull(resultResponse); Assert.AreEqual(expectedMessage, badObjectResult); Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult)); Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode); }