Example #1
0
        public async Task <TProduct> Add(TProduct product)
        {
            product.Validate();
            await _db.Collection <TProduct>().InsertOneAsync(product);

            return(product);
        }
Example #2
0
 public async Task <IEnumerable <DbChapter> > QueryChapters(int level)
 {
     return(await _db
            .Collection <DbChapter>()
            .AsQueryable()
            .Where(x => x.Level == level)
            .ToListAsync());
 }
Example #3
0
        public async Task QueryChapters_ForLevel_ReturnsExpectedChapters()
        {
            // setup
            var chapters = Enumerable
                           .Range(1, 10)
                           .Select(i => DbChapterBuilder.Default.WithLevel(i).Build());

            await _client
            .Collection <DbChapter>()
            .InsertManyAsync(chapters);

            // act
            var result = await _db.QueryChapters(5);

            // assert
            Assert.That(result.Count() == 1);
            Assert.That(result.All(x => x.Level == 5));
        }
Example #4
0
        private async Task Test_Add <TProduct>()
            where TProduct : class, IEntity, ICanBeValidated
        {
            var store   = new MongoStore <TProduct>(_client);
            var product = EntityFactory.Build <TProduct>();

            var result = await store.Add(product);

            var dto = await _client
                      .Collection <TProduct>()
                      .AsQueryable()
                      .SingleAsync(x => x.Id == result.Id);

            Assert.That(dto, Is.EqualTo(result));
        }