17
So I copied the sample code from the Moq home page pretty much verbatim, and am getting a castle proxy exception.
Here's my code (as a console app for an easier sample)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;
namespace MoqTestConsole
{
public interface ILoveThisFramework
{
bool DownloadExists(string s);
}
class Program
{
static void Main(string[] args)
{
Mock<ILoveThisFramework> mock = new Mock<ILoveThisFramework>();
// WOW! No record/replay weirdness?! :)
mock.Setup(framework => framework.DownloadExists("2.0.0.0")).Returns(true);
// Hand mock.Object as a collaborator and exercise it,
// like calling methods on it...
ILoveThisFramework lovable = mock.Object;
bool download = lovable.DownloadExists("2.0.0.0");
// Verify that the given method was indeed called with the expected value
mock.Verify(framework => framework.DownloadExists("2.0.0.0"));
}
}
}
Everything compiles nicely, but when it calls mock.Object The following exception is thrown.
System.TypeInitializationException was unhandled
Message=The type initializer for 'Moq.Mock`1' threw an exception.
Source=Moq
TypeName=Moq.Mock`1
StackTrace:
at Moq.Mock`1.<InitializeInstance>b__0() in d:\Code\moq\src\Source\Mock.Generic.cs:line 138
at Moq.PexProtector.Invoke(Action action) in d:\Code\moq\src\Source\PexProtector.cs:line 56
at Moq.Mock`1.InitializeInstance() in d:\Code\moq\src\Source\Mock.Generic.cs:line 136
at Moq.Mock`1.OnGetObject() in d:\Code\moq\src\Source\Mock.Generic.cs:line 153
at Moq.Mock.GetObject() in d:\Code\moq\src\Source\Mock.cs:line 152
at Moq.Mock.get_Object() in d:\Code\