public async Task GetNonExistingUserByNameReturnsNull()
        {
            // Create a session and user store for this test.
            var      session   = SessionFactory.OpenSession();
            var      userStore = new TestUserStore(session);
            TestUser user;

            using (var transaction = session.BeginTransaction())
            {
                user = await userStore.FindByNameAsync("THISISNOTAUSERNAME");

                transaction.Commit();
            }
            // Check that we have no user.
            Assert.IsNull(user);
        }
        public async Task GetUserByUserName()
        {
            // 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 = "******";
            var    user     = new TestUser {
                UserName = userName
            };

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

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

            // 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 username.
            TestUser loadUser;

            using (var transaction = session.BeginTransaction())
            {
                loadUser = await userStore.FindByNameAsync(userName);

                transaction.Commit();
            }
            // Check we have the same user.
            Assert.AreEqual(user.Id, loadUser.Id);
            Assert.AreEqual(user.UserName, loadUser.UserName);
        }
Пример #3
0
 public async Task GetNonExistingUserByNameReturnsNull()
 {
     // Create a session and user store for this test.
     var session = SessionFactory.OpenSession();
     var userStore = new TestUserStore<TestUser>(session);
     TestUser user;
     using (var transaction = session.BeginTransaction())
     {
         user = await userStore.FindByNameAsync("THISISNOTAUSERNAME");
         transaction.Commit();
     }
     // Check that we have no user.
     Assert.IsNull(user);
 }
Пример #4
0
        public async Task GetUserByUserName()
        {
            // 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 = "******";
            var user = new TestUser { UserName = userName };
            using (var transaction = session.BeginTransaction())
            {
                await userStore.CreateAsync(user);
                transaction.Commit();
            }
            // Check the user has an id and a username.
            Assert.IsNotNull(user.Id);
            Assert.IsNotNull(user.UserName);

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