當前位置: 首頁>>代碼示例>>C#>>正文


C# AdminController.Edit方法代碼示例

本文整理匯總了C#中SportsStore.WebUI.Controllers.AdminController.Edit方法的典型用法代碼示例。如果您正苦於以下問題:C# AdminController.Edit方法的具體用法?C# AdminController.Edit怎麽用?C# AdminController.Edit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SportsStore.WebUI.Controllers.AdminController的用法示例。


在下文中一共展示了AdminController.Edit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Can_Edit_Product

        public void Can_Edit_Product()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
                {
                    new Product{ProductId = 1, Name = "P1"},
                    new Product{ProductId = 2, Name = "P2"},
                    new Product{ProductId = 3, Name = "P3"}
                }.AsQueryable());

            AdminController target = new AdminController(mock.Object);

            var p1 = target.Edit(1).ViewData.Model as Product;
            var p2 = target.Edit(2).ViewData.Model as Product;
            var p3 = target.Edit(3).ViewData.Model as Product;

            target = new AdminController(mock.Object);
            var p4 = (Product)target.Edit(4).ViewData.Model;

            Assert.AreEqual(1, p1.ProductId);
            Assert.AreEqual(2, p2.ProductId);
            Assert.AreEqual(3, p3.ProductId);

            Assert.IsNull(p4);
        }
開發者ID:vikranthc,項目名稱:SportsStore,代碼行數:25,代碼來源:AdminTests.cs

示例2: Cannot_Save_Invalid_Changes

        public void Cannot_Save_Invalid_Changes()
        {
            // Arrange
            // - Create a mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            // Arrange
            // - Crete the controller
            AdminController target = new AdminController(mock.Object);

            // Arrange
            // - Create a product
            Product product = new Product { Name = "Test" };

            // Arrange
            // - Add an error to the model state
            target.ModelState.AddModelError("error", "error");

            // Act
            // - Try to save the product
            ActionResult result = target.Edit(product, null);

            // Assert
            // - Check that the repository was not called
            mock.Verify(m => m.SaveProduct(It.IsAny<Product>()), Times.Never());

            // Assert
            // - Check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
開發者ID:Zanion,項目名稱:SportsStore,代碼行數:30,代碼來源:AdminTests.cs

示例3: Can_Edit_Product

 public void Can_Edit_Product()
 {
     var mock = new Mock<IProductRepository>();
     mock.Setup(x => x.Products).Returns(new List<Product>
     {
         new Product {Name = "P1", ProductId = 1, Category = "Apples"},
         new Product {Name = "P2", ProductId = 2, Category = "Apples"},
         new Product {Name = "P3", ProductId = 3, Category = "Plum"},
     });
     var target = new AdminController(mock.Object);
     var product1 = target.Edit(1).ViewData.Model as Product;
     var product2 = target.Edit(2).ViewData.Model as Product;
     var product3 = target.Edit(3).ViewData.Model as Product;
     Assert.AreEqual(product1.Name, "P1");
     Assert.AreEqual(product2.Name, "P2");
     Assert.AreEqual(product3.Name, "P3");
 }
開發者ID:trupak,項目名稱:SportsStore,代碼行數:17,代碼來源:AdminTests.cs

示例4: Can_Edit_Product

        public void Can_Edit_Product()
        {
            // arrange - create mock repository
            var mock = InitializeMock();

            // Arrange
            AdminController target = new AdminController(mock.Object);

            // Act
            Product p1 = target.Edit(1).ViewData.Model as Product;
            Product p2 = target.Edit(2).ViewData.Model as Product;
            Product p3 = target.Edit(3).ViewData.Model as Product;

            Assert.AreEqual(1, p1.ProductID);
            Assert.AreEqual(2, p2.ProductID);
            Assert.AreEqual(3, p3.ProductID);
        }
開發者ID:jvvpabalan,項目名稱:SportsStore,代碼行數:17,代碼來源:AdminTests.cs

示例5: Edit_All_Products

        public void Edit_All_Products()
        {
            // 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"},
                new Product {ProductID = 2, Name = "P2"},
                new Product {ProductID = 3, Name = "P3"},
            }.AsQueryable());

            AdminController ad = new AdminController(mock.Object);

            Product f1 = ad.Edit(1).ViewData.Model as Product;
            Product f2 = ad.Edit(2).ViewData.Model as Product;
            Product f3 = ad.Edit(3).ViewData.Model as Product;

            Assert.AreEqual(f1.ProductID, 1);
        }
開發者ID:rialhstu,項目名稱:Online-Shopping,代碼行數:18,代碼來源:AdminTest.cs

示例6: Can_Edit_Product

        public void Can_Edit_Product()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
            new Product{ProductID=1,Name="p1"},
            new Product{ProductID=2,Name="p2"},
            new Product{ProductID=3,Name="p3"},
            }.AsQueryable());
            AdminController target = new AdminController(mock.Object);

            Product p1 = target.Edit(1).ViewData.Model as Product;
            Product p2 = target.Edit(2).ViewData.Model as Product;
            Product p3 = target.Edit(3).ViewData.Model as Product;

            Assert.AreEqual(1, p1.ProductID);
            Assert.AreEqual(2, p2.ProductID);
            Assert.AreEqual(3, p3.ProductID);
        }
開發者ID:SergioKritskiy,項目名稱:SportStore,代碼行數:18,代碼來源:AdminTest.cs

示例7: Can_Save_Valid_Changed

 public void Can_Save_Valid_Changed()
 {
     var mock = new Mock<IProductRepository>();
     var target = new AdminController(mock.Object);
     var product = new Product {Name = "test"};
     var result = target.Edit(product);
     mock.Verify(m => m.SaveProduct(product));
     Assert.IsNotInstanceOfType(result, typeof(ViewResult));
 }
開發者ID:trupak,項目名稱:SportsStore,代碼行數:9,代碼來源:AdminTests.cs

示例8: Cannot_Save_Invalid_Changes

 public void Cannot_Save_Invalid_Changes()
 {
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     AdminController target = new AdminController(mock.Object);
     Product product = new Product{Name = "Test"};
     target.ModelState.AddModelError("error", "error");
     ActionResult result = target.Edit(product);
     mock.Verify(m => m.SaveProduct(It.IsAny<Product>()), Times.Never);
     Assert.IsInstanceOfType(result, typeof(ViewResult));
 }
開發者ID:novopashinmm,項目名稱:SportsStore,代碼行數:10,代碼來源:AdminTests.cs

示例9: CanEditProduct

        public void CanEditProduct()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
            {
                new Product {ProductID = 1, Name = "P1"},
                new Product {ProductID = 2, Name = "P2"},
                new Product {ProductID = 3, Name = "P3"}
            });
            var target = new AdminController(mock.Object);

            var p1 = target.Edit(1).ViewData.Model as Product;
            var p2 = target.Edit(2).ViewData.Model as Product;
            var p3 = target.Edit(3).ViewData.Model as Product;

            Assert.AreEqual(1, p1.ProductID);
            Assert.AreEqual(2, p2.ProductID);
            Assert.AreEqual(3, p3.ProductID);
        }
開發者ID:brainiacOnly,項目名稱:SportsStore,代碼行數:19,代碼來源:AdminTests.cs

示例10: CanEditProduct

        public void CanEditProduct()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product(){Id = 1, Name = "P1"},
                new Product(){Id = 2, Name = "P2"},
                new Product(){Id = 3, Name = "P3"}
            });
            AdminController controller = new AdminController(mock.Object);

            Product p1 = controller.Edit(1).ViewData.Model as Product;
            Product p2 = controller.Edit(2).ViewData.Model as Product;
            Product p3 = controller.Edit(3).ViewData.Model as Product;

            Assert.AreEqual(1, p1.Id);
            Assert.AreEqual(2, p2.Id);
            Assert.AreEqual(3, p3.Id);
        }
開發者ID:MichalZawadzki,項目名稱:SportsStore,代碼行數:19,代碼來源:AdminTests.cs

示例11: Can_Edit_Product

 public void Can_Edit_Product()
 {
     // 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"},
         new Product {ProductID = 2, Name = "P2"},
         new Product {ProductID = 3, Name = "P3"},
     });
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act
     Product p1 = target.Edit(1).ViewData.Model as Product;
     Product p2 = target.Edit(2).ViewData.Model as Product;
     Product p3 = target.Edit(3).ViewData.Model as Product;
     // Assert
     Assert.AreEqual(1, p1.ProductID);
     Assert.AreEqual(2, p2.ProductID);
     Assert.AreEqual(3, p3.ProductID);
 }
開發者ID:jojozhuang,項目名稱:Projects,代碼行數:20,代碼來源:AdminTests.cs

示例12: Can_Save_Valid_Changes

        public void Can_Save_Valid_Changes()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            AdminController target = new AdminController(mock.Object);
            Product prod = new Product() { Name = "Test" };

            ActionResult res = target.Edit(prod);

            mock.Verify(m => m.SaveProduct(prod));
            Assert.IsNotInstanceOfType(res, typeof(ViewResult));
        }
開發者ID:Karoliner,項目名稱:sports_store,代碼行數:11,代碼來源:AdminTests.cs

示例13: Cannot_Edit_NonExistent_Product

        public void Cannot_Edit_NonExistent_Product()
        {
            // arrange
            var mock = InitializeMock();

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

            Product result = target.Edit(4).ViewData.Model as Product;

            Assert.IsNull(result);
        }
開發者ID:jvvpabalan,項目名稱:SportsStore,代碼行數:12,代碼來源:AdminTests.cs

示例14: Can_edit_product

        public void Can_edit_product()
        {
            var mock = new Mock<IProductRepository>();
            var controller = new AdminController(mock.Object);

            var product = new Product { Name = "Test" };

            var result = controller.Edit(product, null);
            mock.Verify(m => m.Save(product));

            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
開發者ID:vcaraulean,項目名稱:Pro-ASP-NET-MVC-SportsStore,代碼行數:12,代碼來源:AdminControllerTests.cs

示例15: Cannot_Edit_Nonexistent_Product

 public void Cannot_Edit_Nonexistent_Product()
 {
     var mock = new Mock<IProductRepository>();
     mock.Setup(x => x.Products).Returns(new List<Product>
     {
         new Product {Name = "P1", ProductId = 1, Category = "Apples"},
         new Product {Name = "P2", ProductId = 2, Category = "Apples"},
         new Product {Name = "P3", ProductId = 3, Category = "Plum"},
     });
     var target = new AdminController(mock.Object);
     var product = target.Edit(4).ViewData.Model as Product;
     Assert.IsNull(product);
 }
開發者ID:trupak,項目名稱:SportsStore,代碼行數:13,代碼來源:AdminTests.cs


注:本文中的SportsStore.WebUI.Controllers.AdminController.Edit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。