Ejemplo n.º 1
0
        public async Task GetNonExistingRoleByNameReturnsNull()
        {
            // Create a session and role store for this test.
            var      session   = SessionFactory.OpenSession();
            var      roleStore = new TestRoleStore(session);
            TestRole role;

            using (var transaction = session.BeginTransaction())
            {
                role = await roleStore.FindByNameAsync("THISISNOTAROLENAME");

                transaction.Commit();
            }
            // Check that we have no role.
            Assert.IsNull(role);
        }
Ejemplo n.º 2
0
        public async Task GetRoleByName()
        {
            // Create a session and role store for this test.
            var session   = SessionFactory.OpenSession();
            var roleStore = new TestRoleStore(session);
            // Create and save a role.
            string roleName = "GetRoleByNameTest";
            var    role     = new TestRole {
                Name = roleName
            };

            using (var transaction = session.BeginTransaction())
            {
                await roleStore.CreateAsync(role);

                transaction.Commit();
            }
            // Check the role has an id.
            Assert.IsNotNull(role.Id);

            // Create a new session and role store for this test, so that we actually hit the database and not the cache.
            roleStore.Dispose();
            session.Dispose();
            session   = SessionFactory.OpenSession();
            roleStore = new TestRoleStore(session);
            // Load the role by Name.
            TestRole loadRole;

            using (var transaction = session.BeginTransaction())
            {
                loadRole = await roleStore.FindByNameAsync(roleName);

                transaction.Commit();
            }
            // Check we have the same role.
            Assert.IsNotNull(loadRole);
            Assert.AreEqual(role.Id, loadRole.Id);
            Assert.AreEqual(role.Name, loadRole.Name);
        }
Ejemplo n.º 3
0
 public async Task GetNonExistingRoleByNameReturnsNull()
 {
     // Create a session and role store for this test.
     var session = SessionFactory.OpenSession();
     var roleStore = new TestRoleStore<TestRole>(session);
     TestRole role;
     using (var transaction = session.BeginTransaction())
     {
         role = await roleStore.FindByNameAsync("THISISNOTAROLENAME");
         transaction.Commit();
     }
     // Check that we have no role.
     Assert.IsNull(role);
 }
Ejemplo n.º 4
0
        public async Task GetRoleByName()
        {
            // Create a session and role store for this test.
            var session = SessionFactory.OpenSession();
            var roleStore = new TestRoleStore<TestRole>(session);
            // Create and save a role.
            string roleName = "GetRoleByNameTest";
            var role = new TestRole { Name = roleName };
            using (var transaction = session.BeginTransaction())
            {
                await roleStore.CreateAsync(role);
                transaction.Commit();
            }
            // Check the role has an id.
            Assert.IsNotNull(role.Id);

            // Create a new session and role store for this test, so that we actually hit the database and not the cache.
            roleStore.Dispose();
            session.Dispose();
            session = SessionFactory.OpenSession();
            roleStore = new TestRoleStore<TestRole>(session);
            // Load the role by Name.
            TestRole loadRole;
            using (var transaction = session.BeginTransaction())
            {
                loadRole = await roleStore.FindByNameAsync(roleName);
                transaction.Commit();
            }
            // Check we have the same role.
            Assert.IsNotNull(loadRole);
            Assert.AreEqual(role.Id, loadRole.Id);
            Assert.AreEqual(role.Name, loadRole.Name);
        }