0

I have the following class with the following members:

public class RegistrationPresenter : EPiPresenter<IRegistrationView, LoginPage>, IDisposable
{
    private readonly static string[] DefaultUserRoles = { AppRoles.RegisteredRole, AppRoles.EveryoneRole, AppRoles.ManagerUserRole };

    private readonly INavigator navigator;
    private readonly ISpanishProvincesHelper spanishProvincesHelper;
    private readonly IContentHelper contentHelper;
    private readonly IUserDataHelper userDataHelper;

    public RegistrationPresenter(IRegistrationView view, LoginPage page, INavigator navigator, 
        ISpanishProvincesHelper spanishProvincesHelper, IContentHelper contentHelper, IUserDataHelper userDataHelper)
        : base(view, page)
    {
....
 }

I'm successfully able to Bind all the readonly members with an IoC container (Ninject in my case), except for the static string[], which I don't know how to do it. Which approach should I choose or how could I apply IoC to the DefaultUserRoles values, so I'm able to mock it when Unit testing?

1 Answers1

1

1) are you sure you need to mock your constant?

2) Use Microsoft Fakes, which will happily replace your string with a different one at test-time (an approach that works beautifully when testing more real-world problems, such as mocking the current date/time)

(of course, if you use Fakes, you wouldn't have needed to bother with ninject :) )

gbjbaanb
  • 48,354
  • 6
  • 102
  • 172