public async Task GetLoginsForUser()
        {
            // Create a session and user store for this test.
            var session   = SessionFactory.OpenSession();
            var userStore = new TestUserStore(session);
            // Create and save a user with a login.
            var user = new TestUser {
                UserName = "******"
            };
            int numberOfLogins = 5;

            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);

                for (int i = 0; i < numberOfLogins; i++)
                {
                    var login = new UserLoginInfo("TestProviderList" + i, "ProviderKeyRemove" + i, "TestProviderList" + i);
                    await userStore.AddLoginAsync(user, login);
                }
                transaction.Commit();
            }
            // Check the user has an id and all the logins have been saved.
            Assert.IsNotNull(user.Id);
            Assert.AreEqual(user.Logins.Count, numberOfLogins);
            var userId = user.Id;

            // Create a new session and user store for this test, so that we actually hit the database and not the cache.
            userStore.Dispose();
            session.Dispose();
            session   = SessionFactory.OpenSession();
            userStore = new TestUserStore(session);
            // Load the user.
            TestUser loadUser;
            IList <UserLoginInfo> logins;

            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByIdAsync(userId);

                logins = await userStore.GetLoginsAsync(user);

                transaction.Commit();
            }
            // Check we have the same user and that they have all of the logins.
            Assert.AreEqual(loadUser.Id, user.Id);
            Assert.AreEqual(loadUser.Logins.Count, numberOfLogins);
            Assert.AreEqual(logins.Count, numberOfLogins);
        }
        public async Task RemoveLoginForUser()
        {
            // Create a session and user store for this test.
            var session   = SessionFactory.OpenSession();
            var userStore = new TestUserStore(session);
            // Create and save a user with a login.
            var user = new TestUser {
                UserName = "******"
            };
            var login = new UserLoginInfo("TestProviderRemove", "ProviderKeyRemove", "TestProviderRemove");

            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);

                await userStore.AddLoginAsync(user, login);

                transaction.Commit();
            }
            // Check the user has an id and the login.
            Assert.IsNotNull(user.Id);
            Assert.AreEqual(user.Logins.Count, 1);
            var userId = user.Id;

            // Create a new session and user store for this test, so that we actually hit the database and not the cache.
            userStore.Dispose();
            session.Dispose();
            session   = SessionFactory.OpenSession();
            userStore = new TestUserStore(session);
            // Load the user and remove the login.
            TestUser loadUser;

            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByIdAsync(userId);

                await userStore.RemoveLoginAsync(loadUser, login.LoginProvider, login.ProviderKey);

                transaction.Commit();
            }
            // Check we have the same user and that the login has been removed.
            Assert.AreEqual(loadUser.Id, user.Id);
            Assert.AreEqual(loadUser.Logins.Count, 0);
        }
        public async Task AddLoginForUser()
        {
            // Create a session and user store for this test.
            var session   = SessionFactory.OpenSession();
            var userStore = new TestUserStore(session);
            // Create and save a user with a login.
            var user = new TestUser {
                UserName = "******"
            };
            var login = new UserLoginInfo("TestProviderAdd", "ProviderKeyAdd", "TestProviderAdd");

            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);

                await userStore.AddLoginAsync(user, login);

                transaction.Commit();
            }
            // Check the user has an id and the login.
            Assert.IsNotNull(user.Id);
            Assert.AreEqual(user.Logins.Count, 1);
        }
Пример #4
0
        public async Task GetUserByLogin()
        {
            // Create a session and user store for this test.
            var session = SessionFactory.OpenSession();
            var userStore = new TestUserStore<TestUser>(session);
            // Create and save a user with a login.
            var user = new TestUser { UserName = "******" };
            var login = new UserLoginInfo("TestProviderGetUser", "ProviderKeyGetUser");
            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);
                await userStore.AddLoginAsync(user, login);
                transaction.Commit();
            }
            // Check the user has an id and the login.
            Assert.IsNotNull(user.Id);
            Assert.AreEqual(user.Logins.Count, 1);

            // Create a new session and user store for this test, so that we actually hit the database and not the cache.
            userStore.Dispose();
            session.Dispose();
            session = SessionFactory.OpenSession();
            userStore = new TestUserStore<TestUser>(session);
            // Load the user.
            TestUser loadUser;
            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindAsync(new UserLoginInfo("TestProviderGetUser", "ProviderKeyGetUser"));
                transaction.Commit();
            }
            // Check we have the same user and it has a single login.
            Assert.AreEqual(loadUser.Id, user.Id);
            Assert.AreEqual(loadUser.Logins.Count, 1);
        }
Пример #5
0
        public async Task GetLoginsForUser()
        {
            // Create a session and user store for this test.
            var session = SessionFactory.OpenSession();
            var userStore = new TestUserStore<TestUser>(session);
            // Create and save a user with a login.
            var user = new TestUser { UserName = "******" };
            int numberOfLogins = 5;
            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);
                for (int i = 0; i < numberOfLogins; i++)
                {
                    var login = new UserLoginInfo("TestProviderList" + i, "ProviderKeyRemove" + i);
                    await userStore.AddLoginAsync(user, login);
                }
                transaction.Commit();
            }
            // Check the user has an id and all the logins have been saved.
            Assert.IsNotNull(user.Id);
            Assert.AreEqual(user.Logins.Count, numberOfLogins);
            var userId = user.Id;

            // Create a new session and user store for this test, so that we actually hit the database and not the cache.
            userStore.Dispose();
            session.Dispose();
            session = SessionFactory.OpenSession();
            userStore = new TestUserStore<TestUser>(session);
            // Load the user.
            TestUser loadUser;
            IList<UserLoginInfo> logins;
            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByIdAsync(userId);
                logins = await userStore.GetLoginsAsync(user);
                transaction.Commit();
            }
            // Check we have the same user and that they have all of the logins.
            Assert.AreEqual(loadUser.Id, user.Id);
            Assert.AreEqual(loadUser.Logins.Count, numberOfLogins);
            Assert.AreEqual(logins.Count, numberOfLogins);
        }
Пример #6
0
 public async Task AddLoginForUser()
 {
     // Create a session and user store for this test.
     var session = SessionFactory.OpenSession();
     var userStore = new TestUserStore<TestUser>(session);
     // Create and save a user with a login.
     var user = new TestUser { UserName = "******" };
     var login = new UserLoginInfo("TestProviderAdd", "ProviderKeyAdd");
     using (var transaction = session.BeginTransaction())
     {
         await userStore.CreateAsync(user);
         await userStore.AddLoginAsync(user, login);
         transaction.Commit();
     }
     // Check the user has an id and the login.
     Assert.IsNotNull(user.Id);
     Assert.AreEqual(user.Logins.Count, 1);
 }