gpt4 book ai didi

c# - 认证测试和 PDF

转载 作者:太空狗 更新时间:2023-10-29 22:16:36 26 4
gpt4 key购买 nike

我可以将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com