Zilberman Rafael
Zilberman Rafael

Reputation: 1451

.NET Custom Profile Provider methods

I build method that returns ProfileBase.Create:

public class ProfilesProvider : ProfileBase, IProfilesProvider
{
    public ProfilesProvider GetUserProfile()
    {
        return (HttpContext.Current.Profile) as ProfilesProvider;
    }

    public ProfilesProvider GetUserProfile(string userName)
    {
        if (String.IsNullOrEmpty(userName))
            return (HttpContext.Current.Profile) as ProfilesProvider;

        return Create(userName) as ProfilesProvider;
    }
}

This code working pretty well, but when I'm trying to create Unit testing for this method I got an error:

System.InvalidOperationException: This method cannot be called during the application's pre-start initialization phase.

P.S Here the code of the test:

_mockProfiles.Setup(m => m.GetUserProfile()).Returns(new ProfilesProvider());
        var result = _controller.Settings(model);

        _mockProfiles.Verify(m => m.GetUserProfile(), Times.Once());
        Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

Upvotes: 1

Views: 192

Answers (1)

Zilberman Rafael
Zilberman Rafael

Reputation: 1451

Fixed, I just break the Dependency between ProfileBase and my Class.

Upvotes: 1

Related Questions