public void Constructor_should_create_a_valid_instance()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings);

            subject.CollectionNamespace.Should().Be(_collectionNamespace);
            subject.Pipeline.Should().BeEmpty();
            subject.MessageEncoderSettings.Should().BeEquivalentTo(_messageEncoderSettings);
        }
        public async Task ExecuteAsync_should_return_the_result_without_any_options()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings);

            var result = await ExecuteOperationAsync(subject);

            result.Should().NotBeNull();
        }
Beispiel #3
0
        public void AllowDiskUse_get_and_set_should_work()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);

            subject.AllowDiskUse = true;
            var result = subject.AllowDiskUse;

            result.Should().Be(true);
        }
Beispiel #4
0
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().Supports(Feature.AggregateExplain);
            var subject           = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);
            var cancellationToken = new CancellationTokenSource().Token;

            VerifySessionIdWasSentWhenSupported(subject, "aggregate", async);
        }
        public void MaxTime_should_have_the_correct_value()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings);

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

            subject.MaxTime = TimeSpan.FromSeconds(2);

            subject.MaxTime.Should().Be(TimeSpan.FromSeconds(2));
        }
        public void AllowDiskUse_should_have_the_correct_value()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings);

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

            subject.AllowDiskUse = true;

            subject.AllowDiskUse.Should().Be(true);
        }
        public void Execute_should_return_the_result_without_any_options(
            [Values(false, true)]
            bool async)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result.Should().NotBeNull();
        }
Beispiel #8
0
        public void Comment_get_and_set_should_work()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);
            var value   = "test";

            subject.Comment = value;
            var result = subject.Comment;

            result.Should().BeSameAs(value);
        }
Beispiel #9
0
        public void MaxTime_get_and_set_should_work()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);
            var value   = TimeSpan.FromSeconds(2);

            subject.MaxTime = value;
            var result = subject.MaxTime;

            result.Should().Be(value);
        }
Beispiel #10
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.AggregateExplain);
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result.Should().NotBeNull();
        }
Beispiel #11
0
        public void CreateCommand_should_throw_when_Collation_is_set_but_not_supported()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

            var exception = Record.Exception(() => subject.CreateCommand(Feature.Collation.LastNotSupportedVersion));

            exception.Should().BeOfType <NotSupportedException>();
        }
        public void MaxTime_get_and_set_should_work(
            [Values(-10000, 0, 1, 10000, 99999)] long maxTimeTicks)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

            subject.MaxTime = value;
            var result = subject.MaxTime;

            result.Should().Be(value);
        }
        public async Task ExecuteAsync_should_return_the_result_with_allow_disk_use()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings)
            {
                AllowDiskUse = true,
                MaxTime      = TimeSpan.FromSeconds(20)
            };

            var result = await ExecuteOperationAsync(subject);

            result.Should().NotBeNull();
        }
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-10001, -9999, -1)] long maxTimeTicks)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

            var exception = Record.Exception(() => subject.MaxTime = value);

            var e = exception.Should().BeOfType <ArgumentOutOfRangeException>().Subject;

            e.ParamName.Should().Be("value");
        }
Beispiel #15
0
        public void Constructor_should_create_a_valid_instance()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.Pipeline.Should().Equal(__pipeline);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);

            subject.AllowDiskUse.Should().NotHaveValue();
            subject.Collation.Should().BeNull();
            subject.MaxTime.Should().NotHaveValue();
        }
Beispiel #16
0
        public void Execute_should_return_expected_result_when_MaxTime_is_set(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromSeconds(1)
            };

            var result = ExecuteOperation(subject, async);

            result.Should().NotBeNull();
        }
        public void Execute_should_return_the_result_with_allow_disk_use(
            [Values(false, true)]
            bool async)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings)
            {
                AllowDiskUse = true,
                MaxTime      = TimeSpan.FromSeconds(20)
            };

            var result = ExecuteOperation(subject, async);

            result.Should().NotBeNull();
        }
Beispiel #18
0
        public void Execute_should_throw_when_Collation_is_set_but_not_supported(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.AggregateExplain).DoesNotSupport(Feature.Collation);

            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

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

            exception.Should().BeOfType <NotSupportedException>();
        }
Beispiel #19
0
        public void CreateCommand_should_return_expected_result()
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings);

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) }
            };

            result.Should().Be(expectedResult);
        }
        public void Execute_should_throw_when_maxTime_is_exceeded(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().Supports(Feature.AggregateExplain, Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);

            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromSeconds(9001)
            };

            using (var failPoint = FailPoint.ConfigureAlwaysOn(CoreTestConfiguration.Cluster, _session, FailPointName.MaxTimeAlwaysTimeout))
            {
                var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async));

                exception.Should().BeOfType <MongoExecutionTimeoutException>();
            }
        }
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
Beispiel #22
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(
            [Values(1, 2)]
            int milliseconds)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromMilliseconds(milliseconds)
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "maxTimeMS", milliseconds }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #23
0
        public void CreateCommand_should_return_expected_result_when_AllowDiskUse_is_set(
            [Values(false, true)]
            bool allowDiskUse)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                AllowDiskUse = allowDiskUse
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "allowDiskUse", allowDiskUse }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #24
0
        public void CreateCommand_should_return_expected_result_when_Comment_is_set(
            [Values(null, "test")]
            string comment)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Comment = comment,
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "comment", () => comment, comment != null }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #25
0
        public void Execute_should_return_expected_result_when_Comment_is_set(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Comment = "test"
            };

            using (var profile = Profile(_collectionNamespace.DatabaseNamespace))
            {
                var result = ExecuteOperation(subject, async);

                result.Should().NotBeNull();

                var profileEntries = profile.Find(new BsonDocument("command.aggregate", new BsonDocument("$exists", true)));
                profileEntries.Should().HaveCount(1);
                profileEntries[0]["command"]["comment"].AsString.Should().Be(subject.Comment);
            }
        }
Beispiel #26
0
        public void CreateCommand_should_return_expected_result_when_Collation_is_set(
            [Values("en_US", "fr_CA")]
            string locale)
        {
            var collation = new Collation(locale);
            var subject   = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Collation = collation
            };

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

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "collation", collation.ToBsonDocument() }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #27
0
        public void CreateCommand_should_return_the_expected_result_when_Hint_is_set(
            [Values(null, "{x: 1}")]
            string hintJson)
        {
            var hint    = hintJson == null ? null : BsonDocument.Parse(hintJson);
            var subject = new AggregateExplainOperation(_collectionNamespace, __pipeline, _messageEncoderSettings)
            {
                Hint = hint
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(__pipeline) },
                { "hint", () => hint, hint != null }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values(null, false, true)] bool?allowDiskUse,
            [Values(null, 2000)] int?maxTime)
        {
            var subject = new AggregateExplainOperation(_collectionNamespace, Enumerable.Empty <BsonDocument>(), _messageEncoderSettings)
            {
                AllowDiskUse = allowDiskUse,
                MaxTime      = maxTime.HasValue ? TimeSpan.FromMilliseconds(maxTime.Value) : (TimeSpan?)null
            };

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "explain", true },
                { "pipeline", new BsonArray(subject.Pipeline) },
                { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse.HasValue },
                { "maxTimeMS", () => maxTime.Value, maxTime.HasValue }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }