html agility pack - TypeInitializationException When Using Moles With HtmlAgilityPack -


i attempting use moles test non-static method in separate assembly. when running test without [hosttype("moles")] tag, test runs fine. when replace receive following error:

"the type initializer 'htmlagilitypack.htmlnode' threw exception."

i have attached code samples perform in identical manner.

any great!

class/method being called unit test

using system; using htmlagilitypack; using system.web;  namespace hapandmoles {     public class class1     {         public void foobar()         {             htmldocument foo = new htmldocument();         }     } } 

unit test

using system; using system.text; using microsoft.visualstudio.testtools.unittesting; using hapandmoles; using microsoft.moles.framework; using htmlagilitypack; using system.web;  namespace hapandmoles {     [testclass]     public class unittest1     {         [testmethod]         [hosttype("moles")]         public void testmethod1()         {             class1 bar = new class1();             bar.foobar();         }     } } 

i'm not sure understand example because in fact don't use moles.

if want "mole" our own non-virtual method, in references of test project have right-click on assembly of tested project , choose add moles assembly. create hapandmoles.moles reference.

then add corresponding using , can call class "moled" starting m (class1 => mclass1). show example testing mclass1 behaviour:

using microsoft.visualstudio.testtools.unittesting; using hapandmoles; using hapandmoles.moles;  namespace hapandmoles {     [testclass]     public class unittest1     {         [testmethod]         [hosttype("moles")]         public void testmethod1()         {             bool called = false;             var bar = new mclass1()              {                 foobar = () => called = true             };             ((class1)bar).foobar();             assert.istrue(called);         }     } } 

when want moles of mscorlib, right-click directly on references of test project , can add moles assembly mscorlib. the

using microsoft.moles.framework; 

is needed.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -