コード例 #1
0
        public void Multiple_contexts_can_be_combined_together()
        {
            var objectContext1 = new ObjectContext();
            var context1       = CreateDbContext(objectContext1);
            var objectContext2 = new ObjectContext();
            var context2       = CreateDbContext(objectContext2);

            var interceptionContext1 = new DbInterceptionContext()
                                       .WithDbContext(context1)
                                       .WithDbContext(context2)
                                       .WithObjectContext(objectContext1);

            var interceptionContext2 = interceptionContext1
                                       .WithDbContext(context2)
                                       .WithObjectContext(objectContext1)
                                       .WithObjectContext(objectContext2);

            var combined = DbInterceptionContext.Combine(new[] { interceptionContext1, interceptionContext2 });

            Assert.Equal(2, combined.DbContexts.Count());
            Assert.Equal(2, combined.ObjectContexts.Count());

            Assert.Contains(context1, combined.DbContexts);
            Assert.Contains(context2, combined.DbContexts);
            Assert.Contains(objectContext1, combined.ObjectContexts);
            Assert.Contains(objectContext2, combined.ObjectContexts);
        }
コード例 #2
0
        public void Interception_context_can_be_associated_with_one_or_more_DbContexts()
        {
            var context1 = CreateDbContext(new ObjectContext());
            var interceptionContext1 = new DbInterceptionContext().WithDbContext(context1);

            Assert.Equal(new[] { context1 }, interceptionContext1.DbContexts);

            var context2 = CreateDbContext(new ObjectContext());
            var interceptionContext2 = interceptionContext1.WithDbContext(context2);

            Assert.Contains(context1, interceptionContext2.DbContexts);
            Assert.Contains(context2, interceptionContext2.DbContexts);
            Assert.Empty(interceptionContext2.ObjectContexts);

            Assert.Equal(new[] { context1 }, interceptionContext1.DbContexts);
        }
コード例 #3
0
        public void Interception_context_can_be_associated_with_one_or_more_DbContexts()
        {
            var context1             = CreateDbContext(new ObjectContext());
            var interceptionContext1 = new DbInterceptionContext().WithDbContext(context1);

            Assert.Equal(new[] { context1 }, interceptionContext1.DbContexts);

            var context2             = CreateDbContext(new ObjectContext());
            var interceptionContext2 = interceptionContext1.WithDbContext(context2);

            Assert.Contains(context1, interceptionContext2.DbContexts);
            Assert.Contains(context2, interceptionContext2.DbContexts);
            Assert.Empty(interceptionContext2.ObjectContexts);

            Assert.Equal(new[] { context1 }, interceptionContext1.DbContexts);
        }
コード例 #4
0
        public void Multiple_contexts_can_be_combined_together()
        {
            var objectContext1 = new ObjectContext();
            var context1 = CreateDbContext(objectContext1);
            var objectContext2 = new ObjectContext();
            var context2 = CreateDbContext(objectContext2);

            var interceptionContext1 = new DbInterceptionContext()
                .WithDbContext(context1)
                .WithDbContext(context2)
                .WithObjectContext(objectContext1);

            var interceptionContext2 = interceptionContext1
                .WithDbContext(context2)
                .WithObjectContext(objectContext1)
                .WithObjectContext(objectContext2);

            var combined = DbInterceptionContext.Combine(new[] { interceptionContext1, interceptionContext2 });

            Assert.Equal(2, combined.DbContexts.Count());
            Assert.Equal(2, combined.ObjectContexts.Count());

            Assert.Contains(context1, combined.DbContexts);
            Assert.Contains(context2, combined.DbContexts);
            Assert.Contains(objectContext1, combined.ObjectContexts);
            Assert.Contains(objectContext2, combined.ObjectContexts);
        }
コード例 #5
0
        private InterceptableDbCommand ConfigureCommand(DbCommand command, string commandText)
        {
            command.CommandText = commandText;

            if (_configuration.CommandTimeout.HasValue)
            {
                command.CommandTimeout = _configuration.CommandTimeout.Value;
            }

            var interceptionContext = new DbInterceptionContext();
            if (_contextForInterception != null)
            {
                interceptionContext = interceptionContext.WithDbContext(_contextForInterception);
            }
            return new InterceptableDbCommand(command, interceptionContext);
        }