当前位置: 首页>>代码示例>>C#>>正文


C# Controllers.NavController类代码示例

本文整理汇总了C#中SportsStore.WebUI.Controllers.NavController的典型用法代码示例。如果您正苦于以下问题:C# NavController类的具体用法?C# NavController怎么用?C# NavController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NavController类属于SportsStore.WebUI.Controllers命名空间,在下文中一共展示了NavController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_Create_Categories

        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");
        }
开发者ID:TarRob,项目名称:Learning,代码行数:25,代码来源:UnitTest1.cs

示例2: NavMenu_Includes_Alphabetical_List_Of_Distinct_Categories

        public void NavMenu_Includes_Alphabetical_List_Of_Distinct_Categories()
        {
            // Arrange: Given 4 products in 3 categories in nonalphabetized order
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { Category = "Vegetable", Name = "ProductA" },
                new Product { Category = "Animal", Name = "ProductB" },
                new Product { Category = "Vegetable", Name = "ProductC" },
                new Product { Category = "Mineral", Name = "ProductD" }
            );

            // Act: ... when we render the navigation menu
            var result = new NavController(mockProductsRepository).Menu(null);

            // Assert: ... then the links to categories ...
            var categoryLinks = ((IEnumerable<NavLink>)result.ViewData.Model).Where(x => x.RouteValues["category"] != null);

            // ... are distinct categories in alphabetical order
            CollectionAssert.AreEqual(
                new[] { "Animal", "Mineral", "Vegetable" },             // Expected
                categoryLinks.Select(x => x.RouteValues["category"])    // Actual
            );

            // ... and contain enough information to link to that category
            foreach (var link in categoryLinks)
            {
                link.RouteValues["controller"].ShouldEqual("Products");
                link.RouteValues["action"].ShouldEqual("List");
                link.RouteValues["page"].ShouldEqual(1);
                link.Text.ShouldEqual(link.RouteValues["category"]);
            }
        }
开发者ID:astrateg,项目名称:SportsStore,代码行数:31,代码来源:NavigationByCategory.cs

示例3: Can_Create_Categories

        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");
        }
开发者ID:pixelsyndicate,项目名称:Pro_AspNet_MVC_5_book,代码行数:29,代码来源:PagingUnitTests.cs

示例4: Can_Create_Categories

        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");
        }
开发者ID:PawelHaracz,项目名称:SportsStore,代码行数:12,代码来源:UnitTest1.cs

示例5: Can_Create_Categories

        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");
        }
开发者ID:jvvpabalan,项目名称:SportsStore,代码行数:14,代码来源:UnitTest1.cs

示例6: IndicatesSelectedCategory

        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);
        }
开发者ID:brainiacOnly,项目名称:SportsStore,代码行数:15,代码来源:NavControllerTests.cs

示例7: NavMenu_Shows_Home_Link_At_Top

        public void NavMenu_Shows_Home_Link_At_Top()
        {
            // Arrange: Given any repository
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository();

            // Act: ... when we render the navigation menu
            var result = new NavController(mockProductsRepository).Menu(null);

            // Assert: ... then the top link is to Home
            var topLink = ((IEnumerable<NavLink>)result.ViewData.Model).First();
            topLink.RouteValues["controller"].ShouldEqual("Products");
            topLink.RouteValues["action"].ShouldEqual("List");
            topLink.RouteValues["page"].ShouldEqual(1);
            topLink.RouteValues["category"].ShouldEqual(null);
            topLink.Text.ShouldEqual("Home");
        }
开发者ID:astrateg,项目名称:SportsStore,代码行数:16,代码来源:NavigationByCategory.cs

示例8: NavMenu_Highlights_Current_Category

        public void NavMenu_Highlights_Current_Category()
        {
            // Arrange: Given two categories...
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { Category = "A", Name = "ProductA" },
                new Product { Category = "B", Name = "ProductB" }
            );

            // Act: ... when we render the navigation menu
            var result = new NavController(mockProductsRepository).Menu("B");

            // Assert: ... then only the current category is highlighted
            var highlightedLinks = ((IEnumerable<NavLink>)result.ViewData.Model).Where(x => x.IsSelected).ToList();
            highlightedLinks.Count.ShouldEqual(1);
            highlightedLinks[0].Text.ShouldEqual("B");
        }
开发者ID:astrateg,项目名称:SportsStore,代码行数:16,代码来源:NavigationByCategory.cs

示例9: Indicates_Selected_Category

        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);
        }
开发者ID:akuczynski,项目名称:SportsStore,代码行数:16,代码来源:NavControllerTest.cs

示例10: Menu_GetCategories_Display

        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]);
        }
开发者ID:vinhchung,项目名称:SportsStore,代码行数:17,代码来源:UnitTest1.cs

示例11: NavController_MenuAction_ReturningDistinctCategories_FromProductsCollection

        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");
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:17,代码来源:NavControllerTest.cs

示例12: Can_Create_Categories

        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");
        }
开发者ID:nhebb,项目名称:ProMVC5,代码行数:17,代码来源:UnitTest1.cs

示例13: Indicates_Selected_Category

 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);
 }
开发者ID:tofka,项目名称:Lab-3,代码行数:18,代码来源:NavControllerTest.cs

示例14: NavController_Menu_IndicatesSelectedCategory

        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);
        }
开发者ID:nitzerebbnitzerebb,项目名称:Lab2,代码行数:18,代码来源:NavControllerTests.cs

示例15: Can_Create_Categories

        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]);
        }
开发者ID:erangeljr,项目名称:SportsStore,代码行数:19,代码来源:UnitTest1.cs


注:本文中的SportsStore.WebUI.Controllers.NavController类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。