Пример #1
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.
            Category category = Category.NewCategory();

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

            try
            {
                Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
                category = category.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);
        }
Пример #2
0
        public void Step_14_Insert_Child_Collection_On_New_Category()
        {
            Console.WriteLine("14. Testing insert on 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);
            Assert.IsTrue(product.IsValid, product.BrokenRulesCollection.ToString());

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

            Category category2 = Category.GetByCategoryId(TestCategoryID2);

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

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #3
0
        public void Step_09_New_Entity_Collection()
        {
            Console.WriteLine("9. Testing child collections on a new category.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.NewCategory();
            var      count    = category.Products.Count;

            Assert.IsTrue(count == 0);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #4
0
        private void CreateCategory(string categoryID)
        {
            Category category = Category.NewCategory();

            category.CategoryId  = categoryID;
            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.IsTrue(category.CategoryId == categoryID);
        }
Пример #5
0
        public void Step_07_Rules()
        {
            Console.WriteLine("7. Testing the state of the rules for the entity.");
            Stopwatch watch = Stopwatch.StartNew();

            Category category = Category.NewCategory();

            Assert.IsFalse(category.IsValid);

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

            category.Name = TestUtility.Instance.RandomString(80, false);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            category.Description = TestUtility.Instance.RandomString(255, false);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            // Check Category.
            category.CategoryId = null;
            Assert.IsFalse(category.IsValid);

            category.CategoryId = TestUtility.Instance.RandomString(11, false);
            Assert.IsFalse(category.IsValid);

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

            // Check Name.
            category.Name = null;
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            category.Name = TestUtility.Instance.RandomString(81, false);
            Assert.IsFalse(category.IsValid);

            category.Name = TestUtility.Instance.RandomString(80, false);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            // Check Description.
            category.Description = null;
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            category.Description = TestUtility.Instance.RandomString(256, false);
            Assert.IsFalse(category.IsValid);

            category.Description = TestUtility.Instance.RandomString(80, false);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #6
0
        public void Step_02_Insert()
        {
            Console.WriteLine("2. Inserting 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.IsValid, category.BrokenRulesCollection.ToString());
            category = category.Save();

            Assert.IsTrue(true);
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #7
0
        public void Step_08_Entity_State()
        {
            Console.WriteLine("8. Checking the state of the entity.");
            Stopwatch watch = Stopwatch.StartNew();

            //Insert should fail as there should be a duplicate key.
            Category category = Category.NewCategory();

            Assert.IsTrue(category.IsDirty);

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

            Assert.IsTrue(category.IsNew);
            Assert.IsTrue(category.IsDirty);
            Assert.IsFalse(category.IsDeleted);

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

            Assert.IsFalse(category.IsNew);
            Assert.IsFalse(category.IsDirty);
            Assert.IsFalse(category.IsDeleted);

            category.Name = TestUtility.Instance.RandomString(80, false);
            Assert.IsTrue(category.IsDirty);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
            category = category.Save();

            Assert.IsFalse(category.IsNew);
            Assert.IsFalse(category.IsDirty);
            Assert.IsFalse(category.IsDeleted);

            category.Delete();
            Assert.IsTrue(category.IsDeleted);
            Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
            category = category.Save();
            Assert.IsFalse(category.IsDeleted);
            Assert.IsTrue(category.IsNew);

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #8
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);
        }