Beispiel #1
0
        public void AddRole()
        {
            TransactionContext transContext = database.BeginTransaction <Role>();
            DatabaseResult     result       = DatabaseResult.Succeeded();

            foreach (Role item in _roleList)
            {
                long count = _db.Count <Role>(r => r.Name == item.Name, transContext);

                if (count != 0)
                {
                    continue;
                }

                result = _db.AddAsync(item, transContext).Result;

                if (!result.IsSucceeded())
                {
                    database.Rollback(transContext);
                    break;
                }
            }

            database.Commit(transContext);

            Assert.True(result.IsSucceeded());
        }
Beispiel #2
0
        public void RandomDeleteSomeUserAsync()
        {
            TransactionContext transContext = database.BeginTransaction <User>();

            List <long> ids = new List <long>();

            DatabaseResult result = null;

            try
            {
                long userCount = _db.Count <User>(transContext);

                for (int i = 0; i < userCount; i += 10)
                {
                    int userId = i;

                    User user = _db.ScalarAsync <User>(i, transContext).Result;

                    if (user == null)
                    {
                        continue;
                    }

                    ids.Add(userId);

                    result = _db.DeleteAsync <User>(user, transContext).Result;

                    Assert.True(result.IsSucceeded());

                    if (!result.IsSucceeded())
                    {
                        database.Rollback(transContext);
                        break;
                    }
                }

                database.Commit(transContext);

                Assert.True(transContext.Status == TransactionStatus.Commited);

                if (transContext.Status == TransactionStatus.Commited)
                {
                    IList <User> updatedUsers = _db.Retrieve <User>(u => SQLUtil.In(u.Id, false, ids), null);

                    if (updatedUsers.Count == 0)
                    {
                        result = DatabaseResult.Succeeded();
                    }

                    result = DatabaseResult.Failed();
                }

                result = DatabaseResult.Failed();
            }
            catch (Exception)
            {
                database.Rollback(transContext);
            }
        }