diff --git a/docs/anonymous-types.md b/docs/anonymous-types.md index 55aa33f0f1..6c5f67dc09 100644 --- a/docs/anonymous-types.md +++ b/docs/anonymous-types.md @@ -13,7 +13,7 @@ When validating multiple instances, an [anonymous type](https://docs.microsoft.c ## xUnit - + ```cs [Fact] public async Task Anon() @@ -37,14 +37,14 @@ public async Task Anon() }); } ``` -snippet source | anchor +snippet source | anchor ## NUnit - + ```cs [Test] public async Task Anon() @@ -68,14 +68,14 @@ public async Task Anon() }); } ``` -snippet source | anchor +snippet source | anchor ## MSTest - + ```cs [TestMethod] public async Task Anon() @@ -99,7 +99,7 @@ public async Task Anon() }); } ``` -snippet source | anchor +snippet source | anchor @@ -108,7 +108,7 @@ public async Task Anon() Results in the following: - + ```txt { person1: { @@ -121,5 +121,5 @@ Results in the following: } } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/build-server.md b/docs/build-server.md index 8d9bc10171..fb0db1242f 100644 --- a/docs/build-server.md +++ b/docs/build-server.md @@ -16,12 +16,12 @@ To change this file edit the source file and then run MarkdownSnippets. Use an [on_failure build step](https://www.appveyor.com/docs/build-configuration/#build-pipeline) to call [Push-AppveyorArtifact](https://www.appveyor.com/docs/build-worker-api/#push-artifact). - + ```yml on_failure: - ps: Get-ChildItem *.received.* -recurse | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name } ``` -snippet source | anchor +snippet source | anchor See also [Pushing artifacts from scripts](https://www.appveyor.com/docs/packaging-artifacts/#pushing-artifacts-from-scripts). @@ -38,7 +38,7 @@ In some scenarios, as part of a build, the test assemblies are copied to a diffe For example a possible implementation for [AppVeyor](https://www.appveyor.com/) could be: - + ```cs if (BuildServerDetector.Detected) { @@ -52,5 +52,5 @@ if (BuildServerDetector.Detected) }); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/clipboard.md b/docs/clipboard.md index 492635f2b3..897b5be991 100644 --- a/docs/clipboard.md +++ b/docs/clipboard.md @@ -62,34 +62,34 @@ The clipboard behavior can be disable using the following: ### Per Test - + ```cs var settings = new VerifySettings(); settings.DisableClipboard(); ``` -snippet source | anchor +snippet source | anchor ### For all tests - + ```cs VerifierSettings.DisableClipboard(); ``` -snippet source | anchor +snippet source | anchor If clipboard is disabled for all tests, it can be re-enabled at the test level: - + ```cs var settings = new VerifySettings(); settings.EnableClipboard(); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/compared-to-assertion.md b/docs/compared-to-assertion.md index 777f0f01fb..1a6577a93a 100644 --- a/docs/compared-to-assertion.md +++ b/docs/compared-to-assertion.md @@ -26,7 +26,7 @@ Given the following method: ### Class being tested - + ```cs public static class ClassBeingTested { @@ -53,7 +53,7 @@ public static class ClassBeingTested } } ``` -snippet source | anchor +snippet source | anchor @@ -65,7 +65,7 @@ Compare a traditional assertion based test to a verification test. #### Traditional assertion test: - + ```cs [Fact] public void TraditionalTest() @@ -83,14 +83,14 @@ public void TraditionalTest() Assert.Equal("USA", person.Address.Country); } ``` -snippet source | anchor +snippet source | anchor #### Verification test - + ```cs [Fact] public Task Simple() @@ -99,5 +99,5 @@ public Task Simple() return Verifier.Verify(person); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/comparer.md b/docs/comparer.md index 8a22b593cb..98dc770b3b 100644 --- a/docs/comparer.md +++ b/docs/comparer.md @@ -17,7 +17,7 @@ Using a custom comparer can be helpful when a result has changed, but not enough For samples purposes an image difference hash algorithm from the [ImageHash project](https://github.com/pgrho/phash) will be used: - + ```cs static Task CompareImages( VerifySettings settings, @@ -44,7 +44,7 @@ static Digest HashImage(Stream stream) return ImagePhash.ComputeDigest(bitmap.ToLuminanceImage()); } ``` -snippet source | anchor +snippet source | anchor The returned `CompareResult.NotEqual` takes an optional message that will be rendered in the resulting text displayed to the user on test failure. @@ -53,35 +53,35 @@ The returned `CompareResult.NotEqual` takes an optional message that will be ren ### Instance comparer - + ```cs var settings = new VerifySettings(); settings.UseComparer(CompareImages); settings.UseExtension("png"); await Verifier.Verify("TheImage.png", settings); ``` -snippet source | anchor +snippet source | anchor ### Static comparer - + ```cs VerifierSettings.RegisterComparer( extension: "png", compare: CompareImages); await Verifier.VerifyFile("TheImage.png"); ``` -snippet source | anchor +snippet source | anchor ## Default Comparison - + ```cs static async Task StreamsAreEqual(Stream stream1, Stream stream2) { @@ -131,7 +131,7 @@ static async Task ReadBufferAsync(Stream stream, byte[] buffer) return bytesRead; } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/converter.md b/docs/converter.md index 5d9931198d..22bc934cd6 100644 --- a/docs/converter.md +++ b/docs/converter.md @@ -29,14 +29,14 @@ Both the following examples take an input tiff and convert it to: The info file: - + ```txt { PixelFormat: 'Format8bppIndexed', Size: '473, 355' } ``` -snippet source | anchor +snippet source | anchor Multiple png files: @@ -49,7 +49,7 @@ Multiple png files: This sample uses a typed approach. So the converter acts on an in memory instance matching based on type. - + ```cs VerifierSettings.RegisterFileConverter( canConvert: (target, settings) => Equals(target.RawFormat, ImageFormat.Tiff), @@ -76,26 +76,26 @@ VerifierSettings.RegisterFileConverter( streams); }); ``` -snippet source | anchor +snippet source | anchor - + ```cs using var stream = File.OpenRead("sample.tif"); await Verifier.Verify(Image.FromStream(stream)); ``` -snippet source | anchor +snippet source | anchor Note that this sample also uses the optional `canConvert` to ensure that only `Image`s that are tiffs are converted. - + ```cs canConvert: (target, settings) => Equals(target.RawFormat, ImageFormat.Tiff), ``` -snippet source | anchor +snippet source | anchor @@ -104,7 +104,7 @@ canConvert: (target, settings) => Equals(target.RawFormat, ImageFormat.Tiff), This sample uses a extension approach. So the converter acts on a file or stream based on the extension (configured or detected). - + ```cs VerifierSettings.RegisterFileConverter( fromExtension: "tif", @@ -132,15 +132,15 @@ VerifierSettings.RegisterFileConverter( streams); }); ``` -snippet source | anchor +snippet source | anchor - + ```cs await Verifier.VerifyFile("sample.tif"); ``` -snippet source | anchor +snippet source | anchor @@ -149,7 +149,7 @@ await Verifier.VerifyFile("sample.tif"); If cleanup needs to occur after verification a callback can be passes to `ConversionResult`: - + ```cs return new ConversionResult( info: info, @@ -161,7 +161,7 @@ return new ConversionResult( return Task.CompletedTask; }); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/named-tuples.md b/docs/named-tuples.md index 2eabd65ed9..da2a1e3bca 100644 --- a/docs/named-tuples.md +++ b/docs/named-tuples.md @@ -14,30 +14,30 @@ Due to the use of [ITuple](https://docs.microsoft.com/en-us/dotnet/api/system.ru Given a method that returns a named tuple: - + ```cs static (bool Member1, string Member2, string Member3) MethodWithNamedTuple() { return (true, "A", "B"); } ``` -snippet source | anchor +snippet source | anchor Can be verified: - + ```cs await Verifier.Verify(() => MethodWithNamedTuple()); ``` -snippet source | anchor +snippet source | anchor Resulting in: - + ```txt { Member1: true, @@ -45,5 +45,5 @@ Resulting in: Member3: 'B' } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/naming.md b/docs/naming.md index a2bd410d9f..52d16b7c68 100644 --- a/docs/naming.md +++ b/docs/naming.md @@ -28,7 +28,7 @@ UniqueFor allows for one or more delimiters to be added to the file name. ### XUnit - + ```cs using static VerifyXunit.Verifier; @@ -60,14 +60,14 @@ public class UniqueForSample } } ``` -snippet source | anchor +snippet source | anchor ### NUnit - + ```cs using static VerifyNUnit.Verifier; @@ -99,14 +99,14 @@ public class UniqueForSample } } ``` -snippet source | anchor +snippet source | anchor ### MSTest - + ```cs [TestClass] public class UniqueForSample : @@ -137,7 +137,7 @@ public class UniqueForSample : } } ``` -snippet source | anchor +snippet source | anchor @@ -171,7 +171,7 @@ It can be overridden at two levels: Usage: - + ```cs [UsesVerify] public class ExtensionSample @@ -211,13 +211,13 @@ public class ExtensionSample } } ``` -snippet source | anchor +snippet source | anchor Result in two files: - + ```json { "fruit": "Apple", @@ -225,11 +225,11 @@ Result in two files: "color": "Red" } ``` -snippet source | anchor +snippet source | anchor - + ```xml Joe @@ -237,7 +237,7 @@ Result in two files: Reminder ``` -snippet source | anchor +snippet source | anchor @@ -246,10 +246,10 @@ Result in two files: To access the current Namer `Runtime` or `RuntimeAndVersion` strings use: - + ```cs Debug.WriteLine(Namer.Runtime); Debug.WriteLine(Namer.RuntimeAndVersion); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/parameterised.md b/docs/parameterised.md index 3e5032f070..acf19fa565 100644 --- a/docs/parameterised.md +++ b/docs/parameterised.md @@ -26,7 +26,7 @@ A test with two parameters `param1` + `param2`, and called twice with the values ### InlineData - + ```cs [Theory] [InlineData("Value1")] @@ -38,14 +38,14 @@ public Task InlineDataUsage(string arg) return Verifier.Verify(arg, settings); } ``` -snippet source | anchor +snippet source | anchor ### MemberData - + ```cs [Theory] [MemberData(nameof(GetData))] @@ -62,7 +62,7 @@ public static IEnumerable GetData() yield return new object[] {"Value2"}; } ``` -snippet source | anchor +snippet source | anchor @@ -71,7 +71,7 @@ public static IEnumerable GetData() xUnit only exposes parameter information when the types certain types. For unknown types the parameter information cannot be retrieved from the xUnit context, and instead the parameters need to be explicitly passed in. This is done by calling `UseParameters()` on the base class. - + ```cs [UsesVerify] public class ComplexParametersSample @@ -109,7 +109,7 @@ public class ComplexParametersSample } } ``` -snippet source | anchor +snippet source | anchor `VerifierSettings.NameForParameter` is required since the parameter type has no `ToString()` override that can be used for deriving the name of the `.verified.` file. @@ -121,7 +121,7 @@ public class ComplexParametersSample ### TestCase - + ```cs [TestCase("Value1")] [TestCase("Value2")] @@ -130,7 +130,7 @@ public Task TestCaseUsage(string arg) return Verifier.Verify(arg); } ``` -snippet source | anchor +snippet source | anchor @@ -142,7 +142,7 @@ MSTest does not expose the parameter values via its extensibility context. So pa ### DataRow - + ```cs [DataTestMethod] [DataRow("Value1")] @@ -154,5 +154,5 @@ public Task DataRowUsage(string arg) return Verify(arg, settings); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/scrubbers.md b/docs/scrubbers.md index 28c717879a..ce2cec5913 100644 --- a/docs/scrubbers.md +++ b/docs/scrubbers.md @@ -26,11 +26,11 @@ Allows lines to be selectively removed using a `Func`. For example remove lines containing `text`: - + ```cs verifySettings.ScrubLines(line => line.Contains("text")); ``` -snippet source | anchor +snippet source | anchor @@ -41,11 +41,11 @@ Remove all lines containing any of the defined strings. For example remove lines containing `text1` or `text2` - + ```cs verifySettings.ScrubLinesContaining("text1", "text2"); ``` -snippet source | anchor +snippet source | anchor Case insensitive by default (StringComparison.OrdinalIgnoreCase). @@ -53,11 +53,11 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase). `StringComparison` can be overridden: - + ```cs verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2"); ``` -snippet source | anchor +snippet source | anchor @@ -68,11 +68,11 @@ Allows lines to be selectively replaced using a `Func`. For example converts lines to upper case: - + ```cs verifySettings.ScrubLinesWithReplace(line => line.ToUpper()); ``` -snippet source | anchor +snippet source | anchor @@ -81,11 +81,11 @@ verifySettings.ScrubLinesWithReplace(line => line.ToUpper()); Replaces `Environment.MachineName` with `TheMachineName`. - + ```cs verifySettings.ScrubMachineName(); ``` -snippet source | anchor +snippet source | anchor @@ -100,7 +100,7 @@ Adds a scrubber with full control over the text via a `Func` ### xUnit - + ```cs using static VerifyXunit.Verifier; @@ -152,14 +152,14 @@ LineJ } } ``` -snippet source | anchor +snippet source | anchor ### NUnit - + ```cs using static VerifyNUnit.Verifier; @@ -212,14 +212,14 @@ LineJ } } ``` -snippet source | anchor +snippet source | anchor ### MSTest - + ```cs [TestClass] public class ScrubbersSample : @@ -270,14 +270,14 @@ LineJ } } ``` -snippet source | anchor +snippet source | anchor ### Results - + ```txt LineA @@ -285,17 +285,17 @@ LineC NoMoreLineE LineI ``` -snippet source | anchor +snippet source | anchor - + ```txt { RowVersion: 'TheRowVersion' } ``` -snippet source | anchor +snippet source | anchor @@ -313,7 +313,7 @@ Global scrubbers should be defined only once at appdomain startup. In this examp ### xUnit - + ```cs using static VerifyXunit.Verifier; @@ -343,14 +343,14 @@ public class ScrubberLevelsSample } } ``` -snippet source | anchor +snippet source | anchor ### NUnit - + ```cs using static VerifyNUnit.Verifier; @@ -380,14 +380,14 @@ public class ScrubberLevelsSample } } ``` -snippet source | anchor +snippet source | anchor ### MSTest - + ```cs [TestClass] public class ScrubberLevelsSample : @@ -416,16 +416,16 @@ public class ScrubberLevelsSample : } } ``` -snippet source | anchor +snippet source | anchor ### Result - + ```txt A B C ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/serializer-settings.md b/docs/serializer-settings.md index 1db43d74a6..e22b26def0 100644 --- a/docs/serializer-settings.md +++ b/docs/serializer-settings.md @@ -51,7 +51,7 @@ Note that the output is technically not valid json. [Single quotes are used](doc The default serialization settings are: - + ```cs var settings = new JsonSerializerSettings { @@ -60,7 +60,7 @@ var settings = new JsonSerializerSettings DefaultValueHandling = DefaultValueHandling.Ignore }; ``` -snippet source | anchor +snippet source | anchor @@ -83,11 +83,11 @@ By default empty collections are ignored during verification. To disable this behavior globally use: - + ```cs VerifierSettings.ModifySerialization(_ => _.DontIgnoreEmptyCollections()); ``` -snippet source | anchor +snippet source | anchor @@ -96,7 +96,7 @@ VerifierSettings.ModifySerialization(_ => _.DontIgnoreEmptyCollections()); By default guids are sanitized during verification. This is done by finding each guid and taking a counter based that that specific guid. That counter is then used replace the guid values. This allows for repeatable tests when guid values are changing. - + ```cs var guid = Guid.NewGuid(); var target = new GuidTarget @@ -109,13 +109,13 @@ var target = new GuidTarget await Verifier.Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: - + ```txt { Guid: Guid_1, @@ -124,27 +124,27 @@ Results in the following: OtherGuid: Guid_2 } ``` -snippet source | anchor +snippet source | anchor To disable this behavior globally use: - + ```cs VerifierSettings.ModifySerialization(_ => _.DontScrubGuids()); ``` -snippet source | anchor +snippet source | anchor Strings containing inline Guids can also be scrubbed. To enable this behavior, use: - + ```cs VerifierSettings.ModifySerialization(_ => _.ScrubInlineGuids()); ``` -snippet source | anchor +snippet source | anchor @@ -153,7 +153,7 @@ VerifierSettings.ModifySerialization(_ => _.ScrubInlineGuids()); By default dates (`DateTime` and `DateTimeOffset`) are sanitized during verification. This is done by finding each date and taking a counter based that that specific date. That counter is then used replace the date values. This allows for repeatable tests when date values are changing. - + ```cs var dateTime = DateTime.Now; var dateTimeOffset = DateTimeOffset.Now; @@ -169,13 +169,13 @@ var target = new DateTimeTarget await Verifier.Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: - + ```txt { DateTime: DateTime_1, @@ -186,17 +186,17 @@ Results in the following: DateTimeOffsetString: DateTimeOffset_2 } ``` -snippet source | anchor +snippet source | anchor To disable this behavior globally use: - + ```cs VerifierSettings.ModifySerialization(_ => _.DontScrubDateTimes()); ``` -snippet source | anchor +snippet source | anchor @@ -207,11 +207,11 @@ By default values of `bool` and `bool?` are ignored during verification. So prop To disable this behavior globally use: - + ```cs VerifierSettings.ModifySerialization(_ => _.DontIgnoreFalse()); ``` -snippet source | anchor +snippet source | anchor @@ -220,7 +220,7 @@ VerifierSettings.ModifySerialization(_ => _.DontIgnoreFalse()); `DateTime`, `DateTimeOffset`, `Guid`, `bool`, and empty collection behavior can also be controlled at the verification level: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => @@ -232,8 +232,8 @@ settings.ModifySerialization(_ => }); await Verify(target, settings); ``` -snippet source | anchor - +snippet source | anchor + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => @@ -245,7 +245,7 @@ settings.ModifySerialization(_ => }); await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor @@ -257,7 +257,7 @@ Extra Json.NET settings can be made: ### Globally - + ```cs VerifierSettings.AddExtraSettings(_ => { @@ -265,14 +265,14 @@ VerifierSettings.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All; }); ``` -snippet source | anchor +snippet source | anchor ### Instance - + ```cs var settings = new VerifySettings(); settings.AddExtraSettings(_ => @@ -281,7 +281,7 @@ settings.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All; }); ``` -snippet source | anchor +snippet source | anchor @@ -290,7 +290,7 @@ settings.AddExtraSettings(_ => One common use case is to register a custom [JsonConverter](https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm). As only writing is required, to help with this there is `WriteOnlyJsonConverter`, and `WriteOnlyJsonConverter`. - + ```cs class CompanyConverter : WriteOnlyJsonConverter @@ -304,22 +304,22 @@ class CompanyConverter : } } ``` -snippet source | anchor +snippet source | anchor - + ```cs VerifierSettings.AddExtraSettings(_ => { _.Converters.Add(new CompanyConverter()); }); ``` -snippet source | anchor +snippet source | anchor ## Scoped settings - + ```cs var person = new Person { @@ -333,13 +333,13 @@ settings.ModifySerialization( settings.AddExtraSettings( _ => { _.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; }); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { GivenNames: 'John', @@ -347,7 +347,7 @@ Result: Dob: '\/Date(970358400000+0000)\/' } ``` -snippet source | anchor +snippet source | anchor @@ -356,7 +356,7 @@ Result: To ignore all members that match a certain type: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => _.IgnoreMembersWithType()); @@ -374,13 +374,13 @@ var target = new IgnoreTypeTarget }; await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { ToInclude: { @@ -388,7 +388,7 @@ Result: } } ``` -snippet source | anchor +snippet source | anchor @@ -397,7 +397,7 @@ Result: To ignore instances of a type based on delegate: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization( @@ -416,13 +416,13 @@ var target = new IgnoreInstanceTarget }; await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { ToInclude: { @@ -430,7 +430,7 @@ Result: } } ``` -snippet source | anchor +snippet source | anchor @@ -439,7 +439,7 @@ Result: Members with an [ObsoleteAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.obsoleteattribute) are ignored: - + ```cs class WithObsolete { @@ -458,19 +458,19 @@ public Task WithObsoleteProp() return Verifier.Verify(target); } ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { OtherProperty: 'value2' } ``` -snippet source | anchor +snippet source | anchor @@ -479,7 +479,7 @@ Result: Obsolete members can be included using `IncludeObsoletes`: - + ```cs [Fact] public Task WithObsoletePropIncluded() @@ -494,20 +494,20 @@ public Task WithObsoletePropIncluded() return Verifier.Verify(target, settings); } ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { ObsoleteProperty: 'value1', OtherProperty: 'value2' } ``` -snippet source | anchor +snippet source | anchor @@ -516,7 +516,7 @@ Result: To ignore members of a certain type using an expression: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => @@ -535,19 +535,19 @@ var target = new IgnoreExplicitTarget }; await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { Include: 'Value' } ``` -snippet source | anchor +snippet source | anchor @@ -556,7 +556,7 @@ Result: To ignore members of a certain type using type and name: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => @@ -578,19 +578,19 @@ var target = new IgnoreExplicitTarget }; await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt { Include: 'Value' } ``` -snippet source | anchor +snippet source | anchor @@ -605,7 +605,7 @@ Note that this is global for all members on all types. Ignore by exception type: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization(_ => _.IgnoreMembersThatThrow()); @@ -613,23 +613,23 @@ settings.ModifySerialization(_ => _.IgnoreMembersThatThrow()); var target = new WithCustomException(); await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt {} ``` -snippet source | anchor +snippet source | anchor Ignore by exception type and expression: - + ```cs var settings = new VerifySettings(); settings.ModifySerialization( @@ -638,17 +638,17 @@ settings.ModifySerialization( var target = new WithExceptionIgnoreMessage(); await Verifier.Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Result: - + ```txt {} ``` -snippet source | anchor +snippet source | anchor @@ -657,44 +657,44 @@ Result: By default newlines in json are escaped with `\n`: - + ```cs return Verifier.Verify(new {Property = "a\r\nb\\nc"}); ``` -snippet source | anchor +snippet source | anchor - + ```txt { Property: 'a\nb\nc' } ``` -snippet source | anchor +snippet source | anchor This can be disabled: - + ```cs var settings = new VerifySettings(); settings.DisableNewLineEscaping(); await Verifier.Verify(new {Property = "a\r\nb\\nc"}, settings); ``` -snippet source | anchor +snippet source | anchor - + ```txt { Property: 'a b\nc' } ``` -snippet source | anchor +snippet source | anchor @@ -705,7 +705,7 @@ Certain types, when passed directly in to Verify, are written directly without g The default mapping is: - + ```cs {typeof(string), (target, settings) => (string) target}, {typeof(bool), (target, settings) => ((bool) target).ToString()}, @@ -754,7 +754,7 @@ The default mapping is: } } ``` -snippet source | anchor +snippet source | anchor This bypasses the Guid and DateTime scrubbing mentioned above. @@ -762,10 +762,10 @@ This bypasses the Guid and DateTime scrubbing mentioned above. Extra types can be added to this mapping: - + ```cs VerifierSettings.TreatAsString( (target, settings) => target.Property); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/verify-options.md b/docs/verify-options.md index 652df73f24..2644fd4023 100644 --- a/docs/verify-options.md +++ b/docs/verify-options.md @@ -17,12 +17,12 @@ In some scenarios it makes sense to auto-accept any changes as part of a given t This can be done using `AutoVerify()`: - + ```cs var settings = new VerifySettings(); settings.AutoVerify(); ``` -snippet source | anchor +snippet source | anchor Note that auto accepted changes in `.verified.` files remain visible in source control tooling. @@ -35,7 +35,7 @@ Note that auto accepted changes in `.verified.` files remain visible in source c `OnVerifyMismatch` is called when a received file does not match the existing verified file. - + ```cs public async Task OnHandlersSample() { @@ -57,5 +57,5 @@ public async Task OnHandlersSample() await Verifier.Verify("value", settings); } ``` -snippet source | anchor +snippet source | anchor diff --git a/readme.md b/readme.md index 3774123eb7..ed4e3b3b93 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ Part of the .NET Foundation Given a class to be tested: - + ```cs public static class ClassBeingTested { @@ -81,7 +81,7 @@ public static class ClassBeingTested } } ``` -snippet source | anchor +snippet source | anchor @@ -90,7 +90,7 @@ public static class ClassBeingTested Support for [xUnit](https://xunit.net/) - + ```cs using static VerifyXunit.Verifier; @@ -105,7 +105,7 @@ public class Sample } } ``` -snippet source | anchor +snippet source | anchor * [Verify Xunit Intro](https://www.youtube.com/watch?v=uGVogEltSkY) @@ -116,7 +116,7 @@ public class Sample Support for [NUnit](https://nunit.org/) - + ```cs using static VerifyNUnit.Verifier; @@ -131,7 +131,7 @@ public class Sample } } ``` -snippet source | anchor +snippet source | anchor @@ -140,7 +140,7 @@ public class Sample Support for [MSTest](https://github.com/Microsoft/testfx-docs) - + ```cs [TestClass] public class Sample : @@ -154,7 +154,7 @@ public class Sample : } } ``` -snippet source | anchor +snippet source | anchor @@ -192,7 +192,7 @@ To verify the result: This will result in the `Sample.Test.verified.txt` being created: - + ```txt { GivenNames: 'John', @@ -209,7 +209,7 @@ This will result in the `Sample.Test.verified.txt` being created: Id: Guid_1 } ``` -snippet source | anchor +snippet source | anchor @@ -218,7 +218,7 @@ This will result in the `Sample.Test.verified.txt` being created: If the implementation of `ClassBeingTested` changes: - + ```cs public static class ClassBeingTested { @@ -247,7 +247,7 @@ public static class ClassBeingTested } } ``` -snippet source | anchor +snippet source | anchor And the test is re run it will fail with diff --git a/src/Verify.Tests/Verify.Tests.csproj b/src/Verify.Tests/Verify.Tests.csproj index b1c44edf51..66a017196e 100644 --- a/src/Verify.Tests/Verify.Tests.csproj +++ b/src/Verify.Tests/Verify.Tests.csproj @@ -17,7 +17,7 @@ - +