Skip to content

Commit

Permalink
make callbacks static
Browse files Browse the repository at this point in the history
fixes #303
  • Loading branch information
SimonCropp committed Feb 14, 2021
1 parent 0525f47 commit f063dec
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/build-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ if (BuildServerDetector.Detected)
});
}
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L100-L114' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfoappveyor' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L99-L113' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfoappveyor' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
6 changes: 3 additions & 3 deletions docs/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The clipboard behavior can be disable using the following:
VerifySettings settings = new();
settings.DisableClipboard();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L40-L45' title='Snippet source file'>snippet source</a> | <a href='#snippet-disableclipboard' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L39-L44' title='Snippet source file'>snippet source</a> | <a href='#snippet-disableclipboard' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -78,7 +78,7 @@ settings.DisableClipboard();
```cs
VerifierSettings.DisableClipboard();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L75-L79' title='Snippet source file'>snippet source</a> | <a href='#snippet-disableclipboardglobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L74-L78' title='Snippet source file'>snippet source</a> | <a href='#snippet-disableclipboardglobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If clipboard is disabled for all tests, it can be re-enabled at the test level:
Expand All @@ -89,7 +89,7 @@ If clipboard is disabled for all tests, it can be re-enabled at the test level:
VerifySettings settings = new();
settings.EnableClipboard();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L65-L70' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclipboard' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L64-L69' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclipboard' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ VerifierSettings.DerivePathInfo(
methodName: method.Name);
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L84-L95' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfo' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L83-L94' title='Snippet source file'>snippet source</a> | <a href='#snippet-derivepathinfo' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Return null to any of the values to use the standard behavior. The returned path can be relative to the directory sourceFile exists in.
Expand Down
10 changes: 5 additions & 5 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ VerifierSettings.AddExtraSettings(_ =>
_.TypeNameHandling = TypeNameHandling.All;
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L139-L147' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsglobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L138-L146' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsglobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -336,7 +336,7 @@ settings.AddExtraSettings(_ =>
_.TypeNameHandling = TypeNameHandling.All;
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L149-L158' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsinstance' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L148-L157' title='Snippet source file'>snippet source</a> | <a href='#snippet-extrasettingsinstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -363,7 +363,7 @@ class CompanyConverter :
}
}
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L174-L192' title='Snippet source file'>snippet source</a> | <a href='#snippet-companyconverter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L173-L191' title='Snippet source file'>snippet source</a> | <a href='#snippet-companyconverter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

<!-- snippet: JsonConverter -->
Expand All @@ -375,7 +375,7 @@ VerifierSettings.AddExtraSettings(
_.Converters.Add(new CompanyConverter());
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L163-L171' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonconverter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L162-L170' title='Snippet source file'>snippet source</a> | <a href='#snippet-jsonconverter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -930,7 +930,7 @@ Extra types can be added to this mapping:
VerifierSettings.TreatAsString<ClassWithToString>(
(target, settings) => target.Property);
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L50-L55' title='Snippet source file'>snippet source</a> | <a href='#snippet-treatasstring' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L49-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-treatasstring' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
11 changes: 5 additions & 6 deletions docs/verify-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This can be done using `AutoVerify()`:
VerifySettings settings = new();
settings.AutoVerify();
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L119-L124' title='Snippet source file'>snippet source</a> | <a href='#snippet-autoverify' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L118-L123' title='Snippet source file'>snippet source</a> | <a href='#snippet-autoverify' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Note that auto accepted changes in `.verified.` files remain visible in source control tooling.
Expand All @@ -39,23 +39,22 @@ Note that auto accepted changes in `.verified.` files remain visible in source c
```cs
public async Task OnHandlersSample()
{
VerifySettings settings = new();
settings.OnFirstVerify(
VerifierSettings.OnFirstVerify(
receivedFile =>
{
Debug.WriteLine(receivedFile);
return Task.CompletedTask;
});
settings.OnVerifyMismatch(
VerifierSettings.OnVerifyMismatch(
(filePair, message) =>
{
Debug.WriteLine(filePair.Received);
Debug.WriteLine(filePair.Verified);
Debug.WriteLine(message);
return Task.CompletedTask;
});
await Verifier.Verify("value", settings);
await Verifier.Verify("value");
}
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L14-L36' title='Snippet source file'>snippet source</a> | <a href='#snippet-onhandlers' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L14-L35' title='Snippet source file'>snippet source</a> | <a href='#snippet-onhandlers' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
7 changes: 3 additions & 4 deletions src/Verify.Tests/Snippets/Snippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ public class Snippets

public async Task OnHandlersSample()
{
VerifySettings settings = new();
settings.OnFirstVerify(
VerifierSettings.OnFirstVerify(
receivedFile =>
{
Debug.WriteLine(receivedFile);
return Task.CompletedTask;
});
settings.OnVerifyMismatch(
VerifierSettings.OnVerifyMismatch(
(filePair, message) =>
{
Debug.WriteLine(filePair.Received);
Debug.WriteLine(filePair.Verified);
Debug.WriteLine(message);
return Task.CompletedTask;
});
await Verifier.Verify("value", settings);
await Verifier.Verify("value");
}

#endregion
Expand Down
8 changes: 4 additions & 4 deletions src/Verify.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ public async Task OnVerifyMismatch()
settings.DisableClipboard();
var onFirstVerifyCalled = false;
var onVerifyMismatchCalled = false;
settings.OnFirstVerify(
VerifierSettings.OnFirstVerify(
_ =>
{
onFirstVerifyCalled = true;
return Task.CompletedTask;
});
settings.OnVerifyMismatch(
VerifierSettings.OnVerifyMismatch(
(filePair, _) =>
{
Assert.NotEmpty(filePair.Received);
Expand All @@ -172,15 +172,15 @@ public async Task OnFirstVerify()
settings.DisableClipboard();
var onFirstVerifyCalled = false;
var onVerifyMismatchCalled = false;
settings.OnFirstVerify(
VerifierSettings.OnFirstVerify(
filePair =>
{
Assert.NotEmpty(filePair.Received);
Assert.NotNull(filePair.Received);
onFirstVerifyCalled = true;
return Task.CompletedTask;
});
settings.OnVerifyMismatch(
VerifierSettings.OnVerifyMismatch(
(_, _) =>
{
onVerifyMismatchCalled = true;
Expand Down
10 changes: 5 additions & 5 deletions src/Verify/Callbacks/VerifySettings.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace VerifyTests
{
public partial class VerifySettings
public static partial class VerifierSettings
{
internal FirstVerify? handleOnFirstVerify;
internal static FirstVerify? handleOnFirstVerify;

public void OnFirstVerify(FirstVerify firstVerify)
public static void OnFirstVerify(FirstVerify firstVerify)
{
Guard.AgainstNull(firstVerify, nameof(firstVerify));
handleOnFirstVerify = firstVerify;
}

internal VerifyMismatch? handleOnVerifyMismatch;
internal static VerifyMismatch? handleOnVerifyMismatch;

public void OnVerifyMismatch(VerifyMismatch verifyMismatch)
public static void OnVerifyMismatch(VerifyMismatch verifyMismatch)
{
Guard.AgainstNull(verifyMismatch, nameof(verifyMismatch));
handleOnVerifyMismatch = verifyMismatch;
Expand Down
12 changes: 0 additions & 12 deletions src/Verify/SettingsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ public SettingsTask ScrubInlineGuids()
return this;
}

public SettingsTask OnFirstVerify(FirstVerify firstVerify)
{
CurrentSettings.OnFirstVerify(firstVerify);
return this;
}

public SettingsTask OnVerifyMismatch(VerifyMismatch verifyMismatch)
{
CurrentSettings.OnVerifyMismatch(verifyMismatch);
return this;
}

public SettingsTask DisableClipboard()
{
CurrentSettings.DisableClipboard();
Expand Down
8 changes: 4 additions & 4 deletions src/Verify/Verifier/VerifyEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ void ProcessEquals()

async Task ProcessNotEquals(StringBuilder builder, FilePair item, string? message)
{
if (settings.handleOnVerifyMismatch != null)
if (VerifierSettings.handleOnVerifyMismatch != null)
{
await settings.handleOnVerifyMismatch(item, message);
await VerifierSettings.handleOnVerifyMismatch(item, message);
}

builder.AppendLine($"Received: {Path.GetFileName(item.Received)}");
Expand Down Expand Up @@ -261,9 +261,9 @@ async Task ProcessMissing(StringBuilder builder)

async Task ProcessMissing(StringBuilder builder, FilePair item)
{
if (settings.handleOnFirstVerify != null)
if (VerifierSettings.handleOnFirstVerify != null)
{
await settings.handleOnFirstVerify(item);
await VerifierSettings.handleOnFirstVerify(item);
}

builder.AppendLine($"{Path.GetFileName(item.Verified)}: Empty or does not exist");
Expand Down
2 changes: 0 additions & 2 deletions src/Verify/VerifySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public VerifySettings(VerifySettings? settings)
directory = settings.directory;
autoVerify = settings.autoVerify;
serialization = settings.serialization;
handleOnFirstVerify = settings.handleOnFirstVerify;
handleOnVerifyMismatch = settings.handleOnVerifyMismatch;
stringComparer = settings.stringComparer;
streamComparer = settings.streamComparer;
parameters = settings.parameters;
Expand Down

0 comments on commit f063dec

Please sign in to comment.