public async Task ApplyCappedCollectionModelWithoutIndex() { const int maxDocuments = 100; const int maxSizeInBytes = maxDocuments * 1000; var model = new CappedCollectionModel { CollectionName = _collectionName, MaxSizeInBytes = maxSizeInBytes, MaxNumberOfDocuments = maxDocuments, }; var package = new CollectionModelPackage(_documentDatabase, model, new CollectionModelSettings { ReCreate = true }); bool result = await package.Apply(_workContext); result.Should().BeTrue(); (await _documentDatabase.CollectionExist(_workContext, _collectionName)).Should().BeTrue(); CollectionDetailV1 detail = await _documentDatabase.GetCollectionDetail(_workContext, _collectionName); detail.Should().NotBeNull(); detail.Name.Should().Be(_collectionName); detail.Type.Should().Be("collection"); detail.Readonly.Should().BeFalse(); detail.Capped.Should().BeTrue(); detail.MaxDocuments.Should().HaveValue(); detail.MaxDocuments.Should().Be(maxDocuments); detail.MaxSizeInBytes.Should().HaveValue(); detail.MaxSizeInBytes.Should().BeGreaterOrEqualTo(maxSizeInBytes); }
private async Task <bool> VerifyCollectionModel(IDocumentDatabase db, CollectionModel model) { (await db.CollectionExist(_workContext, _collectionName)).Should().BeTrue(); IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName); foreach (var indexDetail in model.Indexes) { IndexDetailV1 detail = await collection.Index.GetIndexDetail(_workContext, indexDetail.Name); detail.Should().NotBeNull(); if (!indexDetail.IsEquals(detail)) { return(false); } } IEnumerable <IndexDetailV1> dbIndex = await collection.Index.ListIndexes(_workContext); dbIndex.Should().NotBeNull(); dbIndex.Count().Should().Be(model.Indexes.Count + 1); return(dbIndex .Where(x => x.Name != "_id_") .OrderBy(x => x.Name) .Zip(model.Indexes.OrderBy(x => x.Name), (d, m) => new { Db = d, Model = m }) .All(x => x.Model.IsEquals(x.Db))); }
public async Task ApplyUpdateRemovedCollection() { IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName); CollectionModel model = CreateCollectionModel(3); var package = new CollectionModelPackage(db, model, new CollectionModelSettings { ReCreate = true }); bool result = await package.Apply(_workContext); result.Should().BeTrue(); (await VerifyCollectionModel(db, model)).Should().BeTrue(); model = CreateCollectionModel(0); var updatePackage = new CollectionModelPackage(db, model, new CollectionModelSettings { Remove = true }); result = await updatePackage.Apply(_workContext); result.Should().BeTrue(); (await db.CollectionExist(_workContext, _collectionName)).Should().BeFalse(); await db.DropCollection(_workContext, _collectionName); await _documentServer.DropDatabase(_workContext, _dbName); }
public async Task ApplyCollectionModelFull() { IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName); var model = new CollectionModel { CollectionName = _collectionName, Indexes = new List <CollectionIndex> { new CollectionIndex { Name = "TestIndex_1", Unique = true, Keys = new List <IndexKey> { new IndexKey { FieldName = "Field1", Descending = false }, } } } }; var package = new CollectionModelPackage(db, model, new CollectionModelSettings { ReCreate = true }); bool result = await package.Apply(_workContext); result.Should().BeTrue(); (await db.CollectionExist(_workContext, _collectionName)).Should().BeTrue(); IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName); IndexDetailV1 detail = await collection.Index.GetIndexDetail(_workContext, model.Indexes[0].Name); detail.Should().NotBeNull(); detail.Keys.Count.Should().Be(1); model.Indexes[0].IsEquals(detail).Should().BeTrue(); await db.DropCollection(_workContext, _collectionName); await _documentServer.DropDatabase(_workContext, _dbName); }