Last active
August 29, 2015 14:21
-
-
Save jovaneyck/8c81bf83e2e1dacd4548 to your computer and use it in GitHub Desktop.
Working with Thread.CurrentPrinciple in unit tests by providing a very thin abstraction layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IPrincipalInformationProvider | |
{ | |
bool IsLoggedIn { get; } | |
... | |
} | |
public class ThreadBasedPrincipalInformationProvider : IPrincipalInformationProvider | |
{ | |
public bool IsLoggedIn | |
{ | |
get { return Thread.CurrentPrincipal.Identity.IsAuthenticated; } | |
} | |
... | |
} | |
public class NotationController : ApiController | |
{ | |
public NotationController( | |
IPrincipalInformationProvider principalInformationProvider) //Can inject a fake easily | |
{ | |
_principalInformationProvider = principalInformationProvider; | |
} | |
[HttpGet] | |
[Route("Notations", Name = RouteNames.NOTATIONS_SEARCH)] | |
public HttpResponseMessage Get([FromUri] MobileSearchFilterParameter filter) | |
{ | |
... | |
var searchResult = _manager.Search(filter, _principalInformationProvider.IsLoggedIn; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment