Skip to content

Instantly share code, notes, and snippets.

@ChouJustice
Created June 14, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChouJustice/3d0ccf3ccaef72f3d0a37172a2402cc6 to your computer and use it in GitHub Desktop.
Save ChouJustice/3d0ccf3ccaef72f3d0a37172a2402cc6 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using WebCoreLab.Mock;
using WebCoreLab.Models.DBEntity;
namespace WebCoreLab.Repository
{
public class MockRepository
{
private readonly Dictionary<string, dynamic> _mockData;
public MockRepository()
{
_mockData = MockData.DataList;
}
public void Create<T>(T entity) where T : DBEntity
{
var t = (List<T>)_mockData[typeof(T).Name];
t.Add(entity);
}
public void Update<T>(T entity) where T : DBEntity
{
var t = (List<T>)_mockData[typeof(T).Name];
t[t.FindIndex(x => x.Id == entity.Id)] = entity;
}
public void Delete<T>(T entity) where T : DBEntity
{
var t = (List<T>)_mockData[typeof(T).Name];
t.Remove(entity);
}
public IQueryable<T> GetAll<T>() where T : DBEntity
{
var t = (List<T>)_mockData[typeof(T).Name];
return t.AsQueryable();
}
public void Save() { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment