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


C# HomeController.WithCallTo方法代码示例

本文整理汇总了C#中HomeController.WithCallTo方法的典型用法代码示例。如果您正苦于以下问题:C# HomeController.WithCallTo方法的具体用法?C# HomeController.WithCallTo怎么用?C# HomeController.WithCallTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HomeController的用法示例。


在下文中一共展示了HomeController.WithCallTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IndexPageShouldWorkCorrectly

        public void IndexPageShouldWorkCorrectly()
        {
            var products = new List<Product>()
                {
                    new Product
                    {
                        Id = 1,
                        Likes = new List<Like>()
                        {
                            new Like { ProductId = 2, UserId = "358a76f4-9a0e-4b03-a1db-111ede738596" },
                            new Like { ProductId = 2, UserId = "3fdac7f2-6b48-4cdf-b50b-aae093021e26" },
                            new Like { ProductId = 2, UserId = "5a610ecd-bdc4-426b-9667-32af8ceb6326" }
                        },
                        Title = "Product 1"
                    },
                    new Product
                    {
                        Id = 2,
                        Likes = new List<Like>()
                        {
                            new Like { ProductId = 2, UserId = "358a76f4-9a0e-4b03-a1db-111ede738596" },
                            new Like { ProductId = 2, UserId = "3fdac7f2-6b48-4cdf-b50b-aae093021e26" }
                        },
                        Title = "Product 2"
                    },
                    new Product
                    {
                        Id = 3,
                        Likes = new List<Like>()
                        {
                            new Like { ProductId = 3, UserId = "358a76f4-9a0e-4b03-a1db-111ede738596" }
                        },
                        Title = "Product 3"
                    }
                };

            IQueryable<Product> productsAsQueryable = products.AsQueryable();
            homeServiceMock.Setup(h => h.GetTopProducts(It.IsAny<int>()))
                .Returns(productsAsQueryable);

            var controller = new HomeController(homeServiceMock.Object);
            controller.WithCallTo(h => h.Index())
                .ShouldRenderView("Index")
                .WithModel<List<ProductViewModel>>(viewModel =>
                {
                    Assert.AreEqual(3, viewModel.Count);
                    Assert.AreEqual(3, viewModel[0].Likes.Count);
                    Assert.AreEqual("Product 1", viewModel[0].Title);
                    Assert.AreEqual("Product 2", viewModel[1].Title);
                    Assert.AreEqual("Product 3", viewModel[2].Title);
                })
                .AndNoModelErrors();
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:53,代码来源:HomeControllerTests.cs

示例2: EventCreateShouldReturnTheCorrectViewWithCorrectViewModel

 public void EventCreateShouldReturnTheCorrectViewWithCorrectViewModel()
 {
     var controller = new HomeController(this.eventsServiceMock.Object, this.articlesServiceMock.Object);
     controller.WithCallTo(x => x.Index())
        .ShouldRenderView("Index")
        .WithModel<IndexViewModel>(
            viewModel =>
            {
                Assert.AreNotEqual(null, viewModel.Articles);
                Assert.AreNotEqual(null, viewModel.Events);
            })
         .AndNoModelErrors();
 }
开发者ID:baretata,项目名称:ASP.NET-MVC-Individual-Project,代码行数:13,代码来源:HomeControllerTests.cs

示例3: MenuShouldWorkCorrectly

        public void MenuShouldWorkCorrectly()
        {
            var categories = new List<Category>()
            {
                new Category { Id = 1, Name = "Mens"},
                new Category { Id = 2, Name = "Ladies"},
                new Category { Id = 3, Name = "Kids"},
            };

            var sports = new List<Sport>()
            {
                new Sport { Id = 1, Name = "Football"},
                new Sport { Id = 2, Name = "Running"},
                new Sport { Id = 3, Name = "Fitness"},
            };

            var brands = new List<Brand>()
            {
                new Brand { Id = 1, Name = "Adidas"},
                new Brand { Id = 2, Name = "Nike"},
                new Brand { Id = 3, Name = "Puma"},
            };

            homeServiceMock.Setup(h => h.GetCategories()).Returns(categories.AsQueryable());
            homeServiceMock.Setup(h => h.GetSports()).Returns(sports.AsQueryable());
            homeServiceMock.Setup(h => h.GetBrands()).Returns(brands.AsQueryable());

            var controller = new HomeController(homeServiceMock.Object);
            var context = new Mock<HttpContextBase>();
            context.Setup(c => c.Cache).Returns(HttpRuntime.Cache);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
            controller.WithCallTo(h => h.Menu())
                .ShouldRenderPartialView("_NavigationPartial")
                .WithModel<MenuViewModel>(viewModel =>
                {
                    Assert.AreEqual(3, viewModel.Categories.Count);
                    Assert.AreEqual(3, viewModel.Sports.Count);
                    Assert.AreEqual(3, viewModel.Brands.Count);
                    Assert.AreEqual("Mens", viewModel.Categories.FirstOrDefault().Name);
                    Assert.AreEqual("Football", viewModel.Sports.FirstOrDefault().Name);
                    Assert.AreEqual("Puma", viewModel.Brands.LastOrDefault().Name);
                })
                .AndNoModelErrors();
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:44,代码来源:HomeControllerTests.cs


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