Skip to content

Commit

Permalink
Move setting flag to Execute method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Jul 26, 2022
1 parent f5c48ba commit fae4e6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/EFCore.Design/Design/OperationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ public abstract class OperationBase : MarshalByRefObject
/// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
protected OperationBase(IOperationResultHandler resultHandler)
{
EF.IsDesignTime = true;
_resultHandler = resultHandler;
}

Expand All @@ -707,6 +706,7 @@ protected OperationBase(IOperationResultHandler resultHandler)
/// <param name="action">The action to execute.</param>
protected virtual void Execute(Action action)
{
EF.IsDesignTime = true;
try
{
action();
Expand All @@ -715,6 +715,10 @@ protected virtual void Execute(Action action)
{
_resultHandler.OnError(ex.GetType().FullName!, ex.Message, ex.ToString());
}
finally
{
EF.IsDesignTime = false;
}
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions test/EFCore.Design.Tests/Design/OperationExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ public void Operations_have_design_time_flag_set()
var handler = new OperationResultHandler();
var result = "Twilight Sparkle";

Assert.False(EF.IsDesignTime);

new MockOperation<string>(handler, () =>
{
Assert.True(EF.IsDesignTime);
return result;
});

Assert.False(EF.IsDesignTime);
Assert.Equal(result, handler.Result);
}

Expand Down

0 comments on commit fae4e6e

Please sign in to comment.