Esempio n. 1
0
        public void Can_Create_Categories()
        {
            // Arrange
            // - create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[] {
                                                new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                                                new Product {ProductID = 2, Name = "P2", Category = "Apples"},
                                                new Product {ProductID = 3, Name = "P3", Category = "Plums"},
                                                new Product {ProductID = 4, Name = "P4", Category = "Oranges"},
                                                });

            // Arrange - create the controller
            NavController target = new NavController(mock.Object);

            // Act = get the set of categories
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            // Assert
            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Oranges");
            Assert.AreEqual(results[2], "Plums");
        }
        public void Can_Create_Categories()
        {
            // supply test data that does have duplicates and is not in order then pass it to the NavController and assert the data has been cleaned up.

            // arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                new Product {ProductID = 2, Name = "P2", Category = "Apples"},
                new Product {ProductID = 3, Name = "P3", Category = "Plums"},
                new Product {ProductID = 4, Name = "P4", Category = "Oranges"},
                new Product {ProductID = 5, Name = "P5", Category = "Avacados"},
            });

            // arrange = create the controller
            NavController target = new NavController(mock.Object);

            // act = get the set of categoreis
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            // assert = did the controller put them in order and only get distinct?
            Assert.AreEqual(results.Length, 4);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Avacados");
            Assert.AreEqual(results[2], "Oranges");
            Assert.AreEqual(results[3], "Plums");
        }
Esempio n. 3
0
        public void Can_Create_Categories()
        {
            var mockProducts = PrepareProductsForTest();

            NavController controller = new NavController(mockProducts.Object);
            string[] results = ((IEnumerable<string>)controller.Menu().Model).ToArray();

            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Cart1");
            Assert.AreEqual(results[1], "Cart2");
            Assert.AreEqual(results[2], "Cart3");
        }
Esempio n. 4
0
        public void Can_Create_Categories()
        {
            //arrange
            Mock<IProductsRepository> mock = InitializeMock();
            NavController target = new NavController(mock.Object);

            // act
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Oranges");
            Assert.AreEqual(results[2], "Plums");
        }
        public void IndicatesSelectedCategory()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductID = 1, Name = "P1", Category = "Apples"},
                new Product { ProductID = 4, Name = "P2", Category = "Oranges"}
            });

            NavController controller = new NavController(mock.Object);
            string categoryToSelect = "Apples";

            string results = controller.Menu(categoryToSelect).ViewBag.SelectedCategory;

            Assert.AreEqual(categoryToSelect, results);
        }
        public void Indicates_Selected_Category()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product { ProductID = 1 , Name = "P1", Category = "Jabłka"},
                new Product { ProductID = 4 , Name = "P2", Category = "Pomarańcze" }
            }.AsQueryable());

            NavController target = new NavController(mock.Object);

            string categoryToSelect = "Jabłka";

            string result = target.Menu(categoryToSelect).ViewBag.SelectedCategory;

            Assert.AreEqual(categoryToSelect, result);
        }
Esempio n. 7
0
        public void NavController_MenuAction_ReturningDistinctCategories_FromProductsCollection()
        {
            //Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(products.AsQueryable());
            NavController target = new NavController(mock.Object); // TODO: Initialize to an appropriate value

            //Action
            CategoryListViewModel result = (CategoryListViewModel)target.Menu(null).Model;
            string[] cats = result.Categories.ToArray();

            //Assert
            Assert.IsTrue(cats.Length == 4);
            Assert.AreEqual(cats[0], "Accounting");
            Assert.AreEqual(cats[1], "Computers");
            Assert.AreEqual(cats[2], "Fruit");
        }
Esempio n. 8
0
        public void Menu_GetCategories_Display()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(p => p.Products).Returns(
                new Product [] {
                   new Product {ProductID=1, ProductName="P1", Category=new Category{CategoryID=1, CategoryName="Cat1"}},
                new Product {ProductID=2, ProductName="P2", Category=new Category{CategoryID=2, CategoryName="Cat2"}},
                new Product {ProductID=2, ProductName="P3", Category=new Category{CategoryID=1, CategoryName="Cat1"}},
                new Product {ProductID=2, ProductName="P4", Category=new Category{CategoryID=1, CategoryName="Cat1"}},
                new Product {ProductID=2, ProductName="P5", Category=new Category{CategoryID=2, CategoryName="Cat2"}}
            }.AsQueryable());

            NavController controller = new NavController(mock.Object);
            string[] result = ((IEnumerable<string>)controller.Menu().Model).ToArray();
            Assert.AreEqual(1, result[0]);
            Assert.AreEqual(2, result[1]);
        }
Esempio n. 9
0
        public void Can_Create_Categories()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(GetFruitProductArray());

            NavController target = new NavController(mock.Object);

            // Act
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            // Assert
            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Oranges");
            Assert.AreEqual(results[2], "Plums");
        }
Esempio n. 10
0
 public void Indicates_Selected_Category()
 {
     // Arrange
     // - create the mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     mock.Setup(m => m.Products).Returns(new Product[] {
         new Product {ProductID = 1, Name = "P1", Category = "Apples"},
         new Product {ProductID = 4, Name = "P2", Category = "Oranges"},
     }.AsQueryable());
     // Arrange - create the controller
     NavController target = new NavController(mock.Object);
     // Arrange - define the category to selected
     string categoryToSelect = "Apples";
     // Action
     string result = target.Menu(categoryToSelect).ViewBag.SelectedCategory;
     // Assert
     Assert.AreEqual(categoryToSelect, result);
 }
        public void NavController_Menu_IndicatesSelectedCategory()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Apples" },
                new Product {ProductID = 3, Name = "P3", Category = "Plums" },

            }.AsQueryable());
            NavController controller = new NavController(mock.Object);
            string CategoryToSelect = "Apples";

            // Act
            var result = controller.Menu(CategoryToSelect).ViewBag.SelectedCategory;

            // Assert
            Assert.AreEqual<string>(CategoryToSelect, result);
        }
Esempio n. 12
0
        public void Indicates_Selected_Category()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[] {
               new Product{ ProductID = 1, Name = "P1", Category = "c2"},
               new Product{ ProductID = 2, Name = "P2", Category = "c2"},
               new Product{ ProductID = 3, Name = "P3", Category = "c3"},
               new Product{ ProductID = 4, Name = "P4", Category = "c4"},
               new Product{ ProductID = 5, Name = "P5", Category = "c5"}}.AsQueryable());

            NavController controller = new NavController(mock.Object);

            string categorySelected = "c2";

            string result = controller.Menu(categorySelected).ViewBag.SelectedCategory;

            Assert.AreEqual(categorySelected, result);
        }
Esempio n. 13
0
        public void Can_Create_Categories()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product { ProductId = 1, Name = "P1", Category = "Apples"},
                new Product { ProductId = 2, Name = "P2", Category = "Apples"},
                new Product { ProductId = 3, Name = "P3", Category = "Plums"},
                new Product { ProductId = 4, Name = "P4", Category = "Oranges"},
            });

            NavController controller = new NavController(mock.Object);
            string[] results = ((IEnumerable<string>) controller.Menu().Model).ToArray();

            Assert.AreEqual(3, results.Length);
            Assert.AreEqual("Apples",results[0]);
            Assert.AreEqual("Oranges", results[1]);
            Assert.AreEqual("Plums", results[2]);
        }
Esempio n. 14
0
        public void Can_Create_Categories()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product { ProductID = 1 , Name = "P1", Category = "Jabłka"},
                new Product { ProductID = 2 , Name = "P2", Category = "Jabłka" },
                new Product { ProductID = 3, Name = "P3", Category = "Śliwki" },
                new Product { ProductID = 4, Name = "P4", Category = "Pomarańcze" }
            }.AsQueryable());

            NavController target = new NavController(mock.Object);

            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Jabłka");
            Assert.AreEqual(results[1], "Pomarańcze");
            Assert.AreEqual(results[2], "Śliwki");
        }
Esempio n. 15
0
        public void CanCreateCategories()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product() {Id = 1, Name = "P1", Category = "Jabłka"},
                new Product() {Id = 2, Name = "P2", Category = "Jabłka"},
                new Product() {Id = 3, Name = "P3", Category = "Śliwki"},
                new Product() {Id = 4, Name = "P4", Category = "Pomarańcze"}
            });
            NavController controller = new NavController(mock.Object);

            var viewResult = (PartialViewResult) controller.Menu();
            string[] result = ((IEnumerable<string>) viewResult.Model).ToArray();

            Assert.AreEqual(result.Length, 3);
            Assert.AreEqual(result[0], "Jabłka");
            Assert.AreEqual(result[1], "Pomarańcze");
            Assert.AreEqual(result[2], "Śliwki");
        }
Esempio n. 16
0
        public void Can_Create_Categories()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
            {
                new Product { ProductID = 1, Name = "P1", Category = "Apples" },
                new Product { ProductID = 2, Name = "P2", Category = "Apples" },
                new Product { ProductID = 3, Name = "P3", Category = "Plums" },
                new Product { ProductID = 4, Name = "P4", Category = "Oranges" },
            }.AsQueryable());

            NavController controller = new NavController(mock.Object);

            // Action
            string[] categories = ((IEnumerable<string>)controller.Menu(null).Model).ToArray();

            // Assert
            CollectionAssert.AreEqual(categories, new[] { "Apples", "Oranges", "Plums" });
        }
Esempio n. 17
0
        public void Indicates_Selected_Category()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
            {
                new Product { ProductID = 1, Name = "P1", Category = "Apples" },
                new Product { ProductID = 4, Name = "P2", Category = "Oranges" },
            }.AsQueryable());

            NavController controller = new NavController(mock.Object);

            string categoryToSelect = "Apples";

            // Action
            string selectedCategory = controller.Menu(categoryToSelect).ViewBag.SelectedCategory;

            // Assert
            Assert.AreEqual(categoryToSelect, selectedCategory);
        }
Esempio n. 18
0
        public void CanCreateCategories()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(x => x.Products).Returns(new Product[]
            {
                new Product { ProductID = 1, Category = "Apples", Name = "P1" },
                new Product { ProductID = 2, Category = "Apples", Name = "P2" },
                new Product { ProductID = 3, Category = "Plums", Name = "P3" },
                new Product { ProductID = 4, Category = "Oranges", Name = "P4" }
            });

            NavController target = new NavController(mock.Object);

            IEnumerable<string> results = target.Menu().Model as IEnumerable<string>;

            Assert.AreEqual(3, results.Count());
            Assert.AreEqual("Apples", results.ElementAt(0));
            Assert.AreEqual("Oranges", results.ElementAt(1));
            Assert.AreEqual("Plums", results.ElementAt(2));
        }
Esempio n. 19
0
        public void Can_Create_Categories()
        {
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product { ProductID = 1, Name = "p1", Category = "Apples" },
                new Product { ProductID = 2, Name = "p2", Category = "Apples" },
                new Product { ProductID = 3, Name = "p3", Category = "Plums" },
                new Product { ProductID = 4, Name = "p4", Category = "Oranges" }
            }.AsQueryable());

            NavController target = new NavController(mock.Object);

            String[] results = ((IEnumerable<String>)target.Menu().Model).ToArray();

            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Oranges");
            Assert.AreEqual(results[2], "Plums");
        }
Esempio n. 20
0
        public void Can_Create_Categories()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                new Product {ProductID = 2, Name = "P2", Category = "Apples"},
                new Product {ProductID = 3, Name = "P3", Category = "Plums"},
                new Product {ProductID = 4, Name = "P4", Category = "Oranges"}
            });

            NavController controller = new NavController(mock.Object);

            // Act
            string[] result = ((IEnumerable<string>)controller.Menu().Model).ToArray();

            // Assert
            Assert.AreEqual(result[0], "Apples");
            Assert.AreEqual(result[1], "Oranges");
            Assert.AreEqual(result[2], "Plums");
        }
Esempio n. 21
0
        public void Can_Create_Categories()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product{ProductID = 1, Name="P1", Category="Cat1"},
                new Product{ProductID = 2, Name="P2", Category="Cat1"},
                new Product{ProductID = 3, Name="P3", Category="Cat3"},
                new Product{ProductID = 4, Name="P4", Category="Cat2"}
            }.AsQueryable());

            NavController controller = new NavController(mock.Object);

            string[] result = ((IEnumerable<string>)controller.Menu().Model).ToArray();

            Assert.AreEqual(result.Length, 3);
            Assert.AreEqual(result[0], "Cat1");
            Assert.AreEqual(result[1], "Cat2");
            Assert.AreEqual(result[2], "Cat3");
        }
        public void Can_Create_Categories()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
                                                    {
                                                        new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                                                        new Product {ProductID = 2, Name = "P2", Category = "Apples"},
                                                        new Product {ProductID = 3, Name = "P3", Category = "Plums"},
                                                        new Product {ProductID = 4, Name = "P4", Category = "Oranges"}
                                                    }.AsQueryable());
            NavController target = new NavController(mock.Object);

            // Act
            var results = ((IEnumerable<string>)target.Menu().Model).ToList();

            // Assert
            Assert.AreEqual(3, results.Count);
            Assert.AreEqual("Apples", results[0]);
            Assert.AreEqual("Oranges", results[1]);
            Assert.AreEqual("Plums", results[2]);
        }
Esempio n. 23
0
        public void Generate_Category_List()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[] {
               new Product{ ProductID = 1, Name = "P1", Category = "c2"},
               new Product{ ProductID = 2, Name = "P2", Category = "c2"},
               new Product{ ProductID = 3, Name = "P3", Category = "c3"},
               new Product{ ProductID = 4, Name = "P4", Category = "c4"},
               new Product{ ProductID = 5, Name = "P5", Category = "c5"}}.AsQueryable());

            NavController controller = new NavController(mock.Object);

            string[] categories = ((IEnumerable<string>)controller.Menu().Model).ToArray();

            Assert.AreEqual(4, categories.Length);

            Assert.AreEqual("c2", categories[0]);
            Assert.AreEqual("c3", categories[1]);
            Assert.AreEqual("c4", categories[2]);
            Assert.AreEqual("c5", categories[3]);
        }
Esempio n. 24
0
        public void Indicates_Selected_Category()
        {
            // Arrange:
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
                {
                    new Product {ProductId =1, Name="P1", Category="Apples"},
                    new Product {ProductId =4, Name="P1", Category="Oranges"}
                }.AsQueryable());

            // Arrange:
            NavController controller = new NavController(mock.Object);

            // Arrange: define the category to be selected.
            string categoryToSelect = "Apples";

            // Act: get the set of categories
            string result = controller.Menu(categoryToSelect).ViewBag.SelectedCategory;

            // Assert:
            Assert.AreEqual(result,categoryToSelect);
        }
Esempio n. 25
0
        public void Can_Create_Categories()
        {
            // Arrange:
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
                {
                    new Product {ProductId =1, Name="P1", Category="Apples"},
                    new Product {ProductId =1, Name="P1", Category="Oranges"},
                    new Product {ProductId =1, Name="P1", Category="Apples"},
                    new Product {ProductId =1, Name="P1", Category="Grapes"}
                }.AsQueryable());

            // Arrange:
            NavController controller = new NavController(mock.Object);

            // Act: get the set of categories
            var results = controller.Menu().Model as IEnumerable<string>;

            // Assert:
            Assert.IsNotNull(results);
            Assert.AreEqual(results.Count(), 3);
        }
Esempio n. 26
0
        public void Can_Create_Categories()
        {
            //arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                new Product {ProductID = 2, Name = "P2", Category = "Bananas"},
                new Product {ProductID = 3, Name = "P3", Category = "Oranges"},
                new Product {ProductID = 4, Name = "P4", Category = "Oranges"},
                new Product {ProductID = 5, Name = "P5", Category = "Bananas"}
                }.AsQueryable());

            //arrange
            NavController target = new NavController(mock.Object);

            //act
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            //assert
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Bananas");
            Assert.AreEqual(results[2], "Oranges");
        }
        public void Can_Create_Categories()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product(){ProductID = 1, Name = "p1", Category = "Apples"},
                new Product(){ProductID = 2, Name = "p2", Category = "Apples"},
                new Product(){ProductID = 3, Name = "p3", Category = "Plums"},
                new Product(){ProductID = 4, Name = "p4", Category = "Plums"},
                new Product(){ProductID = 5, Name = "p5", Category = "Oranges"}
            }.AsQueryable());

            NavController controller = new NavController(mock.Object);

            // Act
            string[] results = ((IEnumerable<string>)controller.Menu().Model).ToArray();

            // Assert
            Assert.AreEqual(3, results.Length);
            Assert.AreEqual("Apples", results[0]);
            Assert.AreEqual("Oranges", results[1]);
            Assert.AreEqual("Plums", results[2]);
        }
        public void Can_Create_Categories()
        {
            //Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1", Category = "Apples"},
                new Product {ProductID = 2, Name = "P2", Category = "Apples"},
                new Product {ProductID = 3, Name = "P3", Category = "Plums"},
                new Product {ProductID = 4, Name = "P4", Category = "Oranges"}
            }.AsQueryable());

            NavController target = new NavController(mock.Object);

            //Act
            string[] result = ((IEnumerable<string>)target.Menu().Model).ToArray();

            //Assert
            Assert.AreEqual(result.Length, 3);

            Assert.IsTrue(result[0] == "Apples","check for Apples");
            Assert.IsTrue(result[1] == "Oranges", "check for Oranges");
            Assert.IsTrue(result[2] == "Plums", "check for Plums");
        }
Esempio n. 29
0
        public void Menu_SelectedCategoryID_Display()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(p => p.Products).Returns(
                new Product[] {
                   new Product {ProductID=1, ProductName="P1", Category=new Category{CategoryID=1}},
                new Product {ProductID=2, ProductName="P2", Category=new Category{CategoryID=1}},
                new Product {ProductID=2, ProductName="P3", Category=new Category{CategoryID=2}},
                new Product {ProductID=2, ProductName="P4", Category=new Category{CategoryID=1}},
                new Product {ProductID=2, ProductName="P5", Category=new Category{CategoryID=2}}
            }.AsQueryable());

            string selectedCategory = "Cat1";
            NavController controller = new NavController(mock.Object);
            Assert.AreEqual(2, (string)controller.Menu(selectedCategory).ViewBag.SelectedCategoryID);
        }
Esempio n. 30
0
        public void Indicates_Selected_Category()
        {
            //Arrange
            Mock<IProductRepository> mock=new Mock<IProductRepository>();
            mock.Setup(m=>m.Products).Returns(new Product[]
            {
                new Product{ProductID = 1,Name = "P1",Category = "Apples"},
                new Product{ProductID = 2, Name = "P2", Category = "Oranges"} 
            });
            NavController target=new NavController(mock.Object);
            string categoryToSelect = "Apples";

            //Act
            string result = target.Menu(categoryToSelect).ViewBag.SelectedCategory;

            //Assert
            Assert.AreEqual(categoryToSelect,result);
        }