Пример #1
0
        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);
        }
Пример #2
0
        public async Task ApplyCappedCollectionModelWithIndex()
        {
            const int maxDocuments   = 100;
            const int maxSizeInBytes = maxDocuments * 1000;

            var model = new CappedCollectionModel
            {
                CollectionName       = _collectionName,
                MaxSizeInBytes       = maxSizeInBytes,
                MaxNumberOfDocuments = maxDocuments,
                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(_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);

            IDocumentCollection <TestDocument> collection = _documentDatabase.GetCollection <TestDocument>(_collectionName);
            IndexDetailV1 indexDetail = await collection.Index.GetIndexDetail(_workContext, model.Indexes[0].Name);

            indexDetail.Should().NotBeNull();
            indexDetail.Keys.Count.Should().Be(1);

            model.Indexes[0].IsEquals(indexDetail).Should().BeTrue();
        }