Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        public void PostAsync_Create_Throw_DbException_Auditorium()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium55",
                cinemaId      = 24,
                numberOfSeats = 5,
                seatRows      = 6
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 25,
                    Name      = createAuditoriumModel.auditName,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = true
            };

            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);
            Exception         exception         = new Exception("Inner exception error message.");
            DbUpdateException dbUpdateException = new DbUpdateException("Error.", exception);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x.CreateAuditorium(It.IsAny <AuditoriumDomainModel>(),
                                                             It.IsAny <int>(),
                                                             It.IsAny <int>())).Throws(dbUpdateException);

            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);

            //Act
            var result          = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Пример #4
0
        public void PostAsync_Create_createAuditoriumResultModel_IsSuccessful_False_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = "Error occured while creating new auditorium, please try again.";
            int    expectedStatusCode = 400;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium55",
                cinemaId      = 24,
                numberOfSeats = 5,
                seatRows      = 6
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 123,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    Name      = createAuditoriumModel.auditName,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = false,
                ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR
            };
            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x.CreateAuditorium(It.IsAny <AuditoriumDomainModel>(),
                                                             It.IsAny <int>(),
                                                             It.IsAny <int>())).Returns(responseTask);
            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);


            //Act
            var result          = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Пример #5
0
        public void PostAsync_Create_createAuditoriumResultModel_IsSuccessful_True_Auditorium()
        {
            //Arrange
            int expectedStatusCode = 201;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium1",
                cinemaId      = 23,
                numberOfSeats = 5,
                seatRows      = 4
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 15,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    Name      = createAuditoriumModel.auditName,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = true
            };
            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x
                                     .CreateAuditorium(It.IsAny <AuditoriumDomainModel>(), It.IsAny <int>(), It.IsAny <int>())).Returns(responseTask);

            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);

            //Act
            var result                = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var createdResult         = ((CreatedResult)result).Value;
            var auditoriumDomainModel = (AuditoriumDomainModel)createdResult;

            //Assert
            Assert.IsNotNull(auditoriumDomainModel);
            Assert.AreEqual(createAuditoriumModel.cinemaId, auditoriumDomainModel.CinemaId);
            Assert.AreEqual(createAuditoriumModel.auditName, auditoriumDomainModel.Name);
            Assert.IsInstanceOfType(result, typeof(CreatedResult));
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
        }
        public async Task <CreateAuditoriumResultModel> CreateAuditorium(AuditoriumDomainModel domainModel, int numberOfRows, int numberOfSeats)
        {
            var cinema = await _cinemasRepository.GetByIdAsync(domainModel.CinemaId);

            if (cinema == null)
            {
                return(new CreateAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_UNVALID_CINEMAID
                });
            }

            var auditorium = await _auditoriumsRepository.GetByAuditName(domainModel.Name, domainModel.CinemaId);

            var sameAuditoriumName = auditorium.ToList();

            if (sameAuditoriumName != null && sameAuditoriumName.Count > 0)
            {
                return(new CreateAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_SAME_NAME
                });
            }

            Auditorium newAuditorium = new Auditorium
            {
                Name     = domainModel.Name,
                CinemaId = domainModel.CinemaId,
            };

            newAuditorium.Seats = new List <Seat>();

            for (int i = 1; i <= numberOfRows; i++)
            {
                for (int j = 1; j <= numberOfSeats; j++)
                {
                    Seat newSeat = new Seat()
                    {
                        Row    = i,
                        Number = j
                    };

                    newAuditorium.Seats.Add(newSeat);
                }
            }

            Auditorium insertedAuditorium = _auditoriumsRepository.Insert(newAuditorium);

            if (insertedAuditorium == null)
            {
                return(new CreateAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR
                });
            }

            CreateAuditoriumResultModel resultModel = new CreateAuditoriumResultModel
            {
                IsSuccessful = true,
                ErrorMessage = null,
                Auditorium   = new AuditoriumDomainModel
                {
                    Id        = insertedAuditorium.Id,
                    Name      = insertedAuditorium.Name,
                    CinemaId  = insertedAuditorium.CinemaId,
                    SeatsList = new List <SeatDomainModel>()
                }
            };

            foreach (var item in insertedAuditorium.Seats)
            {
                resultModel.Auditorium.SeatsList.Add(new SeatDomainModel
                {
                    AuditoriumId = insertedAuditorium.Id,
                    Id           = item.Id,
                    Number       = item.Number,
                    Row          = item.Row
                });
            }

            return(resultModel);
        }
Пример #7
0
        public async Task <CreateAuditoriumResultModel> AddAuditorium(AuditoriumDomainModel domainModel, int numberOfRows, int numberOfSeats)
        {
            var theatre = await _theatreRepository.GetByIdAsync(domainModel.TheatreId);

            if (theatre == null)
            {
                return(new CreateAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_INVALID_THEATREID
                });
            }

            Auditorium newAuditorium = new Auditorium
            {
                Name      = domainModel.Name,
                TheatreId = domainModel.TheatreId
            };

            newAuditorium.Seats = new List <Seat>();

            for (int i = 1; i <= numberOfRows; i++)
            {
                for (int j = 1; j <= numberOfSeats; j++)
                {
                    Seat newSeat = new Seat()
                    {
                        Row    = i,
                        Number = j
                    };

                    newAuditorium.Seats.Add(newSeat);
                }
            }

            Auditorium insertedAuditorium = _auditoriumsRepository.Insert(newAuditorium);

            if (insertedAuditorium == null)
            {
                return(new CreateAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR
                });
            }

            _auditoriumsRepository.Save();

            CreateAuditoriumResultModel resultModel = new CreateAuditoriumResultModel
            {
                IsSuccessful = true,
                ErrorMessage = null,
                Auditorium   = new AuditoriumDomainModel
                {
                    Id        = insertedAuditorium.Id,
                    Name      = insertedAuditorium.Name,
                    TheatreId = insertedAuditorium.TheatreId,
                    SeatsList = new List <SeatDomainModel>()
                }
            };

            foreach (var item in insertedAuditorium.Seats)
            {
                resultModel.Auditorium.SeatsList.Add(new SeatDomainModel
                {
                    AuditoriumId = insertedAuditorium.Id,
                    Id           = item.Id,
                    Number       = item.Number,
                    Row          = item.Row
                });
            }

            return(resultModel);
        }
        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);
        }