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)); }
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)); }
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)); }
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(); }
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); }