public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state(bool useObsoleteState)
        {
            var objectContext = new ObjectContext();
            var dbContext     = CreateDbContext(objectContext);

            var interceptionContext = new DbCommandTreeInterceptionContext();

            interceptionContext.MutableData.SetExecuted(new Mock <DbCommandTree>().Object);
            if (useObsoleteState)
            {
#pragma warning disable 618
                interceptionContext.UserState = "Cheddar";
#pragma warning restore 618
            }
            else
            {
                interceptionContext.SetUserState("A", "AState");
                interceptionContext.SetUserState("B", "BState");
            }

            interceptionContext = interceptionContext
                                  .WithDbContext(dbContext)
                                  .WithObjectContext(objectContext)
                                  .AsAsync();

            Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts);
            Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts);
            Assert.True(interceptionContext.IsAsync);

            Assert.Null(interceptionContext.Result);
            Assert.Null(interceptionContext.OriginalResult);
            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Null(interceptionContext.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Null(interceptionContext.FindUserState("A"));
                Assert.Null(interceptionContext.FindUserState("B"));
            }
        }
Beispiel #2
0
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext     = CreateDbContext(objectContext);

            var interceptionContext = new DbCommandTreeInterceptionContext();

            interceptionContext.MutableData.SetExecuted(new Mock <DbCommandTree>().Object);

            interceptionContext = interceptionContext
                                  .WithDbContext(dbContext)
                                  .WithObjectContext(objectContext)
                                  .AsAsync();

            Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts);
            Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts);
            Assert.True(interceptionContext.IsAsync);

            Assert.Null(interceptionContext.Result);
            Assert.Null(interceptionContext.OriginalResult);
        }