Question

Evaluating Document Imaging SDK, I'm trying to create a unit test project in my Visual Studio 2012 to check some code snippets. I have referenced LeadTools dlls from installation directory 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' and pointed my unt test project output directory to the same directory (to have all LeadTools binaries next to my output). But running the unit test I'm getting the following execption:

Test method LeadTools.Evaluation.UnitTests.Snippets.PdfToTiffTest.PdfToTiffTest threw exception: Leadtools.RasterException: Raster PDF Engine is needed to use this feature

I suspect that problem is caused by VSTest process is running outside the 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' and can' find necessary LeadTools binaries.

Question: What is the correct way of refencing LeadTools binaries to the test project?

Unit test code:

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);
                    }
                }
            }
        }
    }
}
Was it helpful?

Solution

In VS 2010 that was possible to specify where to resolve assemplies right in Test Settings. To do that in VS 2012, you could do that in App.config as described in this post Assembly Resolution for Unit Tests by Visual Studio Test Team.

Just add app.config to your test project and put there the appropriate <AssemblyResolution> details.

<?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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top