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>(); }
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>(); }
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>(); }
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>(); }
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>(); }
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>(); }
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>(); }
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>(); }
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 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); }
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); }
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); }
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); }
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>(); }
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)); }