public void Delete_InvalidId_Throws() { int invalidId = 0; var mockKindRepository = new Mock <IRepository <Kind> >(); mockKindRepository.Setup(repo => repo.Delete(It.IsAny <int>())); var kindProvider = new KindService(mockKindRepository.Object); kindProvider.Delete(invalidId); mockKindRepository.Verify(mock => mock.Delete(invalidId), Times.Once()); }
public void Delete_ValidId_ObjDeleted() { int validId = 1; var kinds = new List <Kind> { new Kind { KindId = 1, Type = "Product" }, new Kind { KindId = 2, Type = "MyType-2" } }; int countBeforeDelete = kinds.Count; var mockKindRepository = new Mock <IRepository <Kind> >(); mockKindRepository.Setup(repo => repo.Delete(It.IsAny <int>())) .Callback((int id) => { if (id == validId) { kinds.RemoveAll(kind => kind.KindId == id); } }); var kindProvider = new KindService(mockKindRepository.Object); kindProvider.Delete(validId); Assert.AreEqual(kinds.Count, countBeforeDelete - 1); Assert.IsFalse(kinds.Exists(kind => kind.KindId == validId)); mockKindRepository.Verify(mock => mock.Delete(validId), Times.Once()); }
public IHttpActionResult Delete(int id) { return(Json(service.Delete(id))); }