Exemplo n.º 1
0
        public void GetMenuOptions_ProvideProductsByRepository_ShouldReturnMenuOptions()
        {
            // Arrange:
            var expectedResult = new List <(string OptionName, int Count)>
            {
                ("All category", 6),
                ("A", 1),
                ("B", 2),
                ("C", 3)
            };
            var products = new List <Product>
            {
                new Product {
                    ProductID = 1, Category = expectedResult[2].OptionName
                },
                new Product {
                    ProductID = 2, Category = expectedResult[1].OptionName
                },
                new Product {
                    ProductID = 3, Category = expectedResult[2].OptionName
                },
                new Product {
                    ProductID = 4, Category = expectedResult[3].OptionName
                },
                new Product {
                    ProductID = 5, Category = expectedResult[3].OptionName
                },
                new Product {
                    ProductID = 6, Category = expectedResult[3].OptionName
                }
            };

            var repositoryMock = new Mock <IProductRepository>();

            repositoryMock.SetupGet(repo => repo.Products).Returns(products.AsQueryable());

            var configuartionReaderMock = new Mock <IAppConfigurationReader>();

            configuartionReaderMock.Setup(reader => reader.GetAllCategoryOptionName())
            .Returns(expectedResult.First().OptionName);

            var service = new NavService(repositoryMock.Object, configuartionReaderMock.Object);

            // Act:
            var actualResult = service.GetMenuOptions();

            // Assert:
            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 2
0
        public void GetMenuOptions_CallMethod_ShouldReturnOptionsWhereFirstOptionIsAllCategoryOption()
        {
            // Arrange:
            const string FIRST_OPTION = "All category";

            var configuartionReaderMock = new Mock <IAppConfigurationReader>();

            configuartionReaderMock.Setup(reader => reader.GetAllCategoryOptionName()).Returns(FIRST_OPTION);

            var service = new NavService(new Mock <IProductRepository>().Object, configuartionReaderMock.Object);

            // Act:
            var options = service.GetMenuOptions();

            // Assert:
            Assert.AreEqual(expected: FIRST_OPTION, actual: options.First().OptionName);
        }
Exemplo n.º 3
0
        public void GetMenuOptions_ProvideProductsByRepository_ShouldReturnOptionsInAlphabeticalOrderExceptFirstOption()
        {
            // Arrange:
            var          productsCategories = new string[] { "fedcba", "abcdef", "qwerty", "ac3", "bg4" };
            const string FIRST_OPTION       = "All category";

            var products = new List <Product>
            {
                new Product {
                    ProductID = 1, Category = productsCategories[0]
                },
                new Product {
                    ProductID = 2, Category = productsCategories[1]
                },
                new Product {
                    ProductID = 3, Category = productsCategories[2]
                },
                new Product {
                    ProductID = 4, Category = productsCategories[3]
                },
                new Product {
                    ProductID = 5, Category = productsCategories[4]
                }
            };
            var repositoryMock = new Mock <IProductRepository>();

            repositoryMock.SetupGet(repo => repo.Products).Returns(products.AsQueryable());

            var configuartionReaderMock = new Mock <IAppConfigurationReader>();

            configuartionReaderMock.Setup(reader => reader.GetAllCategoryOptionName()).Returns(FIRST_OPTION);

            var service = new NavService(repositoryMock.Object, configuartionReaderMock.Object);

            // Act:
            var options = service.GetMenuOptions();

            // Assert:
            var actual = options.Select(x => x.OptionName).Skip(1);

            Assert.That(actual, Is.Ordered);
        }