コード例 #1
0
        public void List_Includes_All_Products_When_Category_Is_Null()
        {
            // Подгтовка
            IProductsRepository repository = MockProductsRepository(
                new Product { Name = "Artemis", Category = "Greek" },
                new Product { Name = "Neptune", Category = "Roman" }
            );
            ProductsController controler = new ProductsController(repository);
            controler.PageSize = 10;

            // Действие
            var result = controler.List(null, 1);

            // Проверка 
            Assert.IsNotNull(result, "Didn't render view");
            var products = (IList<Product>)result.ViewData.Model;
            Assert.AreEqual(2, products.Count, "Got wrong number of items");
            Assert.AreEqual("Artemis", products[0].Name);
            Assert.AreEqual("Neptune", products[1].Name);
        }
コード例 #2
0
 public void List_Presents_Correct_Page_Of_Products()
 {
     // Подготовка
     IProductsRepository repository = MockProductsRepository(
         new Product { Name="P1"}, new Product { Name = "P2" },
         new Product { Name = "P3" }, new Product { Name = "P4" },
         new Product { Name = "P5" });
     ProductsController controller = new ProductsController(repository);
     controller.PageSize = 3;
     // Действие
     var result = controller.List(null,2);
     // Утверждение
     Assert.IsNotNull(result, "Didn't render view");
     var products = result.ViewData.Model as List<Product>;
     Assert.AreEqual(2, products.Count, "Got wrong number of products.");
     Assert.AreEqual(2, (int)result.ViewData["CurrentPage"], "Wrong page number");
     Assert.AreEqual(2, (int)result.ViewData["TotalPages"], "Wrong page count");
     Assert.AreEqual("P4", products[0].Name);
     Assert.AreEqual("P5", products[1].Name);
 }
コード例 #3
0
        public void List_Filters_By_Category_When_Requested() {
            // Подготовка
            IProductsRepository repository = MockProductsRepository(
                new Product { Name = "Snowball", Category = "Cats" },
                new Product { Name = "Rex", Category = "Dogs" },
                new Product { Name = "Catface", Category = "Cat" },
                new Product { Name = "Woofer", Category = "Dogs" },
                new Product { Name = "Chomper", Category = "Dogs" }
            );
            ProductsController controller = new ProductsController(repository);
            controller.PageSize = 10;

            // Действие
            var result = controller.List("Dogs", 1);

            // Проверка
            Assert.IsNotNull(result, "Didn't render view");
            var products = (IList<Product>)result.ViewData.Model;
            Assert.AreEqual("Rex", products[0].Name);
            Assert.AreEqual("Woofer", products[1].Name);
            Assert.AreEqual("Chomper", products[2].Name);
            Assert.AreEqual("Dogs", result.ViewData["currentCategory"]);
        }