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)
                                       .AsAsync();

            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);

            Assert.True(combined.IsAsync);
        }
        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);
        }
        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);
        }
        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)
                .AsAsync();

            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);

            Assert.True(combined.IsAsync);
        }