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


C# Controllers.AdminController类代码示例

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


AdminController类属于SportsStore.WebUI.Controllers命名空间,在下文中一共展示了AdminController类的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: 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()
        {
            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

示例4: 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

示例5: Index_contains_all_products

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

            var result = ((IEnumerable<Product>)controller.Index().ViewData.Model).ToArray();

            Assert.AreEqual(3, result.Length);
            Assert.AreEqual("P1", result[0].Name);
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:9,代码来源:AdminControllerTests.cs

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: AjaxDelete_PassesProductIdToRepositoryRemoveMethod_DeletesProduct

        public void AjaxDelete_PassesProductIdToRepositoryRemoveMethod_DeletesProduct()
        {
            // Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            AdminController target = new AdminController(mock.Object);

            // Act
            var result = target.AjaxDelete(new Product{ProductID = 3});

            // Assert
            mock.Verify(m => m.RemoveProduct(3), Times.Once());
        }
开发者ID:tenzinkabsang,项目名称:SportsStoreKnockoutified,代码行数:13,代码来源:AdminControllerTests.cs

示例13: Can_Access_Product_Editing_Screen

        public void Can_Access_Product_Editing_Screen()
        {
            // Arrange: Repository that can return any IQueryable<Product>
            var testProducts = new[] { new Product { ProductId = 12 }, new Product { ProductId = 17 } };
            var mockRepository = UnitTestHelpers.MockProductsRepository(testProducts);

            // Act
            var result = new AdminController(mockRepository).Edit(17);

            // Assert
            result.ShouldBeDefaultView();
            ((Product)result.ViewData.Model).ProductId.ShouldEqual(17);
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:13,代码来源:CatalogEditing.cs

示例14: Cannot_save_invalid_changes

        public void Cannot_save_invalid_changes()
        {
            var mock = new Mock<IProductRepository>();
            var controller = new AdminController(mock.Object);
            var product = new Product { Name = "Test" };

            controller.ModelState.AddModelError("error", "error");

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

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:13,代码来源:AdminControllerTests.cs

示例15: Can_Edit_Nonexistint_Product

        public void Can_Edit_Nonexistint_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 result = target.Edit(4).ViewData.Model as Product;
            Assert.IsNull(result);
        }
开发者ID:SergioKritskiy,项目名称:SportStore,代码行数:13,代码来源:AdminTest.cs


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