Ejemplo n.º 1
0
        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"]);
            }
        }
Ejemplo n.º 2
0
        internal async virtual Task <ActionResult <TEntity> > Delete(int id)
        {
            var entity = await service.Delete(id);

            if (entity == null)
            {
                return(NotFound());
            }

            return(entity);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        public IActionResult Delete(string id)
        {
            var user = _userService.Read(id);

            if (user == null)
            {
                return(NotFound());
            }

            _userService.Delete(user.Id);

            return(NoContent());
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 7
0
        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 }));
            }
        }
Ejemplo n.º 8
0
        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()));
            }
        }
Ejemplo n.º 9
0
        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());
            }
        }
Ejemplo n.º 10
0
        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());
            }
        }
Ejemplo n.º 11
0
        [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);
        }
Ejemplo n.º 12
0
        [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);
        }
Ejemplo n.º 13
0
        [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);
        }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 17
0
 public virtual void Delete(T entity)
 {
     services.Delete(entity);
 }