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);
        }
コード例 #2
0
        private DbConnection CreateConnection()
        {
            DbConnection connection = this._providerFactory.CreateConnection();
            DbConnectionPropertyInterceptionContext <string> interceptionContext = new DbConnectionPropertyInterceptionContext <string>().WithValue(this._usersContextInfo.ConnectionString);

            if (this._usersContext != null)
            {
                interceptionContext = interceptionContext.WithDbContext(this._usersContext);
            }
            DbInterception.Dispatch.Connection.SetConnectionString(connection, interceptionContext);
            return(connection);
        }
コード例 #3
0
        private DbConnection CreateConnection()
        {
            var connection = _providerFactory.CreateConnection();

            var interceptionContext = new DbConnectionPropertyInterceptionContext <string>().WithValue(_usersContextInfo.ConnectionString);

            if (_contextForInterception != null)
            {
                interceptionContext = interceptionContext.WithDbContext(_contextForInterception);
            }

            DbInterception.Dispatch.Connection.SetConnectionString(connection, interceptionContext);

            return(connection);
        }
コード例 #4
0
        private DbConnection CreateConnection()
        {
            var connection = _connection == null
                ? _providerFactory.CreateConnection()
                : DbProviderServices.GetProviderServices(_connection).CloneDbConnection(_connection, _providerFactory);

            var interceptionContext = new DbConnectionPropertyInterceptionContext<string>().WithValue(_usersContextInfo.ConnectionString);
            if (_usersContext != null)
            {
                interceptionContext = interceptionContext.WithDbContext(_usersContext);
            }

            DbInterception.Dispatch.Connection.SetConnectionString(connection, interceptionContext);

            return connection;
        }