Ejemplo n.º 1
0
        public void CanDeleteUser()
        {
            using (var sessionFactory = this.Config.BuildSessionFactory())
            using (var session = sessionFactory.OpenSession())
            {
                object id;
                using (var tx = session.BeginTransaction())
                {
                    var tempUser = new User { Username = "******" };
                    id = session.Save(tempUser);
                    tx.Commit();
                }

                session.Flush();

                using (var tx = session.BeginTransaction())
                {
                    try
                    {
                        var user = session.Get<User>(id);
                        session.Delete(user);
                    }
                    catch (Exception e)
                    {
                        Assert.Fail(e.Message);
                    }
                    tx.Commit();
                }
            }
        }
Ejemplo n.º 2
0
        private static void CreateStuff(Configuration cfg)
        {
            using (ISessionFactory sessionFactory = cfg.BuildSessionFactory())
            using (ISession session = sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                try
                {
                    var tempUser = new User { Username = "******" };
                    session.Save(tempUser);

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                    transaction.Rollback();
                }
                finally
                {
                    session.Close();
                }
            }
        }
Ejemplo n.º 3
0
        public void CanCreateUser()
        {
            using (var sessionFactory = this.Config.BuildSessionFactory())
            using (var session = sessionFactory.OpenSession())
            {
                object id;
                using (var tx = session.BeginTransaction())
                {
                    var tempUser = new User { Username = "******" };
                    id = session.Save(tempUser);
                    tx.Commit();
                }

                session.Flush();

                using (var tx = session.BeginTransaction())
                {
                    var user = session.Get<User>(id);
                    Assert.AreEqual(user.Username, "temp");
                    tx.Commit();
                }
            }
        }