Exemplo n.º 1
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_Collation(
            [Values(null, "en_US", "fr_CA")]
            string locale,
            [Values(false, true)]
            bool async)
        {
            var pipeline  = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(new BsonDocument[0]);
            var collation = locale == null ? null : new Collation(locale);
            var options   = new CreateViewOptions <BsonDocument>
            {
                Collation = collation
            };

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

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

            operation.Collation.Should().BeSameAs(collation);
        }
Exemplo n.º 2
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_CancellationToken(
            [Values(false, true)]
            bool async)
        {
            var pipeline          = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(new BsonDocument[0]);
            var cancellationToken = new CancellationTokenSource().Token;

            if (async)
            {
                _subject.CreateViewAsync <BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, cancellationToken).GetAwaiter().GetResult();
            }
            else
            {
                _subject.CreateView <BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, cancellationToken);
            }

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

            call.CancellationToken.Should().Be(cancellationToken);
        }
Exemplo n.º 3
0
        private static UpdateDefinition <TDocument> UnwrapUpdate(BsonValue update)
        {
            var wrapper = update as BsonDocumentWrapper;

            if (wrapper != null)
            {
                if (wrapper.Wrapped is BsonDocument)
                {
                    return(new BsonDocumentUpdateDefinition <TDocument>((BsonDocument)wrapper.Wrapped));
                }
                return(new ObjectUpdateDefinition <TDocument>(wrapper.Wrapped));
            }

            if (update is BsonArray stages)
            {
                var pipeline = new BsonDocumentStagePipelineDefinition <TDocument, TDocument>(stages.Cast <BsonDocument>());
                return(new PipelineUpdateDefinition <TDocument>(pipeline));
            }

            return(new BsonDocumentUpdateDefinition <TDocument>((BsonDocument)update));
        }
Exemplo n.º 4
0
        public void CreateView_should_throw_when_viewOn_is_null(
            [Values(false, true)]
            bool async)
        {
            var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(new BsonDocument[0]);

            var exception = Record.Exception(() =>
            {
                if (async)
                {
                    _subject.CreateViewAsync <BsonDocument, BsonDocument>("viewName", null, pipeline).GetAwaiter().GetResult();
                }
                else
                {
                    _subject.CreateView <BsonDocument, BsonDocument>("viewName", null, pipeline);
                }
            });

            var argumentNullException = exception.Should().BeOfType <ArgumentNullException>().Subject;

            argumentNullException.ParamName.Should().Be("viewOn");
        }
Exemplo n.º 5
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_ViewOn(
            [Values("a", "b")]
            string viewOn,
            [Values(false, true)]
            bool async)
        {
            var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(new BsonDocument[0]);

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

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

            operation.ViewOn.Should().Be(viewOn);
        }
Exemplo n.º 6
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_Pipeline(
            [Values(1, 2)]
            int x,
            [Values(false, true)]
            bool async)
        {
            var stages   = new[] { new BsonDocument("$match", new BsonDocument("x", x)) };
            var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages);

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

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

            operation.Pipeline.Should().Equal(stages);
        }
Exemplo n.º 7
0
        public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_WriteConcern(
            [Values(1, 2)]
            int w,
            [Values(false, true)]
            bool async)
        {
            var writeConcern = new WriteConcern(w);
            var subject      = _subject.WithWriteConcern(writeConcern);
            var pipeline     = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(new BsonDocument[0]);

            if (async)
            {
                subject.CreateViewAsync <BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                subject.CreateView <BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None);
            }

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

            operation.WriteConcern.Should().BeSameAs(writeConcern);
        }