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