Question

I am attempting to use Moles to test a non-static method in a separate assembly. When running the test without the [HostType("Moles")] tag, the test runs fine. When I replace it I receive the following error:

"The type initializer for 'HtmlAgilityPack.HtmlNode' threw an exception."

I have attached code samples that perform in an identical manner.

Any help would be great!

Class/method being called by the 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();
        }
    }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top