Example #1
0
        public async Task <CinemaHallDto> UpdateCinemaHallAsync(CinemaHallDto cinemaHallDto)
        {
            ValidateNull(Logger.Here(), cinemaHallDto);
            var cinemaHall = Map(cinemaHallDto);

            return((await _unitOfWork.RepositoryInfrastructure.UpdateCinemaHallAsync(cinemaHall)) > 0
                ? cinemaHallDto
                : null);
        }
        public async Task <IActionResult> AddCinemaHall(CinemaHallDto cinemaHall)
        {
            var infrastructureService = _service.CreateInfrastructureService();

            Logger.Here().Info(nameof(AddCinemaHall));

            var result = await infrastructureService.AddCinemaHallAsync(cinemaHall);

            return(GetCreatedStatus(result, nameof(GetCinemaHall), "Given cinema hall is not addable."));
        }
Example #3
0
        public async Task <CinemaHallDto> AddCinemaHallAsync(CinemaHallDto cinemaHall)
        {
            ValidateNull(Logger.Here(), cinemaHall);
            var newId = await _unitOfWork.RepositoryInfrastructure.AddCinemaHallAsync(Map(cinemaHall));

            if (newId > 0L)
            {
                cinemaHall.Id = newId;
            }

            return(newId > 0L ? cinemaHall : null);
        }
        public async Task <IActionResult> UpdateCinemaHall(CinemaHallDto cinemaHall)
        {
            var infrastructureService = _service.CreateInfrastructureService();

            Logger.Here().Info(nameof(UpdateCinemaHall));
            if (!await infrastructureService.CinemaHallExistAsync(cinemaHall.Id))
            {
                Logger.Here().Error("{CinemaHall} - does not exist", nameof(UpdateCinemaHall));
                return(BadRequestResponse("Given cinema hall does not exist"));
            }

            if (await _service.CreateReservationService().GetCountReservationsByCinemaHallAsync(cinemaHall.Id) > 0)
            {
                Logger.Here().Info("{CinemaHall} - contains reservations", nameof(DeleteCinemaHall));
                return(BadRequestResponse("Given cinema hall contains reservations."));
            }

            var result = await infrastructureService.UpdateCinemaHallAsync(cinemaHall);

            return(GetUpdatedStatus(result, "Given cinema hall is not updateable."));
        }
Example #5
0
        public async Task Test_Workflow_CinemaHalls_Valid()
        {
            Logger.Info("Load cinema halls ...");
            var response = await Get(BaseUrl, EndpointCinemaHalls);

            await CheckResponseAndLogStatusCodeAsync(Logger, response);

            var cinemaHalls = JsonConvert.DeserializeObject <IEnumerable <CinemaHallDto> >(
                await response.Content.ReadAsStringAsync()
                ).ToList();

            cinemaHalls.Should().HaveCount(DataSeeder.CinemaHalls.Count);
            Logger.Info(cinemaHalls.ToPrettyString());

            var newHall = new CinemaHallDto {
                Label = "New Hall", SizeColumn = 10, SizeRow = 5
            };
            var updateHallReservations = cinemaHalls.First(c =>
                                                           DataSeeder.Reservations
                                                           .Select(r => DataSeeder.Schedules.First(s => r.ScheduleId == s.Id).CinemaHallId)
                                                           .Contains(c.Id));
            var updateHall = cinemaHalls.First(c =>
                                               !DataSeeder.Reservations
                                               .Select(r => DataSeeder.Schedules.First(s => r.ScheduleId == s.Id).CinemaHallId)
                                               .Contains(c.Id));

            updateHall.Label = "Renovated Hall";
            var deleteReferencedHall = DataSeeder.CinemaHalls
                                       .First(c => DataSeeder.Rows.Select(r => r.CinemaHallId).Contains(c.Id)).Id;
            var deletedHall = DataSeeder.CinemaHalls
                              .Last(c => !DataSeeder.Rows.Select(r => r.CinemaHallId).Contains(c.Id))
                              .Id;

            await Authenticate(AdminUser, AdminPassword);

            Logger.Info($"Add new cinema hall: ${newHall.ToPrettyString()} ...");
            response = await Post(BaseUrl, EndpointCinemaHall, newHall);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.Created);

            var newId = await GetCreatedIdAsync(response);

            Logger.Info($"Try update cinema hall with reservations: {updateHallReservations.ToPrettyString()} ...");
            response = await Put(BaseUrl, EndpointCinemaHall, updateHallReservations);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest);

            Logger.Info($"Update cinema hall: ${updateHall.ToPrettyString()} ...");
            response = await Put(BaseUrl, EndpointCinemaHall, updateHall);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent);

            Logger.Info($"Try delete referenced cinema hall: {deleteReferencedHall.ToPrettyString()} ...");
            response = await Delete(BaseUrl, $"{EndpointCinemaHall}/{deleteReferencedHall}");
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest);

            Logger.Info($"Delete cinema hall: ${deletedHall.ToPrettyString()} ...");
            response = await Delete(BaseUrl, $"{EndpointCinemaHall}/{deletedHall}");
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent);

            Logger.Info("Load cinema halls ...");
            response = await Get(BaseUrl, EndpointCinemaHalls);
            await CheckResponseAndLogStatusCodeAsync(Logger, response);

            cinemaHalls = JsonConvert.DeserializeObject <IEnumerable <CinemaHallDto> >(
                await response.Content.ReadAsStringAsync()
                ).ToList();

            var cinemaHall = cinemaHalls.Select(g => g.Id).ToList();

            cinemaHall.Should().Contain(newId);
            cinemaHall.Should().Contain(updateHallReservations.Id);
            cinemaHall.Should().Contain(updateHall.Id);
            cinemaHall.Should().Contain(deleteReferencedHall);
            cinemaHall.Should().NotContain(deletedHall);

            cinemaHalls.First(g => g.Id == newId).Label.Should().Be(newHall.Label);
            cinemaHalls.First(g => g.Id == updateHall.Id).Label.Should().Be(updateHall.Label);

            Logger.Info(cinemaHalls.ToPrettyString());
        }