So i'm using Moq and starting to write unit tests for my controller actions.
All of my controllers inherit from a base CustomController class that provides a userId property set in the constructor to be the value of Membership.GetUser().ProviderUserKey. This way I can pass the userId to my service layer simply by passing contactId.
This does not seem to work well with this unit test:
var serviceMock = new Mock<IFormService>();
serviceMock.Setup(g => g.GetForm(2)).Returns(new FormViewModel() {ID = 2, Name = "Mock Form"});
var controller = new FormController(serviceMock.Object);
var result = controller.Index(2);
Assert.IsNotNull(result, "View Result is null");
It throws an exception on the base CustomController where it tries to set the userId from Membership.GetUser().ProviderUserKey.
"UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\App_Data' is denied."
Has anyone else come across this issue or have any thoughts on a way around it?