Last active
August 22, 2016 16:46
-
-
Save jonfazzaro/be919f9064ce8d135f02c49ddb0c1bd0 to your computer and use it in GitHub Desktop.
In-memory implementation of IDbSet, for unit testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Data.Entity; | |
using System.Linq; | |
using System.Linq.Expressions; | |
public class MemoryDbSet<T> : IDbSet<T> where T : class { | |
readonly List<T> _list = new List<T>(); | |
public MemoryDbSet() { | |
_list = new List<T>(); | |
} | |
public MemoryDbSet(IEnumerable<T> contents) { | |
_list = contents.ToList(); | |
} | |
public T Add(T entity) { | |
_list.Add(entity); | |
return entity; | |
} | |
public T Attach(T entity) { | |
_list.Add(entity); | |
return entity; | |
} | |
public TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, T { | |
throw new NotImplementedException(); | |
} | |
public T Create() { | |
throw new NotImplementedException(); | |
} | |
public T Find(params object[] keyValues) { | |
throw new NotImplementedException(); | |
} | |
public ObservableCollection<T> Local { | |
get { | |
throw new NotImplementedException(); | |
} | |
} | |
public T Remove(T entity) { | |
_list.Remove(entity); | |
return entity; | |
} | |
public IEnumerator<T> GetEnumerator() { | |
return _list.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() { | |
return _list.GetEnumerator(); | |
} | |
public Type ElementType { | |
get { return _list.AsQueryable().ElementType; } | |
} | |
public Expression Expression { | |
get { return _list.AsQueryable().Expression; } | |
} | |
public IQueryProvider Provider { | |
get { return _list.AsQueryable().Provider; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment