Ejemplo n.º 1
0
        public async Task SmallCappedOverFiveCollectionTest()
        {
            const int maxDocuments        = 10;
            const int maxSizeInBytes      = maxDocuments * 1000;
            const int createDocumentCount = maxDocuments + 5;

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

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

            foreach (var index in Enumerable.Range(0, createDocumentCount))
            {
                TestDocument doc = CreateTestDocument(index);
                await collection.Insert(_workContext, doc);
            }

            long count = await collection.Count(_workContext);

            count.Should().Be(maxDocuments);

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(maxDocuments);

            int testIndex = createDocumentCount - maxDocuments;

            foreach (var item in results.OrderBy(x => x.Index))
            {
                TestDocument compareDoc = CreateTestDocument(testIndex++);
                item.IsEqual(compareDoc).Should().BeTrue();
            }
        }