Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }