Exemplo n.º 1
0
        public void AssignsCreatedIdentityFromUserInSession()
        {
            var session  = A.Fake <ISession>();
            var user     = new User();
            var identity = new InvoiceGenIdentity(user);

            ConfigureSessionFromContextResolver_ToReturn(session);
            ConfigureUserFromSessionResolver_ToReturn(session, user);
            ConfigureInvoiceGenIdentityFactory_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(() => _invoiceGenIdentityFactory.Create(user))
            .MustHaveHappened();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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 ConfigureInvoiceGenIdentityFactory_ToReturn(User user, InvoiceGenIdentity identity)
 {
     A.CallTo(() => _invoiceGenIdentityFactory.Create(user))
     .Returns(identity);
 }