예제 #1
0
        // private methods
        private AggregateOperation <TResult> CreateAggregateOperation <TResult>(RenderedPipelineDefinition <TResult> renderedPipeline, AggregateOptions options)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();

            return(new AggregateOperation <TResult>(
                       _databaseNamespace,
                       renderedPipeline.Documents,
                       renderedPipeline.OutputSerializer,
                       messageEncoderSettings)
            {
                AllowDiskUse = options.AllowDiskUse,
                BatchSize = options.BatchSize,
                Collation = options.Collation,
                Comment = options.Comment,
                Hint = options.Hint,
                Let = options.Let,
                MaxAwaitTime = options.MaxAwaitTime,
                MaxTime = options.MaxTime,
                ReadConcern = _settings.ReadConcern,
                RetryRequested = _client.Settings.RetryReads,
#pragma warning disable 618
                UseCursor = options.UseCursor
#pragma warning restore 618
            });
        }
예제 #2
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_DocumentSerializer(
            [Values(false, true)]
            bool isDocumentSerializerNull,
            [Values(false, true)]
            bool async)
        {
            var mockPipeline       = new Mock <PipelineDefinition <BsonDocument, BsonDocument> >();
            var documentSerializer = isDocumentSerializerNull ? null : new BsonDocumentSerializer();
            var stages             = new [] { new BsonDocument("$match", new BsonDocument("x", 1)) };
            var renderedPipeline   = new RenderedPipelineDefinition <BsonDocument>(stages, BsonDocumentSerializer.Instance);

            mockPipeline.Setup(p => p.Render(documentSerializer ?? BsonSerializer.SerializerRegistry.GetSerializer <BsonDocument>(), BsonSerializer.SerializerRegistry)).Returns(renderedPipeline);

            var options = new CreateViewOptions <BsonDocument>
            {
                DocumentSerializer = documentSerializer
            };

            if (async)
            {
                _subject.CreateViewAsync <BsonDocument, BsonDocument>("viewName", "viewOn", mockPipeline.Object, options, CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                _subject.CreateView <BsonDocument, BsonDocument>("viewName", "viewOn", mockPipeline.Object, options, CancellationToken.None);
            }

            var call      = _operationExecutor.GetWriteCall <BsonDocument>();
            var operation = call.Operation.Should().BeOfType <CreateViewOperation>().Subject;

            operation.Pipeline.Should().Equal(stages); // test output of call to Render to see if DocumentSerializer was used
        }
예제 #3
0
 private AggregateOperation <TResult> CreateAggregateOperation <TResult>(RenderedPipelineDefinition <TResult> renderedPipeline, AggregateOptions options)
 {
     return(new AggregateOperation <TResult>(
                _collectionNamespace,
                renderedPipeline.Documents,
                renderedPipeline.OutputSerializer,
                _messageEncoderSettings)
     {
         AllowDiskUse = options.AllowDiskUse,
         BatchSize = options.BatchSize,
         MaxTime = options.MaxTime,
         ReadConcern = _settings.ReadConcern,
         UseCursor = options.UseCursor
     });
 }
예제 #4
0
        private AggregateToCollectionOperation CreateAggregateToCollectionOperation <TResult>(RenderedPipelineDefinition <TResult> renderedPipeline, AggregateOptions options)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();

            return(new AggregateToCollectionOperation(
                       _databaseNamespace,
                       renderedPipeline.Documents,
                       messageEncoderSettings)
            {
                AllowDiskUse = options.AllowDiskUse,
                BypassDocumentValidation = options.BypassDocumentValidation,
                Collation = options.Collation,
                Comment = options.Comment,
                Hint = options.Hint,
                Let = options.Let,
                MaxTime = options.MaxTime,
                ReadConcern = _settings.ReadConcern,
                ReadPreference = _settings.ReadPreference,
                WriteConcern = _settings.WriteConcern
            });
        }
예제 #5
0
 private AggregateToCollectionOperation CreateAggregateToCollectionOperation <TResult>(RenderedPipelineDefinition <TResult> renderedPipeline, AggregateOptions options)
 {
     return(new AggregateToCollectionOperation(
                _collectionNamespace,
                renderedPipeline.Documents,
                _messageEncoderSettings)
     {
         AllowDiskUse = options.AllowDiskUse,
         BypassDocumentValidation = options.BypassDocumentValidation,
         Collation = options.Collation,
         MaxTime = options.MaxTime,
         WriteConcern = _settings.WriteConcern
     });
 }