예제 #1
0
        public void GetSubCategoryFaker_AmountLessThanMaxSubCategoryAmount_ShouldKeepItsAmount()
        {
            var subCategories = SubCategoryFaker.GetSubCategoryList(4);

            _output.WriteLine(JsonConvert.SerializeObject(subCategories, Formatting.Indented));

            Assert.Equal(4, subCategories.Count);
        }
예제 #2
0
        public void GetSubCategoryFaker_AmountBeyondMaxSubCategory_ShouldBeFallBackToMaxSubCategoryAmount()
        {
            var subCategories = SubCategoryFaker.GetSubCategoryList(100);

            _output.WriteLine(JsonConvert.SerializeObject(subCategories, Formatting.Indented));

            Assert.Equal(55, subCategories.Count);
        }
예제 #3
0
        public void GetSubCategoryFaker_CategoryId_ShouldBelessThanMaxCategoryNumbers()
        {
            var subCategories = SubCategoryFaker.GetSubCategoryList(100);

            _output.WriteLine(JsonConvert.SerializeObject(subCategories, Formatting.Indented));

            var result = subCategories.All(s => (int)s.CategoryId <= 10);

            Assert.True(result);
        }
예제 #4
0
        public void GetSubCategoryFaker_CategoryId_ShouldMatchWithCategoryFakerId()
        {
            var subCategories = SubCategoryFaker.GetSubCategoryList(100);

            _output.WriteLine(JsonConvert.SerializeObject(subCategories, Formatting.Indented));

            var isCategoryIdEqual = subCategories.All(s => s.CategoryId == s.Category.Id);

            Assert.True(isCategoryIdEqual);
        }
예제 #5
0
        public void GetSubCategoryFaker_AllCategoryId_ShouldBeIncluded()
        {
            int totalSubCategories = Enum.GetNames(typeof(SubCategoryConstants)).Length;
            var subCategories      = SubCategoryFaker.GetSubCategoryList(totalSubCategories);

            _output.WriteLine(JsonConvert.SerializeObject(subCategories, Formatting.Indented));

            var result = subCategories.GroupBy(s => s.CategoryId).OrderBy(g => g.Key).Select(g => (int)g.Key);
            var totalCategoryNumbers = Enum.GetNames(typeof(CategoryConstants)).Length;
            var categoryIdList       = Enumerable.Range(0, totalCategoryNumbers);

            Assert.Equal(JsonConvert.SerializeObject(result), JsonConvert.SerializeObject(categoryIdList));
        }
예제 #6
0
        public static IList <Product> GetProducts()
        {
            int totalSubCategories = Enum.GetNames(typeof(SubCategoryConstants)).Length;
            var subCategories      = SubCategoryFaker.GetSubCategoryList(totalSubCategories);
            var subImageFaker      = SubImageFaker.GetSubImageFaker();
            var subCategoryId      = 0;

            var productFaker = new Faker <Product>()
                               .RuleFor(p => p.Id, f => Guid.NewGuid().ToString())
                               .RuleFor(p => p.Name, f => f.Commerce.ProductName())
                               .RuleFor(p => p.Description, f => f.Random.Words(f.Random.Number(1, 400)))
                               .RuleFor(p => p.MainImageURL, f => f.Image.PicsumUrl())
                               .RuleFor(p => p.SubImages, f => subImageFaker.Generate(f.Random.Number(0, 4)))
                               .RuleFor(p => p.Price, f => Decimal.Parse(f.Commerce.Price(100m, 100000m), NumberStyles.Currency))
                               .RuleFor(p => p.SubCategory, f =>
            {
                var subCategory = subCategories.Where(c => (int)c.Id == subCategoryId).FirstOrDefault();
                subCategoryId   = (subCategoryId >= totalSubCategories - 1) ? 0 : subCategoryId + 1;
                return(subCategory);
            })
                               .RuleFor(p => p.SubCategoryId, (f, p) => p.SubCategory.Id)
                               .RuleFor(p => p.Reviews, (f, p) => ReviewFaker.GetReviewList(3))
                               .RuleFor(p => p.CreationDate, f => f.Date.Past())
                               .FinishWith((f, p) =>
            {
                // assign product id to each review and subImage entities
                foreach (var review in p.Reviews)
                {
                    review.ProductId = p.Id;
                }

                foreach (var subImage in p.SubImages)
                {
                    subImage.ProductId = p.Id;
                }
            });

            Product SeededProduct(int seed)
            {
                return(productFaker.UseSeed(seed).Generate());
            }

            var products = Enumerable.Range(1, 1)
                           .Select(SeededProduct)
                           .ToList();

            return(products);
        }