I have a model like this:
public class Products
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Product_D { get; set; }
[Required(ErrorMessage="Product is required")]
[Display(Name="Product Name")]
public string Product_Name { get; set; }
[Required(ErrorMessage="Photo of the product is required")]
[Display(Name="Product Photo")]
public byte[] Product_Photo { get; set; }
[NotMapped]
public HttpPostedFileBase Image { get; set; }
[Required(ErrorMessage="Enter the Quantity Available")]
[Display(Name = "Product Quantity")]
public int Product_Quantity { get; set; }
[Required(ErrorMessage="Enter the price of the product")]
[Display(Name = "Product Price")]
public int Product_Price { get; set; }
[Required(ErrorMessage = "Choose your category")]
public string Category { get; set; }
[NotMapped]
public List<System.Web.Mvc.SelectListItem> CategoryList { get; set; }
[Required(ErrorMessage = "Choose your category")]
public string Gender { get; set; }
[NotMapped]
public List<System.Web.Mvc.SelectListItem> GenderList { get; set; }
}
I'm trying to Mock database and i'm adding products to my mock database,I was able to provide values for all other data types and I'm not sure how to play around with Files.
public void MockRepo()
{
IList<Products> products = new List<Products>
{
new Products { Product_D = 1, Product_Name = "C# Unleashed",Product_Quantity = 20, Product_Price = 20 },
new Products { Product_D = 2, Product_Name = "ASP.Net Unleashed",Product_Quantity = 20, Product_Price = 30 },
new Products { Product_D = 3, Product_Name = "Silverlight Unleashed",Product_Quantity = 20, Product_Price = 100 }
};
//Mock Products using MOQ
Mock<IProduct> mockproductrepo = new Mock<IProduct>();
//return all products
mockproductrepo.Setup(r => r.FindAll()).Returns(products);
// returns products by name
mockproductrepo.Setup(r => r.FindByName(It.IsAny<string>())).Returns(products.Single());
//returns products by id
mockproductrepo.Setup(r => r.FindById(It.IsAny<int>())).Returns(products.Single());
}
I don't think a providing the path of the image file would help me. Using File system would make my Test slow.Even If I do that, I should convert the image into Bytes . How can I deal with this ? Thanks in advance
Aucun commentaire:
Enregistrer un commentaire