public void New_interception_context_has_no_state()
        {
            var interceptionContext = new DbCommandTreeInterceptionContext();

            Assert.Empty(interceptionContext.ObjectContexts);
            Assert.Empty(interceptionContext.DbContexts);
            Assert.Equal(null, interceptionContext.Result);
            Assert.Equal(null, interceptionContext.OriginalResult);
            Assert.Null(interceptionContext.UserState);
        }
        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 New_interception_context_has_no_state(bool useObsoleteState)
        {
            var interceptionContext = new DbCommandTreeInterceptionContext();

            Assert.Empty(interceptionContext.ObjectContexts);
            Assert.Empty(interceptionContext.DbContexts);
            Assert.Equal(null, interceptionContext.Result);
            Assert.Equal(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"));
            }
        }
示例#4
0
        public void Result_can_be_mutated()
        {
            var interceptionContext = new DbCommandTreeInterceptionContext();

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

            var commandTree = new Mock <DbCommandTree>().Object;

            interceptionContext.MutableData.SetExecuted(commandTree);

            Assert.Same(commandTree, interceptionContext.Result);
            Assert.Same(commandTree, interceptionContext.OriginalResult);

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

            interceptionContext.Result = commandTree2;

            Assert.Same(commandTree2, interceptionContext.Result);
            Assert.Same(commandTree, interceptionContext.OriginalResult);
        }
示例#5
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);
        }
 public abstract void TreeCreated(DbCommandTreeInterceptionContext interceptionContext);
        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"));
            }
        }