コード例 #1
0
        public void GetAsync_Return_Empty_List()
        {
            //Arrange
            CityDomainModel cityDomainModel = new CityDomainModel
            {
                Id          = 123,
                CinemasList = new List <CinemaDomainModel>(),
                Name        = "Zrenjanin"
            };

            int expectedStatusCode = 200;

            IEnumerable <CityDomainModel> cityDomainModelsIEn = null;

            Task <IEnumerable <CityDomainModel> > responseTask = Task.FromResult(cityDomainModelsIEn);

            _cityService = new Mock <ICityService>();
            _cityService.Setup(x => x.GetAllAsync()).Returns(responseTask);
            CitiesController citiesController = new CitiesController(_cityService.Object);

            //Act
            var result       = citiesController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult = ((OkObjectResult)result).Value;
            List <CityDomainModel> cityDomainModelResultList = (List <CityDomainModel>)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void CinemaService_CreateCinemaAsync_ReturnsListOfCinemas()
        {
            //Arrange
            _city = new City
            {
                Id   = 1,
                Name = "Miami"
            };

            _cityDomainModel = new CityDomainModel()
            {
                Id   = _city.Id,
                Name = _city.Name
            };

            var numOfRows  = 2;
            var numOfSeats = 3;

            _mockCinemaRepository.Setup(x => x.Insert(It.IsAny <Data.Cinema>())).Returns(_cinema);
            _mockCityRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_city);

            //Act
            var resultAction = cinemaService.CreateCinemaAsync(_cinemaDomainModel, numOfSeats, numOfRows, "auditorium123").ConfigureAwait(false).GetAwaiter().GetResult();

            //Assert
            Assert.IsNotNull(resultAction);
            Assert.AreEqual(_cinema.Name, resultAction.Name);
            Assert.IsInstanceOfType(resultAction, typeof(CinemaDomainModel));
        }
コード例 #4
0
        public CityDomainModel Add(AirdnaModel cityRequest)
        {
            var city = Get(cityRequest);

            if (city is null)
            {
                var newKey = 1;
                foreach (var cityTemp in _cities)
                {
                    if (cityTemp.Id > newKey)
                    {
                        newKey = cityTemp.Id;
                    }
                }

                newKey++;

                city = new CityDomainModel()
                {
                    Id = newKey,
                    CityOriginalName = cityRequest.CityOriginalName,
                    Airdna           = (AirdnaModel)cityRequest.Clone(),
                };

                _cities.Add(city);

                _saveChanges();
            }

            return(city);
        }
コード例 #5
0
        public void GetCity_ById_Async_Return_City_OkObjectResult()
        {
            //Arrange
            CityDomainModel cityDomainModel = new CityDomainModel
            {
                Id          = 123,
                CinemasList = new List <CinemaDomainModel>(),
                Name        = "Zrenjanin"
            };

            int expectedStatusCode = 200;
            Task <CityDomainModel> responseTask = Task.FromResult(cityDomainModel);

            _cityService = new Mock <ICityService>();
            _cityService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask);
            CitiesController citiesController = new CitiesController(_cityService.Object);

            //Act
            var             result           = citiesController.GetById(cityDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var             objectResult     = ((OkObjectResult)result).Value;
            CityDomainModel cityDomainResult = (CityDomainModel)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
            Assert.AreEqual(cityDomainModel.Id, cityDomainResult.Id);
        }
コード例 #6
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);
        }
コード例 #7
0
        public async Task <ActionResult <CityDomainModel> > GetById(int id)
        {
            CityDomainModel cityDomainModel = await _cityService.GetByIdAsync(id);

            if (cityDomainModel == null)
            {
                return(NotFound(Messages.CITY_NOT_FOUND));
            }

            return(Ok(cityDomainModel));
        }
コード例 #8
0
        public void Can_Create()
        {
            var city = new CityDomainModel()
            {
                Name = "London"
            };

            _sutDomainService.CreateCity(city);

            _mockMapperService.Verify(x => x.Map <CityDto>(city), Times.Once());
            _mockDataService.Verify(x => x.CreateCity(It.IsAny <CityDto>()));
        }
コード例 #9
0
        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);
        }
コード例 #10
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));
        }
コード例 #11
0
            public Album(CityDomainModel city, CityDomainModel.Album album)
            {
                if (album == null)
                {
                    throw new ArgumentNullException(nameof(album));
                }

                AlbumKey    = album.Key;
                AlbumName   = album.Name;
                CityKey     = city.CityKey;
                CityName    = city.CityName;
                CountryKey  = city.CountryKey;
                CountryName = city.CountryName;
                Description = album.Description;
                IconUrl     = album.IconUrl;
            }
コード例 #12
0
        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);
        }
コード例 #13
0
        public ListAlbumsResponse(CityDomainModel city)
        {
            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }
            if (city.Albums?.Any() != true)
            {
                throw new ArgumentNullException(nameof(city.Albums));
            }

            CityKey     = city.CityKey;
            CityName    = city.CityName;
            CountryKey  = city.CountryKey;
            CountryName = city.CountryName;
            Albums      = city.Albums.Select(x => new Album(city, x)).ToArray();
        }
コード例 #14
0
        public async Task <CityDomainModel> GetByCityNameAsync(string cityName)
        {
            var city = await _citiesRepository.GetByCityNameAsync(cityName);

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

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

            return(cityDomainModel);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public void GetCity_ById_Async_Return_Not_Found()
        {
            //Arrange
            string                 expectedMessage    = Messages.CITY_NOT_FOUND;
            int                    expectedStatusCode = 404;
            CityDomainModel        cityDomainModel    = null;
            Task <CityDomainModel> responseTask       = Task.FromResult(cityDomainModel);

            _cityService = new Mock <ICityService>();
            _cityService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask);
            CitiesController citiesController = new CitiesController(_cityService.Object);

            //Act
            var    result       = citiesController.GetById(123).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var    objectResult = ((NotFoundObjectResult)result).Value;
            string message      = (string)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
            Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode);
            Assert.AreEqual(expectedMessage, message);
        }
コード例 #17
0
        public void CinemaService_CreateCinemaAsync_ReturnsListOfCinemasWithAuditoriumsSeats()
        {
            //Arrange
            List <Data.Cinema> cinemas = new List <Data.Cinema>();

            _city = new City
            {
                Id   = 1,
                Name = "Miami"
            };

            _cityDomainModel = new CityDomainModel()
            {
                Id   = _city.Id,
                Name = _city.Name
            };

            SeatDomainModel seat1 = new SeatDomainModel
            {
                Id           = Guid.NewGuid(),
                AuditoriumId = 1,
                Number       = 2,
                Row          = 1
            };

            SeatDomainModel seat2 = new SeatDomainModel
            {
                Id           = Guid.NewGuid(),
                AuditoriumId = 1,
                Number       = 3,
                Row          = 1
            };

            Seat s1 = new Seat
            {
                Id           = seat1.Id,
                AuditoriumId = seat1.AuditoriumId,
                Number       = seat1.Number,
                Row          = seat1.Row
            };

            Seat s2 = new Seat
            {
                Id           = seat2.Id,
                AuditoriumId = seat2.AuditoriumId,
                Number       = seat2.Number,
                Row          = seat2.Row
            };

            List <SeatDomainModel> seats = new List <SeatDomainModel>();

            seats.Add(seat1);
            seats.Add(seat2);

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

            ss.Add(s1);
            ss.Add(s2);

            AuditoriumDomainModel auditoriumDomainModel = new AuditoriumDomainModel
            {
                Id        = 1,
                CinemaId  = 11,
                Name      = "Test Audit",
                SeatsList = seats
            };

            Auditorium auditorium = new Auditorium
            {
                Id        = auditoriumDomainModel.Id,
                CinemaId  = auditoriumDomainModel.CinemaId,
                AuditName = auditoriumDomainModel.Name,
                Seats     = ss
            };

            List <AuditoriumDomainModel> auditoriumDomainModelList = new List <AuditoriumDomainModel>();

            auditoriumDomainModelList.Add(auditoriumDomainModel);

            List <Auditorium> auditoriumList = new List <Auditorium>();

            auditoriumList.Add(auditorium);

            _cinemaDomainModel.AuditoriumsList = auditoriumDomainModelList;
            _cinema.Auditoriums = auditoriumList;

            int numOfRows  = 3;
            int numOfSeats = 2;

            int expectedAuditoriumCount = 1;

            _mockCityRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_city);
            _mockCinemaRepository.Setup(x => x.GetAll()).ReturnsAsync(cinemas);
            _mockCinemaRepository.Setup(x => x.Insert(It.IsAny <Data.Cinema>())).Returns(_cinema);
            _mockCinemaRepository.Setup(x => x.Save());

            //Act
            var resultAction = cinemaService.CreateCinemaAsync(_cinemaDomainModel, numOfSeats, numOfRows, "auditorium123").ConfigureAwait(false).GetAwaiter().GetResult();


            //Assert
            Assert.IsNotNull(resultAction);
            Assert.AreEqual(expectedAuditoriumCount, resultAction.AuditoriumsList.Count);
            Assert.AreEqual(_cinemaDomainModel.Name, resultAction.Name);
            Assert.IsInstanceOfType(resultAction, typeof(CinemaDomainModel));
        }
コード例 #18
0
        public void CreateCity(CityDomainModel newCityDomainModel)
        {
            var cityDtoModel = _mapperService.Map <CityDto>(newCityDomainModel);

            _cityDataService.CreateCity(cityDtoModel);
        }
コード例 #19
0
        public void UpdateCity(int id, CityDomainModel city)
        {
            var cityDtoModel = _mapperService.Map <CityDto>(city);

            _cityDataService.UpdateCity(id, cityDtoModel);
        }