Пример #1
0
        public async Task <bool> Test(IWorkContext context)
        {
            Verify.IsNotNull(nameof(context), context);
            context = context.WithTag(_tag);

            CollectionDetailV1 detail = await Parent.Database.GetCollectionDetail(context, Parent.Model.CollectionName);

            if (detail == null)
            {
                MongoDbEventSource.Log.Info(context, $"Collection {Parent.Model.CollectionName}, does not exists");
                return(false);
            }

            CappedCollectionModel cappedModel = Parent.Model as CappedCollectionModel;

            if (cappedModel != null)
            {
                bool status = detail.Capped &&
                              cappedModel.MaxNumberOfDocuments == (int)detail.MaxDocuments &&
                              cappedModel.MaxSizeInBytes == (long)detail.MaxSizeInBytes;

                MongoDbEventSource.Log.Info(context, $"Collection {Parent.Model.CollectionName} is capped, isEqual={status}");
            }

            MongoDbEventSource.Log.Info(context, $"Collection {Parent.Model.CollectionName}, exists");
            return(true);
        }
Пример #2
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);
        }
Пример #3
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();
        }