Esempio n. 1
0
        public void FindProductBrandCategoryModelTest()
        {
            // Tests finding the Brand Category of a product
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // 1 Create a brand category
            var bc    = createBrandCategory(testCompany);
            var error = ProductService.InsertOrUpdateBrandCategory(bc, null, testUser, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // 2 Check it has no brands
            var bbcList  = ProductService.FindBrandBrandCategoriesListItemModel(bc);
            int expected = 0,
                actual   = bbcList.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} categories were found when {expected} were expected");

            // 3 Add a brand
            var brand = createBrand();

            error = ProductService.InsertOrUpdateBrand(brand, testUser, "");
            Assert.IsTrue(!error.IsError, error.Message);

            // 4 Add the brand to the category
            var bbcModel = ProductService.AddBrandToBrandCategory(testCompany, brand, bc);

            Assert.IsTrue(bbcModel != null, "Error: A NULL value was returned when a BrandBrandCategoryModel object was expected");

            // 5 Add some products to the brand and choose one.
            int          numProds = 10;
            int          rnd      = RandomInt(0, numProds - 1);
            ProductModel testProd = null;

            for (int i = 0; i < numProds; i++)
            {
                var prod = createProduct(testCompany, testUser, brand);
                error = ProductService.InsertOrUpdateProduct(prod, testUser, "");
                Assert.IsTrue(!error.IsError, error.Message);
                if (i == rnd)
                {
                    testProd = prod;
                }
            }

            // 6 Get its brand category
            var checkBc = ProductService.FindProductBrandCategoryModel(testCompany.Id, testProd.Id);

            Assert.IsTrue(checkBc != null, "Error: A NULL value was returned when a BrandCategoryModel object was expected");

            // 7 Compare the category with (1)
            bc = ProductService.FindBrandCategoryModel(bc.Id, testCompany, false);
            AreEqual(bc, checkBc);
        }
Esempio n. 2
0
        private BrandCategoryModel createBrandCategoryWithBrands(CompanyModel testCompany, UserModel testUser, int numBrandsToAdd)
        {
            // Create a brand category
            BrandCategoryModel brandCategory = createBrandCategory(testCompany);

            ProductService.InsertOrUpdateBrandCategory(brandCategory, null, testUser, "");

            // Now attach random brands
            var brandList = ProductService.FindBrandListModel(0, 1, PageSize, "").Items;
            int actual    = brandList.Count();

            Assert.IsTrue(actual > 0, $"Error: {actual} Brands were found when 1 or more were expected");

            for (int i = 0; i < numBrandsToAdd; i++)
            {
                int rand = RandomInt(0, brandList.Count() - 1);
                ProductService.AddBrandToBrandCategory(testCompany, brandList[rand], brandCategory);
                brandList.RemoveAt(rand);       // So we don't try to add the same item again
            }

            return(brandCategory);
        }
Esempio n. 3
0
        public void FindProductsForBrandCategoryListItemModelTest()
        {
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);

            // Create a new BrandCatgeory
            var brandCategory = createBrandCategory(testCompany);
            var error         = ProductService.InsertOrUpdateBrandCategory(brandCategory, null, user, "");

            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            var model = ProductService.FindProductsForBrandCategoryListItemModel(brandCategory.Id, 0, 0, 1, PageSize, "");

            int expected = 0,
                actual   = model.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");

            // Add some brands to the BrandCategory
            int rnd,
                numBrands   = 16,
                numProducts = 0;
            var brands      = ProductService.FindBrandListModel(0, 1, PageSize, "");

            for (int i = 0; i < numBrands; i++)
            {
                rnd = RandomInt(0, brands.Items.Count());

                var tempBrand = brands.Items[rnd];

                ProductService.AddBrandToBrandCategory(testCompany, tempBrand, brandCategory);
                numProducts += ProductService.FindProductsForBrandModel(tempBrand.Id, "", Enumerations.SortOrder.Asc, true).Count();

                brands.Items.RemoveAt(rnd);     // So we don't add the same brand again
            }

            model = ProductService.FindProductsForBrandCategoryListItemModel(brandCategory.Id, 0, 0, 1, 100000, "");

            expected = numProducts;
            actual   = model.Count();
            Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");

            // Remove some brands from the BrandCategory
            var categoryBrands = db.FindBrandCategory(brandCategory.Id)
                                 .BrandBrandCategories
                                 .ToList();

            for (int i = 0; i < categoryBrands.Count(); i++)
            {
                var tempCatBrand = categoryBrands[i];

                var bm = ProductService.FindBrandModel(tempCatBrand.BrandId);
                ProductService.DeleteBrandFromBrandCategory(bm, brandCategory);

                expected -= ProductService.FindProductsForBrandModel(tempCatBrand.BrandId, "", Enumerations.SortOrder.Asc, true).Count();

                model  = ProductService.FindProductsForBrandCategoryListItemModel(brandCategory.Id, 0, 0, 1, 100000, "");
                actual = model.Count();
                Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");
            }
        }