public void AssignsCreatedIdentityFromUserInSession() { var session = A.Fake <ISession>(); var user = new User(); var identity = new VoterIdentity(user); ConfigureSessionFromContextResolver_ToReturn(session); ConfigureUserFromSessionResolver_ToReturn(session, user); ConfigureVoterIdentityFactory_ToReturn(user, identity); _sut.AssignNancyIdentityFromContext(_context); Assert.That(_context.CurrentUser, Is.Not.Null); Assert.That(_context.CurrentUser, Is.EqualTo(identity)); A.CallTo(() => _nancySessionFromNancyContextResolver.ResolveSession(_context)) .MustHaveHappened(); A.CallTo(() => _userFromSessionResolver.ResolveUser(session)) .MustHaveHappened(); A.CallTo(() => _voterIdentityFactory.Create(user)) .MustHaveHappened(); }
public void AssignNancyIdentityFromContext(NancyContext nancyContext) { if (nancyContext == null) { throw new ArgumentNullException("nancyContext"); } var session = _nancySessionFromNancyContextResolver.ResolveSession(nancyContext); var userFromSession = _userFromSessionResolver.ResolveUser(session); nancyContext.CurrentUser = _invoiceGenIdentityFactory.Create(userFromSession); }
public void SetAuthenticatedUser(User user) { var session = _nancySessionFromNancyContextResolver.ResolveSession(_nancyContext); if (session == null) { throw new SecurityException("There is no current session."); } session[Constants.SessionKeyForUser] = user; _nancyContext.CurrentUser = _invoiceGenIdentityFactory.Create(user); if (user == null) { session.Abandon(); } }
void ConfigureSessionFromContextResolver_ToReturn(ISession session) { A.CallTo(() => _nancySessionFromNancyContextResolver.ResolveSession(A <NancyContext> ._)) .Returns(session); }