Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Verify.Tests/InnerVerifyTests/InnerVerifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ public async Task VerifyExternalFile()

#endregion

// Dispose runs the after callbacks, so this constructor has to run the before half
// too. An unbalanced pair leaves whatever it pushes, sets or counts in the wrong state.
[Fact]
public void RunsBeforeAndAfterCallbacks()
{
var calls = new List<string>();
var settings = new VerifySettings();
settings.OnVerify(
before: () => calls.Add("before"),
after: () => calls.Add("after"));

using (new InnerVerifier(targetDirectory, "callbackBalance", settings))
{
Assert.Equal(["before"], calls);
}

Assert.Equal(["before", "after"], calls);
}

[Fact]
public async Task VerifyExternalFileLocked()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Verify/Verifier/InnerVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public InnerVerifier(string directory, string name, VerifySettings? settings = n
this.settings = settings;
}

// Dispose runs the after callbacks unconditionally, so the before callbacks have
// to run here too. Otherwise an OnVerify(before, after) pair registered by a
// consumer of this API has its after half executed unbalanced, leaving whatever
// the pair pushes, sets or counts in the wrong state.
this.settings.RunBeforeCallbacks();

SetVerifyHasBeenRun(name);

this.directory = directory;
Expand Down
Loading