本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}