2

评估 Document Imaging SDK,我试图在我的 Visual Studio 2012 中创建一个单元测试项目来检查一些代码片段。我已经从安装目录“ C:\LEADTOOLS 18\Bin\Dotnet4\Win32 ”中引用了 LeadTools dll,并将我的 unt 测试项目输出目录指向同一目录(在我的输出旁边有所有 LeadTools 二进制文件)。但是运行单元测试我得到以下执行:

测试方法 LeadTools.Evaluation.UnitTests.Snippets.PdfToTiffTest.PdfToTiffTest 抛出异常:Leadtools.RasterException:需要光栅 PDF 引擎才能使用此功能

我怀疑问题是由 VSTest 进程在 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' 之外运行引起的,并且找不到必要的 LeadTools 二进制文件。

问题:将 LeadTools 二进制文件引用到测试项目的正确方法是什么?

单元测试代码:

using System.IO;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Pdf;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LeadTools.Evaluation.UnitTests.Snippets
{
    [TestClass]
    public class PdfToTiffTest
    {
        [TestMethod]
        public void PdfToTiffTest()
        {
            const string pdfPath = "C:\Samples\source.pdf";
            var tiffPath = Path.ChangeExtension(pdfPath, "tiff");

            // Load the input PDF document
            var document = new PDFDocument(pdfPath);
            using (var codecs = new RasterCodecs())
            {
                // Loop through all the pages in the document
                for (var page = 1; page <= document.Pages.Count; page++)
                {
                    // Render the page into a raster image
                    using (var image = document.GetPageImage(codecs, page))
                    {
                        // Append to (or create if it does not exist) a TIFF file
                        codecs.Save(image, tiffPath, RasterImageFormat.TifJpeg, 24, 1, 1, -1, CodecsSavePageMode.Append);
                    }
                }
            }
        }
    }
}
4

1 回答 1

1

在 VS 2010 中,可以在测试设置中指定在哪里解析组件。要在 VS 2012 中执行此操作,您可以在 App.config 中执行此操作,如Visual Studio 测试团队的单元测试的程序集解决方案中所述。

只需将 app.config 添加到您的测试项目中,并在其中放置适当的 < AssemblyResolution > 详细信息。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="TestExecution" type="Microsoft.VisualStudio.TestTools.Execution.TestExecutionSection, Microsoft.VisualStudio.QualityTools.ExecutionCommon, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </configSections>
  <TestExecution xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
    <AssemblyResolution>
      <RuntimeResolution>
        <Directory path="%ProgramFiles%\SampleApplication\" includeSubDirectories="true"/>
      </RuntimeResolution>
    </AssemblyResolution>
  </TestExecution>
</configuration>
于 2013-06-26T06:39:59.087 回答