public async Task RemoveFormDataAsyncThrowsNotFoundExceptionIfEntityDoesNotExistTest() { var mockLoggerService = new Mock<ILoggerService>(); var mockUnitOfWork = new Mock<IUnitOfWork>(); mockUnitOfWork.Setup(x => x.Repository<FormDataEntity>().GetAsync(It.IsAny<Expression<Func<FormDataEntity, bool>>>())) .Returns(() => Task.FromResult<FormDataEntity>(null)); var persistenceService = new FormsPersistenceService(mockUnitOfWork.Object, mockLoggerService.Object); await persistenceService.RemoveFormDataAsync(It.IsAny<Guid>()); }
public async Task RemoveFormDataAsyncCallsCorrectUnitOfWorkMethodsTest() { var entity = new FormDataEntity(); var mockLoggerService = new Mock<ILoggerService>(); var mockUnitOfWork = new Mock<IUnitOfWork>(); mockUnitOfWork.Setup(x => x.Repository<FormDataEntity>().GetAsync(It.IsAny<Expression<Func<FormDataEntity, bool>>>())) .Returns(() => Task.FromResult(entity)); var persistenceService = new FormsPersistenceService(mockUnitOfWork.Object, mockLoggerService.Object); await persistenceService.RemoveFormDataAsync(It.IsAny<Guid>()); mockUnitOfWork.Verify(m => m.Repository<FormDataEntity>().GetAsync(It.IsAny<Expression<Func<FormDataEntity, bool>>>()), Times.Once); mockUnitOfWork.Verify(m => m.Repository<FormDataEntity>().Remove(entity), Times.Once); mockUnitOfWork.Verify(m => m.SaveChanges(), Times.Once); }