public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_Successful() { IEnumerable <Auditorium> auditoriums = _listOFAuditoriums; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; Auditorium auditorium = _auditorium; Auditorium newAuditorium = _newAuditorium; var numberOfSeatsPerRow = 1; var numberOfRows = 1; Data.Cinema cinema = _cinema; Task <Data.Cinema> responseTaskCinemasRepository = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTaskCinemasRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); Task <IEnumerable <Auditorium> > responseTaskAuditoriumsRepository = Task.FromResult(auditoriums); _mockAuditoriumsRepository.Setup(x => x.GetByAuditName(auditoriumDomainModel.Name, cinema.Id)).Returns(responseTaskAuditoriumsRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockAuditoriumsRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(newAuditorium); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.IsNull(resultAction.ErrorMessage); Assert.IsTrue(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); Assert.AreEqual(1, resultAction.Auditorium.Id); }
public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_InvalidCinemaId() { //Arrange CreateAuditoriumResultModel expectedResultModel = new CreateAuditoriumResultModel() { ErrorMessage = "Cannot create new auditorium, auditorium with given cinemaId does not exist.", IsSuccessful = false }; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; var numberOfSeatsPerRow = 2; var numberOfRows = 2; Data.Cinema cinema = null; Task <Data.Cinema> responseTask = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedResultModel.ErrorMessage, resultAction.ErrorMessage); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); }
public void AuditoriumsService_CreateAuditorium_ReturnCreateAuditoriumResultModel_AuditoriumWithSameNameExists() { //Arrange CreateAuditoriumResultModel expectedResultModel = new CreateAuditoriumResultModel() { ErrorMessage = "Cannot create new auditorium, auditorium with same name already exist.", IsSuccessful = false }; IEnumerable <Auditorium> auditoriums = _listOFAuditoriums; AuditoriumDomainModel auditoriumDomainModel = _auditoriumDomainModel; var numberOfSeatsPerRow = 2; var numberOfRows = 2; Data.Cinema cinema = _cinema; Task <Data.Cinema> responseTaskCinemasRepository = Task.FromResult(cinema); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTaskCinemasRepository); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); Task <IEnumerable <Auditorium> > responseTaskAuditoriumsRepository = Task.FromResult(auditoriums); _mockAuditoriumsRepository.Setup(x => x.GetByAuditName(auditoriumDomainModel.Name, cinema.Id)).Returns(responseTaskAuditoriumsRepository); AuditoriumService auditoriumController = new AuditoriumService(_mockAuditoriumsRepository.Object, _mockCinemasRepository.Object, _mockSeatsRepository.Object, _mockProjectionRepository.Object, _mockTicketService.Object); //Act var resultAction = auditoriumController.CreateAuditorium(_auditoriumDomainModel, numberOfRows, numberOfSeatsPerRow).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedResultModel.ErrorMessage, resultAction.ErrorMessage); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); }
public void AuditoriumService_CreateAuditorium_ReturnsCreatedAuditoriumWithSeats() { //Arrange var expectedSeatCount = 3; int numOfRows = 2; int numOfSeats = 4; Seat s1 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1 }; Seat s2 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; Seat s3 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s4 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s5 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s6 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; List <Auditorium> audits = new List <Auditorium>(); List <Seat> seats = new List <Seat>(); List <SeatDomainModel> seatsList = new List <SeatDomainModel>(); seats.Add(s1); seats.Add(s2); seats.Add(s3); seatsList.Add(s4); seatsList.Add(s5); seatsList.Add(s6); _auditorium.Seats = seats; _auditoriumDomainModel.SeatsList = seatsList; AuditoriumDomainModel ad2 = new AuditoriumDomainModel { Id = 22, CinemaId = 2, Name = "bla bla audit", SeatsList = seatsList }; CreateAuditoriumResultModel cr = new CreateAuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = _auditoriumDomainModel }; _mockCinemaRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_cinema); _mockAuditoriumRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(_auditorium); _mockAuditoriumRepository.Setup(x => x.GetByAuditName(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(audits); _mockAuditoriumRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(_auditorium); //Act var resultAction = _auditoriumService.CreateAuditorium(ad2, numOfRows, numOfSeats).ConfigureAwait(false).GetAwaiter().GetResult(); //Arrange Assert.IsNotNull(resultAction); Assert.AreEqual(resultAction.Auditorium.Id, cr.Auditorium.Id); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); Assert.AreEqual(expectedSeatCount, resultAction.Auditorium.SeatsList.Count); Assert.IsTrue(resultAction.IsSuccessful); Assert.IsNull(resultAction.ErrorMessage); }