public void Execute_should_create_view_when_WriteConcern_is_set(
            [Values("a", "b")]
            string viewName,
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            DropView(viewName);
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings)
            {
                WriteConcern = new WriteConcern(1)
            };

            BsonDocument info;

            using (var binding = CreateReadWriteBinding())
            {
                ExecuteOperation(subject, binding, async);
                info = GetViewInfo(binding, viewName);
            }

            var options = info["options"].AsBsonDocument;

            options["viewOn"].AsString.Should().Be(_collectionNamespace.CollectionName);
            options["pipeline"].AsBsonArray.Cast <BsonDocument>().Should().Equal(_pipeline);
        }
        public void Execute_should_create_view_when_Collation_is_set(
            [Values(null, "en_US")]
            string locale,
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            DropView(_viewName);
            var collation = locale == null ? null : new Collation(locale);
            var subject   = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings)
            {
                Collation = collation
            };

            BsonDocument info;

            using (var binding = CreateReadWriteBinding())
            {
                ExecuteOperation(subject, binding, async);
                info = GetViewInfo(binding, _viewName);
            }

            var options = info["options"].AsBsonDocument;

            options["viewOn"].AsString.Should().Be(_collectionNamespace.CollectionName);
            options["pipeline"].AsBsonArray.Cast <BsonDocument>().Should().Equal(_pipeline);
            if (collation == null)
            {
                options.Contains("collation").Should().BeFalse();
            }
            else
            {
                options["collation"].AsBsonDocument.Should().Equals(collation.ToBsonDocument());
            }
        }
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check();
            var viewName = "view";

            DropView(viewName);
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);

            VerifySessionIdWasSentWhenSupported(subject, "create", async);
        }
        public void WriteConcern_get_and_set_should_work(
            [Values(null, 1, 2)]
            int?w)
        {
            var subject = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);
            var value   = w.HasValue ? new WriteConcern(w.Value) : null;

            subject.WriteConcern = value;
            var result = subject.WriteConcern;

            result.Should().BeSameAs(value);
        }
        public void Collation_get_and_set_should_work(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);
            var value   = locale == null ? null : new Collation(locale);

            subject.Collation = value;
            var result = subject.Collation;

            result.Should().BeSameAs(value);
        }
        public void constructor_should_initialize_instance(
            [Values("a", "b")]
            string viewName)
        {
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);

            subject.Collation.Should().BeNull();
            subject.DatabaseNamespace.Should().BeSameAs(_databaseNamespace);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            subject.Pipeline.Should().Equal(_pipeline);
            subject.ViewName.Should().Be(viewName);
            subject.ViewOn.Should().Be(_collectionNamespace.CollectionName);
            subject.WriteConcern.Should().BeNull();
        }
        public void Execute_should_throw_when_a_write_concern_error_occurs(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().ClusterType(ClusterType.ReplicaSet);
            DropView(_viewName);
            var subject = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings)
            {
                WriteConcern = new WriteConcern(9)
            };

            var exception = Record.Exception(() => ExecuteOperation(subject, async));

            exception.Should().BeOfType <MongoWriteConcernException>();
        }
Ejemplo n.º 8
0
        public void CreateCommand_should_return_expected_result(
            [Values("a", "b")]
            string viewName)
        {
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);

            var result = subject.CreateCommand(Feature.Views.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "create", viewName },
                { "viewOn", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result(
            [Values("a", "b")]
            string viewName)
        {
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

            var result = subject.CreateCommand(session, connectionDescription);

            var expectedResult = new BsonDocument
            {
                { "create", viewName },
                { "viewOn", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 10
0
        public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set(
            [Values(null, 1, 2)]
            int?w)
        {
            var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null;
            var subject      = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };

            var result = subject.CreateCommand(Feature.Views.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "create", _viewName },
                { "viewOn", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 11
0
        public void CreateCommand_should_return_expected_result_when_Collation_is_set(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var collation = locale == null ? null : new Collation(locale);
            var subject   = new CreateViewOperation(_databaseNamespace, _viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings)
            {
                Collation = collation
            };

            var result = subject.CreateCommand(Feature.Views.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "create", _viewName },
                { "viewOn", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "collation", () => collation.ToBsonDocument(), collation != null }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 12
0
        public void Execute_should_create_view(
            [Values("a", "b")]
            string viewName,
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.Views);
            DropView(viewName);
            var subject = new CreateViewOperation(_databaseNamespace, viewName, _collectionNamespace.CollectionName, _pipeline, _messageEncoderSettings);

            BsonDocument info;

            using (var binding = CoreTestConfiguration.GetReadWriteBinding(_session.Fork()))
            {
                ExecuteOperation(subject, binding, async);
                info = GetViewInfo(binding, viewName);
            }

            var options = info["options"].AsBsonDocument;

            options["viewOn"].AsString.Should().Be(_collectionNamespace.CollectionName);
            options["pipeline"].AsBsonArray.Cast <BsonDocument>().Should().Equal(_pipeline);
        }