当前位置: 首页>>代码示例>>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;未经允许,请勿转载。