本文整理汇总了C#中SportsStore.WebUI.Controllers.AdminController.Index方法的典型用法代码示例。如果您正苦于以下问题:C# AdminController.Index方法的具体用法?C# AdminController.Index怎么用?C# AdminController.Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.WebUI.Controllers.AdminController
的用法示例。
在下文中一共展示了AdminController.Index方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: AdminController_IndexAction_Retuns_Products
public void AdminController_IndexAction_Retuns_Products()
{
//Arrange
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(products.AsQueryable());
AdminController target = new AdminController(mock.Object);
//Act
Product[] result = ((IEnumerable<Product>)target.Index().Model).ToArray();
//Assert
Assert.AreEqual(6, result.Length);
Assert.AreEqual(1, result[0].ProductID);
}
示例3: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
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 result = (target.Index().ViewData.Model as IEnumerable<Product>).ToArray();
Assert.AreEqual(result.Length, 3);
Assert.AreEqual(result[0].Name, "P1");
Assert.AreEqual(result[1].Name, "P2");
Assert.AreEqual(result[2].Name, "P3");
}
示例4: Index_Contains_All_Products
public void Index_Contains_All_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);
Product[] result = ((IEnumerable<Product>)target.Index().ViewData.Model).ToArray();
Assert.AreEqual(result.Length, 3);
Assert.AreEqual("P1", result[0].Name);
Assert.AreEqual("P2", result[1].Name);
Assert.AreEqual("P3", result[2].Name);
}
示例5: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
//Arrange create repository
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(p => p.Products).Returns(new Product[]
{
new Product {ProductID = 1, Name = "P1"},
new Product {ProductID = 2, Name = "P2"},
new Product {ProductID = 3, Name = "P3"},
});
AdminController controller = new AdminController(mock.Object);
Product[] result = ((IEnumerable<Product>)controller.Index().Model).ToArray();
Assert.AreEqual(result[0].Name, "P1");
Assert.AreEqual(result[1].Name, "P2");
Assert.AreEqual(result[2].Name, "P3");
}
示例6: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
// Arrange
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);
// Act
List<Product> result = ((IEnumerable<Product>)target.Index().Model).ToList();
// Assert
Assert.AreEqual(3, result.Count);
Assert.AreEqual("P2", result[1].Name);
}
示例7: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
// Arrange
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);
// Act
Product[] products = ((IEnumerable<Product>)target.Index().Model).ToArray();
// Assert
Assert.AreEqual(3, products.Length);
Assert.AreEqual("p1", products[0].Name);
Assert.AreEqual("p2", products[1].Name);
Assert.AreEqual("p3", products[2].Name);
}
示例8: Index_Contains_All_Products
public void Index_Contains_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 target = new AdminController(mock.Object);
// Act
Product[] result = ((ProductsListViewModel)target.Index().ViewData.Model).Products.ToArray();
// Assert
Assert.AreEqual(3, result.Length);
Assert.AreEqual("P1", result[0].Name);
Assert.AreEqual("P2", result[1].Name);
Assert.AreEqual("P3", result[2].Name);
}
示例9: IndexContainsAllProducts
public void IndexContainsAllProducts()
{
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[] result = ((IEnumerable<Product>)((ViewResult)controller.Index()).ViewData.Model).ToArray();
Assert.AreEqual(result.Length, 3);
Assert.AreEqual("P1", result[0].Name);
Assert.AreEqual("P2", result[1].Name);
Assert.AreEqual("P3", result[2].Name);
}
示例10: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
// Arrange - create a mock repository
var mock = InitializeMock();
AdminController target = new AdminController(mock.Object);
//Action
Product[] result = ((IEnumerable<Product>)target.Index().ViewData.Model).ToArray();
// assert
Assert.AreEqual(result.Length, 3);
Assert.AreEqual("P1", result[0].Name);
Assert.AreEqual("P2", result[1].Name);
Assert.AreEqual("P3", result[2].Name);
}
示例11: Index_Contains_All_Products
public void Index_Contains_All_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"},
new Product{ ProductID = 4, Name = "P4"},
new Product{ ProductID = 5, Name = "P5"}}.AsQueryable());
AdminController controller = new AdminController(mock.Object);
Product[] products = ((IEnumerable<Product>)controller.Index().ViewData.Model).ToArray();
Assert.AreEqual(5, products.Length);
}
示例12: Index_Contains_All_Products
public void Index_Contains_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"},
});
// Arrange - create a controller
AdminController target = new AdminController(mock.Object);
// Action
var result = ((IEnumerable<Product>) target.Index().ViewData.Model).ToArray();
// Assert
Assert.AreEqual(result.Length, 3);
Assert.AreEqual("P1", result[0].Name);
Assert.AreEqual("P2", result[1].Name);
Assert.AreEqual("P3", result[2].Name);
}
示例13: Index_Contains_All_Products
public void Index_Contains_All_Products()
{
// arrange - create the mock repository
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"}
});
// arrange - create a controller
AdminController target = new AdminController(mock.Object);
// action
// example of what worked elsewhere - (CartIndexViewModel)target.Index(cart, "myUrl").ViewData.Model;
Product[] results = ((IEnumerable<Product>)target.Index().ViewData.Model).ToArray();
// Assert
Assert.AreEqual(results.Length, 3);
Assert.AreEqual("p1", results[0].Name);
Assert.AreEqual("p2", results[1].Name);
Assert.AreEqual("p3", results[2].Name);
}