public void ModelState_GoodPOI_ReturnNoError()
        {
            var poi = CityPoiItemBuilder.GeneratePointOfInterest();

            var modelStateValidity = ValidatePoi(poi);

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

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeTrue();
        }
Example #3
0
 public BaseCityControllerTest()
 {
     FakeCityRepository = Substitute.For <ICityRepository>();
     CityPoiController  = new CityPoiController(FakeCityRepository);
     PoiController      = new PoiController(FakeCityRepository);
     CityPoiItemBuilder = new CityPoiItemBuilder();
     DtoMapper          = new DtoMapper();
 }
Example #4
0
        public void ModelState_CityWithoutCountry_ReturnAnError()
        {
            var city = CityPoiItemBuilder.GenerateCity();

            city.Country = null;

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeFalse();
        }
        public void ModelState_POIWithoutLatitude_ReturnAnError()
        {
            var poi = CityPoiItemBuilder.GeneratePointOfInterest();

            poi.Latitude = null;

            var modelStateValidity = ValidatePoi(poi);

            modelStateValidity.Should().BeFalse();
        }
        public void ModelState_BadLongitude_ReturnAnError(string longitude)
        {
            var poi = CityPoiItemBuilder.GeneratePointOfInterest();

            poi.Longitude = longitude;

            var modelStateValidity = ValidatePoi(poi);

            modelStateValidity.Should().BeFalse();
        }
Example #7
0
        public void Update_IdDoesNotMatchItemId_ReturnBadRequest()
        {
            var poi    = CityPoiItemBuilder.GeneratePointOfInterest();
            var poiDto = DtoMapper.PoiToPoiDto(poi);


            var result = PoiController.UpdatePointOfInterest(NotMatchingId, poiDto);


            result.Should().BeOfType <BadRequestResult>();
        }
        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>();
        }
Example #10
0
        public void UpdatePointOfInterest_BadRequest_ReturnBadRequestObjectWithError()
        {
            //Arrange
            var poi    = CityPoiItemBuilder.GeneratePointOfInterest();
            var poiDto = DtoMapper.PoiToPoiDto(poi);

            PoiController.ModelState.AddModelError("Error", "Model state error");

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

            //Assert
            result.Should().BeOfType <BadRequestObjectResult>();
        }
        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>();
        }
Example #12
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_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>();
        }
        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);
        }
Example #18
0
        public void GetCities_CititesExist_ReturnCityDtos()
        {
            //Arrange
            const int listLength = 10;
            var       cities     = CityPoiItemBuilder.GenerateCityList(listLength);
            var       dtoList    = cities.Select(city => new CityWithNoPoidto
            {
                CityId     = city.Id,
                Name       = city.Name,
                Country    = city.Country,
                Population = city.Population
            }).ToList();

            FakeCityRepository.GetCities().Returns(cities);


            //Action
            var result = CityPoiController.GetAll();


            // Assert
            result.ShouldBeEquivalentTo(dtoList);
        }
        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);
        }