title: Mocking Files in Moq
body: <p>I have a model like this:</p>
  
  <pre><code> 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&lt;System.Web.Mvc.SelectListItem&gt; CategoryList { get; set; }
  
      [Required(ErrorMessage = "Choose your category")]
      public string Gender { get; set; }
  
  
  
      [NotMapped]
      public List&lt;System.Web.Mvc.SelectListItem&gt; GenderList { get; set; }
  
  }
  </code></pre>
  
  <p>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.</p>
  
  <pre><code> public void MockRepo()
      {
          IList&lt;Products&gt; products = new List&lt;Products&gt;
          {
              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&lt;IProduct&gt; mockproductrepo = new Mock&lt;IProduct&gt;();
          //return all products
          mockproductrepo.Setup(r =&gt; r.FindAll()).Returns(products);
          // returns products by name
          mockproductrepo.Setup(r =&gt; r.FindByName(It.IsAny&lt;string&gt;())).Returns(products.Single());
          //returns products by id
          mockproductrepo.Setup(r =&gt; r.FindById(It.IsAny&lt;int&gt;())).Returns(products.Single());
      }
  </code></pre>
  
  <p>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</p>