private static IInterceptorsResolver GetResolver(Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction, InterceptorDouble interceptorMock) { Mock <IInterceptorsResolver> stub = new Mock <IInterceptorsResolver>(); stub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); return(stub.Object); }
private void ParamTest__GetEntities_EntitiesExists_LoadedEntitiesIntercepted( Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction) { InterceptorDouble interceptorMock = new InterceptorDouble(); IInterceptorsResolver resolverStub = GetResolver(getInterceptorsFunction, interceptorMock); DbContextFakeWrapper contextStub = CreateContextWithTestData(); IDbContextFactory factory = this.GetFactory(contextStub); IRepository rep = this.GetTarget(factory, resolverStub); User u = rep.GetEntities <User>().First(); this.AssertInterceptedOnLoad(interceptorMock, u); }
private void ParamTest__ModifiedEntities_EntitiesIntercepted(Expression <Func <IInterceptorsResolver, IEnumerable <IEntityInterceptor> > > getInterceptorsFunction) { User user1 = new User(1, "John"); User user2 = new User(2, "Mary"); InterceptorDouble interceptorMock = new InterceptorDouble(); Mock <IInterceptorsResolver> interceptorResolverStub = new Mock <IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock }); UnitOfWork uof = this.GetTargetWith(new[] { user1, user2 }, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnSave(interceptorMock, user1, user2); }
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 static void AssertInterceptedOnSave(InterceptorDouble interceptorMock, params User[] users) { interceptorMock.AssertIntercepted(d => d.InterceptedOnSave, users, u => u.Name); }
private void AssertInterceptedOnLoad(InterceptorDouble interceptorMock, User user) { interceptorMock.AssertIntercepted(i => i.InterceptedOnOnLoad, new[] { user }, u => u.Name); }
private void AssertInterceptedOnDelete(InterceptorDouble interceptorMock, params User[] users) { interceptorMock.AssertIntercepted(d => d.InterceptedOnDelete, users, u => u.Name); }
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__ModifiedEntities_EntitiesIntercepted(Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction) { User user1 = new User(1, "John"); User user2 = new User(2, "Mary"); InterceptorDouble interceptorMock = new InterceptorDouble(); Mock<IInterceptorsResolver> interceptorResolverStub = new Mock<IInterceptorsResolver>(); interceptorResolverStub.Setup(getInterceptorsFunction).Returns(new[] {interceptorMock}); UnitOfWork uof = GetTargetWith(new[] {user1, user2}, interceptorResolverStub.Object); uof.SaveChanges(); AssertInterceptedOnSave(interceptorMock, user1, user2); }
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 void ParamTest__GetEntities_EntitiesExists_LoadedEntitiesIntercepted( Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction) { InterceptorDouble interceptorMock = new InterceptorDouble(); IInterceptorsResolver resolverStub = GetResolver(getInterceptorsFunction, interceptorMock); DbContextFakeWrapper contextStub = CreateContextWithTestData(); IDbContextFactory factory = GetFactory(contextStub); IRepository rep = GetTarget(factory, resolverStub); User u = rep.GetEntities<User>().First(); AssertInterceptedOnLoad(interceptorMock, u); }
private void AssertInterceptedOnLoad(InterceptorDouble interceptorMock, User user) { interceptorMock.AssertIntercepted(i => i.InterceptedOnOnLoad, new[] {user}, u => u.Name); }
private static IInterceptorsResolver GetResolver(Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction, InterceptorDouble interceptorMock) { Mock<IInterceptorsResolver> stub = new Mock<IInterceptorsResolver>(); stub.Setup(getInterceptorsFunction).Returns(new[] {interceptorMock}); return stub.Object; }