Esempio n. 1
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);
        }