# Recording
Recording allows information to be statically captured and then (optionally) verified.
The main value of this feature is to simplify addition of information to a snapshot from extensions to Verify. Before to this feature, for an extension to supply information to a snapshot, that extension had to return the information up the stack, and the calling test had to explicitly add that information to the `Verify()` call. Using this feature an extension can `Recording.Add()` in any context, and the information will be added to the snapshot.
## Usage
```cs
[Fact]
public Task Usage()
{
Recording.Start();
Recording.Add("name", "value");
return Verify("TheValue");
}
```
snippet source | anchor
Results in:
```txt
{
target: TheValue,
name: value
}
```
snippet source | anchor
## TryAdd
If `Recording.Add()` is called before `Recording.Start` an exception will be called.
`Recording.TryAdd()` will add an item only if `Recording.IsRecording` is true.
```cs
[Fact]
public Task TryAdd()
{
//using Recording.Add here would throw since Recording.Start has not been called
Recording.TryAdd("name1", "value1");
Recording.Start();
Recording.TryAdd("name2", "value2");
return Verify("TheValue");
}
```
snippet source | anchor
## Scoped
Recording can be scoped via a `using`:
```cs
[Fact]
public Task RecordingScoped()
{
using (Recording.Start())
{
Recording.Add("name1", "value1");
}
// Recording.Add is ignored here
Recording.Add("name2", "value2");
return Verify();
}
```
snippet source | anchor
Results in:
```txt
{
name1: value1
}
```
snippet source | anchor
## Grouping
Values are grouped by key:
```cs
[Fact]
public Task SameKey()
{
Recording.Start();
Recording.Add("name", "value1");
Recording.Add("name", "value2");
return Verify("TheValue");
}
```
snippet source | anchor
Results in:
```txt
{
target: TheValue,
name: [
value1,
value2
]
}
```
snippet source | anchor
To avoid grouping use [Stop](#stop).
## Identifier
Recording can be grouped by an identifier.
The identifier should be statically unique. For example a fully qualified test name or a GUID.
```cs
[Fact]
public Task Identifier()
{
Recording.Start("identifier");
Recording.Add("identifier", "name", "value");
return Verify(Recording.Stop("identifier"));
}
```
snippet source | anchor
Results in:
```txt
[
{
name: value
}
]
```
snippet source | anchor
## Case is ignored
```cs
[Fact]
public Task Case()
{
Recording.Start();
Recording.Add("name", "value1");
Recording.Add("Name", "value2");
return Verify("TheValue");
}
```
snippet source | anchor
Results in:
```txt
{
target: TheValue,
name: value1,
Name: value2
}
```
snippet source | anchor
## Stop
Recording can be stopped and the resulting data can be manually verified:
```cs
[Fact]
public Task Stop()
{
Recording.Start();
Recording.Add("name1", "value1");
Recording.Add("name2", "value2");
var appends = Recording.Stop();
return Verify(appends.Where(_ => _.Name != "name1"));
}
```
snippet source | anchor
Results in:
```txt
[
{
name2: value2
}
]
```
snippet source | anchor
If Stop is called, the results are not automatically verified:
```cs
[Fact]
public Task StopNotInResult()
{
Recording.Start();
Recording.Add("name1", "value1");
Recording.Add("name2", "value2");
Recording.Stop();
return Verify("other data");
}
```
snippet source | anchor
Results in:
```txt
other data
```
snippet source | anchor
## IsRecording
The status of Recording can be checked.
```cs
[Fact]
public void IsRecording()
{
Assert.False(Recording.IsRecording());
Recording.Start();
Assert.True(Recording.IsRecording());
}
```
snippet source | anchor
This can be helpful if the cost of capturing data, to add to recording, is high.
## Clear
The current recorded items can be cleared:
```cs
[Fact]
public Task Clear()
{
Recording.Start();
Recording.Add("name1", "value1");
Recording.Clear();
Recording.Add("name2", "value2");
return Verify();
}
```
snippet source | anchor
Results in:
```txt
{
name2: value2
}
```
snippet source | anchor
## Pause and Resume
Recording can be paused and resumed:
```cs
[Fact]
public Task PauseResume()
{
Recording.Start();
Recording.Pause();
Recording.Add("name1", "value1");
Recording.Resume();
Recording.Add("name2", "value2");
Recording.Pause();
Recording.Add("name3", "value3");
return Verify();
}
```
snippet source | anchor
Results in:
```txt
{
name2: value2
}
```
snippet source | anchor
## Extensions that leverage Recording
* [Verify.EntityFramework](https://github.com/VerifyTests/Verify.EntityFramework#recording)
* [Verify.Http](https://github.com/VerifyTests/Verify.Http)
* [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.ZeroLog](https://github.com/VerifyTests/Verify.ZeroLog)