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); }
/// <summary> /// Sends <see cref="M:System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor.ConnectionStringSetting(System.Data.Common.DbConnection,System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext{System.String})" /> and /// <see cref="M:System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor.ConnectionStringSet(System.Data.Common.DbConnection,System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext{System.String})" /> to any <see cref="T:System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor" /> /// registered on <see cref="T:System.Data.Entity.Infrastructure.Interception.DbInterception" /> before/after /// setting <see cref="P:System.Data.Common.DbConnection.ConnectionString" />. /// </summary> /// <param name="connection">The connection on which the operation will be executed.</param> /// <param name="interceptionContext">Information about the context of the call being made, including the value to be set.</param> public virtual void SetConnectionString( DbConnection connection, DbConnectionPropertyInterceptionContext <string> interceptionContext) { Check.NotNull <DbConnection>(connection, nameof(connection)); Check.NotNull <DbConnectionPropertyInterceptionContext <string> >(interceptionContext, nameof(interceptionContext)); this.InternalDispatcher.Dispatch <DbConnection, DbConnectionPropertyInterceptionContext <string> >(connection, (Action <DbConnection, DbConnectionPropertyInterceptionContext <string> >)((t, c) => t.ConnectionString = c.Value), new DbConnectionPropertyInterceptionContext <string>((DbInterceptionContext)interceptionContext), (Action <IDbConnectionInterceptor, DbConnection, DbConnectionPropertyInterceptionContext <string> >)((i, t, c) => i.ConnectionStringSetting(t, c)), (Action <IDbConnectionInterceptor, DbConnection, DbConnectionPropertyInterceptionContext <string> >)((i, t, c) => i.ConnectionStringSet(t, c))); }
/// <summary> /// Sends <see cref="IDbConnectionInterceptor.ConnectionStringSetting" /> and /// <see cref="IDbConnectionInterceptor.ConnectionStringSet" /> to any <see cref="IDbConnectionInterceptor" /> /// registered on <see cref="DbInterception" /> before/after /// setting <see cref="DbConnection.ConnectionString" />. /// </summary> /// <param name="connection">The connection on which the operation will be executed.</param> /// <param name="interceptionContext">Information about the context of the call being made, including the value to be set.</param> public virtual void SetConnectionString( DbConnection connection, DbConnectionPropertyInterceptionContext <string> interceptionContext) { Check.NotNull(connection, "connection"); Check.NotNull(interceptionContext, "interceptionContext"); InternalDispatcher.Dispatch <DbConnection, DbConnectionPropertyInterceptionContext <string> >( connection, (t, c) => t.ConnectionString = c.Value, new DbConnectionPropertyInterceptionContext <string>(interceptionContext), (i, t, c) => i.ConnectionStringSetting(t, c), (i, t, c) => i.ConnectionStringSet(t, c)); }
/// <summary> /// Sends <see cref="IDbConnectionInterceptor.ConnectionStringSetting" /> and /// <see cref="IDbConnectionInterceptor.ConnectionStringSet" /> to any <see cref="IDbConnectionInterceptor" /> /// registered on <see cref="DbInterception" /> before/after /// setting <see cref="DbConnection.ConnectionString" />. /// </summary> /// <param name="dbConnection">The connection on which the operation will be executed.</param> /// <param name="interceptionContext">Information about the context of the call being made, including the value to be set.</param> public virtual void SetConnectionString(DbConnection dbConnection, DbConnectionPropertyInterceptionContext <string> interceptionContext) { Check.NotNull(dbConnection, "dbConnection"); Check.NotNull(interceptionContext, "interceptionContext"); var clonedInterceptionContext = new DbConnectionPropertyInterceptionContext <string>(interceptionContext); InternalDispatcher.Dispatch <DbConnectionPropertyInterceptionContext <string> >( () => dbConnection.ConnectionString = clonedInterceptionContext.Value, clonedInterceptionContext, i => i.ConnectionStringSetting(dbConnection, clonedInterceptionContext), i => i.ConnectionStringSet(dbConnection, clonedInterceptionContext)); }
public void Initially_has_no_state() { var interceptionContext = new DbConnectionPropertyInterceptionContext <int>(); Assert.Empty(interceptionContext.DbContexts); Assert.Null(interceptionContext.Exception); Assert.False(interceptionContext.IsAsync); Assert.False(interceptionContext.IsExecutionSuppressed); Assert.Equal(0, interceptionContext.Value); Assert.Empty(interceptionContext.ObjectContexts); Assert.Null(interceptionContext.OriginalException); Assert.Equal((TaskStatus)0, interceptionContext.TaskStatus); 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 = 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")); } }
public void SetConnectionString_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionPropertyInterceptionContext <string>().WithValue("foo"); dispatcher.SetConnectionString(mockConnection.Object, interceptionContext); mockConnection.VerifySet(m => m.ConnectionString = "foo", Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSetting(mockConnection.Object, It.IsAny <DbConnectionPropertyInterceptionContext <string> >()), Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSet(mockConnection.Object, It.IsAny <DbConnectionPropertyInterceptionContext <string> >()), Times.Once()); }
public void Initially_has_no_state(bool useObsoleteState) { var interceptionContext = new DbConnectionPropertyInterceptionContext <int>(); Assert.Empty(interceptionContext.DbContexts); Assert.Null(interceptionContext.Exception); Assert.False(interceptionContext.IsAsync); Assert.False(interceptionContext.IsExecutionSuppressed); Assert.Equal(0, interceptionContext.Value); Assert.Empty(interceptionContext.ObjectContexts); Assert.Null(interceptionContext.OriginalException); Assert.Equal((TaskStatus)0, interceptionContext.TaskStatus); 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")); } }
/// <summary> /// Does not write to log unless overridden. /// </summary> /// <param name="connection">The connection.</param> /// <param name="interceptionContext">Contextual information associated with the call.</param> public virtual void ConnectionStringSet( DbConnection connection, DbConnectionPropertyInterceptionContext <string> interceptionContext) { }
public abstract void ConnectionStringSet( DbConnection connection, DbConnectionPropertyInterceptionContext <string> interceptionContext);