Ejemplo n.º 1
0
        public async Task Test_1_Batch_Add_PublisherEntityAsync()
        {
            IList <PublisherEntity> publishers = Mocker.GetPublishers();

            var transactionContext = await database.BeginTransactionAsync <PublisherEntity>(isolationLevel).ConfigureAwait(false);

            DatabaseResult result = DatabaseResult.Failed();

            try
            {
                result = await database.BatchAddAsync <PublisherEntity>(publishers, "tester", transactionContext);

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    throw new Exception();
                }

                await database.CommitAsync(transactionContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                await database.RollbackAsync(transactionContext);

                throw ex;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 2
0
        public void Test_1_Batch_Add_PublisherEntity()
        {
            IList <PublisherEntity> publishers = Mocker.GetPublishers();

            var transactionContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            DatabaseResult result = DatabaseResult.Failed();

            try
            {
                result = database.BatchAdd <PublisherEntity>(publishers, "tester", transactionContext);

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    throw new Exception();
                }

                database.Commit(transactionContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                database.Rollback(transactionContext);
                throw ex;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public void AddSomeUserClaims()
        {
            int            userCount = _userList.Count;
            DatabaseResult result    = DatabaseResult.Failed();

            for (int i = 1; i < userCount; i += 39)
            {
                UserClaim uc = new UserClaim()
                {
                    UserGuid = i.ToString(), ClaimValue = "Nothing", ClaimType = "HB.Nothing"
                };
                result = _db.AddAsync(uc, null).Result;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 5
0
        public void AddUsers()
        {
            TransactionContext transContext = database.BeginTransaction <User>();
            DatabaseResult     result       = DatabaseResult.Failed();

            foreach (User item in _userList)
            {
                result = _db.AddAsync(item, transContext).Result;

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

            database.Commit(transContext);

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 6
0
        public void AddSomeUserRole()
        {
            int            userCount = _userList.Count;
            DatabaseResult result    = DatabaseResult.Failed();

            int roleId = 1;

            for (int i = 1; i < userCount; i += 7)
            {
                UserRole ur = new UserRole()
                {
                    RoleGuid = roleId++.ToString(), UserGuid = i.ToString()
                };

                if (roleId == 5)
                {
                    roleId = 1;
                }

                result = _db.AddAsync(ur, null).Result;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 7
0
        public void RandomUpdateSomeUserAsync()
        {
            TransactionContext transContext = database.BeginTransaction <User>();

            string userNamePrefix = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            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);

                    user.UserName = userNamePrefix + "_update_" + i;

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

                    Assert.True(result.IsSucceeded());

                    if (!result.IsSucceeded())
                    {
                        _output.WriteLine($"user id {userId} update failed.");

                        database.Rollback(transContext);
                        break;
                    }
                }

                database.Commit(transContext);

                Assert.Equal(TransactionStatus.Commited, transContext.Status);

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

                    foreach (User u in updatedUsers)
                    {
                        _output.WriteLine(u.UserName);
                    }
                }
            }
            catch (Exception)
            {
                database.Rollback(transContext);

                result = DatabaseResult.Failed();
            }

            Assert.True(result.IsSucceeded());
        }