public void LoadByIDFailure()
		{
			UserGroup ug1 = new UserGroup();
			ug1.Name = "Group1";
			User ui1 = new User("User1");

			ISession s = OpenSession();
			s.BeginTransaction();
			object gid1 = s.Save(ug1);
			object uid1 = s.Save(ui1);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			//Load user with USER NAME: 
			ICriteria criteria1 = s.CreateCriteria(typeof(User));
			criteria1.Add(Expression.Eq("Name", "User1"));
			Assert.AreEqual(1, criteria1.List().Count);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			//Load group with USER NAME: 
			ICriteria criteria2 = s.CreateCriteria(typeof(UserGroup));
			criteria2.Add(Expression.Eq("Name", "User1"));
			Assert.AreEqual(0, criteria2.List().Count);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			//Load group with GROUP NAME
			ICriteria criteria3 = s.CreateCriteria(typeof(UserGroup));
			criteria3.Add(Expression.Eq("Name", "Group1"));
			Assert.AreEqual(1, criteria3.List().Count);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			//Load user with GROUP NAME
			ICriteria criteria4 = s.CreateCriteria(typeof(User));
			criteria4.Add(Expression.Eq("Name", "Group1"));
			Assert.AreEqual(0, criteria4.List().Count);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			//Load group with USER IDENTITY
			ug1 = (UserGroup) s.Get(typeof(UserGroup), uid1);
			Assert.IsNull(ug1);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			ui1 = (User) s.Get(typeof(User), gid1);
			Assert.IsNull(ui1);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			Party p = (Party) s.Get(typeof(Party), uid1);
			Assert.IsTrue(p is User);
			p = (Party) s.Get(typeof(Party), gid1);
			Assert.IsTrue(p is UserGroup);
			s.Transaction.Commit();
			s.Close();

			s = OpenSession();
			s.BeginTransaction();
			s.Delete("from Party");
			s.Transaction.Commit();
			s.Close();
		}
Example #2
0
        public async Task LoadByIDFailureAsync()
        {
            UserGroup ug1 = new UserGroup();

            ug1.Name = "Group1";
            User ui1 = new User("User1");

            ISession s = OpenSession();

            s.BeginTransaction();
            object gid1 = await(s.SaveAsync(ug1));
            object uid1 = await(s.SaveAsync(ui1));

            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            //Load user with USER NAME:
            ICriteria criteria1 = s.CreateCriteria(typeof(User));

            criteria1.Add(Expression.Eq("Name", "User1"));
            Assert.AreEqual(1, (await(criteria1.ListAsync())).Count);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            //Load group with USER NAME:
            ICriteria criteria2 = s.CreateCriteria(typeof(UserGroup));

            criteria2.Add(Expression.Eq("Name", "User1"));
            Assert.AreEqual(0, (await(criteria2.ListAsync())).Count);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            //Load group with GROUP NAME
            ICriteria criteria3 = s.CreateCriteria(typeof(UserGroup));

            criteria3.Add(Expression.Eq("Name", "Group1"));
            Assert.AreEqual(1, (await(criteria3.ListAsync())).Count);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            //Load user with GROUP NAME
            ICriteria criteria4 = s.CreateCriteria(typeof(User));

            criteria4.Add(Expression.Eq("Name", "Group1"));
            Assert.AreEqual(0, (await(criteria4.ListAsync())).Count);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            //Load group with USER IDENTITY
            ug1 = (UserGroup)await(s.GetAsync(typeof(UserGroup), uid1));
            Assert.IsNull(ug1);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            ui1 = (User)await(s.GetAsync(typeof(User), gid1));
            Assert.IsNull(ui1);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            Party p = (Party)await(s.GetAsync(typeof(Party), uid1));

            Assert.IsTrue(p is User);
            p = (Party)await(s.GetAsync(typeof(Party), gid1));
            Assert.IsTrue(p is UserGroup);
            await(s.Transaction.CommitAsync());
            s.Close();

            s = OpenSession();
            s.BeginTransaction();
            await(s.DeleteAsync("from Party"));
            await(s.Transaction.CommitAsync());
            s.Close();
        }
		public void List()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				User user = new User();
				user.Name = "user";
				UserGroup group = new UserGroup();
				group.Name = "user";

				group.Users.Add(user);

				s.Save(group);
				s.Save(user);

				s.CreateCriteria(typeof(Party)).List();

				s.Delete("from Party");
				t.Commit();
			}
		}
        public void LoadByIDFailure()
        {
            UserGroup ug1 = new UserGroup();

            ug1.Name = "Group1";
            User   ui1 = new User("User1");
            object gid1, uid1;

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    gid1 = s.Save(ug1);
                    uid1 = s.Save(ui1);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    //Load user with USER NAME:
                    ICriteria criteria1 = s.CreateCriteria(typeof(User));
                    criteria1.Add(Expression.Eq("Name", "User1"));
                    Assert.AreEqual(1, criteria1.List().Count);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    //Load group with USER NAME:
                    ICriteria criteria2 = s.CreateCriteria(typeof(UserGroup));
                    criteria2.Add(Expression.Eq("Name", "User1"));
                    Assert.AreEqual(0, criteria2.List().Count);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    //Load group with GROUP NAME
                    ICriteria criteria3 = s.CreateCriteria(typeof(UserGroup));
                    criteria3.Add(Expression.Eq("Name", "Group1"));
                    Assert.AreEqual(1, criteria3.List().Count);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    //Load user with GROUP NAME
                    ICriteria criteria4 = s.CreateCriteria(typeof(User));
                    criteria4.Add(Expression.Eq("Name", "Group1"));
                    Assert.AreEqual(0, criteria4.List().Count);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    //Load group with USER IDENTITY
                    ug1 = (UserGroup)s.Get(typeof(UserGroup), uid1);
                    Assert.IsNull(ug1);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    ui1 = (User)s.Get(typeof(User), gid1);
                    Assert.IsNull(ui1);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    Party p = (Party)s.Get(typeof(Party), uid1);
                    Assert.IsTrue(p is User);
                    p = (Party)s.Get(typeof(Party), gid1);
                    Assert.IsTrue(p is UserGroup);
                    t.Commit();
                    s.Close();
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    s.Delete("from Party");
                    t.Commit();
                    s.Close();
                }
        }