I’ve got an ASP.NET application that allows users to log on. Another part of my application uses the UserId (the user must be logged on to access the controller). How do I fake a logon for unit testing?
Here’s how I get the UserId
Private _UserId As Guid
Public ReadOnly Property UserId() As Guid
Get
_UserId = System.Web.Security.Membership.GetUser().ProviderUserKey
Return _UserId
End Get
End Property
Thanks
EDIT
This is an MVC 3 project.
You can write a wrapper class for your membership so you can create a Mock to use in your unit tests. code is in C#, i apologize but you’ll get my point.
If you are not doing complex stuff in your mock though, i would probably use moq so you don’t need a mock class at all in your unit tests.