Пример #1
0
 public static AdminProductController getMoqAdminProductController()
 {
     var context = new Mock<ControllerContext>();
     var session = new MockHttpSession();
     context.Setup(m => m.HttpContext.Session).Returns(session);
     var controller = new AdminProductController(new ProductBLL(new ProductDALStub()), new LoggingBLL(new LoggingDALStub()));
     controller.ControllerContext = context.Object;
     return controller;
 }
 public void AllProductsTestTrue()
 {
     //Arrange
     var controller = new AdminProductController(new ProductBLL(new ProductDALStub()), new LoggingBLL(new LoggingDALStub()));
     var list = new List<ProductModel>();
     var productModel = new ProductModel();
     productModel.category = "Kaffe";
     productModel.description = "God kaffe";
     productModel.imageURL = "kaffe.kaffebilde.jpg";
     productModel.price = 100;
     productModel.productID = 1;
     productModel.productName = "Svart kaffe";
     productModel.quantity = 10;
     productModel.stock = 100;
     list.Add(productModel);
     list.Add(productModel);
     list.Add(productModel);
     list.Add(productModel);
     //Act
     var result = (ViewResult)controller.AllProducts();
     var resultList = (List<ProductModel>)result.Model;
     //Assert
     Assert.AreEqual(result.ViewName, "");
     Assert.AreEqual(list.Count, resultList.Count);
     for(int i = 0; i < resultList.Count; i++)
     {
         Assert.AreEqual(resultList[i].category, list[i].category);
         Assert.AreEqual(resultList[i].description, list[i].description);
         Assert.AreEqual(resultList[i].imageURL, list[i].imageURL);
         Assert.AreEqual(resultList[i].price, list[i].price);
         Assert.AreEqual(resultList[i].productID, list[i].productID);
         Assert.AreEqual(resultList[i].productName, list[i].productName);
         Assert.AreEqual(resultList[i].quantity, list[i].quantity);
         Assert.AreEqual(resultList[i].stock, list[i].stock);
     }
 }