コード例 #1
0
            public void WhenIdentityIsSetInNancyContext_ReturnsUserFromIdentity()
            {
                var user = new User();
                var identity = new InvoiceGenIdentity(user);
                _nancyContext.CurrentUser = identity;

                var actual = _sut.GetAuthenticatedUser();
                Assert.That(actual, Is.Not.Null);
                Assert.That(actual, Is.EqualTo(user));
            }
コード例 #2
0
 public void UserNameIsLoginValueOfSpecifiedUser()
 {
     var user = new User {
     Login = new Login {
       Value = "MyLogin"
     }
       };
       var actual = new InvoiceGenIdentity(user);
       Assert.That(actual.UserName, Is.EqualTo(user.Login.Value));
 }
コード例 #3
0
        public void UserNameIsLoginValueOfSpecifiedUser()
        {
            var user = new User {
                Login = new Login {
                    Value = "MyLogin"
                }
            };
            var actual = new InvoiceGenIdentity(user);

            Assert.That(actual.UserName, Is.EqualTo(user.Login.Value));
        }
コード例 #4
0
            public void WhenIdentityIsSetInNancyContext_ReturnsUserFromIdentity()
            {
                var user     = new User();
                var identity = new InvoiceGenIdentity(user);

                _nancyContext.CurrentUser = identity;

                var actual = _sut.GetAuthenticatedUser();

                Assert.That(actual, Is.Not.Null);
                Assert.That(actual, Is.EqualTo(user));
            }
コード例 #5
0
            public void SetsUserInNancyContext()
            {
                var user     = new User();
                var identity = new InvoiceGenIdentity(user);

                ConfigureInvoiceGenIdentityFactory_ToReturn(user, identity);

                _sut.SetAuthenticatedUser(user);
                var actual = _nancyContext.CurrentUser;

                Assert.That(actual, Is.Not.Null);
                Assert.That(actual, Is.EqualTo(identity));
            }
コード例 #6
0
        public ApiBootstrapper(Action<ConfigurableBootstrapperConfigurator> configuration)
            : base(configuration)
        {
            InternalConfiguration.Serializers.Clear();
              InternalConfiguration.Serializers.Add(typeof(CustomJsonSerializer));
              BeforeRequest.AddItemToEndOfPipeline(context => {
            if (AuthenticatedUser == null) context.CurrentUser = null;
            else {
              var userIdentity = new InvoiceGenIdentity(AuthenticatedUser);
              context.CurrentUser = userIdentity;
            }
            return null;
              });

              OnError = OnError
            + ErrorPipelines.HandleModelBindingException()
            + ErrorPipelines.HandleRequestValidationException()
            + ErrorPipelines.HandleSecurityException();
        }
        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();
        }
コード例 #8
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();
        }
 void ConfigureInvoiceGenIdentityFactory_ToReturn(User user, InvoiceGenIdentity identity)
 {
     A.CallTo(() => _invoiceGenIdentityFactory.Create(user))
        .Returns(identity);
 }
コード例 #10
0
            public void SetsUserInNancyContext()
            {
                var user = new User();
                var identity = new InvoiceGenIdentity(user);
                ConfigureInvoiceGenIdentityFactory_ToReturn(user, identity);

                _sut.SetAuthenticatedUser(user);
                var actual = _nancyContext.CurrentUser;

                Assert.That(actual, Is.Not.Null);
                Assert.That(actual, Is.EqualTo(identity));
            }
コード例 #11
0
 void ConfigureInvoiceGenIdentityFactory_ToReturn(User user, InvoiceGenIdentity identity)
 {
     A.CallTo(() => _invoiceGenIdentityFactory.Create(user))
     .Returns(identity);
 }