I have been trying to test some code that uses reflection to loads assemblies. The problem I have is I want to inject some exceptions to test when I do not have the rights to load the assembly.
I have not been able to get it to work, is the following syntax possible or will I keep hitting the problem that the Assembly class is part of mscorelib and so not mockable?
[TestMethod, Isolated]
[ExpectedException(typeof(System.Security.SecurityException))]
public void GetExecutingAssemblyMockTest()
{
Isolate.WhenCalled(() => System.Reflection.Assembly.GetExecutingAssembly()).WillThrow(new System.Security.SecurityException());
var ass = System.Reflection.Assembly.GetExecutingAssembly();
Assert.Fail(ass.GetName().ToString());
}