NUnit and Moles error

195 Views Asked by At

I am trying to run NUnit with Moles and I am getting a weird error and I am not quite sure why.

    [Test]
    [Moled]
    public void SendEmail_Test()
    {
        SIEmailService emailService = new SIEmailService
                                            {
                                                SendMailStringStringString = (email, subject, body) => { }
                                            };

        SIServiceLocator serviceLocator = new SIServiceLocator();
        serviceLocator.GetInstance(() => emailService);

        MLocatorFactory.GetInstance = (() => serviceLocator);


        IEmailservice = new EmailService();
        service.SendEmail("[email protected]", null, null, null, DateTime.Now, null);
    }

Error:

The security issue that is being thrown

Any suggestions on how to fix this partially trusted caller issue???? Many thanks.

1

There are 1 best solutions below

2
On

Add to your tests assembly AllowPartiallyTrustedCallersAttribute. But I am not sure why it requires this. May be you are running your tests from network share?