Created
September 2, 2013 00:19
-
-
Save lukencode/6408204 to your computer and use it in GitHub Desktop.
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
public class DataMockHelpers | |
{ | |
public Mock<IQeraUnit> GetMockUnit() | |
{ | |
var unit = new Mock<IQeraUnit>(); | |
return unit; | |
} | |
public Mock<TRepo> MockRepo<TRepo, TEntity>(List<TEntity> seedData = null, bool callBase = false, MockBehavior behavior = MockBehavior.Default) | |
where TRepo : class, IRepo<TEntity> | |
where TEntity : class | |
{ | |
var repo = new Mock<TRepo>(behavior) { CallBase = callBase }; | |
var backingStore = seedData ?? new List<TEntity>(); | |
repo.Setup(x => x.All()).Returns(backingStore.AsQueryable()); | |
repo.Setup(x => x.Insert(It.IsAny<TEntity>())).Callback((TEntity item) => backingStore.Add(item)); | |
repo.Setup(x => x.Single(It.IsAny<Expression<Func<TEntity, bool>>>())).Returns((Expression<Func<TEntity, bool>> filter) => backingStore.AsQueryable().FirstOrDefault(filter)); | |
repo.Setup(x => x.Delete(It.IsAny<TEntity>())).Callback((TEntity item) => backingStore.Remove(item)); | |
return repo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment