diff --git a/readme.md b/readme.md
index ff1771c..2007a96 100644
--- a/readme.md
+++ b/readme.md
@@ -104,3 +104,39 @@ This output type gives the most information, but if verified files are long, it
+ Sixth line changed
7 Seventh line
```
+
+
+### Test level settings
+
+DiffPlex can be used at the test leved:
+
+
+
+```cs
+[Test]
+public Task TestLevelUsage()
+{
+ var target = "The text";
+ var settings = new VerifySettings();
+ settings.UseDiffPlex();
+ return Verify(target, settings);
+}
+```
+snippet source | anchor
+
+
+Or Fluently
+
+
+
+```cs
+[Test]
+public Task TestLevelUsageFluent()
+{
+ var target = "The text";
+ return Verify(target)
+ .UseDiffPlex();
+}
+```
+snippet source | anchor
+
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 20766fc..e81f8cb 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -2,7 +2,7 @@
CS1591;CS0649
- 2.0.1
+ 2.1.0
1.0.0
DiffPlex, Verify
Extends Verify (https://github.com/VerifyTests/Verify) to allow comparison of text via DiffPlex (https://github.com/mmanela/diffplex).
diff --git a/src/Tests/Tests.AtTestLevel.verified.txt b/src/Tests/Tests.AtTestLevel.verified.txt
new file mode 100644
index 0000000..2f1c6c2
--- /dev/null
+++ b/src/Tests/Tests.AtTestLevel.verified.txt
@@ -0,0 +1,22 @@
+{
+ Type: VerifyException,
+ Message:
+Directory: {ProjectDirectory}
+NotEqual:
+ - Received: Tests.AtTestLevelFake.received.txt
+ Verified: Tests.AtTestLevelFake.verified.txt
+
+FileContent:
+
+NotEqual:
+
+Received: Tests.AtTestLevelFake.received.txt
+Verified: Tests.AtTestLevelFake.verified.txt
+Compare Result:
+ The
+- before
++ after
+ text
+
+
+}
\ No newline at end of file
diff --git a/src/Tests/Tests.AtTestLevelCompact.verified.txt b/src/Tests/Tests.AtTestLevelCompact.verified.txt
new file mode 100644
index 0000000..ed618ba
--- /dev/null
+++ b/src/Tests/Tests.AtTestLevelCompact.verified.txt
@@ -0,0 +1,22 @@
+{
+ Type: VerifyException,
+ Message:
+Directory: {ProjectDirectory}
+NotEqual:
+ - Received: Tests.AtTestLevelCompactFake.received.txt
+ Verified: Tests.AtTestLevelCompactFake.verified.txt
+
+FileContent:
+
+NotEqual:
+
+Received: Tests.AtTestLevelCompactFake.received.txt
+Verified: Tests.AtTestLevelCompactFake.verified.txt
+Compare Result:
+13 The
+ - before
+ + after
+15 text
+
+
+}
\ No newline at end of file
diff --git a/src/Tests/Tests.AtTestLevelCompactFake.verified.txt b/src/Tests/Tests.AtTestLevelCompactFake.verified.txt
new file mode 100644
index 0000000..ad0b56c
--- /dev/null
+++ b/src/Tests/Tests.AtTestLevelCompactFake.verified.txt
@@ -0,0 +1,26 @@
+The
+The
+The
+The
+The
+The
+The
+The
+The
+The
+The
+The
+The
+before
+text
+text
+text
+text
+text
+text
+text
+text
+text
+text
+text
+text
\ No newline at end of file
diff --git a/src/Tests/Tests.AtTestLevelFake.verified.txt b/src/Tests/Tests.AtTestLevelFake.verified.txt
new file mode 100644
index 0000000..4d21019
--- /dev/null
+++ b/src/Tests/Tests.AtTestLevelFake.verified.txt
@@ -0,0 +1,3 @@
+The
+before
+text
\ No newline at end of file
diff --git a/src/Tests/Tests.TestLevelUsage.verified.txt b/src/Tests/Tests.TestLevelUsage.verified.txt
new file mode 100644
index 0000000..0398fb4
--- /dev/null
+++ b/src/Tests/Tests.TestLevelUsage.verified.txt
@@ -0,0 +1 @@
+The text
\ No newline at end of file
diff --git a/src/Tests/Tests.TestLevelUsageFluent.verified.txt b/src/Tests/Tests.TestLevelUsageFluent.verified.txt
new file mode 100644
index 0000000..0398fb4
--- /dev/null
+++ b/src/Tests/Tests.TestLevelUsageFluent.verified.txt
@@ -0,0 +1 @@
+The text
\ No newline at end of file
diff --git a/src/Tests/Tests.cs b/src/Tests/Tests.cs
index 96fac15..7c35c70 100644
--- a/src/Tests/Tests.cs
+++ b/src/Tests/Tests.cs
@@ -1,4 +1,6 @@
-[TestFixture]
+using VerifyTests.DiffPlex;
+
+[TestFixture]
public class Tests
{
static Tests()
@@ -23,7 +25,14 @@ public Task Simple()
""",
settings));
}
+
+ [Test]
+ public Task AtTestLevel()
+ {
+ var settings = new VerifySettings();
+ settings.UseMethodName("AtTestLevelFake");
settings.DisableDiff();
+ settings.UseDiffPlex();
return ThrowsTask(() =>
Verify("""
@@ -34,6 +43,46 @@ public Task Simple()
settings));
}
+ [Test]
+ public Task AtTestLevelCompact()
+ {
+ var settings = new VerifySettings();
+ settings.UseMethodName("AtTestLevelCompactFake");
+ settings.DisableDiff();
+ settings.UseDiffPlex(OutputType.Compact);
+
+ return ThrowsTask(() =>
+ Verify("""
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ The
+ after
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ text
+ """,
+ settings));
+ }
+
[Test]
public Task Sample()
{
@@ -44,4 +93,29 @@ public Task Sample()
""";
return Verify(target);
}
+
+ #region TestLevelUsage
+
+ [Test]
+ public Task TestLevelUsage()
+ {
+ var target = "The text";
+ var settings = new VerifySettings();
+ settings.UseDiffPlex();
+ return Verify(target, settings);
+ }
+
+ #endregion
+
+ #region TestLevelUsageFluent
+
+ [Test]
+ public Task TestLevelUsageFluent()
+ {
+ var target = "The text";
+ return Verify(target)
+ .UseDiffPlex();
+ }
+
+ #endregion
}
\ No newline at end of file
diff --git a/src/Verify.DiffPlex/VerifyDiffPlex.cs b/src/Verify.DiffPlex/VerifyDiffPlex.cs
index 15e06ba..e29935d 100644
--- a/src/Verify.DiffPlex/VerifyDiffPlex.cs
+++ b/src/Verify.DiffPlex/VerifyDiffPlex.cs
@@ -8,25 +8,37 @@ public static class VerifyDiffPlex
{
public static void Initialize() => Initialize(OutputType.Full);
- public static void Initialize(OutputType outputType)
- {
- InnerVerifier.ThrowIfVerifyHasBeenRun();
- Func compareFunc = outputType switch
+ static Func GetCompareFunc(OutputType outputType) =>
+ outputType switch
{
OutputType.Compact => CompactCompare,
- _ => VerboseCompare,
+ _ => VerboseCompare
};
- VerifierSettings.SetDefaultStringComparer((received, verified, _) =>
- {
- var builder = compareFunc(received, verified);
- builder.TrimEnd();
- var message = builder.ToString();
- var compareResult = CompareResult.NotEqual(message);
- return Task.FromResult(compareResult);
- });
+ public static void Initialize(OutputType outputType)
+ {
+ InnerVerifier.ThrowIfVerifyHasBeenRun();
+ VerifierSettings.SetDefaultStringComparer((received, verified, _) => GetResult(outputType, received, verified));
+ }
+
+ static Task GetResult(OutputType outputType, string received, string verified)
+ {
+ var compare = GetCompareFunc(outputType);
+ var builder = compare(received, verified);
+ builder.TrimEnd();
+ var message = builder.ToString();
+ var result = CompareResult.NotEqual(message);
+ return Task.FromResult(result);
}
+ public static void UseDiffPlex(this VerifySettings settings, OutputType outputType = OutputType.Full) =>
+ settings.UseStringComparer(
+ (received, verified, _) => GetResult(outputType, received, verified));
+
+ public static SettingsTask UseDiffPlex(this SettingsTask settings, OutputType outputType = OutputType.Full) =>
+ settings.UseStringComparer(
+ (received, verified, _) => GetResult(outputType, received, verified));
+
static StringBuilder VerboseCompare(string received, string verified)
{
var diff = InlineDiffBuilder.Diff(verified, received);