public void Delete_ShouldNotSaveChanges_WhenThereIsNothingToDelete() { // Arrange var entity = new Entitity_Fake { Id = Guid.NewGuid() }; var entities = new Entitity_Fake[0].AsQueryable(); var repositoryMock = new Mock <IRepository <Entitity_Fake> >(); repositoryMock.SetupGet(x => x.QueryAll).Returns(entities); var unitOfWorkMock = new Mock <IUnitOfWork>(); var postService = new Service_Fake(unitOfWorkMock.Object, repositoryMock.Object); // Act postService.Delete(entity.Id); // Assert unitOfWorkMock.Verify(x => x.Complete(), Times.Never); }
public void Delete_ShouldCallRepositoryRemoveAndSaveChanges() { // Arrange var entity = new Entitity_Fake { Id = Guid.NewGuid() }; var entities = new[] { entity }.AsQueryable(); var repositoryMock = new Mock <IRepository <Entitity_Fake> >(); repositoryMock.SetupGet(x => x.QueryAll).Returns(entities); var unitOfWorkMock = new Mock <IUnitOfWork>(); var postService = new Service_Fake(unitOfWorkMock.Object, repositoryMock.Object); // Act postService.Delete(entity.Id); // Assert repositoryMock.Verify(x => x.Remove(It.Is <Entitity_Fake>(y => y == entity)), Times.Once); unitOfWorkMock.Verify(x => x.Complete(), Times.Once); }