title: Unit Testing HtmlHelper that Needs to Access Data Layer
body: <p>I am trying to create a unit test for an HtmlHelper that accesses my data layer to get a string.  I have looked at a lot of posts around this and I am probably missing something.  The problem that I am having is how do I mock the access to my data layer?  I usually do my dependency ijection through the constructor, but I cannot here because the html helper needs to be static.  So I've setup the injection through a property, but how do I access this from my unit test.  Sorry if this is obvious, but its messing me up right now.</p>
  
  <p>Here is what I have -</p>
  
  <pre><code>public static class StringResourceHelper
  {
  
      #region Private Members
  
      private static IStringResourceService _service;
  
      #endregion
  
      #region Public Properties
  
      private static IStringResourceService Service
      {
          get
          {
              if(_service==null)
              {
                  _service = (IStringResourceService)Bootstrapper.Container.Resolve(typeof(IStringResourceService));
              }
  
              return _service;
          }
      }
  
      #endregion
  
      #region Public Methods
  
      public static string StringResource(this HtmlHelper helper, string label)
      {
          int languageCode;
  
          if(helper.ViewData["LanguageCode"] == null || !Int32.TryParse(helper.ViewData["LanguageCode"].ToString(), out languageCode))
          {
              languageCode = Constants.LanguageCodes.English;
          }
  
          return Service.GetString(label, languageCode);
      }
  
      #endregion
  
  }
  </code></pre>
  
  <p>How do I mock the Service.GetString call?</p>