public void CreatePermitTypeTest()
        {
            List<string> errors = new List<string>();
            BLPermitTypes.CreatePermitType(null, ref errors);
            Assert.AreEqual(1, errors.Count);

            errors = new List<string>();

            Permit permit = new Permit();
            permit.price = -1;
            permit.permit_name = "thisnameistoolongforthedatabase";
            permit.v_description = "asdfasdfasdf";
            permit.customer_type = "grad";
            BLPermitTypes.CreatePermitType(permit, ref errors);
            Assert.AreEqual(2, errors.Count);
        }
Ejemplo n.º 2
0
        public void CreatePermitErrorTest()
        {
            Customer customer = new Customer();
            customer.customer_name = "bltestcreatecustomer";
            customer.customer_pw = "fakepassword1"; // TODO: Initialize to an appropriate value
            customer.customer_type = "undertest";
            customer.first_name = "test"; // TODO: Initialize to an appropriate value
            customer.middle_name = "test"; // TODO: Initialize to an appropriate value
            customer.last_name = "test"; // TODO: Initialize to an appropriate value
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                BLCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "bl customertest";
                permit.customer_type = "undergrad";
                permit.price = 50;
                permit.v_description = "test";
                BLPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                BLRecords.CreatePermit(record, ref errors);

                Violation violation = new Violation();
                violation.permit_id = record.permit_id;
                violation.fee = 48;
                violation.v_description = "testing create violations - test1";
                violation.violation_date = DateTime.Parse("11/11/2011");
                violation.paid = false;
                BLViolations.CreateViolation(violation, ref errors);

                Record record1 = new Record();
                record1.customer_id = customer.customer_id;
                record1.permit_type_id = permit.id;
                record1.expire_date = DateTime.Parse("11/11/2011");
                record1.valid = true;
                BLRecords.CreatePermit(record1, ref errors);

                Assert.AreEqual(1, errors.Count);
            }
        }
        public void CreateInvoiceTest()
        {
            //connections variables and dataset
            SqlConnection conn = new SqlConnection(connection_string);
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                Customer customer = new Customer();
                customer.customer_name = "create invoice test";
                customer.customer_pw = "test";
                customer.customer_type = "test";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                int customerId = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "create invoice test";
                permit.customer_type = "test";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Invoice invoice = new Invoice();
                invoice.invoice_type = "create invoice test";
                invoice.customer_id = customerId;
                invoice.item_id = permit.id;
                invoice.amt_paid = 200;
                invoice.pay_method = "visa";
                invoice.pay_date = DateTime.Today;
                invoice.invoice_id = DALInvoices.CreateInvoice(invoice, ref errors);
                Invoice check = DALInvoices.GetInvoiceInfo(invoice.invoice_id, ref errors);

                Assert.AreEqual(0, errors.Count);
                Assert.IsNotNull(check);
                Assert.AreEqual(invoice.invoice_id, check.invoice_id);
                Assert.AreEqual(invoice.invoice_type, check.invoice_type);
                Assert.AreEqual(invoice.customer_id, check.customer_id);
                Assert.AreEqual(invoice.item_id, check.item_id);
                Assert.AreEqual(invoice.amt_paid, check.amt_paid);
                Assert.AreEqual(invoice.pay_method, check.pay_method);
                Assert.AreEqual(invoice.pay_date, check.pay_date);

            }
        }
Ejemplo n.º 4
0
        public static void CreatePermitType(Permit permit, ref List<string> errors)
        {
            // Check permit object
            if (permit == null)
            {
                errors.Add("Permit cannot be null");
            }

            // Check that all integer inputs are positive and non-zero
            else if (permit != null)
            {
                if (permit.price <= 0)
                {
                    errors.Add("Invalid permit price.");
                }

                // Check string input lengths -- see below for @CustomerType check
                if (permit.permit_name.Length > 20 || permit.v_description.Length > 300)
                {
                    errors.Add("String input exceeds maximum length.");
                }

                // Check @CustomerType for three possible values: undergrad/grad/faculty
                if (!(permit.customer_type.Equals("undergrad") ||
                    permit.customer_type.Equals("grad") ||
                    permit.customer_type.Equals("faculty")))
                {
                    errors.Add("Invalid permit type.");
                }
            }

            // Return if any errors exist
            if (errors.Count > 0)
            {
                AsynchLog.LogNow(errors);
                return;
            }

            permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);
        }
        public void CreatePermitTest()
        {
            //connections variables and dataset
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                Customer customer = new Customer();
                customer.customer_name = "create record test";
                customer.customer_pw = "test";
                customer.customer_type = "test";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                customer.customer_id = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "create record test";
                permit.customer_type = "test";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                record.permit_id = DALRecords.CreatePermit(record, ref errors);
                Record check = DALRecords.GetPermitInfo(customer.customer_id, ref errors);

                //remember to create get permit record based on customer id
                Assert.AreEqual(0, errors.Count);
                Assert.AreEqual(record.permit_id, check.permit_id);
                Assert.AreEqual(record.customer_id, check.customer_id);
                Assert.AreEqual(record.permit_type_id, check.permit_type_id);
                Assert.AreEqual(record.expire_date, check.expire_date);
                Assert.AreEqual(record.valid, check.valid);
            }
        }
 public static Permit GetPermitsBasedOnCustomer(int customer_id, ref List<string> errors)
 {
     //connections variables and dataset
     SqlConnection conn = new SqlConnection(connection_string);
     DataSet dS = new DataSet();
     Permit permit = new Permit();
     try
     {
         string strSql = "getPermitsBasedOnCustomer";
         SqlDataAdapter adapter = new SqlDataAdapter(strSql, conn);
         adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
         adapter.SelectCommand.Parameters.Add(new SqlParameter("@customer_id", SqlDbType.Int));
         adapter.SelectCommand.Parameters["@customer_id"].Value = customer_id;
         adapter.Fill(dS, "result_table");
     }
     catch (Exception e)
     {
         errors.Add("Error: " + e.ToString());
     }
     finally
     {
         conn.Dispose();
         conn = null;
     }
     if (dS.Tables["result_table"].Rows.Count == 0)
     {
         //errors.Add("customer should be able to purchase one permit type");
         return null;
     }
     else
     {
         permit.id = (int)dS.Tables["result_table"].Rows[0]["id"];
         permit.permit_name = dS.Tables["result_table"].Rows[0]["permit_name"].ToString();
         permit.customer_type = dS.Tables["result_table"].Rows[0]["customer_type"].ToString();
         permit.price = (int)dS.Tables["result_table"].Rows[0]["price"];
         permit.v_description = dS.Tables["result_table"].Rows[0]["v_description"].ToString();
         return permit;
     }
 }
        public static int CreatePermitType(Permit permit, ref List<string> errors)
        {
            //connections variables and dataset
            SqlConnection conn = new SqlConnection(connection_string);
            string id = string.Empty;
            try
            {
                string strSql = "createPermitType";
                SqlDataAdapter adapter = new SqlDataAdapter(strSql, conn);
                DataSet dS = new DataSet();

                //add parameters to adapter
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@PermitName", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@CustomerType", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Price", SqlDbType.Int));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Vdescription", SqlDbType.VarChar, 300));
                adapter.SelectCommand.Parameters["@PermitName"].Value = permit.permit_name;
                adapter.SelectCommand.Parameters["@CustomerType"].Value = permit.customer_type;
                adapter.SelectCommand.Parameters["@Price"].Value = permit.price;
                adapter.SelectCommand.Parameters["@Vdescription"].Value = permit.v_description;

                adapter.Fill(dS, "result_table");

                id = dS.Tables["result_table"].Rows[0][0].ToString();
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
            finally
            {
                conn.Dispose();
                conn = null;
            }
            int retId;
            Int32.TryParse(id, out retId);
            return retId;
        }
 public void UpdatePermitTable(Permit permit, ref List<string> errors)
 {
     BLPermitTypes.UpdatePermitTable(permit, ref errors);
 }
 public void CreatePermitType(Permit permit, ref List<string> errors)
 {
     BLPermitTypes.CreatePermitType(permit, ref errors);
 }
        public void createViolationTest()
        {
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                Customer customer = new Customer();
                customer.customer_name = "create record test";
                customer.customer_pw = "test";
                customer.customer_type = "test";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                customer.customer_id = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "create record test";
                permit.customer_type = "test";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                record.permit_id = DALRecords.CreatePermit(record, ref errors);
                Record r_check = DALRecords.GetPermitInfo(customer.customer_id, ref errors);

                Violation violation = new Violation();
                violation.permit_id = record.permit_id;
                violation.fee = 48;
                violation.v_description = "testing create violations - test1";
                violation.violation_date = DateTime.Parse("11/11/2011");
                violation.paid = true;
                violation.violation_id = DALViolations.CreateViolation(violation, ref errors);

                Violation violation2 = new Violation();
                violation2.permit_id = record.permit_id;
                violation2.fee = 100;
                violation2.v_description = "testing create violations - test2";
                violation2.violation_date = DateTime.Parse("11/11/2011");
                violation2.paid = false;
                violation2.violation_id = DALViolations.CreateViolation(violation2, ref errors);

                List<Violation> check = DALViolations.GetCustomerViolations(record.customer_id, ref errors);
                Violation check_single_vio = DALViolations.GetViolationById(violation.violation_id, ref errors);

                Assert.AreEqual(0, errors.Count);
                Assert.AreNotEqual(0, check.Count);
                bool pass = false;

                Assert.AreEqual(violation.violation_id, check_single_vio.violation_id);
                Assert.AreEqual(violation.permit_id, check_single_vio.permit_id);
                Assert.AreEqual(violation.fee, check_single_vio.fee);
                Assert.AreEqual(violation.paid, check_single_vio.paid);
                Assert.AreEqual(violation.v_description, check_single_vio.v_description);
                Assert.AreEqual(violation.violation_date, check_single_vio.violation_date);
                foreach (Violation v in check)
                {
                    Assert.AreEqual(violation.permit_id, v.permit_id);
                    Assert.AreEqual(violation2.permit_id, v.permit_id);
                    if (v.violation_id == violation.violation_id)
                    {
                        //Assert.AreEqual(violation.violation_id, v.violation_id);
                        Assert.AreEqual(violation.fee, v.fee);
                        Assert.AreEqual(violation.paid, v.paid);
                        Assert.AreEqual(violation.v_description, v.v_description);
                        Assert.AreEqual(violation.violation_date, v.violation_date);
                        pass = true;
                    }
                    if (v.violation_id == violation2.violation_id)
                    {
                        //Assert.AreEqual(violation.violation_id, v.violation_id);
                        Assert.AreEqual(violation2.fee, v.fee);
                        Assert.AreEqual(violation2.paid, v.paid);
                        Assert.AreEqual(violation2.v_description, v.v_description);
                        Assert.AreEqual(violation2.violation_date, v.violation_date);
                        pass = true;
                    }
                }
                Assert.AreEqual(true, pass);
            }
        }
        public void ListViolationsTest()
        {
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                Customer customer = new Customer();
                customer.customer_name = "create record test";
                customer.customer_pw = "test";
                customer.customer_type = "test";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                customer.customer_id = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "create record test";
                permit.customer_type = "test";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                record.permit_id = DALRecords.CreatePermit(record, ref errors);
                Record r_check = DALRecords.GetPermitInfo(customer.customer_id, ref errors);

                Violation violation = new Violation();
                violation.permit_id = record.permit_id;
                violation.fee = 48;
                violation.v_description = "testing create violations - test1";
                violation.violation_date = DateTime.Parse("11/11/2011");
                violation.paid = false;
                violation.violation_id = DALViolations.CreateViolation(violation, ref errors);

                Violation violation2 = new Violation();
                violation2.permit_id = record.permit_id;
                violation2.fee = 48;
                violation2.v_description = "testing create violations - test1";
                violation2.violation_date = DateTime.Parse("11/11/2011");
                violation2.paid = false;
                violation2.violation_id = DALViolations.CreateViolation(violation2, ref errors);

                List<Violation> expected_violations = new List<Violation>();
                expected_violations.Add(violation);
                expected_violations.Add(violation2);
                List<Violation> check = DALViolations.ListViolations(ref errors);

                Assert.AreEqual(0, errors.Count);
                for (int i = 0;i<expected_violations.Count;i++)
                {
                    Assert.AreEqual(expected_violations[i].violation_id, check[i].violation_id);
                    Assert.AreEqual(expected_violations[i].permit_id, check[i].permit_id);
                    Assert.AreEqual(expected_violations[i].fee, check[i].fee);
                    Assert.AreEqual(expected_violations[i].violation_date, check[i].violation_date);
                    Assert.AreEqual(expected_violations[i].v_description, check[i].v_description);
                    Assert.AreEqual(expected_violations[i].paid, check[i].paid);
                }
            }
        }
Ejemplo n.º 12
0
        public static List<Permit> GetPermitsList(ref List<string> errors)
        {
            //connections variables and database
            SqlConnection conn = new SqlConnection(connection_string);
            DataSet dS = new DataSet();
            List <Permit> permits = new List<Permit>();
            try
            {
                string strSql = "getPermitsList";
                SqlDataAdapter adapter = new SqlDataAdapter(strSql, conn);
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                adapter.Fill(dS, "result_table");
                foreach (DataRow dr in dS.Tables["result_table"].Rows)
                {
                    Permit permit = new Permit();
                    permit.id = (int)dS.Tables["result_table"].Rows[0]["id"];
                    permit.permit_name = dS.Tables["result_table"].Rows[0]["permit_name"].ToString();
                    permit.customer_type = dS.Tables["result_table"].Rows[0]["customer_type"].ToString();
                    permit.price = (int) dS.Tables["result_table"].Rows[0]["price"];
                    permit.v_description = dS.Tables["result_table"].Rows[0]["v_description"].ToString();
                    permits.Add(permit);

                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
            finally
            {
                conn.Dispose();
                conn = null;
            }
            return permits;
        }
Ejemplo n.º 13
0
        public static void UpdatePermitTable(Permit permit, ref List<String> errors)
        {
            //connections variables and dataset
            SqlConnection conn = new SqlConnection(connection_string);
            try
            {
                string strSql = "updatePermitTable";
                SqlDataAdapter adapter = new SqlDataAdapter(strSql, conn);
                DataSet dS = new DataSet();

                //add parameters to adapter
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@PermitName", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@CustomerType", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Price", SqlDbType.Int));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@VDescription", SqlDbType.VarChar, 300));
                adapter.SelectCommand.Parameters["@PermitName"].Value = permit.permit_name;
                adapter.SelectCommand.Parameters["@CustomerType"].Value = permit.customer_type;
                adapter.SelectCommand.Parameters["@Price"].Value = permit.price;
                adapter.SelectCommand.Parameters["@Vdescription"].Value = permit.v_description;

                //fill result to result_table in dataset
                adapter.Fill(dS, "result_table");
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
                //ss
            finally
            {
                conn.Dispose();
                conn = null;
            }
        }
        public void getPermitsBasedOnCustomerTest()
        {
            //connections variables and dataset
            SqlConnection conn = new SqlConnection(connection_string);
            List<string> errors = new List<string>();

            using (var scop = new System.Transactions.TransactionScope())
            {
                //calling the method to be tested against
                Customer customer = new Customer();
                customer.customer_name = "get customerpermit";
                customer.customer_pw = "test";
                customer.customer_type = "type1";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                customer.customer_id = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "get customerpermits";
                permit.customer_type = "type1";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Customer customer2 = new Customer();
                customer2.customer_name = "get customerpermit2";
                customer2.customer_pw = "test";
                customer2.customer_type = "type1";
                customer2.first_name = "test";
                customer2.middle_name = "test";
                customer2.last_name = "test";
                customer2.customer_id = DALCustomers.CreateCustomer(customer2, ref errors);

                Permit permit2 = new Permit();
                permit2.permit_name = "get customerpermit2";
                permit2.customer_type = "type1";
                permit2.price = 50;
                permit2.v_description = "test";
                permit2.id = DALPermitTypes.CreatePermitType(permit2, ref errors);

                Permit check = DALCustomers.getPermitsBasedOnCustomer(customer.customer_id, ref errors);
                Permit check2 = DALCustomers.getPermitsBasedOnCustomer(customer2.customer_id, ref errors);

                Assert.AreEqual(0, errors.Count);
                Assert.IsNotNull(check);
                Assert.AreEqual(permit.id, check.id);
                Assert.AreEqual(permit.permit_name, check.permit_name);
                Assert.AreEqual(permit.customer_type, check.customer_type);
                Assert.AreEqual(permit.price, check.price);
                Assert.AreEqual(permit.v_description, check.v_description);
                Assert.IsNotNull(check2);
                Assert.AreEqual(permit.id, check2.id);
                Assert.AreEqual(permit.permit_name, check2.permit_name);
                Assert.AreEqual(permit.customer_type, check2.customer_type);
                Assert.AreEqual(permit.price, check2.price);
                Assert.AreEqual(permit.v_description, check2.v_description);
            }
        }
        public void getCustomerInvoiceHistoryTest()
        {
            //connections variables and dataset
            SqlConnection conn = new SqlConnection(connection_string);
            List<string> errors = new List<string>();
            using (var scop = new System.Transactions.TransactionScope())
            {
                Customer customer = new Customer();
                customer.customer_name = "get customer invoice";
                customer.customer_pw = "test";
                customer.customer_type = "test";
                customer.first_name = "test";
                customer.middle_name = "test";
                customer.last_name = "test";
                customer.customer_id = DALCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "get customer invoice1";
                permit.customer_type = "test";
                permit.price = 50;
                permit.v_description = "test";
                permit.id = DALPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                record.permit_id = DALRecords.CreatePermit(record, ref errors);

                Violation violation1 = new Violation();
                violation1.permit_id = record.permit_id;
                violation1.fee = 48;
                violation1.v_description = "testing create violation1s - test1";
                violation1.violation_date = DateTime.Parse("11/11/2011");
                violation1.paid = true;
                violation1.violation_id = DALViolations.CreateViolation(violation1, ref errors);

                Violation violation2 = new Violation();
                violation2.permit_id = record.permit_id;
                violation2.fee = 100;
                violation2.v_description = "testing create violations - test2";
                violation2.violation_date = DateTime.Parse("11/11/2011");
                violation2.paid = false;
                violation2.violation_id = DALViolations.CreateViolation(violation2, ref errors);

                Invoice invoice1 = new Invoice();
                invoice1.invoice_type = "getcustomerinvoice1";
                invoice1.customer_id = customer.customer_id;
                invoice1.item_id = record.permit_id;
                invoice1.amt_paid = 200;
                invoice1.pay_method = "visa";
                invoice1.pay_date = DateTime.Parse("11/11/2011");
                invoice1.invoice_id = DALInvoices.CreateInvoice(invoice1, ref errors);

                Invoice invoice2 = new Invoice();
                invoice2.invoice_type = "getcustomerinvoie2";
                invoice2.customer_id = customer.customer_id;
                invoice2.item_id = violation1.violation_id;
                invoice2.amt_paid = 200;
                invoice2.pay_method = "visa";
                invoice2.pay_date = DateTime.Parse("11/11/2011");
                invoice2.invoice_id = DALInvoices.CreateInvoice(invoice2, ref errors);

                Invoice invoice3 = new Invoice();
                invoice3.invoice_type = "getcustomerinvoice3";
                invoice3.customer_id = customer.customer_id;
                invoice3.item_id = 500;
                invoice3.amt_paid = 200;
                invoice3.pay_method = "visa";
                invoice3.pay_date = DateTime.Parse("11/11/2011");
                invoice3.invoice_id = DALInvoices.CreateInvoice(invoice3, ref errors);

                List<Invoice> exepectedInvoices = new List<Invoice>();
                exepectedInvoices.Add(invoice1); exepectedInvoices.Add(invoice2); exepectedInvoices.Add(invoice3);
                List<Invoice> check = DALCustomers.getCustomerInvoiceHistory(customer.customer_id, ref errors);
                int index = 0;
                Assert.AreEqual(0, errors.Count);
                foreach (Invoice i in exepectedInvoices)
                {
                    Assert.AreEqual(i.invoice_id, check[index].invoice_id);
                    Assert.AreEqual(i.invoice_type, check[index].invoice_type);
                    Assert.AreEqual(i.customer_id, check[index].customer_id);
                    Assert.AreEqual(i.item_id, check[index].item_id);
                    Assert.AreEqual(i.amt_paid, check[index].amt_paid);
                    Assert.AreEqual(i.pay_method, check[index].pay_method);
                    Assert.AreEqual(i.pay_date, check[index].pay_date);
                    index++;
                }
            }
        }
        public void CreateCustomerTest()
        {
            Customer customer = new Customer();
            List<string> errors = new List<string>();
            customer.customer_name = "bltestcreatecustomer";
            customer.customer_pw = "fakepassword1"; // TODO: Initialize to an appropriate value
            customer.customer_type = "undergrad";
            customer.first_name = "test"; // TODO: Initialize to an appropriate value
            customer.middle_name = "test"; // TODO: Initialize to an appropriate value
            customer.last_name = "test"; // TODO: Initialize to an appropriate value
            Customer check = new Customer();
            using (var scop = new System.Transactions.TransactionScope())
            {
                //insert
                BLCustomers.CreateCustomer(customer, ref errors);
                //check = BLCustomers.GetCustomerInfo(customer.customer_id.ToString(), ref errors);
                check = BLCustomers.CheckCustomerLoginPassword(customer.customer_name, customer.customer_pw, ref errors);
                Assert.AreEqual(0, errors.Count);
                Assert.IsNotNull(check);
                Assert.AreEqual(customer.customer_id, check.customer_id);
                Assert.AreEqual(customer.customer_name, check.customer_name);
                Assert.AreEqual(customer.customer_pw, check.customer_pw);
                Assert.AreEqual(customer.customer_type, check.customer_type);
                Assert.AreEqual(customer.first_name, check.first_name);
                Assert.AreEqual(customer.middle_name, check.middle_name);
                Assert.AreEqual(customer.last_name, check.last_name);

                //update test
                customer.customer_pw = "fakepassword1"; // TODO: Initialize to an appropriate value
                customer.first_name = "updated BL "; // TODO: Initialize to an appropriate value
                customer.middle_name = "updated BL"; // TODO: Initialize to an appropriate value
                customer.last_name = "updated BL"; // TODO: Initialize to an appropriate value
                BLCustomers.UpdateCustomer(customer, ref errors);
                check = BLCustomers.GetCustomerInfo(customer.customer_id.ToString(), ref errors);
                Assert.AreEqual(0, errors.Count);
                Assert.IsNotNull(check);
                Assert.AreEqual(customer.customer_id, check.customer_id);
                Assert.AreEqual(customer.customer_name, check.customer_name);
                Assert.AreEqual(customer.customer_pw, check.customer_pw);
                Assert.AreEqual(customer.customer_type, check.customer_type);
                Assert.AreEqual(customer.first_name, check.first_name);
                Assert.AreEqual(customer.middle_name, check.middle_name);
                Assert.AreEqual(customer.last_name, check.last_name);

                //delete test
                BLCustomers.DeleteCustomer(customer.customer_id.ToString(), ref errors);
                check = BLCustomers.GetCustomerInfo(customer.customer_id.ToString(), ref errors);
                Assert.AreEqual(0, errors.Count);
                Assert.IsNull(check);

                //get record, invoice and violation test
                BLCustomers.CreateCustomer(customer, ref errors);

                Permit permit = new Permit();
                permit.permit_name = "bl customertest";
                permit.customer_type = "undergrad";
                permit.price = 50;
                permit.v_description = "test";
                BLPermitTypes.CreatePermitType(permit, ref errors);

                Record record = new Record();
                record.customer_id = customer.customer_id;
                record.permit_type_id = permit.id;
                record.expire_date = DateTime.Parse("11/11/2011");
                record.valid = true;
                BLRecords.CreatePermit(record, ref errors);

                Invoice invoice1 = new Invoice();
                invoice1.invoice_type = "purchase";
                invoice1.customer_id = customer.customer_id;
                invoice1.item_id = record.permit_id;
                invoice1.amt_paid = 200;
                invoice1.pay_method = "debit";
                invoice1.pay_date = DateTime.Parse("11/11/2011");
                BLInvoices.CreateInvoice(invoice1, ref errors);

                Violation violation = new Violation();
                violation.permit_id = record.permit_id;
                violation.fee = 48;
                violation.v_description = "testing create violations - test1";
                violation.violation_date = DateTime.Parse("11/11/2011");
                violation.paid = false;
                BLViolations.CreateViolation(violation, ref errors);

                Invoice invoice2 = new Invoice();
                invoice2.invoice_type = "violation";
                invoice2.customer_id = customer.customer_id;
                //invoice2.item_id = violation.violation_id;
                invoice2.item_id = 500;
                invoice2.amt_paid = 220;
                invoice2.pay_method = "debit";
                invoice2.pay_date = DateTime.Parse("11/11/2011");
                BLInvoices.CreateInvoice(invoice2, ref errors);

                List<Violation> expected_violations = new List<Violation>();
                expected_violations.Add(violation);
                List<Violation> violations = BLViolations.GetCustomerViolations(record.customer_id.ToString(), ref errors);
                for (int index = 0; index < expected_violations.Count; index++)
                {
                    Assert.AreEqual(violations[index].permit_id, expected_violations[index].permit_id);
                    Assert.AreEqual(violations[index].fee, expected_violations[index].fee);
                    Assert.AreEqual(violations[index].v_description, expected_violations[index].v_description);
                    Assert.AreEqual(violations[index].violation_date, expected_violations[index].violation_date);
                    Assert.AreEqual(violations[index].paid, expected_violations[index].paid);
                }
                List<Invoice> expected_invoices = new List<Invoice>();
                expected_invoices.Add(invoice1);
                expected_invoices.Add(invoice2);
                List<Invoice> invoices = new List<Invoice>();
                invoices = BLCustomers.GetCustomerInvoiceHistory(customer.customer_id.ToString(), ref errors);

                Assert.AreEqual(0, errors.Count);
                for (int index = 0; index < expected_invoices.Count; index++)
                {
                    Assert.AreEqual(expected_invoices[index].invoice_id, invoices[index].invoice_id);
                    Assert.AreEqual(expected_invoices[index].invoice_type, invoices[index].invoice_type);
                    Assert.AreEqual(expected_invoices[index].customer_id, invoices[index].customer_id);
                    Assert.AreEqual(expected_invoices[index].item_id, invoices[index].item_id);
                    Assert.AreEqual(expected_invoices[index].amt_paid, invoices[index].amt_paid);
                    Assert.AreEqual(expected_invoices[index].pay_method, invoices[index].pay_method);
                    Assert.AreEqual(expected_invoices[index].pay_date, invoices[index].pay_date);
                }

                //update record and invoice test
                record.valid = false;
                BLRecords.UpdateRecordTable(record, ref errors);
                violation.fee = 250;
                violation.paid = true;
                BLViolations.UpdateAmountViolation(violation, ref errors);
                BLViolations.UpdatePayViolation(violation.violation_id.ToString(), ref errors);

                expected_violations = new List<Violation>();
                expected_violations.Add(violation);
                violations = BLViolations.GetCustomerViolations(record.customer_id.ToString(), ref errors);
                for (int index = 0; index < expected_violations.Count; index++)
                {
                    Assert.AreEqual(violations[index].permit_id, expected_violations[index].permit_id);
                    Assert.AreEqual(violations[index].fee, expected_violations[index].fee);
                    Assert.AreEqual(violations[index].v_description, expected_violations[index].v_description);
                    Assert.AreEqual(violations[index].violation_date, expected_violations[index].violation_date);
                    Assert.AreEqual(violations[index].paid, expected_violations[index].paid);
                }

                //update invoice test
                invoice2.amt_paid = 110;
                invoice2.pay_method = "credit";
                invoice2.pay_date = DateTime.Parse("12/11/2011");
                BLInvoices.UpdateInvoiceTable(invoice2, ref errors);

                expected_invoices = new List<Invoice>();
                expected_invoices.Add(invoice1);
                expected_invoices.Add(invoice2);
                invoices = new List<Invoice>();
                invoices = BLCustomers.GetCustomerInvoiceHistory(customer.customer_id.ToString(), ref errors);

                Assert.AreEqual(0, errors.Count);
                for (int index = 0; index < expected_invoices.Count; index++)
                {
                    Assert.AreEqual(expected_invoices[index].invoice_id, invoices[index].invoice_id);
                    Assert.AreEqual(expected_invoices[index].invoice_type, invoices[index].invoice_type);
                    Assert.AreEqual(expected_invoices[index].customer_id, invoices[index].customer_id);
                    Assert.AreEqual(expected_invoices[index].item_id, invoices[index].item_id);
                    Assert.AreEqual(expected_invoices[index].amt_paid, invoices[index].amt_paid);
                    Assert.AreEqual(expected_invoices[index].pay_method, invoices[index].pay_method);
                    Assert.AreEqual(expected_invoices[index].pay_date, invoices[index].pay_date);
                }

                //getpermit based on customer level test
                System.Diagnostics.Debug.WriteLine(customer.customer_id);
                Permit check_permit = BLPermitTypes.GetPermitsBasedOnCustomer(record.customer_id.ToString(), ref errors);
                Assert.AreEqual(0, errors.Count);
                Assert.AreEqual(permit.id, check_permit.id);
                Assert.AreEqual(permit.permit_name, check_permit.permit_name);
                Assert.AreEqual(permit.customer_type, check_permit.customer_type);
                Assert.AreEqual(permit.price, check_permit.price);
                Assert.AreEqual(permit.v_description, check_permit.v_description);

                //getpermit list
                List<Permit> permits = BLPermitTypes.GetPermitsList(ref errors);
                Assert.AreEqual(1, permits.Count);

            }
        }