public async Task <TProduct> Add(TProduct product) { product.Validate(); await _db.Collection <TProduct>().InsertOneAsync(product); return(product); }
public async Task <IEnumerable <DbChapter> > QueryChapters(int level) { return(await _db .Collection <DbChapter>() .AsQueryable() .Where(x => x.Level == level) .ToListAsync()); }
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)); }
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)); }