public override void Init()
        {
            base.Init();

            using (var context = new CountVonCountTestDbContext())
            {
                context.WordMetrics.AddRange(_expectedWordMetrics);
                context.SaveChanges();
            }
        }
Example #2
0
        private static void InitDb()
        {
            using (var context = new CountVonCountTestDbContext())
            {
                // Force DB initialisation using migration scripts
                context.Database.Initialize(true);
                ClearDb(context);

                context.SaveChanges();
            }
        }
        public void WhenGetIsCalledAndNoParametersAreSuppliedThenAllEntitiesAreReturned()
        {
            using (var context = new CountVonCountTestDbContext())
            {
                var sut = new EntityFrameworkRepository <CountVonCountTestDbContext>(context);

                var entities = sut.Get <WordMetric>();

                Assert.AreEqual(_expectedWordMetrics.Count, entities.Count());
            }
        }
        public void WhenGetIsCalledAndTakeIsSuppliedThenUpToThatNumberOfEntitiesAreReturned()
        {
            using (var context = new CountVonCountTestDbContext())
            {
                var sut = new EntityFrameworkRepository <CountVonCountTestDbContext>(context);

                const int take     = 3;
                var       entities = sut.Get <WordMetric>(null, null, take);

                Assert.AreEqual(take, entities.Count());
            }
        }
        public void WhenGetIsCalledAndOrderByIsSuppliedAllEntitiesAreReturnedInOrder()
        {
            using (var context = new CountVonCountTestDbContext())
            {
                var sut = new EntityFrameworkRepository <CountVonCountTestDbContext>(context);

                IOrderedQueryable <WordMetric> OrderByDesc(IQueryable <WordMetric> words) => words.OrderByDescending(x => x.Count);

                var expectedOrder = OrderByDesc(_expectedWordMetrics.AsQueryable()).ToList();
                var entities      = sut.Get <WordMetric>(null, OrderByDesc);

                CollectionAssert.AreEqual(expectedOrder, entities, new WordMetricComparer());
            }
        }
        public void WhenGetIsCalledAndWhereIsSuppliedEntitiesSatisfyingTheClauseAreReturned()
        {
            using (var context = new CountVonCountTestDbContext())
            {
                var sut = new EntityFrameworkRepository <CountVonCountTestDbContext>(context);

                var secondTopCount   = _expectedWordMetrics.OrderByDescending(w => w.Count).ToArray()[1].Count;
                var expectedEntities = _expectedWordMetrics.Where(w => w.Count > secondTopCount);
                Expression <Func <WordMetric, bool> > where = wordM => wordM.Count > secondTopCount;

                var entities = sut.Get(where);

                CollectionAssert.AreEqual(expectedEntities.OrderBy(x => x.Count), entities.OrderBy(x => x.Count),
                                          new WordMetricComparer());
            }
        }
Example #7
0
        public void WhenUpsertIsCalledAllEntitiesAreWroteToTheDb()
        {
            var mockHashRepository = new Mock <IHashRepository>();

            mockHashRepository.Setup(h => h.Hash(It.IsAny <IEnumerable <WordMetric> >())).Returns(_expectedWordMetrics);

            using (var context = new CountVonCountTestDbContext())
            {
                var sut = new EntityFrameworkRepository <CountVonCountTestDbContext>(context, mockHashRepository.Object);

                sut.Upsert(_expectedWordMetrics);
            }

            using (var context = new CountVonCountTestDbContext())
            {
                CollectionAssert.AreEqual(_expectedWordMetrics.OrderBy(x => x.Id),
                                          context.WordMetrics.OrderBy(x => x.Id), new WordMetricComparer());
            }
        }