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 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)); }
public IActionResult DeletePointOfInterest(int cityId, int id, [FromBody] PoiDTO pointOfInterestData) { if (!CitiesRepository.CityExists(cityId)) { return(NotFound()); } if (id == 0) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var pointOfInterest = toEntity.ConvertToEntity(cityId, id, pointOfInterestData); CitiesRepository.DeletePointOfInterest(pointOfInterest); return(new NoContentResult()); }
public IActionResult AddPointOfInterestForCity(int cityId, [FromBody] PoiDTO pointOfInterestData) { if (!CitiesRepository.CityExists(cityId)) { return(NotFound()); } if (pointOfInterestData == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var pointOfInterest = toEntity.ConvertToEntity(cityId, pointOfInterestData); CitiesRepository.AddPointOfInterestForCity(cityId, pointOfInterest); return(CreatedAtRoute("GetCity", new { id = pointOfInterest.Id }, pointOfInterest)); }