Beispiel #1
0
        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);
        }
Beispiel #2
0
        public async Task TestCollectionModelFullFail()
        {
            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);

            foreach (var variation in Enumerable.Range(1, 2))
            {
                CollectionModel model = CreateCollectionModel(variation);

                var package = new CollectionModelPackage(db, model, new CollectionModelSettings {
                    ReCreate = true
                });

                bool result = await package.Apply(_workContext);

                result.Should().BeTrue();

                package = new CollectionModelPackage(db, model, new CollectionModelSettings());
                result  = await package.Test(_workContext);

                result.Should().BeTrue();

                model.Indexes[0].Keys.Add(new IndexKey {
                    FieldName = "xxxx"
                });
                result = await package.Test(_workContext);

                result.Should().BeFalse();

                await db.DropCollection(_workContext, _collectionName);
            }

            await _documentServer.DropDatabase(_workContext, _dbName);
        }
Beispiel #3
0
        public async Task CreateSingleIndexTest()
        {
            await _documentServer.DropDatabase(_workContext, _dbName);

            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);
            await db.CreateCollection(_workContext, _collectionName);

            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            IEnumerable <IndexDetailV1> list = await collection.Index.ListIndexes(_workContext);

            list.Should().NotBeNull();
            list.Count().Should().Be(1);

            list.First().Name.Should().Be("_id_");

            var model = new CollectionIndex
            {
                Name   = "TestIndex_1",
                Unique = true,
                Sparse = false,
                Keys   = new List <IndexKey>
                {
                    new IndexKey {
                        FieldName = "FirstName"
                    },
                    new IndexKey {
                        FieldName = "Last Name"
                    },
                }
            };

            await collection.Index.CreateIndex(_workContext, model);

            list = await collection.Index.ListIndexes(_workContext);

            list.Should().NotBeNull();
            list.Count().Should().Be(2);

            list.First().Name.Should().Be("_id_");

            IndexDetailV1 detail = list.Skip(1).First();

            detail.Name.Should().Be(model.Name);
            detail.Unique.Should().Be(model.Unique);
            detail.Sparse.Should().Be(model.Sparse);
            detail.Keys.Count.Should().Be(model.Keys.Count);
            detail.Keys[0].FieldName.Should().Be(model.Keys[0].FieldName);
            detail.Keys[0].Descending.Should().Be(model.Keys[0].Descending);
            detail.Keys[1].FieldName.Should().Be(model.Keys[1].FieldName);
            detail.Keys[1].Descending.Should().Be(model.Keys[1].Descending);

            await db.DropCollection(_workContext, _collectionName);

            await _documentServer.DropDatabase(_workContext, _dbName);
        }
        /// <summary>
        /// Reset collections, destroy and re-create collections
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task ResetCollections(IWorkContext context)
        {
            Verify.IsNotNull(nameof(context), context);
            context = context.WithTag(_tag);

            IDocumentDatabase db = _documentServer.GetDatabase(_configuration.DatabaseName);

            foreach (var model in _models)
            {
                context.Telemetry.Info(context, $"{nameof(ResetCollections)} for collection={model.CollectionName}");
                await db.DropCollection(context, model.CollectionName).ConfigureAwait(false);
            }

            await ApplyCollectionModels(context).ConfigureAwait(false);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public async Task ApplyCollectionModelMultipleIndexesFull()
        {
            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);

            CollectionModel model = CreateCollectionModel(2);

            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();

            await db.DropCollection(_workContext, _collectionName);

            await _documentServer.DropDatabase(_workContext, _dbName);
        }
Beispiel #8
0
        public async Task ApplyCollectionModelCompositeKeyFull()
        {
            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
                            },
                            new IndexKey {
                                FieldName = "Field2", Descending = true
                            },
                        }
                    }
                }
            };

            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();

            await db.DropCollection(_workContext, _collectionName);

            await _documentServer.DropDatabase(_workContext, _dbName);
        }
Beispiel #9
0
        public async Task TestCollectionModelFull()
        {
            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);

            CollectionModel model = CreateCollectionModel(1);

            var package = new CollectionModelPackage(db, model, new CollectionModelSettings {
                ReCreate = true
            });

            bool result = await package.Apply(_workContext);

            result.Should().BeTrue();

            package = new CollectionModelPackage(db, model, new CollectionModelSettings());
            result  = await package.Test(_workContext);

            result.Should().BeTrue();

            await db.DropCollection(_workContext, _collectionName);

            await _documentServer.DropDatabase(_workContext, _dbName);
        }