Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 10, 2023
1 parent 97550f4 commit 250d13e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/mdsource/recording.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ snippet: RecordingTests.Identifier.verified.txt
* [Verify.MicrosoftLogging](https://github.com/VerifyTests/Verify.MicrosoftLogging)
* [Verify.NServiceBus](https://github.com/VerifyTests/Verify.NServiceBus#recording)
* [Verify.Serilog](https://github.com/VerifyTests/Verify.Serilog)
* [Verify.SqlServer](https://github.com/VerifyTests/Verify.SqlServer#recording)
* [Verify.SqlServer](https://github.com/VerifyTests/Verify.SqlServer#recording)
* [Verify.ZeroLog](https://github.com/VerifyTests/Verify.ZeroLog)
12 changes: 10 additions & 2 deletions src/Verify/Recording/Recording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ public static partial class Recording
public static void Add(string name, object item) =>
CurrentState().Add(name, item);

public static bool IsRecording() =>
asyncLocal.Value != null;
public static bool IsRecording()
{
var state = asyncLocal.Value;
if (state == null)
{
return false;
}

return !state.Paused;
}

public static IReadOnlyCollection<ToAppend> Stop()
{
Expand Down
11 changes: 9 additions & 2 deletions src/Verify/Recording/Recording_Named.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ public static partial class Recording
public static void Add(string identifier, string name, object item) =>
CurrentStateNamed(identifier).Add(name, item);

public static bool IsRecording(string identifier) =>
namedState.ContainsKey(identifier);
public static bool IsRecording(string identifier)
{
if (!namedState.TryGetValue(identifier, out var state))
{
return false;
}

return !state.Paused;
}

public static IReadOnlyCollection<ToAppend> Stop(string identifier)
{
Expand Down
9 changes: 5 additions & 4 deletions src/Verify/Recording/State.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
class State
{
List<ToAppend> items = new();
bool paused;

internal IReadOnlyCollection<ToAppend> Items => items;

public bool Paused { get; private set; }

public void Add(string name, object item)
{
Guard.AgainstNullOrEmpty(name);
if (paused)
if (Paused)
{
return;
}
Expand All @@ -21,10 +22,10 @@ public void Add(string name, object item)
}

public void Pause() =>
paused = true;
Paused = true;

public void Resume() =>
paused = false;
Paused = false;

public void Clear()
{
Expand Down

0 comments on commit 250d13e

Please sign in to comment.