Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Unit testing a class with a dependency on FilterAccess

$
0
0

Hi

I am trying to write some unit tests for our solution, and honestly I am finding it a bit like pulling teeth.

But I have managed to get as far as making/finding/altering a FakeContentRepository, such that I can CRUD pages and blocks.

however, I have a service that I am trying to write tests for, which gets pages from the repo, and then does the following:

var filterAccess = new FilterAccess(AccessLevel.Publish);
var filteredPages = repoPageList.Where(x=> !filterAccess.ShouldFilter(x)).ToArray();

I cannot see a way to change this up so that it is testable, certainly without changing up the code above. 

Could anyone offer some suggestions please. 

FilterAccess class seems to new up stuff in the ShouldFilter method, so I cant even inject any supporting Interfaces into the serviceLocator.

return new DefaultContentAccessEvaluator((IPublishedStateAssessor) new SimplifiedPublishedStateAssessor(args), (IPrincipalAccessor) new HttpPrincipalAccessor()).HasAccess(content, principal, requestedLevel)

thanks


Viewing all articles
Browse latest Browse all 9076