Ejemplo n.º 1
0
        public void Step_07_Rules()
        {
            Console.WriteLine("7. Testing the state of the rules for the entity.");
            Stopwatch watch = Stopwatch.StartNew();

            LineItem lineItem = LineItem.NewLineItem();

            Assert.IsFalse(lineItem.IsValid);

            lineItem.OrderId = LineItemOrderID;
            Assert.IsFalse(lineItem.IsValid);

            lineItem.LineNum = TestUtility.Instance.RandomNumber();
            Assert.IsFalse(lineItem.IsValid);

            lineItem.ItemId = TestUtility.Instance.RandomString(10, false);
            Assert.IsTrue(lineItem.IsValid);

            lineItem.Quantity = TestUtility.Instance.RandomNumber(int.MinValue, int.MaxValue);
            Assert.IsTrue(lineItem.IsValid);

            lineItem.UnitPrice = TestUtility.Instance.RandomNumber(0, 500);
            Assert.IsTrue(lineItem.IsValid);

            // Check LineItem.
            lineItem.OrderId = -10; //Doesn't exist so valid should return false.
            Assert.IsFalse(lineItem.IsValid, "This test will fail until we implement exists rule to check fk..");

            lineItem.OrderId = LineItemOrderID;
            Assert.IsFalse(lineItem.IsValid);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }