Wondering if I need to use the Genericrepository pattern and UnitOfWork to mock the repository.I am using MOQ.Is it now redundant since I have noticed that EF 4.1 has IDBSet
public class MockDbSet<T> : IDbSet<T> where T : class, new()
{
private List<T> _entities;
public MockDbSet(List<T> entities)
{
_entities = entities;
}
public virtual T Add(T entity)
{
_entities.Add(entity);
return entity;
}
public virtual T Attach(T entity)
{
_entities.Add(entity);
return entity;
}
public TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, T
{
return new T() as TDerivedEntity;
}
public virtual T Create()
{
return new T();
}
public virtual T Find(params object[] keyValues)
{
throw new NotImplementedException();
}
public System.Collections.ObjectModel.ObservableCollection<T> Local
{
get
{
return new ObservableCollection<T>(_entities);
}
}
public virtual T Remove(T entity)
{
_entities.Remove(entity);
return entity;
}
public IEnumerator<T> GetEnumerator()
{
return _entities.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _entities.GetEnumerator();
}
public Type ElementType
{
get { return _entities.AsQueryable().ElementType; }
}
public System.Linq.Expressions.Expression Expression
{
get { return _entities.AsQueryable().Expression; }
}
public IQueryProvider Provider
{
get { return _entities.AsQueryable().Provider; }
}
}
In addition i want to add, that generic repository and unit of work on Entity Framework is redundant, check out this link http://rob.conery.io/2014/03/04/repositories-and-unitofwork-are-not-a-good-idea/
This is duplicate of many topics already discussed on SO but I agree that some of them can be hard to find because they are nested in other question
I hope this will give you some answers. If not, don't hesitate to ask for more information either here or in a new question.