Exemple #1
0
        public async Task <IActionResult> OnGet(
            [FromServices] GetProducts getProducts,
            [FromServices] CountProducts countProducts,
            int p,
            string c)
        {
            bool filter = !string.IsNullOrWhiteSpace(c);
            int  count;

            if (filter)
            {
                count = await countProducts.Do(c);
            }
            else
            {
                count = await countProducts.Do();
            }
            int pages = (int)Math.Ceiling((decimal)count / productsPerPage);

            if (p < 1)
            {
                return(RedirectToPage("Shop", new { p = 1, c }));
            }

            if (pages != 0 && p > pages)
            {
                return(RedirectToPage("Shop", new { p = pages, c }));
            }

            if (filter)
            {
                Products = await getProducts.Do(
                    c,
                    (p - 1) *productsPerPage,
                    productsPerPage);
            }
            else
            {
                Products = await getProducts.Do(
                    (p - 1) *productsPerPage,
                    productsPerPage);
            }

            PageNumber = p;
            PageCount  = pages;

            return(Page());
        }
        public void calculationOfCostTest()
        {
            //Arrange
            var expected = new int[] { 6, 15, 24, 21 };
            int number = 3;
            IProperty stubCost = Substitute.For<IProperty>();
            stubCost.GetCost().Returns(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });

            CountProducts target = new CountProducts();

            //Act
            var actual = target.calculation(number, stubCost);

            //Assert
            CollectionAssert.AreEqual(expected, actual);
        }
        public void calculationOfRevenueTest()
        {
            //Arrange
            var expected = new int[] { 50, 66, 60 };
            int number = 4;

            IProperty stubRevenue = Substitute.For<IProperty>();
            stubRevenue.GetRevenue().Returns(new int[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 });

            CountProducts target = new CountProducts();

            //Act
            var actual = target.calculation(number, stubRevenue);

            //Assert
            CollectionAssert.AreEqual(expected, actual);
        }