Search code examples
tiffapproval-tests

Verify a Tif with ApprovalTests


I have been asked to update a system where header information gets injected into a tif via a 3rd party console application. I don't need to worry about that bit.

The part I have been asked to look at it the merge process that generates the header information.

The current file generated by the process is assumed as correct, before I make any changes, so I want to add this as an approved result, from that I can then check that the changes I make will alter the file as expected.

I thought this would be a good opportunity to look at using ApprovalTests

The problem I have is that for what ever reason the links to the videos are considered corruptible (Possibly show me kittens jumping into boxes or something, which will stop me working, which ironically means I slow down my work done because I cannot see any help videos).

What I have been looking at is the Approvals.Verify and Approvals.VerifyFile extensions.

But what appears to be happening is confusing me.

using VerifyFile creates a received file, but the contents of the file are just a line the name of the file I have asked it to verify.

using Verify(new FileInfo("FileNameHere")) does not appear to generate the received file that I need to flag as approved, but the test does return saying that it cannot find the approved tif file.

I am probably using VerifyFile completely wrong and might be looking at using Verify wrong as well.

useful info?

Might be useful to know, that as this is a legacy application, running as a windows service, I have wrapped the service in a harness that allows me to call the routines, so the files are physically being written elsewhere on the machine outside of my control (well there is a config, but the return of the service I call generates a file in a fixed location if it is successful). I have tried copying that into the Unit Test project, but that doesn't appear to help.


Solution

  • Verify(File) and VerifyFile(string) are both meant to verify an existing file. As such they merely setting the received file to the file you pass in. You will still need to move/approval/create the approved file.

    Here is the pseudo code and process.

    [UseReporter(typeof(DiffReporter), typeof(ClipboardReporter)]
    public void TestTiff()
    {
        string tif = YourProcessToCreateTifFile();
        Approvals.VerifyFile(tif);
    }
    

    [Note: if you don't have an image diff installed, like TortoiseDiff, you might want to use the FileLauncherReporter]

    Run this, once you get the result, move the file over by pasting your clipboard into a cmd window. It will move the temporary tif to your test directory with the name ClassName.TestTiff.approved.tif

    After that the test should pass until something changes.

    Happy Testing!