public void ValidateCustomerWithCheckPayment()
        {
            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction);

            var paymentType = (from p in paymentTypes where p.Description == "Check" select p).First();

            Customer customer = new Customer();
            customer.FirstName = "Bill";
            customer.LastName = "Gates";
            customer.EmailAddress = "*****@*****.**";
            customer.PaymentTypeID = paymentType.PaymentTypeID;
            customer.CreditLimit = 1000.00m;

            customerDataService.CreateSession();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
            customerBusinessRules.ValidateCustomer(customer, customerDataService);
            customerDataService.CloseSession();

            string returnMessage = Utilities.GetReturnMessage(customerBusinessRules.ValidationMessage);

            Assert.AreEqual(true, customerBusinessRules.ValidationStatus, returnMessage);
        }
        /// <summary>
        /// Update Customer
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="transaction"></param>
        public void UpdateCustomer(Customer customer, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();

            try
            {
                CustomerDataService.CreateSession();
                customerBusinessRules.ValidateCustomer(customer, CustomerDataService);

                if (customerBusinessRules.ValidationStatus == true)
                {
                    Customer originalCustomerInformation = CustomerDataService.GetCustomerByCustomerID(customer.CustomerID);
                    PopulateCustomerInformation(customer, originalCustomerInformation);
                    CustomerDataService.BeginTransaction();
                    CustomerDataService.UpdateCustomer(originalCustomerInformation);
                    CustomerDataService.CommitTransaction(true);
                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("Customer successfully updated at " + DateTime.Now.ToString());
                }
                else
                {
                    transaction.ReturnStatus     = customerBusinessRules.ValidationStatus;
                    transaction.ReturnMessage    = customerBusinessRules.ValidationMessage;
                    transaction.ValidationErrors = customerBusinessRules.ValidationErrors;
                }
            }
            catch (Exception ex)
            {
                CustomerDataService.RollbackTransaction(true);
                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                CustomerDataService.CloseSession();
            }
        }
        /// <summary>
        /// Create Customer
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="transaction"></param>
        public void CreateCustomer(Customer customer, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();

            try
            {
                CustomerDataService.CreateSession();

                customerBusinessRules.ValidateCustomer(customer, CustomerDataService);

                if (customerBusinessRules.ValidationStatus == true)
                {
                    CustomerDataService.BeginTransaction();
                    CustomerDataService.CreateCustomer(customer);
                    CustomerDataService.CommitTransaction(true);
                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("Customer successfully created at " + customer.DateCreated.ToString());
                }
                else
                {
                    transaction.ReturnStatus = customerBusinessRules.ValidationStatus;
                    transaction.ReturnMessage = customerBusinessRules.ValidationMessage;
                    transaction.ValidationErrors = customerBusinessRules.ValidationErrors;
                }

            }
            catch (Exception ex)
            {
                CustomerDataService.RollbackTransaction(true);
                transaction.ReturnMessage = new List<string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                CustomerDataService.CloseSession();
            }
        }
        public void ValidateCustomerWithCreditCardPayment()
        {
            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction);

            var paymentType = (from p in paymentTypes where p.Description == "Visa" select p).First();

            Customer customer = new Customer();
            customer.FirstName = "Bill";
            customer.LastName = "Gates";
            customer.EmailAddress = "*****@*****.**";
            customer.PaymentTypeID = paymentType.PaymentTypeID;
            customer.CreditCardNumber = "1112223333";
            customer.CreditCardExpirationDate = Convert.ToDateTime("12/31/2014");
            customer.CreditCardSecurityCode = "111";

            customerDataService.CreateSession();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
            customerBusinessRules.ValidateCustomer(customer, customerDataService);
            customerDataService.CloseSession();

            string returnMessage = Utilities.GetReturnMessage(customerBusinessRules.ValidationMessage);

            Assert.AreEqual(true, customerBusinessRules.ValidationStatus, returnMessage);
        }