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"));
            }
        }
        public void Result_can_be_mutated(bool useObsoleteState)
        {
            var interceptionContext = new DbCommandTreeInterceptionContext();

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

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

            Assert.Same(commandTree, interceptionContext.Result);
            Assert.Same(commandTree, interceptionContext.OriginalResult);
            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Equal("Cheddar", interceptionContext.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Equal("AState", interceptionContext.FindUserState("A"));
                Assert.Equal("BState", interceptionContext.FindUserState("B"));
                Assert.Null(interceptionContext.FindUserState("C"));
            }

            var commandTree2 = new Mock <DbCommandTree>().Object;
            interceptionContext.Result = commandTree2;

            Assert.Same(commandTree2, interceptionContext.Result);
            Assert.Same(commandTree, interceptionContext.OriginalResult);
            if (useObsoleteState)
            {
#pragma warning disable 618
                Assert.Equal("Cheddar", interceptionContext.UserState);
#pragma warning restore 618
            }
            else
            {
                Assert.Equal("AState", interceptionContext.FindUserState("A"));
                Assert.Equal("BState", interceptionContext.FindUserState("B"));
                Assert.Null(interceptionContext.FindUserState("C"));
            }
        }