public async Task GetUserByEmail()
        {
            // Create a session and user store for this test.
            var session   = SessionFactory.OpenSession();
            var userStore = new TestUserStore(session);
            // Create and save a user.
            string userName = "******";
            string email    = "*****@*****.**";
            var    user     = new TestUser {
                UserName = userName, Email = email
            };

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

                transaction.Commit();
            }
            // Check the user has an id and a username and email.
            Assert.IsNotNull(user.Id);
            Assert.IsNotNull(user.UserName);
            Assert.IsNotNull(user.Email);

            // 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 using the email.
            TestUser loadUser;

            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByEmailAsync(email);

                transaction.Commit();
            }
            // Check we have the same user.
            Assert.AreEqual(user.Id, loadUser.Id);
            Assert.AreEqual(user.UserName, loadUser.UserName);
            Assert.AreEqual(user.Email, loadUser.Email);
        }
Beispiel #2
0
        public async Task GetUserByEmail()
        {
            // Create a session and user store for this test.
            var session = SessionFactory.OpenSession();
            var userStore = new TestUserStore<TestUser>(session);
            // Create and save a user.
            string userName = "******";
            string email = "*****@*****.**";
            var user = new TestUser { UserName = userName, Email = email };
            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);
                transaction.Commit();
            }
            // Check the user has an id and a username and email.
            Assert.IsNotNull(user.Id);
            Assert.IsNotNull(user.UserName);
            Assert.IsNotNull(user.Email);

            // 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 using the email.
            TestUser loadUser;
            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByEmailAsync(email);
                transaction.Commit();
            }
            // Check we have the same user.
            Assert.AreEqual(user.Id, loadUser.Id);
            Assert.AreEqual(user.UserName, loadUser.UserName);
            Assert.AreEqual(user.Email, loadUser.Email);
        }