Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming you're using the Repository pattern from Rob Conery's MVC Store Front:</p> <p><a href="http://blog.wekeroad.com/mvc-storefront/mvc-storefront-part-1/" rel="nofollow noreferrer">http://blog.wekeroad.com/mvc-storefront/mvc-storefront-part-1/</a></p> <p>I followed Rob Conery's tutorial but ran into the same want as you. Best thing to do is move the Mock Repositories you've created into a seperate project called Mocks then you can swap them out pretty easily with the real ones when you instantiate your service. If your feeling adventurous you could create a factory that takes a value from the config file to instantiate either a mock or a real repository, </p> <p>e.g.</p> <pre><code>public static ICatalogRepository GetCatalogRepository(bool useMock) { if(useMock) return new FakeCatalogRepository(); else return new SqlCatalogRepository(); } </code></pre> <p>or use a dependency injection framework :)</p> <pre><code>container.Resolve&lt;ICatalogRepository&gt;(); </code></pre> <p>Good luck!</p> <p><strong>EDIT:</strong> In response to your comments, sounds like you want to use a list and LINQ to emulate a db's operations e.g. GetProducts, StoreProduct. I've done this before. Here's an example:</p> <pre><code>public class Product { public int Identity { get; set; } public string Name { get; set; } public string Description { get; set; } //etc } public class FakeCatalogRepository() { private List&lt;Product&gt; _fakes; public FakeCatalogCatalogRepository() { _fakes = new List&lt;Product&gt;(); //Set up some initial fake data for(int i=0; i &lt; 5; i++) { Product p = new Product { Identity = i, Name = "product"+i, Description = "description of product"+i }; _fakes.Add(p); } } public void StoreProduct(Product p) { //Emulate insert/update functionality _fakes.Add(p); } public Product GetProductByIdentity(int id) { //emulate "SELECT * FROM products WHERE id = 1234 var aProduct = (from p in _fakes.AsQueryable() where p.Identity = id select p).SingleOrDefault(); return aProduct; } } </code></pre> <p>Does that make a bit more sense?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload