Design guidance on Business Layer Paging

517 views Asked by At

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.

1

There are 1 answers

0
Mike Parkhill On BEST ANSWER

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.