Created
October 28, 2011 20:54
NullReferenceRhinoMocks
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 void SetCookie(IHttpContextService context) | |
{ | |
if (context == null) | |
return; | |
if (context.User == null) | |
return; | |
if (context.User.Identity == null) | |
return; | |
if (!context.User.Identity.IsAuthenticated) | |
return; | |
this.UserName = context.User.Identity.Name; | |
// Create a cookie for username and key | |
var cookie = new HttpCookie("Token", this.UserNameOnly + "|" + GetKey(this.Input)); | |
context.CookieCollection.Add(cookie); | |
} |
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
[Test] | |
public void Should_SetACookie() | |
{ | |
var httpContextService = MockRepository.GenerateStub<IHttpContextService>(); | |
var cookieCollection = new HttpCookieCollection(); | |
IPrincipal user = new GenericPrincipal(new GenericIdentity("Test"), | |
new[] {"TestRole"}); | |
httpContextService.Stub(c => c.User).Return(user); | |
httpContextService.Stub(c => c.CookieCollection).Return(cookieCollection); | |
cookieSetter.SetCookie(httpContextService); | |
httpContextService.VerifyAllExpectations(); | |
} |
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
httpContextService.Stub(c => c.User).Return(user).Repeat.Any(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment