Created
November 27, 2009 02:26
-
-
Save jfromaniello/243787 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class DaoStub<T> : IDao<T> | |
{ | |
public DaoStub() | |
{ | |
Repository = new List<T>(); | |
Mock = new Mock<IDao<T>>(); | |
} | |
protected List<T> Repository { get; private set; } | |
public DaoStub<T> PushEntity(T entity) | |
{ | |
Repository.Add(entity); | |
return this; | |
} | |
public DaoStub<T> PushEntities(IEnumerable<T> entities) | |
{ | |
Repository.AddRange(entities); | |
return this; | |
} | |
public DaoStub<T> PushEntities(params T[] entities) | |
{ | |
Repository.AddRange(entities); | |
return this; | |
} | |
public static DaoStub<T> New() | |
{ | |
return new DaoStub<T>(); | |
} | |
#region IDao<T> Members | |
public T Get(object id) | |
{ | |
return Repository.FirstOrDefault(t => t.To<BaseEntity>().Id == id.To<int>()); | |
} | |
public T GetProxy(object id) | |
{ | |
return Repository.First(t => t.To<BaseEntity>().Id == id.To<int>()); | |
} | |
public void Refresh(T entity) | |
{ | |
Mock.Object.Refresh(entity); | |
} | |
public virtual T MakePersistent(T entity) | |
{ | |
return Mock.Object.MakePersistent(entity); | |
} | |
public virtual void MakeTransient(T entity) | |
{ | |
Mock.Object.MakeTransient(entity); | |
} | |
public virtual IEnumerable<T> RetrieveAll() | |
{ | |
return Repository; | |
} | |
public IEnumerable<T> RetrieveAll(params string[] properties) | |
{ | |
return RetrieveAll(); | |
} | |
public virtual IEnumerable<T> Retrieve(Expression<Func<T, bool>> predicate) | |
{ | |
return Repository.Where(predicate.Compile()); | |
} | |
public IEnumerable<T> Retrieve(Expression<Func<T, bool>> predicate, params string[] properties) | |
{ | |
return Repository.Where(predicate.Compile()); | |
} | |
public virtual int Count(Expression<Func<T, bool>> predicate) | |
{ | |
return Repository.Count(predicate.Compile()); | |
} | |
public virtual Mock<IDao<T>> Mock { get; private set; } | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment