1 min read
Create an Asp.Net Core MVC app with the repository pattern Part 3 – Create a MockRepository
Now it’s time to create a MockRepository that inherits from the interface it’s method.
Inside the constructor we create some mockdata with orders.
private List<Order> orders;
public MockOrderRepository()
{
orders = new List<Order>()
{
new Order() { CustomerName = "Sherlock", CoffeeSelected = Coffee.Cappuccino},
new Order() { CustomerName = "Pluto", CoffeeSelected = Coffee.Espresso},
new Order() { CustomerName = "Garfield", CoffeeSelected = Coffee.Frappuccino}
};
}

Now in the method GetAllOrders return the list of orders.
public IEnumerable<Order> GetAllOrders()
{
return orders;
}

Next let’s create a controller that implements the Order interface repository.