Pergunta

WCF/C# N-Tier app.

We have implemented Paging in our business Layer using this snippet as a basic guideline.

I'm just wondering- in an effort to make the paging functionality testable, should I make the pager a public property of our Manager classes or inject it in the constructor? We already inject a repository for unit testing but I do not feel it's right to go down the route of injecting too much.

Alternatively, is it better to keep the pager private? The page size will be specified in a config file anyway so I guess I could specify the page size in the test app.config.

Foi útil?

Solução

I would inject your pager as something like:

  public interface IPager {
     int PageSize {get;}
  }

Your concrete class would then be something simple like:

  internal class ConfigPager : IPager {
     public int PageSize {
         get{

             int pageSize = 10;  // default value
             Int32.TryParse(ConfigurationManager.AppSettings["PageSize"], out pageSize);
             return pageSize;
         }
     }
  }

By injecting the IPager you're able to more fully test your manager class to make sure that it actually respects different settings for PageSize since you can easily mock it and test different sizes. This will call out any cases where someone might try to hard-code a page size value in your manager.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top