Exemplo n.º 1
0
        public void Step_04_Update()
        {
            Console.WriteLine("4. Updating the lineItem.");
            Stopwatch watch = Stopwatch.StartNew();

            LineItem lineItem  = LineItem.GetByOrderId(LineItemOrderID);
            var      quantity  = lineItem.Quantity;
            var      unitPrice = lineItem.UnitPrice;

            lineItem.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            Assert.IsFalse(lineItem.Quantity == quantity);
            Assert.IsFalse(lineItem.UnitPrice == unitPrice);

            lineItem.Quantity  = quantity;
            lineItem.UnitPrice = unitPrice;

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            Assert.IsTrue(lineItem.Quantity == quantity);
            Assert.IsTrue(lineItem.UnitPrice == unitPrice);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
        public void Step_08_Concurrency_Duplicate_Update()
        {
            Console.WriteLine("8. Updating the lineItem.");
            Stopwatch watch = Stopwatch.StartNew();

            LineItem lineItem  = LineItem.GetByOrderId(LineItemOrderID);
            LineItem lineItem2 = LineItem.GetByOrderId(LineItemOrderID);
            var      quantity  = lineItem.Quantity;
            var      unitPrice = lineItem.UnitPrice;

            lineItem.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            lineItem2.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem2.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            try
            {
                lineItem2 = lineItem2.Save();
                Assert.Fail("Concurrency exception should have been thrown.");
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemplo n.º 3
0
        public void Step_06_UpdatePrimaryKey()
        {
            Console.WriteLine("6. Updating the non Identity Primary Key.");
            Stopwatch watch = Stopwatch.StartNew();

            Console.WriteLine("\tGetting lineItem \"{0}\"", LineItemOrderID);
            LineItem lineItem = LineItem.GetByOrderId(LineItemOrderID);

            lineItem.OrderId = LineItemOrderID2;
            lineItem         = lineItem.Save();
            Console.WriteLine("\tSet lineItemID to \"{0}\"", LineItemOrderID2);
            Assert.IsTrue(lineItem.OrderId == LineItemOrderID2);

            try
            {
                LineItem.GetByOrderId(LineItemOrderID);
                Assert.Fail("Record exists when it should have been updated.");
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }

            LineItem validLineItem = LineItem.GetByOrderId(LineItemOrderID2);

            Assert.IsTrue(validLineItem.OrderId == LineItemOrderID2);
            Console.WriteLine("\tPrimaryKey has been updated.");

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public void Step_01_Insert_Duplicate()
        {
            Console.WriteLine("1. Testing Duplicate Records.");
            Stopwatch watch = Stopwatch.StartNew();

            //Insert should fail as there should be a duplicate key.
            LineItem lineItem = LineItem.NewLineItem();

            lineItem.OrderId   = LineItemOrderID;
            lineItem.LineNum   = TestUtility.Instance.RandomNumber();
            lineItem.ItemId    = TestUtility.Instance.RandomString(10, false);
            lineItem.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            try
            {
                Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
                lineItem = lineItem.Save();

                // Fail as a duplicate record was entered.
                Assert.Fail("Fail as a duplicate record was entered and an exception was not thrown.");
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemplo n.º 5
0
        public void Step_05_Delete()
        {
            Console.WriteLine("5. Deleting the lineItem.");
            Stopwatch watch = Stopwatch.StartNew();

            LineItem lineItem = LineItem.GetByOrderId(LineItemOrderID);

            lineItem.Delete();

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            Assert.IsTrue(lineItem.IsNew);
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemplo n.º 6
0
        private void CreateLineItem(int orderID, int lineNum)
        {
            LineItem lineItem = LineItem.NewLineItem();

            lineItem.OrderId   = orderID;
            lineItem.LineNum   = lineNum;
            lineItem.ItemId    = TestUtility.Instance.RandomString(10, false);
            lineItem.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            Assert.IsTrue(lineItem.OrderId == orderID);
        }
Exemplo n.º 7
0
        public void Step_02_Insert()
        {
            Console.WriteLine("2. Inserting new lineItem.");
            Stopwatch watch = Stopwatch.StartNew();

            LineItem lineItem = LineItem.NewLineItem();

            lineItem.OrderId   = LineItemOrderID;
            lineItem.LineNum   = TestUtility.Instance.RandomNumber();
            lineItem.ItemId    = TestUtility.Instance.RandomString(10, false);
            lineItem.Quantity  = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);

            Assert.IsTrue(lineItem.IsValid, lineItem.BrokenRulesCollection.ToString());
            lineItem = lineItem.Save();

            Assert.IsTrue(true);
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }