Exemple #1
0
        public void Dataset_WhenGettingEntityListWithNullPredicate_ExpectException()
        {
            var list    = new MockEntityList();
            var dataset = new Dataset <MockEntity>(list);

            var _ = dataset.Get(null);
        }
Exemple #2
0
        public void Dataset_WhenConstructingWithPopulatedList_ExpectDatasetToBePopulated()
        {
            var list = new MockEntityList();

            var sut = new Dataset <MockEntity>(list);

            Assert.IsTrue(sut.Get().Count() == list.Count);
        }
Exemple #3
0
        public void Dataset_WhenGettingEntityList_ExpectEntityList()
        {
            var list    = new MockEntityList();
            var dataset = new Dataset <MockEntity>(list);

            var sut = dataset.Get();

            Assert.IsTrue(sut.SequenceEqual(list));
        }
Exemple #4
0
        public IEnumerable <TEntity> RemoveRange(IEnumerable <TEntity> entities)
        {
            foreach (TEntity e in entities)
            {
                Remove(e);
            }

            return(MockEntityList.AsEnumerable <TEntity>());
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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());
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 public IEnumerator <TEntity> GetEnumerator()
 {
     return(MockEntityList.GetEnumerator());
 }
Exemple #13
0
 public IQueryable <TEntity> AsQueryable()
 {
     return(MockEntityList.AsQueryable <TEntity>());
 }