moles - Why doesn't framework detour? -


i unit testing code depends on itextsharp open source pdf library. 1 of classes intextsharp pdfreader 1 of constructors accepts byte array. simplified problem following:

    [testmethod]     [hosttype("moles")]     public void readpdf()     {         mpdfreader.constructorbytearray = (@this, pdfin) =>         {             new mpdfreader(@this)             {                                 };         };          pdfreader reader = new pdfreader(new byte[] { 10, 20, 30 });     } 

however, code still calls real pdfreader , not 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, blows "..system.io.ioexception: pdf header signature not found.. "

not sure i'm doing wrong....

-stan

i assume attempting defuse constructor call accepts byte array. try removing instance parameter in constructor overload:

[testmethod] [hosttype("moles")] public void readpdf() {     mpdfreader.constructorbytearray = (@this, pdfin) =>     {         new mpdfreader()         {         };     };     pdfreader reader = new pdfreader(new byte[] { 10, 20, 30 }); } 

Comments