Beispiel #1
0
        public void CatalogSettingsFactory_Should_Throw_ArgumentException_If_CategoriesPerPage_IsLessThan_Zero()
        {
            var ex = Assert.Throws <ArgumentException>(() => CatalogSettings.Create(
                                                           -1,
                                                           10,
                                                           CatalogSettings.ViewType.LIST,
                                                           CatalogSettings.ViewType.LIST
                                                           ));

            Assert.Equal("category per page cannot be less than zero", ex.Message);
        }
Beispiel #2
0
        public void SetProductsPerPage_Should_Throw_ArgumentException_If_ProductsPerPage_IsLessThan_Zero()
        {
            var settings = CatalogSettings.Create(
                10,
                10,
                CatalogSettings.ViewType.LIST,
                CatalogSettings.ViewType.LIST
                );

            var ex = Assert.Throws <ArgumentException>(() => settings.SetProductsPerPage(-1));

            Assert.Equal("products per page cannot be less than zero", ex.Message);
        }
Beispiel #3
0
        public void SetProductReviewsPerPage_Should_Throw_InvalidOperationException_If_ProductReviews_AreNot_Allowed()
        {
            var settings = CatalogSettings.Create(
                10,
                10,
                CatalogSettings.ViewType.LIST,
                CatalogSettings.ViewType.LIST
                );

            var ex = Assert.Throws <InvalidOperationException>(() => settings.SetProductReviewsPerPage(10));

            Assert.Equal("Reviews not allowed", ex.Message);
        }
Beispiel #4
0
        public async Task <Guid> CreateCatalogSettings(int categoriesPerPage, int productsPerPage, CatalogSettings.ViewType categoriesViewType, CatalogSettings.ViewType productsViewType, bool showPrices, bool allowReviews, int reviewsPerPage)
        {
            try
            {
                var settings = CatalogSettings.Create(categoriesPerPage, productsPerPage, categoriesViewType, productsViewType);
                settings.ShowPrices(showPrices);
                settings.AllowProductReviews(allowReviews);

                if (settings.ProductReviewsAllowed)
                {
                    settings.SetProductReviewsPerPage(reviewsPerPage);
                }

                Repository.Add(settings);
                await Repository.SaveChangesAsync();

                return(settings.Id);
            }
            catch
            {
                throw;
            }
        }