/// <summary>
        /// Apply collection model, create collection and its create indexes
        /// </summary>
        /// <param name="context">context</param>
        /// <returns>task</returns>
        public async Task ApplyCollectionModels(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(ApplyCollectionModels)} for collection={model.CollectionName}");

                var package = new CollectionModelPackage(db, model);
                await package.Apply(context).ConfigureAwait(false);
            }
        }
Пример #2
0
        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());
        }
Пример #3
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);
        }
Пример #4
0
        public DocumentSearchTests()
        {
            _documentServer = new DocumentServer(Constants.ConnectionString);

            _testDocuments = Enumerable.Range(0, 10)
                             .Select(x => CreateTestDocument(x))
                             .OrderBy(x => x._id)
                             .ToList();

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

            _collection = db.GetCollection <TestDocument>(_collectionName);

            ResetDatabase()
            .GetAwaiter()
            .GetResult();
        }