示例#1
0
 protected async Task <TResult> ExecuteOperationAsync <TResult>(IWriteOperation <TResult> operation)
 {
     using (var binding = SuiteConfiguration.GetReadWriteBinding())
     {
         return(await operation.ExecuteAsync(binding, CancellationToken.None));
     }
 }
        public async Task ExecuteAsync_should_create_collection_when_Capped_is_set(
            [Values(false, true)]
            bool capped)
        {
            var maxSize = capped ? (long?)10000 : null;
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                Capped  = capped,
                MaxSize = maxSize
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
                if (capped)
                {
                    stats["capped"].ToBoolean().Should().BeTrue();
                }
                else
                {
                    stats.Contains("capped").Should().BeFalse();
                }
            }
        }
示例#3
0
        // helper methods
        public void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
            }
        }
示例#4
0
        // helper methods
        public void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                operation.Execute(binding);
            }
        }
        public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var indexName = "x_1";
                var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

                await subject.ExecuteAsync(binding, CancellationToken.None); // should not throw
            }
        }
示例#6
0
        public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await dropCollectionOperation.ExecuteAsync(binding, CancellationToken.None);

                await subject.ExecuteAsync(binding, CancellationToken.None); // this will throw if we have a problem...
            }
        }
        public async Task ExecuteAsync_should_return_expected_result_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new ListIndexesOperation(_collectionNamespace, _messageEncoderSettings);
                await DropCollectionAsync(binding);

                var result = await subject.ExecuteAsync(binding, Timeout.InfiniteTimeSpan, CancellationToken.None);

                result.Count().Should().Be(0);
            }
        }
示例#8
0
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new ListDatabaseNamesOperation(_messageEncoderSettings);
                EnsureDatabaseExists(binding);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result.Should().Contain(_databaseNamespace.DatabaseName);
            }
        }
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new RenameCollectionOperation(_collectionNamespace, _newCollectionNamespace, _messageEncoderSettings);
                EnsureCollectionExists(binding, _collectionNamespace);
                EnsureCollectionDoesNotExist(binding, _newCollectionNamespace);

                var result = await subject.ExecuteAsync(binding);

                result["ok"].ToBoolean().Should().BeTrue();
            }
        }
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                EnsureDatabaseExists(binding);
                var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);

                var result = await subject.ExecuteAsync(binding, Timeout.InfiniteTimeSpan, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
                result["dropped"].ToString().Should().Be(_databaseNamespace.DatabaseName);
            }
        }
        public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await dropCollectionOperation.ExecuteAsync(binding);

                Func <Task> action = async() => { await subject.ExecuteAsync(binding); };

                action.ShouldNotThrow();
            }
        }
示例#12
0
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var createCollectionOperation = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await createCollectionOperation.ExecuteAsync(binding, CancellationToken.None);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
                result["ns"].ToString().Should().Be(_collectionNamespace.FullName);
            }
        }
        public async Task ExecuteAsync_should_return_expected_result_when_database_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new ListIndexesOperation(_collectionNamespace, _messageEncoderSettings);
                await DropDatabaseAsync(binding);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                var list = await result.ToListAsync();

                list.Count.Should().Be(0);
            }
        }
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new ListIndexesOperation(_collectionNamespace, _messageEncoderSettings);
                await EnsureCollectionExistsAsync(binding);

                var expectedNames = new[] { "_id_" };

                var result = await subject.ExecuteAsync(binding, Timeout.InfiniteTimeSpan, CancellationToken.None);

                result.Select(index => index["name"].AsString).Should().BeEquivalentTo(expectedNames);
            }
        }
        public async Task ExecuteAsync_should_return_expected_result()
        {
            var function = "return 1";
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            BsonValue result;

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                result = await subject.ExecuteAsync(binding);
            }

            result.Should().Be(1);
        }
        public async Task ExecuteAsync_should_create_collection()
        {
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
            }
        }
        public async Task ExecuteAsync_should_return_expected_result_when_dropTarget_is_true_and_newCollectionNamespace_exists()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new RenameCollectionOperation(_collectionNamespace, _newCollectionNamespace, _messageEncoderSettings)
                {
                    DropTarget = true
                };
                EnsureCollectionExists(binding, _collectionNamespace);
                EnsureCollectionExists(binding, _newCollectionNamespace);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
            }
        }
        public async Task ExecuteAsync_should_return_expected_result_when_args_are_provided()
        {
            var function = "function(x) { return x; }";
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            subject.Args = new BsonValue[] { 1 };

            BsonValue result;

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                result = await subject.ExecuteAsync(binding);
            }

            result.Should().Be(1);
        }
        public void ExecuteAsync_should_throw_when_dropTarget_is_false_and_newCollectionNamespace_exists()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new RenameCollectionOperation(_collectionNamespace, _newCollectionNamespace, _messageEncoderSettings)
                {
                    DropTarget = false
                };
                EnsureCollectionExists(binding, _collectionNamespace);
                EnsureCollectionExists(binding, _newCollectionNamespace);

                Func <Task> action = () => subject.ExecuteAsync(binding);

                action.ShouldThrow <MongoCommandException>();
            }
        }
        public async Task ExecuteAsync_should_return_expected_result_when_noLock_is_provided()
        {
            var function = "return 1";
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            subject.NoLock = true;

            BsonValue result;

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                result = await subject.ExecuteAsync(binding, CancellationToken.None);
            }

            result.Should().Be(1);
        }
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var keys                 = new BsonDocument("x", 1);
                var requests             = new[] { new CreateIndexRequest(keys) };
                var createIndexOperation = new CreateIndexesOperation(_collectionNamespace, requests, _messageEncoderSettings);
                await createIndexOperation.ExecuteAsync(binding, CancellationToken.None);

                var indexName = "x_1";
                var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
            }
        }
示例#22
0
        public async Task ExecuteAsync_should_create_collection_when_AutoIndexId_is_set(
            [Values(false, true)]
            bool autoIndexId)
        {
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                AutoIndexId = autoIndexId
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();

                var listIndexesOperation = new ListIndexesOperation(_collectionNamespace, _messageEncoderSettings);
                var indexes = await listIndexesOperation.ExecuteAsync(binding, CancellationToken.None);

                indexes.Count().Should().Be(autoIndexId ? 1 : 0);
            }
        }
        public async Task ExecuteAsync_should_create_collection_when_AutoIndexId_is_set(
            [Values(false, true)]
            bool autoIndexId)
        {
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                AutoIndexId = autoIndexId
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
                stats["systemFlags"].ToInt32().Should().Be(autoIndexId ? 1 : 0);
            }
        }
示例#24
0
        public async Task ExecuteAsync_should_create_collection_when_UsePowerOf2Sizes_is_set(
            [Values(false, true)]
            bool usePowerOf2Sizes)
        {
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                UsePowerOf2Sizes = usePowerOf2Sizes
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
                stats["userFlags"].ToInt32().Should().Be(usePowerOf2Sizes ? 1 : 0);
            }
        }
示例#25
0
        // helper methods
        private void EnsureTestData()
        {
            if (_testDataHasBeenCreated)
            {
                return;
            }

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                dropCollectionOperation.Execute(binding);

                var requests = Enumerable.Range(1, 5)
                               .Select(id => new BsonDocument("_id", id))
                               .Select(document => new InsertRequest(document));
                var insertOperation = new BulkInsertOperation(_collectionNamespace, requests, _messageEncoderSettings);
                insertOperation.Execute(binding);
            }

            _testDataHasBeenCreated = true;
        }
示例#26
0
        public async Task ExecuteAsync_should_create_collection_when_MaxSize_is_set()
        {
            var maxSize = 10000L;
            var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                Capped  = true,
                MaxSize = maxSize
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
                stats["capped"].ToBoolean().Should().BeTrue();
                // TODO: not sure how to verify that the maxSize took effect
            }
        }
示例#27
0
        public async Task ExecuteAsync_should_create_collection_when_MaxDocuments_is_set()
        {
            var maxDocuments = 123L;
            var subject      = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                Capped       = true,
                MaxSize      = 10000L,
                MaxDocuments = maxDocuments
            };

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();

                var stats = await GetCollectionStatsAsync(binding);

                stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
                stats["capped"].ToBoolean().Should().BeTrue();
                stats["max"].ToInt64().Should().Be(maxDocuments);
            }
        }