示例#1
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);
        }
        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);
        }
        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);
        }
示例#4
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);
        }
示例#5
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);
        }
        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);
        }