public async Task <IActionResult> Delete(int id) { if (await _placeService.Delete(id)) { return(Ok()); } _logger.LogError($"Could not delete place with id {id}"); return(BadRequest("Failed to delete place")); }
public void TestDeletePlace(int?id) { switch (id) { case null: Assert.Throws <ArgumentNullException>(() => service.Delete(null)); break; case 1: var place = service.SelectById(1); var result = service.Delete(place); Assert.That(result.Equals("Successful!")); Assert.Throws <Exception>(() => service.SelectById(1), "PlaceId can't be null!"); break; default: break; } }
public ActionResult DeletePlace(int id) { // Get Tree list place List <int> lst = new List <int>(); placeService.TreeListId(id, ref lst); if (lst != null) { placeService.Delete(lst); } ModelState.Clear(); return(Redirect(Request.UrlReferrer.ToString())); }
public void PlaceServiceDelete_PlaceId_ReturnsExceptionNotFound() { // Arrange int placeId = 100; var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(u => u.Places.Add(new Place { Id = 1, Name = "Kharkiv railway station" })); //uowMock.Setup(u => u.Places.Get(placeId)).Returns(new Place { Name = "Kharkiv railway station" }); var placeService = new PlaceService(uowMock.Object); // Act Action deletingPlace = () => placeService.Delete(placeId); // Assert Assert.ThrowsException <Exception>(deletingPlace); }