# Converters Converters are used to split a target into its component parts, then verify each of those parts. When a target is split the result is: * An info file (containing the metadata of the target) serialized as json. File name: `{TestType}.{TestMethod}.info.verified.txt` * Zero or more documents of a specified extension. File name: `{TestType}.{TestMethod}.{Index}.verified.{Extension}` ## Usage scenarios * tiff => png per page * spreadsheet => csv per sheet * pdf => png per page ## Example Both the following examples take an input tiff and convert it to: The info file: ```txt { PixelFormat: Format8bppIndexed, Size: 473, 355 } ``` snippet source | anchor Multiple png files: Converter page one verifiedConverter page one verified ### Typed converter This sample uses a typed approach. So the converter acts on an in memory instance matching based on type. ```cs VerifierSettings.RegisterFileConverter( canConvert: (target, context) => Equals(target.RawFormat, ImageFormat.Tiff), conversion: (image, settings) => { var pages = image.GetFrameCount(FrameDimension.Page); var targets = new List(); for (var index = 0; index < pages; index++) { image.SelectActiveFrame(FrameDimension.Page, index); var page = new MemoryStream(); image.Save(page, ImageFormat.Png); targets.Add(new("png", page)); } return new( info: new { image.PixelFormat, image.Size }, targets); }); ``` snippet source | anchor ```cs using var stream = File.OpenRead("sample.tif"); await Verify(Image.FromStream(stream)); ``` 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, context) => Equals(target.RawFormat, ImageFormat.Tiff), ``` snippet source | anchor ### Stream Conversion This sample uses a extension approach. So the converter acts on a file or stream based on the extension (configured or detected). ```cs VerifierSettings.RegisterStreamConverter( extension: "tif", conversion: (name, stream, settings) => { using var image = Image.FromStream(stream); var pages = image.GetFrameCount(FrameDimension.Page); var targets = new List(); for (var index = 0; index < pages; index++) { image.SelectActiveFrame(FrameDimension.Page, index); var page = new MemoryStream(); image.Save(page, ImageFormat.Png); targets.Add(new("png", page)); } return new( info: new { image.PixelFormat, image.Size }, targets); }); ``` snippet source | anchor ```cs await VerifyFile("sample.tif"); ``` snippet source | anchor ### Cleanup If cleanup needs to occur after verification a callback can be passes to `ConversionResult`: ```cs return new( info: null, "bin", stream: File.OpenRead(withStreamRequiringCleanupPath), cleanup: () => { File.Delete(withStreamRequiringCleanupPath); return Task.CompletedTask; }); ``` snippet source | anchor ## Shipping Converters can be shipped as NuGet packages: * [Verify.Aspose](https://github.com/VerifyTests/VerifyTests.Aspose): Verification of documents (pdf, docx, xlsx, and pptx) via Aspose. * [Verify.EntityFramework](https://github.com/VerifyTests/Verify.EntityFramework): Verification of EntityFramework bits. * [Verify.ImageMagick](https://github.com/VerifyTests/Verify.ImageMagick): Verification and comparison of images via [Magick.NET](https://github.com/dlemstra/Magick.NET). * [Verify.ImageSharp](https://github.com/VerifyTests/Verify.ImageSharp): Verification of images via [ImageSharp](https://github.com/SixLabors/ImageSharp). * [Verify.NServiceBus](https://github.com/NServiceBusExtensions/Verify.NServiceBus): Verify NServiceBus Test Contexts. * [Verify.RavenDb](https://github.com/VerifyTests/Verify.RavenDb): Verification of [RavenDb](https://ravendb.net) bits. * [Verify.SqlServer](https://github.com/VerifyTests/Verify.SqlServer): Verification of SqlServer bits. * [Verify.Syncfusion](https://github.com/VerifyTests/Verify.Syncfusion): Converts documents (pdf, docx, xlsx, and pptx) to png/csv/text for verification. * [Verify.Web](https://github.com/VerifyTests/Verify.Web): Verification of web bits. * [Verify.WinForms](https://github.com/VerifyTests/Verify.WinForms): Verification of WinForms UIs. * [Verify.Xaml](https://github.com/VerifyTests/Verify.Xaml): Verification of Xaml UIs.