public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
            {
                var objectContext = new ObjectContext();
                var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

                var interceptionContext = new DbTransactionInterceptionContext <int>();

                interceptionContext.Exception = new Exception("Cheez Whiz");
                interceptionContext.Result    = 23;
                interceptionContext.UserState = "Norwegian Jarlsberg";

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

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

                Assert.Equal(0, interceptionContext.Result);
                Assert.Equal(0, interceptionContext.OriginalResult);
                Assert.Null(interceptionContext.Exception);
                Assert.Null(interceptionContext.OriginalException);
                Assert.False(interceptionContext.IsExecutionSuppressed);
                Assert.Null(interceptionContext.UserState);
            }
Example #2
0
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new BeginTransactionInterceptionContext();

            var mutableData = ((IDbMutableInterceptionContext <DbTransaction>)interceptionContext).MutableData;
            var transaction = new Mock <DbTransaction>().Object;

            mutableData.SetExecuted(transaction);
            mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));

            interceptionContext = interceptionContext
                                  .WithDbContext(dbContext)
                                  .WithObjectContext(objectContext)
                                  .WithIsolationLevel(IsolationLevel.RepeatableRead)
                                  .AsAsync();

            interceptionContext = new BeginTransactionInterceptionContext(interceptionContext);

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

            Assert.Null(interceptionContext.Result);
            Assert.Null(interceptionContext.OriginalResult);
            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
            public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
            {
                var objectContext  = new ObjectContext();
                var dbContext      = DbContextMockHelper.CreateDbContext(objectContext);
                var mockConnection = new Mock <DbConnection>().Object;

                var interceptionContext = new DbTransactionInterceptionContext();

                var mutableData = ((IDbMutableInterceptionContext)interceptionContext).MutableData;

                mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));
                mutableData.UserState = "Caerphilly";

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

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

                Assert.Null(interceptionContext.Exception);
                Assert.Null(interceptionContext.OriginalException);
                Assert.False(interceptionContext.IsExecutionSuppressed);
                Assert.Null(interceptionContext.UserState);
            }
Example #4
0
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbCommandInterceptionContext <string>();

            var mutableData = ((IDbMutableInterceptionContext <string>)interceptionContext).MutableData;

            mutableData.SetExecuted("Wensleydale");
            mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));

            interceptionContext = interceptionContext
                                  .WithDbContext(dbContext)
                                  .WithObjectContext(objectContext)
                                  .AsAsync()
                                  .WithCommandBehavior(CommandBehavior.SchemaOnly);

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

            Assert.Null(interceptionContext.Result);
            Assert.Null(interceptionContext.OriginalResult);
            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new EnlistTransactionInterceptionContext();

            interceptionContext.SuppressExecution();
            interceptionContext.Exception = new Exception("Cheez Whiz");

            var transaction = new CommittableTransaction();

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

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

            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
Example #6
0
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbConnectionPropertyInterceptionContext <int>();

            interceptionContext.SuppressExecution();
            interceptionContext.Exception = new Exception("Cheez Whiz");
            interceptionContext.UserState = "Tilsit";

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

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

            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
            Assert.Null(interceptionContext.UserState);
        }
Example #7
0
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state(bool useObsoleteState)
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbCommandInterceptionContext <string>();

            var mutableData = ((IDbMutableInterceptionContext <string>)interceptionContext).MutableData;

            mutableData.SetExecuted("Wensleydale");
            mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));

            if (useObsoleteState)
            {
#pragma warning disable 618
                mutableData.UserState = new object();
#pragma warning restore 618
            }
            else
            {
                mutableData.SetUserState("A", "AState");
                mutableData.SetUserState("B", "BState");
            }

            interceptionContext = interceptionContext
                                  .WithDbContext(dbContext)
                                  .WithObjectContext(objectContext)
                                  .AsAsync()
                                  .WithCommandBehavior(CommandBehavior.SchemaOnly);

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

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

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

            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
            public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state(bool useObsoleteState)
            {
                var objectContext  = new ObjectContext();
                var dbContext      = DbContextMockHelper.CreateDbContext(objectContext);
                var mockConnection = new Mock <DbConnection>().Object;

                var interceptionContext = new DbTransactionInterceptionContext();

                var mutableData = ((IDbMutableInterceptionContext)interceptionContext).MutableData;

                mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));
                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)
                                      .WithConnection(mockConnection)
                                      .AsAsync();

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

                Assert.Null(interceptionContext.Exception);
                Assert.Null(interceptionContext.OriginalException);
                Assert.False(interceptionContext.IsExecutionSuppressed);
                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"));
                }
            }
Example #9
0
        public void Cloning_the_base_interception_context_preserves_contextual_information()
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbCommandInterceptionContext()
                                      .WithDbContext(dbContext)
                                      .WithObjectContext(objectContext)
                                      .WithCommandBehavior(CommandBehavior.SchemaOnly)
                                      .AsAsync();

            Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts);
            Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts);
            Assert.True(interceptionContext.IsAsync);
            Assert.Equal(CommandBehavior.SchemaOnly, interceptionContext.CommandBehavior);
        }
        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state(bool useObsoleteState)
        {
            var objectContext = new ObjectContext();
            var dbContext     = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbConnectionPropertyInterceptionContext <int>();

            interceptionContext.SuppressExecution();
            interceptionContext.Exception = new Exception("Cheez Whiz");
            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)
                                  .WithValue(23)
                                  .AsAsync();

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

            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.False(interceptionContext.IsExecutionSuppressed);
            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"));
            }
        }