public IActionResult Delete(string id) { var items = _service.Get(id); if (items == null) { return(NotFound()); } _service.Remove(items.Id); return(NoContent()); }
public void RemoveTest() { //Arange bool isRemoved = false; Mock <IUnitOfWork> unitOfWorkMock = new Mock <IUnitOfWork>(); Mock <IRepository <Rate> > repositoryMock = new Mock <IRepository <Rate> >(); repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <Rate, bool> > >())) .Returns <Expression <Func <Rate, bool> > >(predicate => _rates.Where(predicate.Compile()).AsQueryable()); repositoryMock.Setup(repo => repo.Remove(It.IsAny <Rate>())).Callback(() => isRemoved = true); unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <Rate>()).Returns(repositoryMock.Object); RateService _rateService = new RateService(unitOfWorkMock.Object); //Act _rateService.Remove(_rates[0].Id); //Assert Assert.True(isRemoved); }