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