Exemplo n.º 1
0
        public async Task CreateAndRemoveCollectionsTest()
        {
            const int    count  = 10;
            const string dbName = "TestDatabase_01";

            IList <string> collectionList = Enumerable.Range(0, count).Select(x => $"Collection_{x}").ToList();

            await _documentServer.DropDatabase(_workContext, dbName);

            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, dbName);

            IEnumerable <CollectionDetailV1> collections = await db.ListCollections(_workContext);

            collections.Should().NotBeNull();
            collections.Count().Should().Be(0);

            foreach (var collectionName in collectionList)
            {
                await db.CreateCollection(_workContext, collectionName);
            }

            collections = await db.ListCollections(_workContext);

            collections.Should().NotBeNull();
            collections.Count().Should().Be(count);

            collections
            .OrderBy(x => x.Name)
            .Zip(collectionList.OrderBy(x => x), (f, s) => new { F = f, S = s })
            .All(x => x.F.Name == x.S)
            .Should().BeTrue();

            foreach (var collectionName in collectionList)
            {
                await db.DropCollection(_workContext, collectionName);
            }

            collections = await db.ListCollections(_workContext);

            collections.Should().NotBeNull();
            collections.Count().Should().Be(0);

            await _documentServer.DropDatabase(_workContext, dbName);
        }