I am unit testing code that depends on iTextSharp open source Pdf library. One of the classes inTextSharp is PdfReader with one of the constructors that accepts byte array. I simplified the problem to the following:
[TestMethod]
[HostType("Moles")]
public void ReadPdf()
{
MPdfReader.ConstructorByteArray = (@this, pdfIn) =>
{
new MPdfReader(@this)
{
};
};
PdfReader reader = new PdfReader(new byte[] { 10, 20, 30 });
}
However, this code still calls the real PdfReader and not the mock:
iTextSharp.text.pdf.PdfReader.CheckPdfHeader iTextSharp.text.pdf.PdfReader.ReadPdf() iTextSharp.text.pdf.PdfReader..ctor(Byte[] pdfIn, Byte[] ownerPassword) iTextSharp.text.pdf.PdfReader..ctor(Byte[] pdfIn)
and not surprisedly, it blows up with "..System.IO.IOException: PDF header signature not found.. "
Not sure what I'm doing wrong....
-Stan