Example #1
0
        public async Task <IEnumerable <ReservationDomainModel> > GetAllReservations()
        {
            var data = await _reservationRepository.GetAll();

            if (data == null)
            {
                return(null);
            }

            List <ReservationDomainModel> result = new List <ReservationDomainModel>();
            ReservationDomainModel        model;

            foreach (var item in data)
            {
                model = new ReservationDomainModel
                {
                    ProjectionId = item.ProjectionId,
                    SeatId       = item.SeatId,
                    UserId       = item.UserId
                };
                result.Add(model);
            }

            return(result);
        }
Example #2
0
        public void GetById_Return_Reservation_Ok_Object_Result()
        {
            //Arrange
            ReservationDomainModel reservationDomainModel = new ReservationDomainModel
            {
                Id           = Guid.NewGuid(),
                ProjectionId = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            int expectedStatusCode = 200;
            Task <ReservationDomainModel> responseTask = Task.FromResult(reservationDomainModel);

            _reservationService = new Mock <IReservationService>();
            _reservationService.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).Returns(responseTask);
            ReservationsController reservationsController = new ReservationsController(_reservationService.Object);

            //Act
            var result       = reservationsController.GetById(reservationDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult = ((OkObjectResult)result).Value;
            ReservationDomainModel reservationDomainResult = (ReservationDomainModel)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
            Assert.AreEqual(reservationDomainModel.Id, reservationDomainResult.Id);
        }
Example #3
0
        public async Task <IEnumerable <ReservationDomainModel> > DeleteByUserIdProjectionId(Guid userId, Guid projectionId)
        {
            var data = await _reservationRepository.DeleteByUserIdProjectionId(userId, projectionId);

            if (data == null)
            {
                return(null);
            }

            _reservationRepository.Save();

            List <ReservationDomainModel> domainModelList = new List <ReservationDomainModel>();

            foreach (Reservation reservation in data)
            {
                ReservationDomainModel domainModel = new ReservationDomainModel
                {
                    ProjectionId = reservation.ProjectionId,
                    SeatId       = reservation.SeatId,
                    UserId       = reservation.UserId
                };

                domainModelList.Add(domainModel);
            }
            return(domainModelList);
        }
Example #4
0
        public void GetAsync_Return_All_Reservations()
        {
            //Arrange
            ReservationDomainModel reservationDomainModel = new ReservationDomainModel
            {
                Id           = Guid.NewGuid(),
                ProjectionId = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };
            int expectedStatusCode  = 200;
            int expectedResultCount = 1;

            List <ReservationDomainModel> reservationDomainModels = new List <ReservationDomainModel>();

            reservationDomainModels.Add(reservationDomainModel);

            IEnumerable <ReservationDomainModel>         reservationsIEn = reservationDomainModels;
            Task <IEnumerable <ReservationDomainModel> > responseTask    = Task.FromResult(reservationsIEn);

            _reservationService = new Mock <IReservationService>();
            _reservationService.Setup(x => x.GetAllAsync()).Returns(responseTask);
            ReservationsController reservationsController = new ReservationsController(_reservationService.Object);

            //Act
            var result     = reservationsController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultList = ((OkObjectResult)result).Value;
            List <ReservationDomainModel> reservationDomainModelsResult = (List <ReservationDomainModel>)resultList;

            //Assert
            Assert.IsNotNull(reservationDomainModelsResult);
            Assert.AreEqual(expectedResultCount, reservationDomainModelsResult.Count);
            Assert.AreEqual(reservationDomainModel.Id, reservationDomainModelsResult[0].Id);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
Example #5
0
        public async Task <CreateReservationResultModel> AddReservation(ReservationDomainModel newReservation)
        {
            Reservation reservationToCreate = new Reservation()
            {
                ProjectionId = newReservation.ProjectionId,
                SeatId       = newReservation.SeatId,
                UserId       = newReservation.UserId
            };

            var data = _reservationRepository.Insert(reservationToCreate);

            if (data == null)
            {
                return(new CreateReservationResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.RESERVATION_CREATION_ERROR
                });
            }


            _reservationRepository.Save();

            CreateReservationResultModel result = new CreateReservationResultModel()
            {
                IsSuccessful = true,
                ErrorMessage = null,
                Reservation  = newReservation,
            };

            return(result);
        }
        public async Task <ActionResult <ReservationDomainModel> > GetById(Guid id)
        {
            ReservationDomainModel reservationDomainModel = await _reservationService.GetByIdAsync(id);

            if (reservationDomainModel == null)
            {
                return(NotFound(Messages.RESERVATION_NOT_FOUND));
            }

            return(Ok(reservationDomainModel));
        }
        public void TestInitialize()
        {
            _projection = new Projection
            {
                Id         = Guid.NewGuid(),
                Auditorium = new Auditorium {
                    Name = "ImeSale"
                },
                Movie = new Movie {
                    Title = "ImeFilma"
                },
                MovieId      = Guid.NewGuid(),
                DateTime     = DateTime.Now.AddDays(1),
                AuditoriumId = 1
            };

            _projectionDomainModel = new ProjectionDomainModel
            {
                Id             = _projection.Id,
                AuditoriumName = "ImeSale",
                AuditoriumId   = 1,
                MovieId        = Guid.NewGuid(),
                MovieTitle     = "ImeFilma",
                ProjectionTime = DateTime.Now.AddDays(1)
            };

            _reservationDomainModel = new ReservationDomainModel
            {
                ProjectionId = _projection.Id,
                SeatId       = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            List <Projection> projectionsModelsList = new List <Projection>();

            projectionsModelsList.Add(_projection);
            IEnumerable <Projection>         projections  = projectionsModelsList;
            Task <IEnumerable <Projection> > responseTask = Task.FromResult(projections);

            _mockProjectionsRepository = new Mock <IProjectionsRepository>();
            _mockProjectionsRepository.Setup(x => x.GetAll()).Returns(responseTask);



            List <ReservationDomainModel> reservationDomainModelsList = new List <ReservationDomainModel>();

            reservationDomainModelsList.Add(_reservationDomainModel);
            IEnumerable <ReservationDomainModel>         reservations            = reservationDomainModelsList;
            Task <IEnumerable <ReservationDomainModel> > reservationResponseTask = Task.FromResult(reservations);

            _mockReservationService = new Mock <IReservationService>();
            _mockReservationService.Setup(x => x.DeleteByProjectionId(It.IsAny <Guid>())).Returns(reservationResponseTask);
        }
        public void TestInitialize()
        {
            _seat = new Seat
            {
                Id           = Guid.NewGuid(),
                AuditoriumId = 1,
                Row          = 2,
                Number       = 2
            };

            _seatDomainModel = new SeatDomainModel
            {
                Id           = _seat.Id,
                AuditoriumId = 1,
                Row          = 2,
                Number       = 2
            };

            _reservationDomainModel = new ReservationDomainModel
            {
                ProjectionId = Guid.NewGuid(),
                SeatId       = _seat.Id,
                UserId       = Guid.NewGuid()
            };

            _numberOfSeatsModel = new NumberOfSeatsModel
            {
                MaxNumber = 2,
                MaxRow    = 2
            };


            List <Seat> seatsModelsList = new List <Seat>();

            seatsModelsList.Add(_seat);
            IEnumerable <Seat>         seats        = seatsModelsList;
            Task <IEnumerable <Seat> > responseTask = Task.FromResult(seats);

            _mockSeatsRepository = new Mock <ISeatsRepository>();

            List <ReservationDomainModel> reservationDomainModelsList = new List <ReservationDomainModel>();

            reservationDomainModelsList.Add(_reservationDomainModel);
            IEnumerable <ReservationDomainModel>         reservations            = reservationDomainModelsList;
            Task <IEnumerable <ReservationDomainModel> > reservationResponseTask = Task.FromResult(reservations);

            _mockReservationService = new Mock <IReservationService>();
        }
        public void TestInitialize()
        {
            _user = new User
            {
                Id          = Guid.NewGuid(),
                FirstName   = "Ime",
                LastName    = "Prezime",
                UserName    = "******",
                IsAdmin     = false,
                IsSuperUser = false,
                IsUser      = true
            };

            _userDomainModel = new UserDomainModel
            {
                Id          = _user.Id,
                FirstName   = "Ime",
                LastName    = "Prezime",
                UserName    = "******",
                IsAdmin     = false,
                IsSuperUser = false,
                IsUser      = true
            };

            _reservationDomainModel = new ReservationDomainModel
            {
                ProjectionId = Guid.NewGuid(),
                SeatId       = Guid.NewGuid(),
                UserId       = _user.Id
            };

            List <User> userModelsList = new List <User>();

            userModelsList.Add(_user);
            IEnumerable <User>         users        = userModelsList;
            Task <IEnumerable <User> > responseTask = Task.FromResult(users);

            _mockUsersRepository = new Mock <IUsersRepository>();

            List <ReservationDomainModel> reservationDomainModelsList = new List <ReservationDomainModel>();

            reservationDomainModelsList.Add(_reservationDomainModel);
            IEnumerable <ReservationDomainModel>         reservations            = reservationDomainModelsList;
            Task <IEnumerable <ReservationDomainModel> > reservationResponseTask = Task.FromResult(reservations);

            _mockReservationService = new Mock <IReservationService>();
        }
Example #10
0
        public async Task<ReservationDomainModel> GetByIdAsync(Guid id)
        {
            var reservation = await _reservationsRepository.GetByIdAsync(id);

            if (reservation == null)
            {
                return null;
            }

            ReservationDomainModel reservationModel = new ReservationDomainModel
            {
                Id = reservation.Id,
                ProjectionId = reservation.ProjectionId,
                UserId = reservation.UserId
            };

            return reservationModel;
        }
Example #11
0
        public void TestInitialize()
        {
            _reservationDomainModel = new ReservationDomainModel
            {
                ProjectionId = Guid.NewGuid(),
                SeatId       = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            _reservationResultModel = new CreateReservationResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Reservation  = _reservationDomainModel
            };

            _failedReservationResultModel = new CreateReservationResultModel
            {
                ErrorMessage = "Error",
                IsSuccessful = false,
                Reservation  = null
            };

            _createReservationModel = new CreateReservationModel
            {
                ProjectionId = _reservationDomainModel.ProjectionId,
                SeatIds      = new List <Guid>
                {
                    _reservationDomainModel.SeatId
                },
                UserId = _reservationDomainModel.UserId
            };

            List <ReservationDomainModel> reservationList = new List <ReservationDomainModel>();

            reservationList.Add(_reservationDomainModel);
            IEnumerable <ReservationDomainModel>         reservations = reservationList;
            Task <IEnumerable <ReservationDomainModel> > responseTask = Task.FromResult(reservations);

            _mockReservationService = new Mock <IReservationService>();
            _mockUserService        = new Mock <IUserService>();
            _mockProjectionService  = new Mock <IProjectionService>();
        }
Example #12
0
        public async Task <ReservationDomainModel> DeleteById(Guid projectionId, Guid seatId, Guid userId)
        {
            var deletedReservation = await _reservationRepository.DeleteById(projectionId, seatId, userId);

            if (deletedReservation == null)
            {
                return(null);
            }
            _reservationRepository.Save();

            ReservationDomainModel result = new ReservationDomainModel
            {
                ProjectionId = deletedReservation.ProjectionId,
                SeatId       = deletedReservation.SeatId,
                UserId       = deletedReservation.UserId
            };

            return(result);
        }
Example #13
0
        public async Task <ReservationDomainModel> GetById(Guid seatId, Guid projectionId, Guid userId)
        {
            var reservationObject = await _reservationRepository.GetById(seatId, projectionId, userId);

            if (reservationObject == null)
            {
                return(null);
            }


            ReservationDomainModel result = new ReservationDomainModel
            {
                ProjectionId = reservationObject.ProjectionId,
                SeatId       = reservationObject.SeatId,
                UserId       = reservationObject.UserId
            };

            return(result);
        }
Example #14
0
        public async Task<IEnumerable<ReservationDomainModel>> GetAllAsync()
        {
            var reservations = await _reservationsRepository.GetAll();

            List<ReservationDomainModel> reservationList = new List<ReservationDomainModel>();

            foreach (var reservation in reservations)
            {
                ReservationDomainModel reservationModel = new ReservationDomainModel
                {
                    Id = reservation.Id,
                    ProjectionId = reservation.ProjectionId,
                    UserId = reservation.UserId
                };


                reservationList.Add(reservationModel);
            }

            return reservationList;
        }
Example #15
0
        public async Task <ActionResult <ReservationResultModel> > MakeReservation([FromBody] ReservationModel model)
        {
            ReservationDomainModel reservationModel = new ReservationDomainModel
            {
                ShowId    = model.ShowId,
                UserId    = model.UserId,
                SeatsList = model.SeatIds
            };

            ReservationResultModel reservationResultModel;

            try
            {
                reservationResultModel = await _reservationService.CreateReservation(reservationModel);
            }
            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

            if (!reservationResultModel.isSuccessful)
            {
                ErrorResponseModel errorResponseModel = new ErrorResponseModel
                {
                    ErrorMessage = reservationResultModel.ErrorMessage
                };
                return(BadRequest(errorResponseModel));
            }
            return(Created("reservations//" + reservationResultModel.ReservationDomainModel.Id, reservationResultModel.ReservationDomainModel));
        }
        public void TestInitialize()
        {
            _reservation = new Reservation
            {
                ProjectionId = Guid.NewGuid(),
                SeatId       = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            _reservationDomainModel = new ReservationDomainModel
            {
                ProjectionId = _reservation.ProjectionId,
                SeatId       = _reservation.SeatId,
                UserId       = _reservation.UserId
            };

            List <Reservation> reservationList = new List <Reservation>();

            reservationList.Add(_reservation);
            IEnumerable <Reservation>         reservations = reservationList;
            Task <IEnumerable <Reservation> > responseTask = Task.FromResult(reservations);

            _mockReservationsRepository = new Mock <IReservationsRepository>();
        }
Example #17
0
        public async Task <IEnumerable <ReservationDomainModel> > GetBySeatId(Guid seatId)
        {
            var data = await _reservationRepository.GetBySeatId(seatId);

            if (data == null)
            {
                return(null);
            }

            List <ReservationDomainModel> domainModelList = new List <ReservationDomainModel>();

            foreach (Reservation reservation in data)
            {
                ReservationDomainModel domainModel = new ReservationDomainModel
                {
                    ProjectionId = reservation.ProjectionId,
                    SeatId       = reservation.SeatId,
                    UserId       = reservation.UserId
                };

                domainModelList.Add(domainModel);
            }
            return(domainModelList);
        }
Example #18
0
        public void GetById_Return_NotFound()
        {
            //Arrange
            ReservationDomainModel reservationDomainModel = null;
            string expectedMessage = Messages.RESERVATION_NOT_FOUND;

            int expectedStatusCode = 404;
            Task <ReservationDomainModel> responseTask = Task.FromResult(reservationDomainModel);

            _reservationService = new Mock <IReservationService>();
            _reservationService.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).Returns(responseTask);
            ReservationsController reservationsController = new ReservationsController(_reservationService.Object);

            //Act
            var    result       = reservationsController.GetById(Guid.NewGuid()).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var    objectResult = ((NotFoundObjectResult)result).Value;
            string errorMessage = (string)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
            Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode);
            Assert.AreEqual(expectedMessage, errorMessage);
        }
Example #19
0
        public async Task <ReservationResultModel> CreateReservation(ReservationDomainModel requestedReservation)
        {
            // get taken seats for show
            var takenSeats = await GetTakenSeats(requestedReservation.ShowId);

            var seats = await _seatRepository.GetAllAsync();

            // check if show id is valid
            var show = await _showRepository.GetByIdAsync(requestedReservation.ShowId);

            if (show == null)
            {
                return(new ReservationResultModel
                {
                    isSuccessful = false,
                    ErrorMessage = Messages.SHOW_DOES_NOT_EXIST_FOR_RESERVATION
                });
            }

            // check if user id is valid
            var user = await _userRepository.GetByIdAsync(requestedReservation.UserId);

            if (user == null)
            {
                return(new ReservationResultModel
                {
                    isSuccessful = false,
                    ErrorMessage = Messages.USER_FOR_RESERVATION_DOES_NOT_EXIST
                });
            }

            // get all seats for auditorium
            seats = seats.Where(seat => seat.AuditoriumId == show.AuditoriumId);

            //check if requested seats exist in the auditorium
            var duplicateSeats = seats
                                 .Select(x => x.Id)
                                 .Intersect(requestedReservation.SeatsList
                                            .Select(x => x.Id));

            if (duplicateSeats.Count() != requestedReservation.SeatsList.Count())
            {
                return(new ReservationResultModel
                {
                    isSuccessful = false,
                    ErrorMessage = Messages.SEAT_DOES_NOT_EXIST_FOR_AUDITORIUM
                });
            }

            // check if requested seats are more than 1 and in the same row
            List <SeatDomainModel> seatModels = new List <SeatDomainModel>();

            foreach (var seat in requestedReservation.SeatsList)
            {
                var reqSeat = await _seatRepository.GetByIdAsync(seat.Id);

                SeatDomainModel seatDomain = new SeatDomainModel
                {
                    Id           = reqSeat.Id,
                    Number       = reqSeat.Number,
                    Row          = reqSeat.Row,
                    AuditoriumId = reqSeat.AuditoriumId
                };

                seatModels.Add(seatDomain);
            }

            // check if seats are duplicates
            var row           = seatModels[0].Number;
            var differentRows = seatModels.Select(x => x.Number).Distinct();

            if (differentRows.Count() < seatModels.Count)
            {
                return(new ReservationResultModel
                {
                    isSuccessful = false,
                    ErrorMessage = Messages.SEATS_CANNOT_BE_DUPLICATES
                });
            }

            // check if seats are in the same row
            if (requestedReservation.SeatsList.Count() > 1)
            {
                var singleSeat = seatModels[0];

                foreach (var x in seatModels)
                {
                    if (singleSeat.Row != x.Row)
                    {
                        return(new ReservationResultModel
                        {
                            isSuccessful = false,
                            ErrorMessage = Messages.SEATS_NOT_IN_THE_SAME_ROW
                        });
                    }
                }
            }

            // check if seats are next to each other
            if (requestedReservation.SeatsList.Count() > 1)
            {
                seatModels = seatModels.OrderByDescending(x => x.Number).ToList();

                var singleSeat2 = seatModels[0];

                var counter = 1;

                foreach (var x in seatModels.Skip(1))
                {
                    if (x.Number + counter != singleSeat2.Number)
                    {
                        return(new ReservationResultModel
                        {
                            isSuccessful = false,
                            ErrorMessage = Messages.SEATS_MUST_BE_NEXT_TO_EACH_OTHER
                        });
                    }
                    else
                    {
                        counter++;
                    }
                }
            }

            // check if requested seats are already taken
            if (takenSeats != null)
            {
                foreach (var takenSeat in takenSeats)
                {
                    foreach (var requestedSeat in requestedReservation.SeatsList)
                    {
                        if (takenSeat.Id == requestedSeat.Id)
                        {
                            return(new ReservationResultModel
                            {
                                isSuccessful = false,
                                ErrorMessage = Messages.SEATS_ALREADY_TAKEN_ERROR
                            });
                        }
                    }
                }
            }

            // insert in database
            Reservation reservationToInsert = new Reservation
            {
                ShowId           = requestedReservation.ShowId,
                UserId           = requestedReservation.UserId,
                ReservationSeats = new List <ReservationSeat>()
            };

            var insertedReservation = _reservationsRepository.Insert(reservationToInsert);

            foreach (var rs in requestedReservation.SeatsList)
            {
                reservationToInsert.ReservationSeats.Add(new ReservationSeat
                {
                    SeatId        = rs.Id,
                    ReservationId = insertedReservation.Id
                });
            }

            _reservationsRepository.Save();

            return(new ReservationResultModel
            {
                isSuccessful = true,
                ReservationDomainModel = new ReservationDomainModel
                {
                    Id = insertedReservation.Id,
                    ShowId = insertedReservation.ShowId,
                    UserId = insertedReservation.UserId
                }
            });
        }
Example #20
0
        public async Task <ActionResult <ReservationDomainModel> > PostAsync([FromBody] CreateReservationModel reservationModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //PaymentResponse
            List <ReservationDomainModel> reservationResultList = new List <ReservationDomainModel>();
            int bonusPointsToAdd = 0;

            foreach (Guid seatId in reservationModel.SeatIds)
            {
                bonusPointsToAdd++;
                ReservationDomainModel domainModel = new ReservationDomainModel
                {
                    ProjectionId = reservationModel.ProjectionId,
                    SeatId       = seatId,
                    UserId       = reservationModel.UserId
                };

                CreateReservationResultModel createReservationResultModel;
                try
                {
                    createReservationResultModel = await _reservationService.AddReservation(domainModel);
                }
                catch (DbUpdateException e)
                {
                    ErrorResponseModel errorResponse = new ErrorResponseModel
                    {
                        ErrorMessage = e.InnerException.Message ?? e.Message,
                        StatusCode   = System.Net.HttpStatusCode.BadRequest
                    };

                    return(BadRequest(errorResponse));
                }

                if (!createReservationResultModel.IsSuccessful)
                {
                    ErrorResponseModel errorResponse = new ErrorResponseModel
                    {
                        ErrorMessage = createReservationResultModel.ErrorMessage,
                        StatusCode   = System.Net.HttpStatusCode.BadRequest
                    };

                    return(BadRequest(errorResponse));
                }
                reservationResultList.Add(createReservationResultModel.Reservation);
            }
            try
            {
                var bonusPointsResult = _userService.AddBonusPointsByUserId(reservationModel.UserId, bonusPointsToAdd);

                if (bonusPointsResult == -1 || bonusPointsToAdd < 0)
                {
                    ErrorResponseModel errorResponse = new ErrorResponseModel
                    {
                        ErrorMessage = Messages.USER_BONUSPOINTS_ERROR,
                        StatusCode   = System.Net.HttpStatusCode.BadRequest
                    };

                    return(BadRequest(errorResponse));
                }
            }
            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = Messages.USER_BONUSPOINTS_ERROR,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }
            return(Created("reservations//", reservationResultList));
        }