Пример #1
0
        public void UpdateTest()
        {
            TestContext.Run(engine => {
                List<User> users = engine.Select<User>().ToList();
                
                if (users.Count == 0)
                {
                    UserCreator.CreateNewUserWithName(engine, "Name3");
                    UserCreator.CreateNewUserWithName(engine, "Name1");
                    UserCreator.CreateNewUserWithName(engine, "Name4");
                    UserCreator.CreateNewUserWithName(engine, "Name2");
                }

                users = engine.Select<User>().ToList();

                User lastUser = users.Last();

                lastUser.Username = Guid.NewGuid().ToString();

                engine.Update(lastUser);
                
                List<User> users2 = engine.Select<User>().ToList();
                User lastUser2 = users2.Last();

                Assert.Equal(lastUser.Username, lastUser2.Username);
            });
        }
Пример #2
0
        public void DeleteTest()
        {
            TestContext.Run(engine => {
                UserCreator.CreateNewUserWithName(engine, "Name1");
                UserCreator.CreateNewUserWithName(engine, "Name2");

                List<User> users = engine.Select<User>().ToList();
                
                User lastUser = users.Last();

                engine.Delete(lastUser);
                
                List<User> users2 = engine.Select<User>().ToList();
                User lastUser2 = users2.Last();

                Assert.NotEqual(lastUser.Id, lastUser2.Id);
            });
        }
Пример #3
0
        public void Rollback_check_users_count()
        {
            using (Transaction transaction = _engine.BeginTransaction())
            {
                bool didRollback = false;

                try
                {
                    UserCreator.CreateNewUserWithName(_engine, "transaction test");

                    int id = 0;

                    User user = new User();
                    user.Name        = Guid.NewGuid().ToString();
                    user.Surname     = "Foo";
                    user.Password    = "******";
                    user.CreatedDate = DateTime.Now;

                    _engine.Insert(user);
                    Assert.NotEqual(0, user.Id);

                    id = user.Id;

                    transaction.Rollback();

                    didRollback = true;

                    var users = _engine.Select <User>().Where(x => x.Id == id).ToList();

                    int newCount = users.Count;

                    Assert.Equal(0, newCount);
                }
                catch
                {
                    if (!didRollback)
                    {
                        transaction.Rollback();
                    }

                    throw;
                }
            }
        }
Пример #4
0
        public void OrderBy_with_multiple_column_and_multiple_order_type()
        {
            TestContext.Run(engine => {
                UserCreator.CreateNewUserWithName(engine, "C");
                UserCreator.CreateNewUserWithName(engine, "A");
                UserCreator.CreateNewUserWithName(engine, "D");
                UserCreator.CreateNewUserWithName(engine, "B");

                List<User> orderedByLinq = engine.Select<User>().ToList().OrderBy(x => x.Name).ThenByDescending(x => x.Id).ToList();
                List<User> orderedByAngelORM = engine.Select<User>().OrderBy(x => x.Name).OrderByDescending(x => x.Id).ToList();

                Assert.Equal(orderedByLinq.Count, orderedByAngelORM.Count);

                for (int i = 0; i < orderedByLinq.Count; i++)
                {
                    Assert.Equal(orderedByLinq[i].Id, orderedByAngelORM[i].Id);
                }
            });
        }
Пример #5
0
        public void InsertTest_inserted_id_assings_to_id_property()
        {
            TestContext.Run(engine => {
                UserCreator.CreateNewUserWithName(engine, "UpdateTest");

                int lastUserId = (int)(decimal)engine.ExecuteScalar("SELECT IDENT_CURRENT('User')");

                User user = new User();
                user.Name = "foo";
                user.Username = "******";
                user.Password = "******";
                user.Email = "*****@*****.**";
                user.CreatedDate = DateTime.Now;
                user.Active = true;

                engine.Insert(user);

                Assert.Equal(lastUserId + 1, user.Id);
            });
        }
Пример #6
0
        public void Rollback_update()
        {
            using (Transaction transaction = _engine.BeginTransaction())
            {
                bool didRollback = false;

                try
                {
                    UserCreator.CreateNewUserWithName(_engine, "User1");
                    UserCreator.CreateNewUserWithName(_engine, "User2");
                    UserCreator.CreateNewUserWithName(_engine, "User3");
                    UserCreator.CreateNewUserWithName(_engine, "User4");

                    User user = _engine.Select <User>().ToList()[1];

                    string temp = user.Name;
                    user.Name = Guid.NewGuid().ToString();

                    int affectedRows = _engine.Update(user);

                    Assert.Equal(1, affectedRows);

                    transaction.Rollback();

                    didRollback = true;

                    int newCount = _engine.Select <User>().ToList().Count;

                    Assert.Equal(0, newCount);
                }
                catch
                {
                    if (!didRollback)
                    {
                        transaction.Rollback();
                    }

                    throw;
                }
            }
        }