public async void UpdateRequestAsync()
        {
            var newItem = A.New <Request>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.Type = $"{newItem.Type} ({items.Count})";
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var insertedItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    insertedItem.Type = $"{insertedItem.Type} ({DateTime.Now})";
                    if (32 < insertedItem.Type.Length)
                    {
                        insertedItem.Type = insertedItem.Type.Substring(0, 31);
                    }
                    Assert.NotNull(insertedItem);
                    Assert.NotEqual(0, insertedItem.RequestId);

                    var result = await _dbContext.UpdateAsync(dbTransaction, insertedItem);

                    dbTransaction.Commit();
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }
        }
Exemple #2
0
        public async Task InsertBenefitAsync()
        {
            var newItem = A.New <Benefit>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.BenefitId = items.Max(product => product.BenefitId) + 1;
                newItem.Name      = $"{newItem.Name} ({items.Count})";
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.BenefitId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }
        }
        public async void GetCompanyAsync_DbConnection()
        {
            _logger.LogInformation("GetCompanyAsync_DbConnection...");
            var newItem = A.New <Company>();

            newItem.Name           = $"{newItem.Name} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})";
            newItem.ObjectDocument = $"{{\"Test\": \"{newItem.Name}\"}}";
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    newItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(newItem);
                    Assert.NotEqual(0, newItem.CompanyId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, newItem.CompanyId);

                Assert.NotNull(result);
                Assert.Equal(newItem.CompanyId, result.CompanyId);
            }
        }
Exemple #4
0
        public async void GetClaimAsync_DbConnection()
        {
            _logger.LogInformation("GetClaimAsync_DbConnection...");
            var newItem = A.New <Claim>();
            var policy  = _policiesFixture.Items[A.Random.Next(0, _policiesFixture.Items.Count - 1)];

            newItem.PolicyId       = policy.PolicyId;
            newItem.ObjectDocument = $"{{\"Test\": \"{newItem.PolicyId} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})\"}}";
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    newItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(newItem);
                    Assert.NotEqual(0, newItem.ClaimId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, newItem.ClaimId);

                Assert.NotNull(result);
                Assert.Equal(newItem.ClaimId, result.ClaimId);
            }
        }
        public async void InsertQuoteAsync()
        {
            var newItem = A.New <Quote>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.QuoteId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }
        }
        public async void UpdatePolicyAsync()
        {
            var newItem = A.New <Policy>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var insertedItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    Assert.NotNull(insertedItem);
                    Assert.NotEqual(0, insertedItem.PolicyId);

                    var result = await _dbContext.UpdateAsync(dbTransaction, insertedItem);

                    dbTransaction.Commit();
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }
        }
        public async void UpdateQuestionAsync()
        {
            var newItem = A.New <Question>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.Text = $"{newItem.Text} ({items.Count})";
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var insertedItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    insertedItem.Text = $"{insertedItem.Text} ({DateTime.Now})";
                    Assert.NotNull(insertedItem);
                    Assert.NotEqual(0, insertedItem.QuestionId);

                    var result = await _dbContext.UpdateAsync(dbTransaction, insertedItem);

                    dbTransaction.Commit();
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }
        }
        public async void DeleteInvoiceAsync()
        {
            var newItem = A.New <Invoice>();

            newItem.Identifier = Guid.NewGuid().ToString();
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.InvoiceId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            Invoice existingInvoice;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "InvoiceId",
                    SortOrder = SortOrders.DESC
                };
                existingInvoice = (await _dbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            using (var transaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    await _dbContext.DeleteAsync(transaction, existingInvoice);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, existingInvoice.InvoiceId);

                Assert.Null(result);
            }
        }
Exemple #9
0
 public async void GetPolicyCustomersAsync()
 {
     using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
     {
         var result = (await _dbContext.GetPolicyCustomersAsync(dbConnection, 7178));
         Assert.NotNull(result);
     }
 }
Exemple #10
0
 private async Task <IEnumerable <Policy> > GetPoliciesAsync()
 {
     _logger.LogInformation("GetPoliciesAsync...");
     using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
     {
         return(await _dbContext.GetAllAsync(dbConnection));
     }
 }
        public async void GetQuestionsAsync()
        {
            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAllAsync(dbConnection);

                Assert.NotNull(result);
            }
        }
Exemple #12
0
        public async void GetLeadCountAsync()
        {
            _logger.LogInformation("GetLeadCountAsync...");
            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetCountAsync(dbConnection);

                Assert.NotEqual(0, result);
            }
        }
        public async void GetPaymentsAsync()
        {
            _logger.LogInformation("GetPaymentsAsync...");
            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAllAsync(dbConnection);

                Assert.NotNull(result);
            }
        }
Exemple #14
0
        public async void UpdateLeadAsync()
        {
            _logger.LogInformation("UpdateLeadAsync...");
            var newItem = A.New <Lead>();

            newItem.Name           = $"{newItem.Name} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})";
            newItem.ObjectDocument = $"{{\"Test\": \"{newItem.Name}\"}}";
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    newItem = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(newItem);
                    Assert.NotEqual(0, newItem.LeadId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var itemToUpdate = A.New <Lead>();
                    itemToUpdate.LeadId         = newItem.LeadId;
                    itemToUpdate.Name           = $"{itemToUpdate.Name} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})";
                    itemToUpdate.ObjectDocument = $"{{\"Test\": \"{itemToUpdate.Name}\"}}";
                    var result = await _dbContext.UpdateAsync(dbTransaction, itemToUpdate);

                    dbTransaction.Commit();
                    Assert.True(result);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var updatedItem = await _dbContext.GetAsync(dbConnection, newItem.LeadId);

                Assert.NotNull(updatedItem);
                Assert.NotEqual(updatedItem.Name, newItem.Name);
            }
        }
        public async void DeleteProductAsync()
        {
            var newItem = A.New <Product>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.ProductId = items.Max(product => product.ProductId) + 1;
                newItem.Name      = $"{newItem.Name} ({items.Count})";
            }

            Product existingProduct;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "ProductId",
                    SortOrder = SortOrders.DESC
                };
                existingProduct = (await _dbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            using (var transaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    await _dbContext.DeleteAsync(transaction, existingProduct);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, existingProduct.ProductId);

                Assert.Null(result);
            }
        }
        public async void GetQuestionsAsync_PageRequest()
        {
            var pageRequest = new PageRequest()
            {
                SortBy    = "QuestionId",
                SortOrder = SortOrders.DESC,
                PageIndex = 4,
                PageSize  = 50
            };

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetPageAsync(dbConnection, pageRequest);

                Assert.NotNull(result);
            }
        }
        public async void GetPaymentAsync()
        {
            var newItem = A.New <Payment>();

            newItem.Identifier     = Guid.NewGuid().ToString();
            newItem.CurrencyAlpha3 = "EUR";
            newItem.ObjectDocument = $"{{\"Test\": \"{newItem.Identifier} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})\"}}";
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.PaymentId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            _logger.LogInformation("GetPaymentAsync...");
            var pageRequest = new PageRequest
            {
                SortBy    = "PaymentId",
                SortOrder = SortOrders.DESC,
                PageIndex = 0,
                PageSize  = 50
            };

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetPageAsync(dbConnection, pageRequest);

                Assert.NotNull(result);

                var first     = result.Items.First();
                var firstItem = await _dbContext.GetAsync(dbConnection, first.PaymentId);

                Assert.NotNull(firstItem);
            }
        }
        public async void GetPaymentsAsync_PageRequest()
        {
            _logger.LogInformation("GetPaymentsAsync_PageRequest...");
            var pageRequest = new PageRequest
            {
                SortBy    = "PaymentId",
                SortOrder = SortOrders.DESC,
                PageIndex = 0,
                PageSize  = 50
            };

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetPageAsync(dbConnection, pageRequest);

                Assert.NotNull(result);
            }
        }
        public async void GetRequestsAsync_PageRequest_SortByType_Filtered()
        {
            var pageRequest = new PageRequest()
            {
                Filter    = "denim",
                SortBy    = "Type",
                SortOrder = SortOrders.DESC,
                PageIndex = 4,
                PageSize  = 50
            };

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetPageAsync(dbConnection, pageRequest);

                Assert.NotNull(result);
            }
        }
Exemple #20
0
        public async void DeleteBenefitAsync()
        {
            await InsertBenefitAsync();

            Benefit existingBenefit;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "BenefitId",
                    SortOrder = SortOrders.DESC
                };
                existingBenefit = (await _dbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            using (var transaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    await _dbContext.DeleteAsync(transaction, existingBenefit);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, existingBenefit.BenefitId);

                Assert.Null(result);
            }
        }
Exemple #21
0
        public async void InsertClaimAsync_Multiple(int count)
        {
            _logger.LogInformation($"InsertClaimAsync_Multiple '{count}'...");

            var objectHash = count;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                objectHash += await _dbContext.GetCountAsync(dbConnection);
            }

            var newItems = A.ListOf <Claim>(count);

            foreach (var newItem in newItems)
            {
                var policy = _policiesFixture.Items[A.Random.Next(0, _policiesFixture.Items.Count - 1)];
                newItem.PolicyId       = policy.PolicyId;
                newItem.ObjectDocument = $"{{\"Test\": \"{newItem.PolicyId} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})\"}}";
                newItem.ObjectHash     = objectHash++;
                using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
                {
                    try
                    {
                        var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                        dbTransaction.Commit();

                        Assert.NotNull(result);
                        Assert.NotEqual(0, result.ClaimId);
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                }
            }
        }
Exemple #22
0
        public async void InsertLeadAsync_Multiple(int count)
        {
            _logger.LogInformation($"InsertLeadAsync_Multiple '{count}'...");

            var objectHash = count;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                objectHash += await _dbContext.GetCountAsync(dbConnection);
            }

            var newItems = A.ListOf <Lead>(count);

            foreach (var newItem in newItems)
            {
                newItem.Name           = $"{newItem.Name} ({DateTime.Now:yyyyMMddHHmmssfff} - {Guid.NewGuid()})";
                newItem.ObjectDocument = $"{{\"Test\": \"{newItem.Name}\"}}";
                newItem.ObjectHash     = objectHash++;
                using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
                {
                    try
                    {
                        var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                        dbTransaction.Commit();

                        Assert.NotNull(result);
                        Assert.NotEqual(0, result.LeadId);
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                }
            }
        }
        public async void DeleteQuestionAsync()
        {
            var newItem = A.New <Question>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.Text = $"{newItem.Text} ({items.Count})";
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.QuestionId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            Question existingQuestion;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "QuestionId",
                    SortOrder = SortOrders.DESC
                };
                existingQuestion = (await _dbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            using (var transaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    await _dbContext.DeleteAsync(transaction, existingQuestion);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, existingQuestion.QuestionId);

                Assert.Null(result);
            }
        }
Exemple #24
0
        public async void DeleteAgentAsync()
        {
            var newItem = A.New <Agent>();

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var items = (await _dbContext.GetAllAsync(dbConnection)).ToList();
                newItem.Name           = $"{newItem.Name} ({items.Count})";
                newItem.ObjectDocument = JsonConvert.SerializeObject(new { Identifier = Guid.NewGuid() });
                newItem.ObjectHash     = newItem.ObjectDocument.GetHashCode();
            }
            using (var dbTransaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    var result = await _dbContext.InsertAsync(dbTransaction, newItem);

                    dbTransaction.Commit();

                    Assert.NotNull(result);
                    Assert.NotEqual(0, result.AgentId);
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
            }

            Agent existingAgent;

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "AgentId",
                    SortOrder = SortOrders.DESC
                };
                existingAgent = (await _dbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            using (var transaction = await DbConnectionFactory.BeginUserTransactionAsync(UserId))
            {
                try
                {
                    await _dbContext.DeleteAsync(transaction, existingAgent);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            using (var dbConnection = await DbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var result = await _dbContext.GetAsync(dbConnection, existingAgent.AgentId);

                Assert.Null(result);
            }
        }