public void Dataset_WhenGettingEntityListWithNullPredicate_ExpectException() { var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); var _ = dataset.Get(null); }
public void Dataset_WhenConstructingWithPopulatedList_ExpectDatasetToBePopulated() { var list = new MockEntityList(); var sut = new Dataset <MockEntity>(list); Assert.IsTrue(sut.Get().Count() == list.Count); }
public void Dataset_WhenGettingEntityList_ExpectEntityList() { var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); var sut = dataset.Get(); Assert.IsTrue(sut.SequenceEqual(list)); }
public IEnumerable <TEntity> RemoveRange(IEnumerable <TEntity> entities) { foreach (TEntity e in entities) { Remove(e); } return(MockEntityList.AsEnumerable <TEntity>()); }
public void Dataset_WhenGettingEntityListWithPredicate_ExpectFilteredEntityList() { const int id = 1; var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); var sut = dataset.Get(x => x.Id == id); Assert.IsTrue(sut.Single().Id == id); }
public IEnumerable <TEntity> AddRange(IEnumerable <TEntity> entities) { long longId = this.Max <TEntity, long>(e => e.CacheId) + 1; Type entityType = typeof(TEntity); PropertyInfo idProperty = GetIdProperty(entityType); foreach (TEntity entity in entities) { SetEntityKey(idProperty, entity, ref longId); MockEntityList.Add(entity); } return(MockEntityList.ToList()); }
public void Dataset_WhenSettingEntityById_ExpectAlteredEntityList() { const int id = 1; const int value = int.MaxValue; var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); var entity = list.Single(x => x.Id == id); entity.Value = value; dataset.SetById(entity); var sut = dataset.Get(); Assert.IsTrue(sut.Single(x => x.Id == id).Value == value); }
public TEntity Remove(TEntity entity) { Type entityType = entity.GetType(); PropertyInfo idProperty = GetIdProperty(entityType); if (idProperty != null) { object key = idProperty.GetValue(entity); TEntity found = FindByKey(key); if (found != null) { MockEntityList.Remove(entity); } } return(entity); }
public void Dataset_WhenSettingEntityList_ExpectAlteredEntityList() { const int id = 1; const int value = int.MaxValue; var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); // ReSharper disable once CollectionNeverUpdated.Local var newList = new MockEntityList(); newList.Single(x => x.Id == id).Value = value; dataset.Set(newList); var sut = dataset.Get(); Assert.IsTrue(sut.Single(x => x.Id == id).Value == value); }
public void Dataset_WhenSettingEntityListWithDifferingItemCount_ExpectException() { const int id = 1; const int value = int.MaxValue; var list = new MockEntityList(); var dataset = new Dataset <MockEntity>(list); var newList = new MockEntityList { new MockEntity() { Id = id, Value = value } }; dataset.Set(newList); }
public TEntity Add(TEntity entity) { Type entityType = entity.GetType(); PropertyInfo idProperty = GetIdProperty(entityType); if (idProperty != null) { object key = idProperty.GetValue(entity); TEntity found = FindByKey(key); //if (found != null) //{ // throw new DbUpdateExceptionBase(); //} } MockEntityList.Add(entity); return(entity); }
public IEnumerator <TEntity> GetEnumerator() { return(MockEntityList.GetEnumerator()); }
public IQueryable <TEntity> AsQueryable() { return(MockEntityList.AsQueryable <TEntity>()); }