Example #1
0
        public void ModelState_GoodItem_ReturnNoError()
        {
            var city = CityPoiItemBuilder.GenerateCity();

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeTrue();
        }
Example #2
0
        public void ModelState_CityWithoutCountry_ReturnAnError()
        {
            var city = CityPoiItemBuilder.GenerateCity();

            city.Country = null;

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeFalse();
        }
        public void Delete_CityIsNotInRepository_ReturnsNotFound()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();

            //Action
            var result = PoiController.DeletePointOfIntetest(city.Id, city.PointsOfInterest.First().Id);

            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }
        public void GetPoi_PoiDoesNotExist_ReturnNotFoundResult()
        {
            var city = CityPoiItemBuilder.GenerateCity();

            FakeCityRepository.CityExists(city.Id).Returns(true);


            var result = PoiController.GetPointOfInterest(city.Id, BadId);


            result.Should().BeOfType <NotFoundResult>();
        }
        public void GetPoiList_NoPoiFound_ReturnObjectNotFound()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();

            city.PointsOfInterest = null;
            FakeCityRepository.GetPointsOfInterestForCity(city.Id).Returns(city.PointsOfInterest);

            //Action
            var result = PoiController.GetPointsOfInterestForCity(city.Id);

            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }
        public void Delete_PoiIsNotInRepository_ReturnsNotFound()
        {
            const int badId = 0;
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();

            FakeCityRepository.CityExists(city.Id).Returns(true);
            FakeCityRepository.GetCity(city.Id, true).Returns(city);

            //Action
            var result = PoiController.DeletePointOfIntetest(city.Id, badId);

            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }
Example #7
0
        public void UpdatePointOfInterest_PoiFound_CallsUpdateOnRepository()
        {
            var city = CityPoiItemBuilder.GenerateCity();
            var poi  = CityPoiItemBuilder.GeneratePointOfInterest();

            city.PointsOfInterest.Add(poi);
            poi.CityId = city.Id;
            var poiDto = DtoMapper.PoiToPoiDto(poi);

            FakeCityRepository.GetCity(city.Id, IncludePointsOfInterest).Returns(city);

            var result = PoiController.UpdatePointOfInterest(poi.Id, poiDto);

            result.Should().BeOfType <NoContentResult>();
        }
        public void Delete_ItemIsInRepository_ReturnNoContentResult()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();
            var poi  = city.PointsOfInterest.First();

            FakeCityRepository.CityExists(city.Id).Returns(true);
            FakeCityRepository.GetPointOfInterestForCity(city.Id, poi.Id).Returns(poi);
            FakeCityRepository.GetCity(city.Id, true).Returns(city);


            //Action
            var result = PoiController.DeletePointOfIntetest(city.Id, city.PointsOfInterest.First().Id);


            // Assert
            result.Should().BeOfType <NoContentResult>();
        }
        public void Delete_CityAndPoiIsInRepository_CallDeletePoiInRepository()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();
            var poi  = city.PointsOfInterest.First();

            FakeCityRepository.GetCity(city.Id, true).Returns(city);
            FakeCityRepository.GetPointOfInterestForCity(city.Id, poi.Id).Returns(poi);
            FakeCityRepository.CityExists(city.Id).Returns(true);


            //Action
            PoiController.DeletePointOfIntetest(city.Id, poi.Id);


            // Assert
            FakeCityRepository.Received().DeletePointOfInterest(city.PointsOfInterest.First());
        }
        public void GetCity_ItemExistAndPOIisNotRequested_ReturnCityWithNoPOIDTO()
        {
            var city    = CityPoiItemBuilder.GenerateCity();
            var cityDto = new CityWithNoPoidto
            {
                CityId     = city.Id,
                Name       = city.Name,
                Country    = city.Country,
                Population = city.Population
            };

            FakeCityRepository.GetCity(city.Id, false).Returns(city);


            var result = CityPoiController.GetCity(city.Id, false);


            result.Should().BeOfType <ObjectResult>().Which.Value.ShouldBeEquivalentTo(cityDto);
        }
        public void GetPOIList_CityExist_ReturnPOIList()
        {
            //Arrange
            var city = CityPoiItemBuilder.GenerateCity();

            FakeCityRepository.GetPointsOfInterestForCity(city.Id).Returns(city.PointsOfInterest);
            FakeCityRepository.CityExists(city.Id).Returns(true);

            var poiDto = new PointsOfInterestDto
            {
                PoiList = city.PointsOfInterest
            };

            //Action
            var result = PoiController.GetPointsOfInterestForCity(city.Id);


            // Assert
            result.Should().BeOfType <ObjectResult>().Which.Value.ShouldBeEquivalentTo(poiDto);
        }
        public void GetPoi_PoiExist_ReturnPointOfInterestDTO()
        {
            var city   = CityPoiItemBuilder.GenerateCity();
            var poi    = city.PointsOfInterest.First();
            var poiDto = new PointOfInterestDto
            {
                CityId      = poi.CityId,
                Name        = poi.Name,
                Address     = poi.Address,
                Description = poi.Description,
                Id          = poi.Id,
                Latitude    = poi.Latitude,
                Longitude   = poi.Longitude
            };

            FakeCityRepository.GetPointOfInterestForCity(city.Id, poi.Id).Returns(poi);
            FakeCityRepository.CityExists(city.Id).Returns(true);


            var result = PoiController.GetPointOfInterest(city.Id, poi.Id);


            result.Should().BeOfType <ObjectResult>().Which.Value.ShouldBeEquivalentTo(poiDto);
        }