Exemplo n.º 1
0
        public void DeletePointOfInterest_WhenCityExist_ReturnNoContentResult()

        {
            //Arrange
            var anyCity = CityFaker.Generate();
            var anyPoi  = anyCity.PointsOfInterests.FirstOrDefault();

            anyPoi.Id = 1;
            var poiDTO = new PoiDTO()
            {
                Id           = anyPoi.Id,
                Name         = "Château de Versaille",
                Descritption = "La planque à Marie Antoinette",
                Latitude     = "80.090",
                Longitude    = "130.234"
            };

            MockCityRepository.CityExists(anyCity.Id).Returns(true);

            //Action
            var result = CityController.DeletePointOfInterest(anyCity.Id, anyPoi.Id, poiDTO);

            // Assert
            result.Should().BeOfType <NoContentResult>();
        }
Exemplo n.º 2
0
        public void AddPointOfInterestForCity_CityExist_ReturnsCreatedAtRouteResult()
        {
            //Arrange
            var anyCity = CityFaker.Generate();
            var anyPoi  = new PointOfInterest()
            {
                Name         = "Château Frontenac",
                Descritption = "Emblème de la ville",
                Latitude     = "46° 48\' 25.79\" N",
                Longitude    = " -71° 12\' 10.80\" W"
            };

            var poiDTO = new PoiDTO()
            {
                Name         = anyPoi.Name,
                Descritption = anyPoi.Descritption,
                Latitude     = anyPoi.Latitude,
                Longitude    = anyPoi.Longitude
            };

            MockCityRepository.CityExists(anyCity.Id).Returns(true);

            //Action
            var result = CityController.AddPointOfInterestForCity(anyCity.Id, poiDTO);


            // Assert
            result.Should().BeOfType <CreatedAtRouteResult>();
        }
Exemplo n.º 3
0
        public void ModelState_ValideItem_ReturnNoError()
        {
            var city = CityFaker.Generate();

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeTrue();
        }
Exemplo n.º 4
0
        public void ModelSate_CityWithoutCountry_NotValide()
        {
            var city = CityFaker.Generate();

            city.Country = null;

            var modelStateValidity = ValidateCity(city);

            modelStateValidity.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void ModelSate_LongitudeWithBadFormat_ReturnFalse(string longitude)
        {
            var city            = CityFaker.Generate();
            var pointOfInterest = city.PointsOfInterests.First();

            pointOfInterest.Latitude = longitude;

            var modelStateValidity = ValidatePoi(pointOfInterest);

            modelStateValidity.Should().BeFalse();
        }
Exemplo n.º 6
0
        public void AddPointOfInterest_InvalidPoiData_ReturnBadRequest()
        {
            CityController.ModelState.AddModelError("Error", "Model State Error");

            var city = CityFaker.Generate();

            MockCityRepository.CityExists(city.Id).Returns(true);
            var result = CityController.AddPointOfInterestForCity(city.Id, new PoiDTO());

            result.Should().BeOfType <BadRequestObjectResult>();
        }
Exemplo n.º 7
0
        public void ModelSate_PointOfInterestWithoutLatitude_NotValide()
        {
            var city            = CityFaker.Generate();
            var pointOfInterest = city.PointsOfInterests.First();

            pointOfInterest.Latitude = null;

            var modelStateValidity = ValidatePoi(pointOfInterest);

            modelStateValidity.Should().BeFalse();
        }
Exemplo n.º 8
0
        public void UpdatePointOfInterest_InvalidPoiData_ReturnBadRequest()
        {
            CityController.ModelState.AddModelError("Error", "Model State Error");

            var city = CityFaker.Generate();

            city.Id = 1;
            MockCityRepository.CityExists(city.Id).Returns(true);
            var pointOfInterestId = city.PointsOfInterests.First().Id;
            var result            = CityController.UpdatePointOfInterest(city.Id, pointOfInterestId, new PoiDTO());

            result.Should().BeOfType <BadRequestResult>();
        }
Exemplo n.º 9
0
        public void ModelSate_PointOfInterestWithoutName_NotValide()
        {
            var city            = CityFaker.Generate();
            var pointOfInterest = city.PointsOfInterests.First();

            pointOfInterest.Name      = null;
            pointOfInterest.Latitude  = "48.55655855";
            pointOfInterest.Longitude = "-70.5598523";


            var modelStateValidity = ValidatePoi(pointOfInterest);

            modelStateValidity.Should().BeFalse();
        }
Exemplo n.º 10
0
        public void UpdatePointOfInterest_WhenPoiDTODontExist_ReturnBadRequestResult()

        {
            //Arrange
            var anyCity = CityFaker.Generate();
            var anyPoi = anyCity.PointsOfInterests.FirstOrDefault();
            MockCityRepository.CityExists(anyCity.Id).Returns(true);

            //Action
            var result = CityController.UpdatePointOfInterest(anyCity.Id, anyPoi.Id, null);

            // Assert 
            result.Should().BeOfType<BadRequestResult>();
        }
Exemplo n.º 11
0
        public void GetAPointOfInterestForCity_CityDontExist_ReturnsBadRequestResult()
        {
            //Arrange
            var anyCity   = CityFaker.Generate();
            var anyPoiKey = anyCity.PointsOfInterests.FirstOrDefault();

            MockCityRepository.CityExists(anyCity.Id).Returns(false);

            //Action
            var result = CityController.GetAPointOfInterestForCity(anyCity.Id, anyPoiKey.Id);


            // Assert
            result.Should().BeOfType <BadRequestResult>();
        }
Exemplo n.º 12
0
        public void AddPointOfInterestForCity_PoiIsNull_ReturnsBadRequestResult()
        {
            //Arrange
            var anyCity = CityFaker.Generate();

            MockCityRepository.CityExists(anyCity.Id).Returns(true);
            MockCityRepository.AddPointOfInterestForCity(anyCity.Id, null);

            //Action
            var result = CityController.AddPointOfInterestForCity(anyCity.Id, null);


            // Assert
            result.Should().BeOfType <BadRequestResult>();
        }
Exemplo n.º 13
0
        public void GetCity_CityDontExist_ReturnsNotFoundResult()
        {
            //Arrange
            bool includePoi = true;
            var  anyCity    = CityFaker.Generate();

            MockCityRepository.CityExists(anyCity.Id).Returns(false);
            MockCityRepository.GetCity(anyCity.Id, includePoi).Returns(anyCity);

            //Action
            var result = CityController.GetCity(anyCity.Id, includePoi);


            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }
Exemplo n.º 14
0
        public void GetAll_CitiesExist_ReturnCitiesDTO()
        {
            //Arrange
            int    nbOfCities = 4;
            var    cities     = CityFaker.Generate(nbOfCities);
            string name       = "";
            var    citiesDTO  = ToDTO.ToCitiesDto(cities);

            MockCityRepository.GetCities().Returns(cities);

            //Action
            var result = CityController.GetCities(name);


            // Assert
            result.Should().BeOfType <ObjectResult>()
            .Which.Value.ShouldBeEquivalentTo(citiesDTO);
        }
Exemplo n.º 15
0
        public void GetAPointOfInterestForCity_CityAndPoiExist_ReturnsThePoiForTheCity()
        {
            //Arrange
            var anyCity         = CityFaker.Generate();
            var anyPoi          = anyCity.PointsOfInterests.FirstOrDefault();
            var aPoiForACityDTO = ToDTO.ToAPoiForACityDto(anyPoi);

            MockCityRepository.CityExists(anyCity.Id).Returns(true);
            MockCityRepository.GetPointOfInterestForCity(anyCity.Id, anyPoi.Id).Returns(anyPoi);

            //Action
            var result = CityController.GetAPointOfInterestForCity(anyCity.Id, anyPoi.Id);


            // Assert
            result.Should().BeOfType <ObjectResult>()
            .Which.Value.ShouldBeEquivalentTo(aPoiForACityDTO);
        }
        public void GetAllPointsOfInterestForCity_CityExist_ReturnsAllPoiForACityDTO()
        {
            //Arrange
            var anyCity           = CityFaker.Generate();
            var allPoiForACityDTO = ToDTO.ToPoiDto(anyCity.PointsOfInterests);

            MockCityRepository.CityExists(anyCity.Id).Returns(true);
            MockCityRepository.GetPointsOfInterestForCity(anyCity.Id).Returns(anyCity.PointsOfInterests);



            //Action
            var result = CityController.GetAllPointsOfInterestForCity(anyCity.Id);


            // Assert
            result.Should().BeOfType <ObjectResult>()
            .Which.Value.ShouldBeEquivalentTo(allPoiForACityDTO);
        }
Exemplo n.º 17
0
        public void GetAll_ForASpecificCity_ReturnTheCityDTO()
        {
            //Arrange
            int nbOfCities = 4;
            var cities     = CityFaker.Generate(nbOfCities);

            cities[0].Name = "Paris";
            string name      = cities[0].Name;
            var    citiesDTO = ToDTO.ToCitiesDto(cities);

            MockCityRepository.GetCities().Returns(cities);

            //Action
            var result = CityController.GetCities(name);


            // Assert
            result.Should().BeOfType <ObjectResult>();
            citiesDTO[0].Name.ShouldBeEquivalentTo(name);
        }
Exemplo n.º 18
0
        public void GetCityWithoutPoi_CityExist_ReturnsCityWithoutPoiDTO()
        {
            //Arrange
            bool includePoi        = false;
            var  anyCity           = CityFaker.Generate();
            var  cityWithoutPoiDto = ToDTO.ToCityWithoutPoiDto(anyCity);

            MockCityRepository.CityExists(anyCity.Id).Returns(true);
            MockCityRepository.GetCity(anyCity.Id, includePoi).Returns(anyCity);



            //Action
            var result = CityController.GetCity(anyCity.Id, includePoi);


            // Assert
            result.Should().BeOfType <ObjectResult>()
            .Which.Value.ShouldBeEquivalentTo(cityWithoutPoiDto);
        }
Exemplo n.º 19
0
        public void UpdatePointOfInterestForCity_CityExist_CallsUpdateOnCityRepository()
        {
            //Arrange
            var anyCity = CityFaker.Generate();
            var anyPoi = anyCity.PointsOfInterests.FirstOrDefault();
            anyPoi.Id = 1;
            var poiDTO = new PoiDTO()
            {
                Name = "Château de Versaille",
                Descritption = "La planque à Marie Antoinette",
                Latitude = "80.090",
                Longitude = "130.234"
            };
            MockCityRepository.CityExists(anyCity.Id).Returns(true);

            //Action
            var result = CityController.UpdatePointOfInterest(anyCity.Id, anyPoi.Id, poiDTO);

            // Assert 
            MockCityRepository.Received().UpdatePointOfInterest(Arg.Is<PointOfInterest>(x => x.Id == anyPoi.Id));
        }
Exemplo n.º 20
0
        public void UpdatePointOfInterest_WhenCityDontExist_ReturnNotFoundResult()

        {
            //Arrange
            var anyCity = CityFaker.Generate();
            var anyPoi = anyCity.PointsOfInterests.FirstOrDefault();
            var poiDTO = new PoiDTO()
            {
                Name = "Château de Versaille",
                Descritption = "La planque à Marie Antoinette",
                Latitude = "48° 41\' 25.79\" N",
                Longitude = " -81° 19\' 10.80\" W"
            };
            MockCityRepository.CityExists(anyCity.Id).Returns(false);

            //Action
            var result = CityController.UpdatePointOfInterest(anyCity.Id, anyPoi.Id, poiDTO);

            // Assert 
            result.Should().BeOfType<NotFoundResult>();
        }