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?

2
  • 3
    Why do you need to inject constants? Commented Mar 28, 2014 at 14:09
  • 1
    Yes, if you need to inject some other value then they're not constants.
    – david.pfx
    Commented Mar 28, 2014 at 14:21

1 Answer 1

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 :) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.