コード例 #1
0
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);

            try
            {
                Customer customer = dbc.GetRandomCustomer();

                Log(customer.ToString());

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = customer;

                Log(order.ToString());

                dbc.AddOrder(order);

                Order result = dbc.GetOrder(order.OrderId);
                if (result == null)
                {
                    Fail("Failed to insert new Order record");
                    return;
                }
                else if (!order.Equals(result))
                {
                    Fail("Inserted Order record having inconsistent data");
                    return;
                }

                order          = (Order)ObjectFactory.Create(ObjectType.Order);
                order.OrderId  = result.OrderId;
                order.Customer = customer;
                dbc.UpdateOrder(order);

                result = dbc.GetOrder(order.OrderId);
                if (!order.Equals(result))
                {
                    Fail("Failed to update Order record");
                    return;
                }

                dbc.DeleteOrder(order.OrderId);
                if (dbc.GetOrder(order.OrderId) != null)
                {
                    Fail("Failed to delete Order record");
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
コード例 #2
0
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);

            try
            {
                Customer customer = dbc.GetRandomCustomer();

                Log(customer.ToString());

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = customer;

                Log(order.ToString());

                dbc.AddOrder(order);

                Order result = dbc.GetOrder(order.OrderId);
                if (result == null)
                {
                    Fail("Failed to insert new Order record");
                    return;
                }
                else if (!order.Equals(result))
                {
                    Fail("Inserted Order record having inconsistent data");
                    return;
                }

                order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.OrderId = result.OrderId;
                order.Customer = customer;
                dbc.UpdateOrder(order);

                result = dbc.GetOrder(order.OrderId);
                if (!order.Equals(result))
                {
                    Fail("Failed to update Order record");
                    return;
                }

                dbc.DeleteOrder(order.OrderId);
                if (dbc.GetOrder(order.OrderId) != null)
                    Fail("Failed to delete Order record");
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
コード例 #3
0
        public override void Run(object context)
        {
            DbController           dbc      = new DbController(Connection);
            IList <BusinessObject> bObjects = new List <BusinessObject>();

            try
            {
                Connection.AutoCommit = false;
                Connection.BeginGFXDTransaction();

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = dbc.GetRandomCustomer();
                dbc.AddOrder(order);

                IList <Product> products = dbc.GetRandomProducts(5);
                foreach (Product product in products)
                {
                    OrderDetail ordDetail = new OrderDetail();
                    ordDetail.OrderId   = order.OrderId;
                    ordDetail.ProductId = product.ProductId;
                    ordDetail.UnitPrice = product.RetailPrice;
                    ordDetail.Quantity  = DbHelper.GetRandomNumber(1);
                    ordDetail.Discount  = 0;

                    dbc.AddOrderDetail(ordDetail);
                    bObjects.Add(ordDetail);

                    product.UnitsInStock -= ordDetail.Quantity;
                    dbc.UpdateProduct(product);

                    order.SubTotal += (ordDetail.UnitPrice * ordDetail.Quantity);
                }

                dbc.UpdateOrder(order);
                bObjects.Add(order);

                Connection.Commit();

                if (!dbc.ValidateTransaction(bObjects))
                {
                    Fail(dbc.GetValidationErrors(bObjects));
                }
            }
            catch (Exception e)
            {
                Connection.Rollback();
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
コード例 #4
0
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);
            IList<BusinessObject> bObjects = new List<BusinessObject>();

            try
            {
                Connection.AutoCommit = false;
                Connection.BeginGFXDTransaction();

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = dbc.GetRandomCustomer();
                dbc.AddOrder(order);
                
                IList<Product> products = dbc.GetRandomProducts(5);
                foreach (Product product in products)
                {
                    OrderDetail ordDetail = new OrderDetail();
                    ordDetail.OrderId = order.OrderId;
                    ordDetail.ProductId = product.ProductId;
                    ordDetail.UnitPrice = product.RetailPrice;
                    ordDetail.Quantity = DbHelper.GetRandomNumber(1);
                    ordDetail.Discount = 0;

                    dbc.AddOrderDetail(ordDetail);
                    bObjects.Add(ordDetail);

                    product.UnitsInStock -= ordDetail.Quantity;
                    dbc.UpdateProduct(product);

                    order.SubTotal += (ordDetail.UnitPrice * ordDetail.Quantity);
                }

                dbc.UpdateOrder(order);
                bObjects.Add(order);

                Connection.Commit();

                if (!dbc.ValidateTransaction(bObjects))
                    Fail(dbc.GetValidationErrors(bObjects));
            }
            catch (Exception e)
            {
                Connection.Rollback();
                Fail(e);
            }
            finally
            {                
                base.Run(context);
            }
        }