I am new to JustMock mocking framework and I am trying to mock a private method. I am fully aware that unit testing a private method is a commonly bad practice, but in this case, I have no choice. I have been looking at the official documentation(http://www.telerik.com/help/justmock/advanced-usage-mocking-non-public-members-and-types.html) but nothing seem to work.
here is my example code:
using System;
using Telerik.JustMock;
public class Program
{
public class Foo
{
public void useA()
{
a();
}
private void a()
{
Console.WriteLine("AAAAAAAAAAAAAAA");
}
}
public static void Main()
{
var mockeClass = Mock.Create<Foo>(Behavior.CallOriginal);
Mock.NonPublic.Arrange(mockeClass, "a").DoInstead(() => Console.WriteLine("Mock success!!!"));
mockeClass.useA();
}
}
And here is the error log:
Run-time exception (line 21): The type initializer for 'Telerik.JustMock.Core.Context.MockingContext' threw an exception.
Stack Trace:
[System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
[System.TypeInitializationException: The type initializer for 'Telerik.JustMock.Core.Context.MockingContext' threw an exception.]
at Program.Main(): line 21
I am just confused why it does not work.