public void DeleteMethod_NullEntity_ThrowsException() { var repoDeleteCalls = productRepoCalls["Delete"]; try { productService.Delete(null); Assert.Fail("ArgumentNullException expected, but none thrown"); } catch (Exception ex) { Assert.IsInstanceOf <ArgumentNullException>(ex); Assert.AreEqual("entity", ((ArgumentNullException)ex).ParamName); Assert.AreEqual(repoDeleteCalls, productRepoCalls["Delete"]); } }
internal async virtual Task <ActionResult <TEntity> > Delete(int id) { var entity = await service.Delete(id); if (entity == null) { return(NotFound()); } return(entity); }
public void Delete(string id) { var fixService = new Kn_FixService(); //删除前先把该问题的答复权限删除 fixService.GenericService.Delete(p => p.IssueID == id); fixService.GenericService.Save(); //通过ID删除问题本身 GenericService.Delete(id); GenericService.Save(); }
public IActionResult Delete(string id) { var user = _userService.Read(id); if (user == null) { return(NotFound()); } _userService.Delete(user.Id); return(NoContent()); }
public IActionResult Delete(string id) { var circle = _circleService.Read(id); if (circle == null) { return(NotFound()); } _circleService.Delete(circle.Id); return(NoContent()); }
public void ShouldDeleteWithReturnCodeZero() { Mock <IGenericRepository <ExamProgram> > examProgramRepositoryMock = new Mock <IGenericRepository <ExamProgram> >(); Mock <IActivityLoggerService> activityLoggerMock = new Mock <IActivityLoggerService>(); examProgramRepositoryMock.Setup((e) => e.Delete(new ExamProgram())).Returns(0); IGenericService <ExamProgram> examProgramService = new GenericService <ExamProgram>(examProgramRepositoryMock.Object, activityLoggerMock.Object); int result = examProgramService.Delete(new ExamProgram()); Assert.Equal(0, result); }
public ActionResult DeleteConfirmed(int productId, int featureId) { var feature = service.GetById(featureId); if (feature == null) { return(new HttpNotFoundResult()); } else { service.Delete(feature); return(RedirectToAction("Edit", "Product", new { id = productId })); } }
public async Task<ActionResult> Delete(long id) { try { var result = await _service.Delete(id); if (result.NotFound) return Json(new AjaxResult("دیدگاه مورد نظر یافت نشد.")); if (result.Succeeded) return Json(new AjaxResult(true, "دیدگاه مورد نظر با موفقیت حذف شد.")); return Json(new AjaxResult(result.State.Errors.JoinMessages())); } catch (Exception e) { return Json(new AjaxResult(e.JoinMessages())); } }
public void Generic_Delete_Service() { var fakeContext = new FakeContext("Generic_Delete_Service"); fakeContext.FillWithAll(); using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object)) { var repository = new GenericRepository <Product>(context); var service = new GenericService <Product>(repository); var countBefore = service.GetAll().Count(); Assert.Equal(5, countBefore); var response = service.Delete(1); Assert.Equal("{ Message = Produto removido com sucesso. }", response.ToString()); Assert.Equal(4, service.GetAll().Count()); } }
public void Generic_Delete_Product_NotFound_Service_Warehouse() { var fakeContext = new FakeContext("Generic_Delete_Product_NotFound_Service_Warehouse"); fakeContext.FillWith <Product>(); using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object)) { var repository = new GenericRepository <Product>(context); var service = new GenericService <Product>(repository); var countBefore = service.GetAll().Count(); Assert.Equal(5, countBefore); var response = service.Delete(6); Assert.Equal("{ Message = Produto não encontrado. }", response.ToString()); Assert.Equal(5, service.GetAll().Count()); } }
[Test] public void Delete_WhenRepositoryReturnsNull_ShouldReturnNotFound() { //Arrange Guid id = new Guid(); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.GetById(id)) .Returns(() => null); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService result = service.Delete(id); //Assert Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.IsTrue(result.ErrorCode == ErrorCode.NotFound); }
[Test] public void Delete_WhenRepositoryThrowException_ShouldReturnError() { //Arrange EventModel expectedItem = TestsFacade.EventsFacade.BuildEventModelItem(); Exception expectedException = new Exception(Guid.NewGuid().ToString()); Guid id = new Guid(); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.GetById(id)) .Throws(expectedException); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService result = service.Delete(id); //Assert Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.IsTrue(result.Exception == expectedException); }
[Test] public void Delete_WhenCalled_ShouldReturnOk() { //Arrange EventModel expectedItem = TestsFacade.EventsFacade.BuildEventModelItem(); var repositoryMock = _mock.Mock <IGenericRepository <EventModel> >(); repositoryMock .Setup(items => items.GetById(expectedItem.Id)) .Returns(() => expectedItem); repositoryMock .Setup(items => items.Remove(expectedItem)); GenericService <EventModel> service = _mock.Create <GenericService <EventModel> >(); //Act ResultService result = service.Delete(expectedItem.Id); //Assert Assert.IsNotNull(result); Assert.IsInstanceOf <ResultService>(result); Assert.IsTrue(result.Success); }
public IActionResult Delete(int Id) { service.Delete(Id); return(RedirectToAction("List")); }
public void DeleteById_Should_ThrowException_IfArgumentIsNull() { Assert.Throws <ArgumentNullException>(() => _genericServiceNullable.Delete((int?)null)); }
public void DeleteByEntity_Should_InvokeGenericRepositoryDeleteByEntity_Once() { _genericService.Delete(_testEntity); _mockGenericRepository.Verify(x => x.Delete(_testEntity), Times.Once); }
public virtual void Delete(T entity) { services.Delete(entity); }