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


C# AdminController.Delete方法代码示例

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


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

示例1: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            // Arrange - create a Product
            Product prod = new Product { ProductID = 2, Name = "Test" };

            // 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"},
                    prod,
                    new Product {ProductID = 3, Name = "P3"},
                }
            );

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

            // Act - delete the product
            target.Delete(prod.ProductID);

            // Assert - ensure that the repository delete method was
            // called with the correct Product
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:xpk-rodaire,项目名称:SportsStore,代码行数:25,代码来源:AdminTests.cs

示例2: Delete_product_called_with_right_parameters

        public void Delete_product_called_with_right_parameters()
        {
            var mock = CreateRepositoryMock();
            var controller = new AdminController(mock.Object);

            controller.Delete(2);

            mock.Verify(m => m.Delete(2));
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:9,代码来源:AdminControllerTests.cs

示例3: Can_Delete_Product

        public void Can_Delete_Product()
        {
            var mockRepository = new Mock<IProductsRepository>();
            var product = new Product {ProductId = 24, Name = "P24"};

            mockRepository.Setup(x => x.Products).Returns(new[] {product}.AsQueryable());

            var controller = new AdminController(mockRepository.Object);
            var result = controller.Delete(24);

            mockRepository.Verify(x=>x.DeleteProduct(product));
            result.ShouldBeRedirectionTo(new {action = "Index"});
            controller.TempData["message"].ShouldEqual("P24 was deleted");
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:14,代码来源:CatalogEditing.cs

示例4: Cant_Delete_InValid_Products

        public void Cant_Delete_InValid_Products()
        {
            // Arrange - create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(products.AsQueryable());

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

            // Act - delete the product
            target.Delete(100);
            // Assert - ensure that the repository delete method was
            // called with the correct Product
            mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never());
        }
开发者ID:najamsk,项目名称:SportsStore,代码行数:15,代码来源:AdminControllerTest.cs

示例5: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            Product prod = new Product {ProductID = 2, Name = "Test"};
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            });

            AdminController target = new AdminController(mock.Object);
            target.Delete(prod.ProductID);
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:novopashinmm,项目名称:SportsStore,代码行数:15,代码来源:AdminTests.cs

示例6: Cannot_Delete_Invalid_Products

        public void Cannot_Delete_Invalid_Products()
        {
            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);

            target.Delete(100);

            mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never());
        }
开发者ID:pasena,项目名称:SportsStore,代码行数:16,代码来源:AdminControllerTest.cs

示例7: CanDeleteValidProducts

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

            controller.Delete(prod.Id);

            mock.Verify(m => m.DeleteProduct(prod.Id));
        }
开发者ID:MichalZawadzki,项目名称:SportsStore,代码行数:16,代码来源:AdminTests.cs

示例8: Cannot_Delete_Invalid_Products

 public void Cannot_Delete_Invalid_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());
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act - delete using an ID that doesn't exist
     target.Delete(100);
     // Assert - ensure that the repository delete method was
     // called with the correct Product
     mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never());
 }
开发者ID:tofka,项目名称:Lab-3,代码行数:17,代码来源:AdminControllerTest.cs

示例9: Cannot_Delete_InValid_Products

        public void Cannot_Delete_InValid_Products()
        {
            Product product = new Product() { Name = "Test", ProductID = 1 };

            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(x => x.Products).Returns(new Product[]
            {
                new Product{ ProductID = 1, Name = "Test"}
            }.AsQueryable());

            AdminController controller = new AdminController(mock.Object);

            controller.Delete(33);

            mock.Verify(x => x.DeleteProduct(It.IsAny<Product>()),Times.Never());
        }
开发者ID:CacoDurban,项目名称:SportsStore,代码行数:17,代码来源:AdminControllerTest.cs

示例10: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            var prod = new Product() {ProductID = 2, Name = "Test"};

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(repo => repo.Products).Returns(new Product[]
            {
                new Product() {ProductID = 1, Name = "p1"},
                prod,
                new Product() {ProductID = 2, Name = "p2"}
            });

            AdminController target = new AdminController(mock.Object);
            target.Delete(prod.ProductID);

            //assert - ensure that the repository delete method was called with the correct product
            mock.Verify(repo => repo.DelteProduct(prod.ProductID));
        }
开发者ID:Gluba,项目名称:SportsStore,代码行数:18,代码来源:AdminTests.cs

示例11: Cannot_Delete_Invalid_Products

        public void Cannot_Delete_Invalid_Products()
        {
            // Arrange
            // - Create the mock repository
            Mock<IProductRepository>    mock    = new Mock<IProductRepository>();
            AdminController             target  = new AdminController(mock.Object);

            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());

            // Act
            ActionResult    result = target.Delete(100);

            // Assert
            mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never());
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
开发者ID:eugeniomiro,项目名称:SportsStore,代码行数:20,代码来源:ControllersTests.cs

示例12: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            // arrange - create a product
            Product prod = new Product { ProductID = 2, Name = "Test" };

            // arrange - create the mock repo
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product{ProductID = 1, Name = "P1"},
                new Product {ProductID = 3, Name = "P3"}
            });

            // Arrange - Set up what i'm going to work with
            AdminController target = new AdminController(mock.Object);

            // act - delete the product
            target.Delete(prod.ProductID);

            // assert - ensure the repo delete was called with the correct product
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:pixelsyndicate,项目名称:Pro_AspNet_MVC_5_book,代码行数:21,代码来源:AdminTests.cs

示例13: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            // przygotowanie - tworzenie produktu
            Product prod = new Product { ProductID = 2, Name = "Test" };

            // przygotowanie - tworzenie imitacji repozytorium
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1"},
                prod,
                new Product {ProductID = 3, Name = "P3"},
            });

            // przygotowanie - utworzenie kontrolera
            AdminController target = new AdminController(mock.Object);

            // działanie - usunięcie produktu
            target.Delete(prod.ProductID);

            // asercje - upewnienie się, że metoda repozytorium
            // została wywołana z właściwym produktem
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:PawelHaracz,项目名称:SportsStore,代码行数:23,代码来源:AdminTest.cs

示例14: Can_Delete_Valid_Product

        public void Can_Delete_Valid_Product()
        {
            // Arrange
            // - Create the mock repository
            Mock<IProductRepository>    mock    = new Mock<IProductRepository>();
            AdminController             target  = new AdminController(mock.Object);
            Product                     product = new Product { ProductID = 2, Name = "Test" };

            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductID = 1, Name = "P1" },
                product,
                new Product { ProductID = 3, Name = "P3" }
            }.AsQueryable());

            // Act
            ActionResult    result = target.Delete(product.ProductID);

            // Assert
            mock.Verify(m => m.DeleteProduct(product));
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
开发者ID:eugeniomiro,项目名称:SportsStore,代码行数:21,代码来源:ControllersTests.cs

示例15: Can_Delete_Valid_Products

        public void Can_Delete_Valid_Products()
        {
            // Arrange - 상품을 생성한다.
            Product prod = new Product { ProductID = 2, Name = "TesT" };

            // Arrange - Mock 리파지토리를 생성한다.
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1" },
                prod,
                new Product {ProductID = 3, Name = "P3" }
            });

            // Arrange - 컨트롤러를 생성한다.
            AdminController target = new AdminController(mock.Object);

            // Act - 상품ㅇ르 삭제한다.
            target.Delete(prod.ProductID);

            // Assert - 리파지토리의 DeleteProduct 메서드가
            // 올바른 상품과 함께 호출되었는지 확인한다.
            mock.Verify(m => m.DeleteProduct(prod.ProductID));
        }
开发者ID:EthanK28,项目名称:pro-asp-mvc5,代码行数:24,代码来源:AdminTests.cs


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