Esempio n. 1
0
 public void SignOff_ThrowsIfNoOwin(bool useBigFatPhony)
 {
     var authenticationManager = useBigFatPhony ? new BigFatPhonyAuthenticationManager() : null;
     var instance = new OwinAuthenticator(authenticationManager, null, null);
     var exception = Assert.Throws<InvalidOperationException>(() => instance.SignOut().GetAwaiter().GetResult());
     exception.ShouldNotBeNull();
     exception.Message.ShouldContain("no owin");
 }
Esempio n. 2
0
        public void SignOff_ThrowsIfNoOwin(bool useBigFatPhony)
        {
            var authenticationManager = useBigFatPhony ? new BigFatPhonyAuthenticationManager() : null;
            var instance  = new OwinAuthenticator(authenticationManager, null, null);
            var exception = Assert.Throws <InvalidOperationException>(() => instance.SignOut().GetAwaiter().GetResult());

            exception.ShouldNotBeNull();
            exception.Message.ShouldContain("no owin");
        }
Esempio n. 3
0
        public void SignOff_InvokesSignOut_OnIAuthenticationManager()
        {
            var authenticationManager = new Mock<IAuthenticationManager>(MockBehavior.Strict);
            var userStore = new Mock<IUserStore<User, int>>(MockBehavior.Strict);
            var userManager = new UserManager<User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);
            authenticationManager.Setup(x => x.SignOut());

            instance.SignOut().Wait();

            authenticationManager.Verify(x => x.SignOut(), Times.Once);
        }
Esempio n. 4
0
        public void SignOff_InvokesSignOut_OnIAuthenticationManager()
        {
            var authenticationManager = new Mock <IAuthenticationManager>(MockBehavior.Strict);
            var userStore             = new Mock <IUserStore <User, int> >(MockBehavior.Strict);
            var userManager           = new UserManager <User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);

            authenticationManager.Setup(x => x.SignOut());

            instance.SignOut().Wait();

            authenticationManager.Verify(x => x.SignOut(), Times.Once);
        }
Esempio n. 5
0
        public void SignOn_InvokesSignOut_OnIAuthenticationManager()
        {
            var user = new User { Name = Guid.NewGuid().ToString() };
            var authenticationManager = new Mock<IAuthenticationManager>(MockBehavior.Strict);
            var userStore = new Mock<IUserStore<User, int>>(MockBehavior.Strict);
            var userManager = new UserManager<User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);
            authenticationManager.Setup(x => x.SignOut(DefaultAuthenticationTypes.ExternalCookie));
            authenticationManager.Setup(x => x.SignIn(It.IsAny<AuthenticationProperties>(), It.IsAny<ClaimsIdentity>()));

            instance.SignOn(user).Wait();

            authenticationManager.Verify(x => x.SignOut(DefaultAuthenticationTypes.ExternalCookie), Times.Once);
        }
Esempio n. 6
0
        public void SignOn_InvokesSignIn_OnIAuthenticationManager_PassingCookiePersistenceData(bool isPersistent)
        {
            var user = new User { Name = Guid.NewGuid().ToString() };
            var authenticationManager = new Mock<IAuthenticationManager>(MockBehavior.Strict);
            var userStore = new Mock<IUserStore<User, int>>(MockBehavior.Strict);
            var userManager = new UserManager<User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);
            authenticationManager.Setup(x => x.SignOut(It.IsAny<string>()));
            Expression<Func<ClaimsIdentity, bool>> expectedIdentity = x => x.Name.Equals(user.Name);
            Expression<Func<AuthenticationProperties, bool>> expectedProperties = x => x.IsPersistent == isPersistent;
            authenticationManager.Setup(x => x.SignIn(It.Is(expectedProperties), It.Is(expectedIdentity)));

            instance.SignOn(user, isPersistent).Wait();

            authenticationManager.Verify(x => x.SignIn(It.Is(expectedProperties), It.Is(expectedIdentity)), Times.Once);
        }
Esempio n. 7
0
        public void SignOn_InvokesSignOut_OnIAuthenticationManager()
        {
            var user = new User {
                Name = Guid.NewGuid().ToString()
            };
            var authenticationManager = new Mock <IAuthenticationManager>(MockBehavior.Strict);
            var userStore             = new Mock <IUserStore <User, int> >(MockBehavior.Strict);
            var userManager           = new UserManager <User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);

            authenticationManager.Setup(x => x.SignOut(DefaultAuthenticationTypes.ExternalCookie));
            authenticationManager.Setup(x => x.SignIn(It.IsAny <AuthenticationProperties>(), It.IsAny <ClaimsIdentity>()));

            instance.SignOn(user).Wait();

            authenticationManager.Verify(x => x.SignOut(DefaultAuthenticationTypes.ExternalCookie), Times.Once);
        }
Esempio n. 8
0
        public void SignOn_InvokesSignIn_OnIAuthenticationManager_PassingCookiePersistenceData(bool isPersistent)
        {
            var user = new User {
                Name = Guid.NewGuid().ToString()
            };
            var authenticationManager = new Mock <IAuthenticationManager>(MockBehavior.Strict);
            var userStore             = new Mock <IUserStore <User, int> >(MockBehavior.Strict);
            var userManager           = new UserManager <User, int>(userStore.Object);
            var instance = new OwinAuthenticator(authenticationManager.Object, userManager, null);

            authenticationManager.Setup(x => x.SignOut(It.IsAny <string>()));
            Expression <Func <ClaimsIdentity, bool> >           expectedIdentity   = x => x.Name.Equals(user.Name);
            Expression <Func <AuthenticationProperties, bool> > expectedProperties = x => x.IsPersistent == isPersistent;

            authenticationManager.Setup(x => x.SignIn(It.Is(expectedProperties), It.Is(expectedIdentity)));

            instance.SignOn(user, isPersistent).Wait();

            authenticationManager.Verify(x => x.SignIn(It.Is(expectedProperties), It.Is(expectedIdentity)), Times.Once);
        }