Exemple #1
0
        public void Step_15_Insert_Child_Collection()
        {
            Console.WriteLine("15. Testing insert on child collections in a category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(category.Products.Count == 0);

            Product product = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 1);

            product.ProductId   = TestProductID;
            product.Name        = TestUtility.Instance.RandomString(80, false);
            product.Description = TestUtility.Instance.RandomString(255, false);
            product.Image       = TestUtility.Instance.RandomString(80, false);

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

            Category category2 = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(category.Products.Count == category2.Products.Count);
            Assert.IsTrue(category.CategoryId == category2.Products[0].CategoryId);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #2
0
        public void Step_23_Concurrency_Duplicate_Update()
        {
            Console.WriteLine("23. Updating the category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);
            var      name     = category.Name;
            var      desc     = category.Description;

            category.Name        = TestUtility.Instance.RandomString(80, false);
            category.Description = TestUtility.Instance.RandomString(255, false);

            Category category2 = Category.GetByCategoryId(TestCategoryID);

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

            Assert.IsFalse(string.Equals(category.Name, name, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsFalse(string.Equals(category.Description, desc, StringComparison.InvariantCultureIgnoreCase));

            category2.Name        = TestUtility.Instance.RandomString(80, false);
            category2.Description = TestUtility.Instance.RandomString(255, false);

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

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #3
0
        public void Step_21_Double_Delete()
        {
            Console.WriteLine("20. Deleting the category twice.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsFalse(category.IsDeleted);
            category.Delete();

            Assert.IsTrue(category.IsDeleted);

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

            Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsFalse(category.IsDeleted);

            category.Delete();

            // Shouldn't be able to call delete twice. I'd think.
            Assert.IsTrue(category.IsDeleted);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
            category = category.Save();

            Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsTrue(category.IsNew);
            Assert.IsFalse(category.IsDeleted);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #4
0
        public void Step_18_Update_PK_Of_Child_Collection()
        {
            Console.WriteLine("18. Testing update of PK on child collections in a category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(category.Products.Count == 0);

            Product product = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 1);

            product.ProductId   = TestProductID;
            product.Name        = TestUtility.Instance.RandomString(80, false);
            product.Description = TestUtility.Instance.RandomString(255, false);
            product.Image       = TestUtility.Instance.RandomString(80, false);

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

            category.CategoryId = TestCategoryID2;

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

            Category category2 = Category.GetByCategoryId(TestCategoryID2);

            Assert.IsTrue(category2.Products.Count == 1);
            Assert.IsTrue(string.Equals(category2.Products[0].CategoryId, category.CategoryId, StringComparison.InvariantCultureIgnoreCase));

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

            Console.WriteLine("\tGetting category \"{0}\"", TestCategoryID);
            Category category = Category.GetByCategoryId(TestCategoryID);

            category.CategoryId = TestCategoryID2;

            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
            category = category.Save();
            Console.WriteLine("\tSet categoryID to \"{0}\"", TestCategoryID2);
            Assert.IsTrue(category.CategoryId == TestCategoryID2);

            try
            {
                Category.GetByCategoryId(TestCategoryID);
                Assert.Fail("Record exists when it should have been updated.");
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }

            Category validCategory = Category.GetByCategoryId(TestCategoryID2);

            Assert.IsTrue(validCategory.CategoryId == TestCategoryID2);
            Console.WriteLine("\tPrimaryKey has been updated.");

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #6
0
        public void Step_04_Update()
        {
            Console.WriteLine("4. Updating the category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);
            var      name     = category.Name;
            var      desc     = category.Description;

            category.Name        = TestUtility.Instance.RandomString(80, false);
            category.Description = TestUtility.Instance.RandomString(255, false);

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

            Assert.IsFalse(string.Equals(category.Name, name, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsFalse(string.Equals(category.Description, desc, StringComparison.InvariantCultureIgnoreCase));

            category.Name        = name;
            category.Description = desc;

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

            Assert.IsTrue(string.Equals(category.Name, name, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsTrue(string.Equals(category.Description, desc, StringComparison.InvariantCultureIgnoreCase));

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #7
0
        public void Step_10_Existing_Entity_With_No_Collection()
        {
            Console.WriteLine("10. Testing child collections on a category with no child collection items.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);
            var      count    = category.Products.Count;

            Assert.IsTrue(count == 0);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #8
0
        public void Step_24_Concurrency_Update_Children()
        {
            Console.WriteLine("24. Testing update on child collections in a category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(category.Products.Count == 0);

            Product product = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 1);

            product.ProductId   = TestProductID;
            product.Name        = TestUtility.Instance.RandomString(80, false);
            product.Description = TestUtility.Instance.RandomString(255, false);
            product.Image       = TestUtility.Instance.RandomString(80, false);

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

            Category category2 = Category.GetByCategoryId(TestCategoryID);

            var newName = TestUtility.Instance.RandomString(80, false);

            foreach (Product item in category.Products)
            {
                item.Name = newName;
            }

            foreach (Product item in category2.Products)
            {
                item.Name = newName;
            }

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

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

            Assert.IsTrue(string.Equals(category2.Products[0].Name, newName, StringComparison.InvariantCultureIgnoreCase));

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #9
0
        public void Step_05_Delete()
        {
            Console.WriteLine("5. Deleting the category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            category.Delete();

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

            Assert.IsTrue(category.IsNew);
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #10
0
        public void Step_22_Double_Delete()
        {
            Console.WriteLine("20. Deleting the category twice.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase));
            Assert.IsFalse(category.IsDeleted);
            category.Delete();

            //Delete the category the other way before calling save which would call a delete. This should simulate a concurency issue.
            Category.DeleteCategory(TestCategoryID);
            try
            {
                Category.GetByCategoryId(TestCategoryID);
                Assert.Fail("Record exists when it should have been deleted.");
            }
            catch (Exception)
            {
                // Exception was thrown if record doesn't exist.
                Assert.IsTrue(true);
            }

            // Call delete on an already deleted item.
            Assert.IsTrue(category.IsDeleted);

            try
            {
                Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
                category = category.Save();
                Assert.Fail("Record exists when it should have been deleted.");
            }
            catch (Exception)
            {
                // Exception was thrown if record doesn't exist.
                Assert.IsTrue(true);
            }

            Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase));
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #11
0
        public void Step_20_Insert_Duplicate_Item_In_Child_Collection()
        {
            Console.WriteLine("20. Testing insert of a duplicate Product into a child collections.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.GetByCategoryId(TestCategoryID);

            Assert.IsTrue(category.Products.Count == 0);

            Product product = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 1);

            product.ProductId   = TestProductID;
            product.Name        = TestUtility.Instance.RandomString(80, false);
            product.Description = TestUtility.Instance.RandomString(255, false);
            product.Image       = TestUtility.Instance.RandomString(80, false);

            Product product2 = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 2);

            product2.ProductId   = TestProductID;
            product2.Name        = TestUtility.Instance.RandomString(80, false);
            product2.Description = TestUtility.Instance.RandomString(255, false);
            product2.Image       = TestUtility.Instance.RandomString(80, false);

            try
            {
                Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
                category = category.Save();
                Assert.Fail("Should throw a duplicate entry exception.");
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Exemple #12
0
        public void Step_16_Update_Child_Collection_On_New_Category()
        {
            Console.WriteLine("16. Testing update on new child collections in a new category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.NewCategory();

            category.CategoryId  = TestCategoryID2;
            category.Name        = TestUtility.Instance.RandomString(80, false);
            category.Description = TestUtility.Instance.RandomString(255, false);

            Assert.IsTrue(category.Products.Count == 0);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            Product product = category.Products.AddNew();

            Assert.IsTrue(category.Products.Count == 1);

            product.ProductId   = TestProductID;
            product.Name        = TestUtility.Instance.RandomString(80, false);
            product.Description = TestUtility.Instance.RandomString(255, false);
            product.Image       = TestUtility.Instance.RandomString(80, false);

            var newName = TestUtility.Instance.RandomString(80, false);

            foreach (Product item in category.Products)
            {
                item.Name = newName;
            }

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

            Category category2 = Category.GetByCategoryId(TestCategoryID2);

            Assert.IsTrue(string.Equals(category2.Products[0].Name, newName, StringComparison.InvariantCultureIgnoreCase));

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