public async Task CreateAndRemoveDatabaseTest() { const int count = 10; IEnumerable <DatabaseDetailV1> result = await _documentServer.ListDatabases(_workContext); result.Should().NotBeNull(); result.Count().Should().BeGreaterThan(1); IList <string> dbList = Enumerable.Range(0, count).Select(x => $"Database_{x}").ToList(); IEnumerable <string> dbToDelete = result.Where(x => dbList.Contains(x.Name)).Select(x => x.Name).ToList(); foreach (var dbName in dbToDelete) { await _documentServer.DropDatabase(_workContext, dbName); } IEnumerable <DatabaseDetailV1> baseResult = await _documentServer.ListDatabases(_workContext); foreach (var dbName in dbList) { IDocumentDatabase db = _documentServer.GetDatabase(_workContext, dbName); await db.CreateCollection(_workContext, "TestCollection"); } IEnumerable <DatabaseDetailV1> afterGetDatbase = await _documentServer.ListDatabases(_workContext); IEnumerable <DatabaseDetailV1> afterFilter = afterGetDatbase.Where(x => !baseResult.Any(y => y.Name.Equals(x.Name, StringComparison.OrdinalIgnoreCase))); afterFilter.Count().Should().Be(count); afterFilter .OrderBy(x => x.Name) .Zip(dbList.OrderBy(x => x), (f, s) => new { F = f, S = s }) .All(x => x.F.Name == x.S) .Should().BeTrue(); foreach (var dbName in dbList) { await _documentServer.DropDatabase(_workContext, dbName); } IEnumerable <DatabaseDetailV1> afterDelete = await _documentServer.ListDatabases(_workContext); afterDelete.Count().Should().Be(baseResult.Count()); }
public CollectionModelPackageTests() { _documentServer = new DocumentServer(Constants.ConnectionString); _documentServer.DropDatabase(_workContext, _dbName) .GetAwaiter() .GetResult(); }
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); }
public CappedCollectionModelPackageTests() { string databaseName = $"TestCappedDatabase_{nameof(CappedCollectionModelPackageTests)}"; _documentServer = new DocumentServer(Constants.ConnectionString); _documentServer .DropDatabase(_workContext, databaseName) .GetAwaiter() .GetResult(); _documentDatabase = new DocumentDatabase(new DatabaseConfigurationBuilder(Constants.ConnectionString, databaseName).ToString()); }