public void TestInitialize()
        {
            _auditorium = new Auditorium
            {
                Id        = 1,
                CinemaId  = 1,
                AuditName = "Novi auditorium",
            };

            _auditoriumDomainModel = new AuditoriumDomainModel
            {
                Id       = _auditorium.Id,
                CinemaId = _auditorium.CinemaId,
                Name     = _auditorium.AuditName
            };

            _cinema = new Data.Cinema
            {
                Id     = 1,
                CityId = 1,
                Name   = "test bioskop 1"
            };

            _cinemaDomainModel = new CinemaDomainModel
            {
                Id     = _cinema.Id,
                CityId = _cinema.CityId,
                Name   = _cinema.Name
            };

            _mockAuditoriumRepository = new Mock <IAuditoriumsRepository>();
            _mockCinemaRepository     = new Mock <ICinemasRepository>();
            _auditoriumService        = new AuditoriumService(_mockAuditoriumRepository.Object, _mockCinemaRepository.Object);
        }
예제 #2
0
        public async Task <CreateCinemaResultModel> AddCinema(CinemaDomainModel newCinema)
        {
            Data.Cinema cinemaToCreate = new Data.Cinema()
            {
                Name = newCinema.Name
            };

            var data = _cinemasRepository.Insert(cinemaToCreate);

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

            _cinemasRepository.Save();

            CreateCinemaResultModel createCinemaResultModel = new CreateCinemaResultModel()
            {
                Cinema = new CinemaDomainModel
                {
                    Id   = data.Id,
                    Name = data.Name
                },
                IsSuccessful = true,
                ErrorMessage = null
            };

            return(createCinemaResultModel);
        }
예제 #3
0
        public void GetAsync_Return_All_Cinemas()
        {
            //Arrange
            CinemaDomainModel cinemaDomainModel = _cinemaDomainModel;
            IEnumerable <CinemaDomainModel>         cinemaDomainModels = _cinemaDomainModelsList;
            Task <IEnumerable <CinemaDomainModel> > responseTask       = Task.FromResult(cinemaDomainModels);
            int expectedResultCount = 1;
            int expectedStatusCode  = 200;

            _cinemaService = new Mock <ICinemaService>();
            _cinemaService.Setup(x => x.GetAllAsync()).Returns(responseTask);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object);

            //ACT
            var result     = cinemasController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultList = ((OkObjectResult)result).Value;
            var cinemaDomainModelResultList = (List <CinemaDomainModel>)resultList;

            //Assert
            Assert.IsNotNull(cinemaDomainModelResultList);
            Assert.AreEqual(expectedResultCount, cinemaDomainModelResultList.Count);
            Assert.AreEqual(cinemaDomainModel.Id, cinemaDomainModelResultList[0].Id);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
예제 #4
0
        public async Task <CinemaDomainModel> DeleteCinema(int cinemaId)
        {
            var deletedAuditoriums = await _auditoriumService.DeleteAuditoriumsByCinemaId(cinemaId);

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

            var deletedCinema = _cinemasRepository.Delete(cinemaId);

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

            _cinemasRepository.Save();

            CinemaDomainModel result = new CinemaDomainModel
            {
                Id   = deletedCinema.Id,
                Name = deletedCinema.Name
            };

            return(result);
        }
예제 #5
0
        public async Task <IEnumerable <CityDomainModel> > GetAllAsync()
        {
            var cities = await _citiesRepository.GetAll();

            List <CityDomainModel> cityList = new List <CityDomainModel>();

            foreach (var city in cities)
            {
                CityDomainModel cityModel = new CityDomainModel
                {
                    Id          = city.Id,
                    Name        = city.Name,
                    CinemasList = new List <CinemaDomainModel>()
                };

                foreach (var cinema in city.Cinemas)
                {
                    CinemaDomainModel cinemaModel = new CinemaDomainModel
                    {
                        Id     = cinema.Id,
                        CityId = city.Id,
                        Name   = cinema.Name
                    };

                    cityModel.CinemasList.Add(cinemaModel);
                }

                cityList.Add(cityModel);
            }

            return(cityList);
        }
        public void DeleteAsync_DeleteCinema_IsSuccessful()
        {
            //Arrange
            int cinemaDeleteId     = 12;
            int expectedStatusCode = 202;

            CinemaDomainModel cinemaDomainModel = new CinemaDomainModel
            {
                Id              = cinemaDeleteId,
                CityId          = 1234,
                Name            = "Bioskop",
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

            Task <CinemaDomainModel> responseTask = Task.FromResult(cinemaDomainModel);


            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();
            _cinemaService.Setup(x => x.DeleteCinemaAsync(It.IsAny <int>())).Returns(responseTask);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);

            //Act
            var result       = cinemasController.DeleteAsync(cinemaDeleteId).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult = ((AcceptedResult)result).Value;
            CinemaDomainModel cinemaDomainModelResult = (CinemaDomainModel)objectResult;


            //Assert
            Assert.IsNotNull(cinemaDomainModel);
            Assert.IsInstanceOfType(result, typeof(AcceptedResult));
            Assert.AreEqual(expectedStatusCode, ((AcceptedResult)result).StatusCode);
            Assert.AreEqual(cinemaDeleteId, cinemaDomainModelResult.Id);
        }
예제 #7
0
        public async Task <CityDomainModel> GetByIdAsync(int id)
        {
            var city = await _citiesRepository.GetByIdAsync(id);

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

            CityDomainModel cityModel = new CityDomainModel
            {
                Id          = city.Id,
                Name        = city.Name,
                CinemasList = new List <CinemaDomainModel>()
            };

            foreach (var cinema in city.Cinemas)
            {
                CinemaDomainModel cinemaModel = new CinemaDomainModel
                {
                    Id     = cinema.Id,
                    CityId = city.Id,
                    Name   = cinema.Name
                };

                cityModel.CinemasList.Add(cinemaModel);
            }
            return(cityModel);
        }
        public void DeleteAsync_DeleteCinema_Failed_Throw_DbException()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;


            CinemaDomainModel cinemaDomainModel = new CinemaDomainModel
            {
                Id              = 123,
                CityId          = 555,
                Name            = "ime",
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

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

            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();
            _cinemaService.Setup(x => x.DeleteCinemaAsync(It.IsAny <int>())).Throws(dbUpdateException);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);

            //Act
            var result          = cinemasController.DeleteAsync(cinemaDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #9
0
        public void CinemaService_GetAllCinemasAsync_ReturnsListOfCinemas()
        {
            //Arrange
            var expectedCount = 2;

            Data.Cinema cinema2 = new Data.Cinema
            {
                Id     = 22,
                CityId = 1,
                Name   = "Los bioskop"
            };
            CinemaDomainModel cinemaDomainModel2 = new CinemaDomainModel
            {
                Id     = cinema2.Id,
                CityId = cinema2.CityId,
                Name   = cinema2.Name
            };
            List <Data.Cinema> cinemas = new List <Data.Cinema>();

            cinemas.Add(_cinema);
            cinemas.Add(cinema2);
            _mockCinemaRepository.Setup(x => x.GetAll()).ReturnsAsync(cinemas);

            //Act
            var resultAction = cinemaService.GetAllAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var result       = resultAction.ToList();

            //Assert
            Assert.IsNotNull(resultAction);
            Assert.AreEqual(expectedCount, result.Count);
            Assert.AreEqual(_cinema.Name, result[0].Name);
            Assert.IsInstanceOfType(resultAction, typeof(IEnumerable <CinemaDomainModel>));
        }
        public void DeleteAsync_DeleteCinema_Failed_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = Messages.CINEMA_DOES_NOT_EXIST;
            int    expectedStatusCode = 400;


            CinemaDomainModel cinemaDomainModel = null;

            Task <CinemaDomainModel> responseTask = Task.FromResult(cinemaDomainModel);

            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();
            _cinemaService.Setup(x => x.DeleteCinemaAsync(It.IsAny <int>())).Returns(responseTask);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);

            //Act
            var result          = cinemasController.DeleteAsync(123).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #11
0
        public async Task <IEnumerable <CinemaDomainModel> > GetAllAsync()
        {
            var data = await _cinemasRepository.GetAll();

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

            foreach (var cinema in data)
            {
                model = new CinemaDomainModel
                {
                    Id              = cinema.Id,
                    Name            = cinema.Name,
                    CityId          = cinema.CityId,
                    AuditoriumsList = new List <AuditoriumDomainModel>()
                };

                foreach (var auditorium in cinema.Auditoriums)
                {
                    AuditoriumDomainModel auditoriumModel = new AuditoriumDomainModel
                    {
                        Id       = auditorium.Id,
                        CinemaId = cinema.Id,
                        Name     = auditorium.AuditName
                    };

                    model.AuditoriumsList.Add(auditoriumModel);
                }

                result.Add(model);
            }

            return(result);
        }
예제 #12
0
        public async Task <ActionResult> Post([FromBody] CinemaModel cinemaModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CinemaDomainModel cinemaWithoutAuditorium = new CinemaDomainModel()
            {
                Name = cinemaModel.Name
            };
            CreateCinemaWithAuditoriumModel cinemaWithAuditoriumModel = new CreateCinemaWithAuditoriumModel
            {
                AuditoriumName  = cinemaModel.auditName,
                CinemaName      = cinemaModel.Name,
                NumberOfRows    = cinemaModel.seatRows,
                NumberOfColumns = cinemaModel.numberOfSeats
            };

            CreateCinemaResultModel createCinema;

            try
            {
                if (cinemaModel.auditName != null && cinemaModel.numberOfSeats > 0 && cinemaModel.seatRows > 0)
                {
                    createCinema = await _cinemaService.AddCinemaWithAuditorium(cinemaWithAuditoriumModel);
                }
                else
                {
                    createCinema = await _cinemaService.AddCinema(cinemaWithoutAuditorium);
                }
            }
            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

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

                return(BadRequest(errorResponse));
            }

            return(Created("cinemas//" + createCinema.Cinema.Id, createCinema.Cinema));
        }
예제 #13
0
 public void TestInitialize()
 {
     _cinemaDomainModel = new CinemaDomainModel()
     {
         Id   = 1,
         Name = "NewName"
     };
     _cinemaDomainModelsList = new List <CinemaDomainModel>();
     _cinemaDomainModelsList.Add(_cinemaDomainModel);
     _cinemaService = new Mock <ICinemaService>();
 }
예제 #14
0
        public CinemaDomainModel ReadById(object id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            Cinema            cinema       = Uow.GetRepository <Cinema>().ReadById(id);
            CinemaDomainModel cinemaDomain = Mapper.Map <Cinema, CinemaDomainModel>(cinema);

            return(cinemaDomain);
        }
예제 #15
0
        public void Delete(CinemaDomainModel entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            Cinema cinema = Mapper.Map <CinemaDomainModel, Cinema>(entity);

            Uow.GetRepository <Cinema>().Delete(cinema);
            Uow.Save();
        }
예제 #16
0
        public ActionResult Edit([Bind(Include = "Id,Name,Address,ImagePath,PhoneNumber")] CinemaViewModel cinemaViewModel)
        {
            ModelState.Remove("Image");
            if (!ModelState.IsValid)
            {
                return(View(cinemaViewModel));
            }
            CinemaDomainModel cinemaDomainModel = Mapper.Map <CinemaViewModel, CinemaDomainModel>(cinemaViewModel);

            _cinemaService.Update(cinemaDomainModel);
            return(RedirectToAction("Index"));
        }
        public void PostAsync_CreateCinema_Throw_DbException_Cinema()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;

            CreateCinemaModel createCinemaModel = new CreateCinemaModel
            {
                Name          = "Bioskop12345",
                CityName      = "grad",
                NumberOfSeats = 12,
                SeatRows      = 12
            };

            CinemaDomainModel cinemaDomainModel = new CinemaDomainModel
            {
                Id              = 123,
                CityId          = 1423,
                Name            = createCinemaModel.Name,
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

            CityDomainModel cityDomainModel = new CityDomainModel
            {
                Id          = 123,
                Name        = "grad123",
                CinemasList = new List <CinemaDomainModel>()
            };

            Task <CinemaDomainModel> responseTask  = Task.FromResult(cinemaDomainModel);
            Task <CityDomainModel>   responseTask2 = Task.FromResult(cityDomainModel);
            Exception         exception            = new Exception("Inner exception error message.");
            DbUpdateException dbUpdateException    = new DbUpdateException("Error.", exception);

            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();

            _cinemaService.Setup(x => x.CreateCinemaAsync(It.IsAny <CinemaDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Throws(dbUpdateException);
            _cityService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);

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

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #18
0
        public async Task <ActionResult <CinemaDomainModel> > PostAsync([FromBody]   CreateCinemaModel createCinemaModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CityDomainModel cityModel = await _cityService.GetByCityNameAsync(createCinemaModel.CityName);

            if (cityModel == null)
            {
                return(BadRequest(Messages.CITY_NOT_FOUND));
            }

            CinemaDomainModel cinemaDomainModel = new CinemaDomainModel
            {
                Name   = createCinemaModel.Name,
                CityId = cityModel.Id,
            };

            CinemaDomainModel insertedModel;

            try
            {
                insertedModel = await _cinemaService.CreateCinemaAsync(cinemaDomainModel, createCinemaModel.NumberOfSeats, createCinemaModel.SeatRows, createCinemaModel.AuditName);
            }

            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

            if (insertedModel == null)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = Messages.CINEMA_CREATION_ERROR,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

            return(Created("//cinemas" + insertedModel.Id, insertedModel));
        }
예제 #19
0
        public ActionResult DeleteConfirmed(long id)
        {
            CinemaDomainModel cinemaDomainModel = _cinemaService.ReadById(id);

            if (cinemaDomainModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            string physicalPath = HttpContext.Server.MapPath(cinemaDomainModel.ImagePath);

            System.IO.File.Delete(physicalPath);
            _cinemaService.Delete(cinemaDomainModel);
            return(RedirectToAction("Index"));
        }
예제 #20
0
        public async Task <CreateCinemaResultModel> AddCinema(CinemaDomainModel newCinema)
        {
            var cinema = await _cinemasRepository.GetByCinemaName(newCinema.Name);

            var sameCinemaName = cinema.ToList();

            if (sameCinemaName != null && sameCinemaName.Count > 0)
            {
                return(new CreateCinemaResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.CINEMA_SAME_NAME
                });
            }

            Data.Cinema cinemaToCreate = new Data.Cinema()
            {
                Name = newCinema.Name
            };

            var data = _cinemasRepository.Insert(cinemaToCreate);

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

            _cinemasRepository.Save();

            CinemaDomainModel domainModel = new CinemaDomainModel()
            {
                Id   = data.Id,
                Name = data.Name
            };

            CreateCinemaResultModel cinemaResultModel = new CreateCinemaResultModel()
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Cinema       = domainModel
            };

            return(cinemaResultModel);
        }
예제 #21
0
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CinemaDomainModel cinemaDomainModel = _cinemaService.ReadById(id);

            if (cinemaDomainModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            CinemaViewModel cinemaViewModel = Mapper.Map <CinemaDomainModel, CinemaViewModel>(cinemaDomainModel);

            return(View(cinemaViewModel));
        }
        public void PostAsync_Create_IsSuccessful_True_Cinema()
        {
            //Arrange
            int expectedStatusCode = 201;

            CreateCinemaModel createCinemaModel = new CreateCinemaModel()
            {
                Name          = "bioskop123",
                CityName      = "grad",
                SeatRows      = 15,
                NumberOfSeats = 11
            };

            CityDomainModel cityDomainModel = new CityDomainModel
            {
                Id          = 123,
                Name        = "grad123",
                CinemasList = new List <CinemaDomainModel>()
            };

            CinemaDomainModel cinemaDomainModel = new CinemaDomainModel
            {
                CityId          = 1234,
                Name            = createCinemaModel.Name,
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

            Task <CinemaDomainModel> responseTask  = Task.FromResult(cinemaDomainModel);
            Task <CityDomainModel>   responseTask2 = Task.FromResult(cityDomainModel);

            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();
            _cityService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            _cinemaService.Setup(x => x.CreateCinemaAsync(It.IsAny <CinemaDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(responseTask);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);


            //Act
            var result              = cinemasController.PostAsync(createCinemaModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var createdResult       = ((CreatedResult)result).Value;
            var cinemaReturnedModel = (CinemaDomainModel)createdResult;

            //Assert
            Assert.IsNotNull(cinemaReturnedModel);
            Assert.IsInstanceOfType(result, typeof(CreatedResult));
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
        }
예제 #23
0
        public async Task <CinemaDomainModel> GetCinemaByIdAsync(int id)
        {
            var data = await _cinemasRepository.GetByIdAsync(id);

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

            CinemaDomainModel domainModel = new CinemaDomainModel
            {
                Id   = data.Id,
                Name = data.Name
            };

            return(domainModel);
        }
예제 #24
0
        public async Task <CinemaDomainModel> DeleteCinema(int id)
        {
            var data = _cinemasRepository.Delete(id);

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

            _cinemasRepository.Save();

            CinemaDomainModel domainModel = new CinemaDomainModel
            {
                Id   = data.Id,
                Name = data.Name
            };

            return(domainModel);
        }
        public async Task <ActionResult> Post([FromBody] CinemaModels cinemaModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CinemaDomainModel domainModel = new CinemaDomainModel
            {
                Name = cinemaModel.Name
            };

            CreateCinemaResultModel createCienema;

            try
            {
                createCienema = await _cinemaService.AddCinema(domainModel);
            }

            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

            if (createCienema == null)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = Messages.CINEMA_CREATION_ERROR,
                    StatusCode   = System.Net.HttpStatusCode.InternalServerError
                };

                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, errorResponse));
            }

            return(Created("cinemas//" + createCienema.Cinema.Id, createCienema.Cinema));
        }
        public void PostAsync_Create_IsSuccessful_False_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = Messages.CINEMA_CREATION_ERROR;
            int    expectedStatusCode = 400;

            CreateCinemaModel createCinemaModel = new CreateCinemaModel
            {
                Name          = "bioskop",
                CityName      = "grad",
                NumberOfSeats = 13,
                SeatRows      = 13
            };

            CityDomainModel cityDomainModel = new CityDomainModel
            {
                Id          = 123,
                Name        = "grad123",
                CinemasList = new List <CinemaDomainModel>()
            };

            CinemaDomainModel        cinemaDomainModel = null;
            Task <CinemaDomainModel> responseTask      = Task.FromResult(cinemaDomainModel);
            Task <CityDomainModel>   responseTask2     = Task.FromResult(cityDomainModel);

            _cinemaService = new Mock <ICinemaService>();
            _cityService   = new Mock <ICityService>();
            _cityService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            _cinemaService.Setup(x => x.CreateCinemaAsync(It.IsAny <CinemaDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(responseTask);
            CinemasController cinemasController = new CinemasController(_cinemaService.Object, _cityService.Object);

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

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #27
0
        public async Task <ActionResult> Post([FromBody] CreateCinemaModel cinemaModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CinemaDomainModel domainModel = new CinemaDomainModel
            {
                Name = cinemaModel.Name
            };

            CreateCinemaResultModel createCinemaResultModel;

            try
            {
                createCinemaResultModel = await _cinemaService.AddCinema(domainModel);
            }
            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };
                return(BadRequest(errorResponse));
            }
            if (!createCinemaResultModel.IsSuccessful)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel()
                {
                    ErrorMessage = createCinemaResultModel.ErrorMessage,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };

                return(BadRequest(errorResponse));
            }

            return(Created("auditoriums//" + createCinemaResultModel.Cinema.Id, createCinemaResultModel));
        }
예제 #28
0
        public void TestInitialize()
        {
            _cinema = new Data.Cinema
            {
                Id     = 11,
                CityId = 1,
                Name   = "Smekerski bioskop"
            };

            _cinemaDomainModel = new CinemaDomainModel
            {
                Id     = _cinema.Id,
                CityId = _cinema.CityId,
                Name   = _cinema.Name
            };

            _mockCinemaRepository     = new Mock <ICinemasRepository>();
            _mockAuditoriumRepository = new Mock <IAuditoriumsRepository>();
            _mockSeatRepository       = new Mock <ISeatsRepository>();
            _mockCityRepository       = new Mock <ICitiesRepository>();

            cinemaService = new CinemaService(_mockCinemaRepository.Object, _mockAuditoriumRepository.Object, _mockSeatRepository.Object, _mockCityRepository.Object);
        }
예제 #29
0
        public void TestInitialize()
        {
            _cinema = new Data.Cinema
            {
                Id          = 1,
                Name        = "CinemaName",
                Auditoriums = new List <Auditorium>()
            };
            _newCinema = new CinemaDomainModel
            {
                Id   = 1,
                Name = "CinemaName"
            };
            _listOfCinemas = new List <Data.Cinema>();
            _listOfCinemas.Add(_cinema);

            _mockCinemasRepository     = new Mock <ICinemasRepository>();
            _mockAuditoriumService     = new Mock <IAuditoriumService>();
            _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>();
            _mockProjectionsRepository = new Mock <IProjectionsRepository>();
            _mockSeatsRepository       = new Mock <ISeatsRepository>();
            _mockTicketService         = new Mock <ITicketService>();
        }
예제 #30
0
        public ActionResult Create([Bind(Include = "Id,Image,Name,Address,PhoneNumber")] CinemaViewModel cinemaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(cinemaViewModel));
            }
            string extension = Path.GetExtension((cinemaViewModel.Image.FileName));

            if (extension == null)
            {
                return(RedirectToAction("Index"));
            }
            string virtualPath  = FormVirtualPath(extension);
            string physicalPath = HttpContext.Server.MapPath(virtualPath);

            cinemaViewModel.ImagePath = virtualPath;

            CinemaDomainModel cinemaDomainModel = Mapper.Map <CinemaViewModel, CinemaDomainModel>(cinemaViewModel);

            _cinemaService.Add(cinemaDomainModel);
            cinemaViewModel.Image.SaveAs(physicalPath);
            return(RedirectToAction("Index"));
        }