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