private UnitOfWork GetTargetWith(Mock <DbContext> context, FakeExceptionHandler handler) { ContextUtilitiesDouble utilitiesStub = new ContextUtilitiesDouble(new[] { new User() }); Mock <IInterceptorsResolver> resolverStub = new Mock <IInterceptorsResolver>(); return(this.GetTargetWith(utilitiesStub, resolverStub.Object, context, handler)); }
private UnitOfWork GetTargetWith(IEntityInterceptor interceptor, IExceptionHandler handler) { ContextUtilitiesDouble utilitiesStub = new ContextUtilitiesDouble(new[] { new User() }); Mock <IInterceptorsResolver> resolverStub = new Mock <IInterceptorsResolver>(); resolverStub.Setup(r => r.GetGlobalInterceptors()).Returns(new[] { interceptor }); return(this.GetTargetWith(utilitiesStub, resolverStub.Object, new Mock <DbContext>(), handler)); }
private void ParamTest__DeletedEntities_DeletedEntitiesIntercepted(Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction) { InterceptorDouble interceptorMock = new InterceptorDouble(); Mock <IInterceptorsResolver> resolverMock = new Mock <IInterceptorsResolver>(); resolverMock.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); User u1 = new User(1, "John"); User u2 = new User(2, "Mary"); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(new[] { u1, u2 }, EntityEntryState.Deleted); UnitOfWork uof = this.GetTargetWith(contextStub, resolverMock.Object); uof.SaveChanges(); this.AssertInterceptedOnDelete(interceptorMock, u1, u2); }
private void ParamTest__OnDeleteModifiesEntities_ModifiedEntitiesAlsoIntercepted( Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction) { var u1 = new User(1, "John").AsEntry(EntityEntryState.Deleted); var u2 = new User(2, "Mary").AsEntry(EntityEntryState.Modified); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(); contextStub.AddEntriesByCallNumber(1, new[] { u1 }); // 1st call to GetChangedEntities --> one deleted entity contextStub.AddEntriesByCallNumber(2, new[] { u1, u2 }); // 2nd call to GetChangedEntities --> deleted and modified entities InterceptorDouble interceptorMock = new InterceptorDouble(); Mock <IInterceptorsResolver> interceptorResolverStub = new Mock <IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); UnitOfWork uof = this.GetTargetWith(contextStub, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnSave(interceptorMock, u2.Entity as User); }
private void ParamTest__OnSaveModifiesOtherEntities_NewModifiedEntitiesAlsoIntercepted( Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction) { User user1 = new User(1, "John"); User user2 = new User(2, "Mary"); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(); contextStub.AddEntitiesByCallNumber(1, new[] { user1 }); // 1st call to GetChangedEntities --> user1 contextStub.AddEntitiesByCallNumber(2, new[] { user1, user2 }); // 2nd call to GetChangedEntities --> user1 and user2 InterceptorDouble interceptorMock = new InterceptorDouble(); Mock <IInterceptorsResolver> interceptorResolverStub = new Mock <IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); UnitOfWork uof = this.GetTargetWith(contextStub, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnSave(interceptorMock, user1, user2); }
private void ParamTest__OnSaveModifiesOtherEntities_NewModifiedEntitiesAlsoIntercepted( Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction) { User user1 = new User(1, "John"); User user2 = new User(2, "Mary"); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(); contextStub.AddEntitiesByCallNumber(1, new[] {user1}); // 1st call to GetChangedEntities --> user1 contextStub.AddEntitiesByCallNumber(2, new[] {user1, user2}); // 2nd call to GetChangedEntities --> user1 and user2 InterceptorDouble interceptorMock = new InterceptorDouble(); Mock<IInterceptorsResolver> interceptorResolverStub = new Mock<IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] {interceptorMock}); UnitOfWork uof = GetTargetWith(contextStub, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnSave(interceptorMock, user1, user2); }
private void ParamTest__OnSaveDeletesEntities_DeletedEntitiesAlsoIntercepted( Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction) { var u1 = new User(1, "John").AsEntry(); var u2 = new User(2, "Mary").AsEntry(EntityEntryState.Deleted); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(); contextStub.AddEntriesByCallNumber(1, new[] { u1 }); // 1st call to GetChangedEntities --> modified entity contextStub.AddEntriesByCallNumber(2, new[] { u1, u2 }); // 2nd call to GetChangedEntities --> modified and deleted entities InterceptorDouble interceptorMock = new InterceptorDouble(); Mock<IInterceptorsResolver> interceptorResolverStub = new Mock<IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); UnitOfWork uof = GetTargetWith(contextStub, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnDelete(interceptorMock, u2.Entity as User); }
private void ParamTest__DeletedEntities_DeletedEntitiesIntercepted(Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction) { InterceptorDouble interceptorMock = new InterceptorDouble(); Mock<IInterceptorsResolver> resolverMock = new Mock<IInterceptorsResolver>(); resolverMock.Setup(getInterceptorsFunction).Returns(new[] {interceptorMock}); User u1 = new User(1, "John"); User u2 = new User(2, "Mary"); ContextUtilitiesDouble contextStub = new ContextUtilitiesDouble(new[] {u1, u2}, EntityEntryState.Deleted); UnitOfWork uof = GetTargetWith(contextStub, resolverMock.Object); uof.SaveChanges(); AssertInterceptedOnDelete(interceptorMock, u1, u2); }
private UnitOfWork GetTargetWith(IEnumerable<object> changedEntities, IInterceptorsResolver interceptorsResolver) { ContextUtilitiesDouble contextUtilitiesStub = new ContextUtilitiesDouble(changedEntities); return GetTargetWith(contextUtilitiesStub, interceptorsResolver, new Mock<DbContext>()); }
private UnitOfWork GetTargetWith(Mock<DbContext> context) { ContextUtilitiesDouble contextUtilitiesStub = new ContextUtilitiesDouble(Enumerable.Empty<object>()); return GetTargetWith(contextUtilitiesStub, new Mock<IInterceptorsResolver>().Object, context); }
private UnitOfWork GetTargetWith(IEntityInterceptor interceptor, IExceptionHandler handler) { ContextUtilitiesDouble utilitiesStub = new ContextUtilitiesDouble(new[] {new User()}); Mock<IInterceptorsResolver> resolverStub = new Mock<IInterceptorsResolver>(); resolverStub.Setup(r => r.GetGlobalInterceptors()).Returns(new[] {interceptor}); return GetTargetWith(utilitiesStub, resolverStub.Object, new Mock<DbContext>(), handler); }
private UnitOfWork GetTargetWith(Mock<DbContext> context, FakeExceptionHandler handler) { ContextUtilitiesDouble utilitiesStub = new ContextUtilitiesDouble(new[] {new User()}); Mock<IInterceptorsResolver> resolverStub = new Mock<IInterceptorsResolver>(); return GetTargetWith(utilitiesStub, resolverStub.Object, context, handler); }
private UnitOfWork GetTargetWith(IEnumerable <object> changedEntities, IInterceptorsResolver interceptorsResolver) { ContextUtilitiesDouble contextUtilitiesStub = new ContextUtilitiesDouble(changedEntities); return(this.GetTargetWith(contextUtilitiesStub, interceptorsResolver, new Mock <DbContext>())); }
private UnitOfWork GetTargetWith(Mock <DbContext> context) { ContextUtilitiesDouble contextUtilitiesStub = new ContextUtilitiesDouble(Enumerable.Empty <object>()); return(this.GetTargetWith(contextUtilitiesStub, new Mock <IInterceptorsResolver>().Object, context)); }