c# - 认证测试和 PDF

标签 c# testing approval-tests

我可以将 ApprovalTests 与 PDF 一起使用吗?我尝试使用 FileLauncher,但似乎相同的 PDF 在文件(位)级别略有不同。还是我用错了?

[TestMethod]
[UseReporter(typeof(FileLauncherReporter))]
public void TestPdf()
{
    var createSomePdf = PdfCreate();

    ApprovalTests.Approvals.Verify(new FileInfo(createSomePdf.FileName));

}

最佳答案

Pdf 很可能是用时间戳创建的。根据用于创建 pdf 的方法,您可以模拟创建的时间。但我不得不擦洗它。

这是我用来执行此操作的代码。

    public static void VerifyPdf(string coverFile)
    {
        ScrubPdf(coverFile);
        Approvals.Verify(new ExistingFileWriter(coverFile));
    }

    private static void ScrubPdf(string coverFile)
    {
        long location;
        using (var pdf = File.OpenRead(coverFile))
        {
            location = Find("/CreationDate (", pdf);

        }
        using (var pdf = File.OpenWrite(coverFile))
        {
            pdf.Seek(location, SeekOrigin.Begin);

            var original = "/CreationDate (D:20110426104115-07'00')";
            var desired = new System.Text.ASCIIEncoding().GetBytes(original);

            pdf.Write(desired, 0, desired.Length);
            pdf.Flush();
        }
    }

关于c# - 认证测试和 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12812336/

相关文章:

c# - 根据集合中现有对象的属性,使用 LINQ 将对象插入集合中

c# - 处置对象(简化)

Django 测试装置 : How to cope with test data involving time?

c++ - 打印 STL 容器以进行批准测试的公约

specflow - 有人使用过 Specflow 的批准测试吗?

c# - AES 及其密码模式

c# - 在 3 层设置中在哪里可以找到自定义成员资格、角色、配置文件提供程序?

javascript - 在 Jest JS 中返回一个 double

android - 如何测试使用 Retrofit 和 Dagger2 的 REST API

.net - 如何从构建日志中删除批准的调试信息