public void ShouldThrowArgumentNullException_WhenItemParameterIsNull() { var asyncRepository = new Mock <IAsyncRepository <IDbModel> >(); var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>(); var genericAsyncService = new GenericAsyncService <IDbModel>(asyncRepository.Object, unitOfWorkFactory.Object); IDbModel invalidItem = null; Assert.That( () => genericAsyncService.Update(invalidItem), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("Invalid item to update!")); }
public void ShouldReturnTheCorrectItem_WhenParametersAreCorrect() { var mockAsyncRepository = new Mock <IAsyncRepository <IDbModel> >(); var mockUnitOfWork = new Mock <IDisposableUnitOfWork>(); var mockUnitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>(); mockUnitOfWorkFactory.Setup(factory => factory.CreateUnitOfWork()).Returns(mockUnitOfWork.Object); var genericAsyncService = new GenericAsyncService <IDbModel>(mockAsyncRepository.Object, mockUnitOfWorkFactory.Object); var validItem = new Mock <IDbModel>(); var actualResult = genericAsyncService.Update(validItem.Object); Assert.That(actualResult, Is.SameAs(validItem.Object)); }
public void ShouldInvokeUnitOfWorkSaveChangesAsyncMethodOnce_WhenParametersAreCorrect() { var mockAsyncRepository = new Mock <IAsyncRepository <IDbModel> >(); var mockUnitOfWork = new Mock <IDisposableUnitOfWork>(); var mockUnitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>(); mockUnitOfWorkFactory.Setup(factory => factory.CreateUnitOfWork()).Returns(mockUnitOfWork.Object); var genericAsyncService = new GenericAsyncService <IDbModel>(mockAsyncRepository.Object, mockUnitOfWorkFactory.Object); var validItem = new Mock <IDbModel>(); genericAsyncService.Update(validItem.Object); mockUnitOfWork.Verify(repo => repo.SaveChangesAsync(), Times.Once); }