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


C# AdminController.Edit方法代碼示例

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


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

示例1: CanEditArticle

        public void CanEditArticle()
        {
            var articleIds = GetArticleIds();

            var mock = new Mock<IArticleRepository>();
            mock.Setup(m => m.Articles).Returns(GetArticles(articleIds));

            var controller = new AdminController(mock.Object);

            var article1 = controller.Edit(articleIds[0]).ViewData.Model as Article;
            var article2 = controller.Edit(articleIds[1]).ViewData.Model as Article;
            var article3 = controller.Edit(articleIds[2]).ViewData.Model as Article;

            Assert.AreEqual(articleIds[0], article1.ArticleId);
            Assert.AreEqual(articleIds[1], article2.ArticleId);
            Assert.AreEqual(articleIds[2], article3.ArticleId);
        }
開發者ID:KuuuPER,項目名稱:RussianTeaClubSite,代碼行數:17,代碼來源:UnitTest1.cs

示例2: Cannot_Edit_Nonexistent_Client

 public void Cannot_Edit_Nonexistent_Client()
 {
     // Arrange - create the mock repository
     Mock<IClientRepository> mock = new Mock<IClientRepository>();
     mock.Setup(m => m.Clients).Returns(new Client[] {
        new Client {ClientId = 1, ContractNumber = "L1"},
     new Client {ClientId = 2, ContractNumber = "L2"},
     new Client {ClientId = 3, ContractNumber = "L3"},
       }.AsQueryable());
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act
     Client result = (Client)target.Edit(4).ViewData.Model;
     // Assert
     Assert.IsNull(result);
 }
開發者ID:TimHanes,項目名稱:OB,代碼行數:16,代碼來源:AdminTests.cs

示例3: Cannot_Save_Invalid_Changes

 public void Cannot_Save_Invalid_Changes()
 {
     // Arrange - create mock repository
     Mock<IClientRepository> mock = new Mock<IClientRepository>();
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Arrange - create a client
     Client client = new Client { ContractNumber = "Test" };
     // Arrange - add an error to the model state
     target.ModelState.AddModelError("error", "error");
     // Act - try to save the client
     ActionResult result = target.Edit(client);
     // Assert - check that the repository was not called
     mock.Verify(m => m.SaveClient(It.IsAny<Client>()), Times.Never());
     // Assert - check the method result type
     Assert.IsInstanceOfType(typeof(ViewResult), result);
 }
開發者ID:TimHanes,項目名稱:OB,代碼行數:17,代碼來源:AdminTests.cs

示例4: Cannot_Save_Invalid_Changes

 public void Cannot_Save_Invalid_Changes()
 {
     // Arrange - create mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     // Arrange - create 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);
     // 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:kademat,項目名稱:FoodStore,代碼行數:17,代碼來源:AdminTests.cs

示例5: Cannot_Edit_Nonexistent_Product

 public void Cannot_Edit_Nonexistent_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 result = (Product) target.Edit(4).ViewData.Model;
     // Assert
     Assert.IsNull(result);
 }
開發者ID:kademat,項目名稱:FoodStore,代碼行數:17,代碼來源:AdminTests.cs

示例6: CannotEditNonexistenceArticle

        public void CannotEditNonexistenceArticle()
        {
            var articleIds = GetArticleIds();

            var mock = new Mock<IArticleRepository>();
            mock.Setup(m => m.Articles).Returns(GetArticles(articleIds));

            var controller = new AdminController(mock.Object);

            var result = controller.Edit(Guid.Parse("E3D32116-62DF-4830-8005-CAEEB6D34892")).ViewData.Model as Article;

            Assert.IsNull(result);
        }
開發者ID:KuuuPER,項目名稱:RussianTeaClubSite,代碼行數:13,代碼來源:UnitTest1.cs

示例7: Can_Edit_Client

 public void Can_Edit_Client()
 {
     // Arrange - create the mock repository
     Mock<IClientRepository> mock = new Mock<IClientRepository>();
     mock.Setup(m => m.Clients).Returns(new Client[] {
     new Client {ClientId = 1, ContractNumber = "L1"},
     new Client {ClientId = 2, ContractNumber = "L2"},
     new Client {ClientId = 3, ContractNumber = "L3"}
       }.AsQueryable());
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act
     Client l1 = target.Edit(1).ViewData.Model as Client;
     Client l2 = target.Edit(2).ViewData.Model as Client;
     Client l3 = target.Edit(3).ViewData.Model as Client;
     // Assert
     Assert.AreEqual(1, l1.ClientId);
     Assert.AreEqual(2, l2.ClientId);
     Assert.AreEqual(3, l3.ClientId);
 }
開發者ID:TimHanes,項目名稱:OB,代碼行數:20,代碼來源:AdminTests.cs

示例8: Can_Save_Valid_Changes

        public void Can_Save_Valid_Changes()
        {
            // Arrange - create mock repository
            Mock<IClientRepository> mock = new Mock<IClientRepository>();
            // Arrange - create the controller
            AdminController target = new AdminController(mock.Object);
            // Arrange - create a client
            Client client = new Client { ContractNumber = "Test" };
            // Act - try to save the client
            ActionResult result = target.Edit(client);
            // Assert - check that the repository was called
            mock.Verify(m => m.SaveClient(client));
            // Assert - check the method result type

            Assert.IsNotInstanceOfType( typeof(ViewResult), result);
        }
開發者ID:TimHanes,項目名稱:OB,代碼行數:16,代碼來源:AdminTests.cs

示例9: 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:kademat,項目名稱:FoodStore,代碼行數:21,代碼來源:AdminTests.cs

示例10: Can_Save_Valid_Changes

 public void Can_Save_Valid_Changes()
 {
     // Arrange - create mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Arrange - create a product
     Product product = new Product {Name = "Test"};
     // Act - try to save the product
     ActionResult result = target.Edit(product);
     // Assert - check that the repository was called
     mock.Verify(m => m.SaveProduct(product));
     // Assert - check the method result type
     Assert.IsNotInstanceOfType(result, typeof (ViewResult));
 }
開發者ID:kademat,項目名稱:FoodStore,代碼行數:15,代碼來源:AdminTests.cs


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