コード例 #1
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var indexDocument  = CreateIndexDocument();
            var documentSource = new BatchableSource <BsonDocument>(new[] { indexDocument });
            var operation      = new InsertOpcodeOperation(_databaseName, "system.indexes", documentSource).WithWriteConcern(_writeConcern);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
コード例 #2
0
        public void Constructor_should_initialize_object()
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documents, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.CollectionNamespace.FullName.Should().Be(_collectionNamespace.FullName);
            subject.Documents.Count.Should().Be(_documents.Length);
            subject.Serializer.Should().BeSameAs(BsonDocumentSerializer.Instance);
            subject.MessageEncoderSettings.Should().BeEquivalentTo(_messageEncoderSettings);
        }
コード例 #3
0
        public void MaxBatchCount_should_work()
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documents, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.MaxBatchCount.Should().Be(null);

            subject.MaxBatchCount = 20;

            subject.MaxBatchCount.Should().Be(20);
        }
コード例 #4
0
        public void ContinueOnError_should_work()
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documents, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.ContinueOnError.Should().Be(false);

            subject.ContinueOnError = true;

            subject.ContinueOnError.Should().Be(true);
        }
コード例 #5
0
        public void WriteConcern_should_work()
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documents, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.WriteConcern.Should().Be(WriteConcern.Acknowledged);

            subject.WriteConcern = WriteConcern.W2;

            subject.WriteConcern.Should().Be(WriteConcern.W2);
        }
コード例 #6
0
        public async Task ExecuteAsync_should_insert_a_single_document()
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documentSource, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = await ExecuteOperationAsync(subject);

            result.Should().HaveCount(1);

            var list = await ReadAllFromCollectionAsync();

            list.Should().HaveCount(1);
        }
コード例 #7
0
 // constructors
 public Builder(InsertOpcodeOperation <TDocument> original)
 {
     _collectionName  = original._collectionName;
     _continueOnError = original._continueOnError;
     _databaseName    = original._databaseName;
     _documentSource  = original._documentSource;
     _maxBatchCount   = original.MaxBatchCount;
     _maxDocumentSize = original.MaxDocumentSize;
     _maxMessageSize  = original.MaxMessageSize;
     _serializer      = original._serializer;
     _writeConcern    = original.WriteConcern;
 }
コード例 #8
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var indexDocument  = CreateIndexDocument();
            var documentSource = new BatchableSource <BsonDocument>(new[] { indexDocument });
            var operation      = new InsertOpcodeOperation(_collectionNamespace.DatabaseNamespace.SystemIndexesCollection, documentSource, _messageEncoderSettings)
            {
                WriteConcern = _writeConcern
            };
            var results = await operation.ExecuteAsync(binding, timeout, cancellationToken).ConfigureAwait(false);

            return(results.First().Response);
        }
コード例 #9
0
        public void Execute_should_insert_a_single_document(
            [Values(false, true)]
            bool async)
        {
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, _documentSource, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result.Should().HaveCount(1);

            var list = ReadAllFromCollection(async);

            list.Should().HaveCount(1);
        }
コード例 #10
0
        private async Task <BsonDocument> ExecuteUsingInsertAsync(IChannelSourceHandle channelSource, CancellationToken cancellationToken)
        {
            var systemIndexesCollection = _collectionNamespace.DatabaseNamespace.SystemIndexesCollection;

            foreach (var createIndexRequest in _requests)
            {
                var document = createIndexRequest.CreateIndexDocument();
                document.InsertAt(0, new BsonElement("ns", _collectionNamespace.FullName));
                var documentSource = new BatchableSource <BsonDocument>(new[] { document });
                var operation      = new InsertOpcodeOperation(systemIndexesCollection, documentSource, _messageEncoderSettings);
                await operation.ExecuteAsync(channelSource, cancellationToken).ConfigureAwait(false);
            }

            return(new BsonDocument("ok", 1));
        }
コード例 #11
0
        public async Task ExecuteAsync_should_insert_multiple_documents()
        {
            var documentSource = new BatchableSource <BsonDocument>(new[]
            {
                BsonDocument.Parse("{_id: 1, x: 1}"),
                BsonDocument.Parse("{_id: 2, x: 2}"),
                BsonDocument.Parse("{_id: 3, x: 3}"),
                BsonDocument.Parse("{_id: 4, x: 4}"),
            });
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, documentSource, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = await ExecuteOperationAsync(subject);

            result.Should().HaveCount(1);

            var list = await ReadAllFromCollectionAsync();

            list.Should().HaveCount(4);
        }
コード例 #12
0
        public void Execute_should_insert_multiple_documents(
            [Values(false, true)]
            bool async)
        {
            var documentSource = new BatchableSource <BsonDocument>(new[]
            {
                BsonDocument.Parse("{_id: 1, x: 1}"),
                BsonDocument.Parse("{_id: 2, x: 2}"),
                BsonDocument.Parse("{_id: 3, x: 3}"),
                BsonDocument.Parse("{_id: 4, x: 4}"),
            });
            var subject = new InsertOpcodeOperation <BsonDocument>(_collectionNamespace, documentSource, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result.Should().HaveCount(1);

            var list = ReadAllFromCollection(async);

            list.Should().HaveCount(4);
        }