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 Result_can_be_mutated(bool useObsoleteState) { var interceptionContext = new DbCommandInterceptionContext <string>(); 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); ((IDbMutableInterceptionContext <string>)interceptionContext).MutableData.SetExecuted("Wensleydale"); Assert.Equal("Wensleydale", interceptionContext.Result); Assert.Equal("Wensleydale", 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); interceptionContext.Result = "Double Gloucester"; if (useObsoleteState) { #pragma warning disable 618 interceptionContext.UserState = "Cheddar"; #pragma warning restore 618 } else { interceptionContext.SetUserState("A", "AState"); interceptionContext.SetUserState("B", "BState"); } Assert.Equal("Double Gloucester", interceptionContext.Result); Assert.Equal("Wensleydale", 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")); } Assert.False(interceptionContext.IsExecutionSuppressed); Assert.False(interceptionContext.IsExecutionSuppressed); interceptionContext.Result = null; if (useObsoleteState) { #pragma warning disable 618 interceptionContext.UserState = null; #pragma warning restore 618 } else { interceptionContext.SetUserState("A", null); interceptionContext.SetUserState("B", null); } Assert.Null(interceptionContext.Result); 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.Equal("Wensleydale", interceptionContext.OriginalResult); Assert.False(interceptionContext.IsExecutionSuppressed); }