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 GroupOperation <BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
            {
                Collation = collation
            };

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

            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", _collectionNamespace.CollectionName },
                      { "key", _key },
                      { "$reduce", _reduceFunction },
                      { "initial", _initial },
                      { "collation", () => collation.ToBsonDocument(), collation != null }
                  } }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_finalizeFunction_is_set(
            [Values(false, true)]
            bool isFinalizeFunctionNull)
        {
            var finalizeFunction = isFinalizeFunctionNull ? null : _finalizeFunction;
            var subject          = new GroupOperation <BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
            {
                FinalizeFunction = finalizeFunction
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", _collectionNamespace.CollectionName },
                      { "key", _key },
                      { "$reduce", _reduceFunction },
                      { "initial", _initial },
                      { "finalize", finalizeFunction, finalizeFunction != null }
                  } }
            };

            result.Should().Be(expectedResult);
        }
Exemplo n.º 3
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(
            [Values(null, 1, 2)]
            int?seconds)
        {
            var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;
            var subject = new GroupOperation <BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", _collectionNamespace.CollectionName },
                      { "key", _key },
                      { "$reduce", _reduceFunction },
                      { "initial", _initial }
                  } },
                { "maxTimeMS", () => seconds.Value * 1000, seconds.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Exemplo n.º 4
0
        public void CreateCommand_should_return_expected_result_when_maxTime_was_provided()
        {
            var collectionNamespace = new CollectionNamespace("databaseName", "collectionName");
            var key                    = new BsonDocument("key", 1);
            var initial                = new BsonDocument("x", 1);
            var reduceFunction         = new BsonJavaScript("reduceFunction");
            var messageEncoderSettings = new MessageEncoderSettings();
            var subject                = new GroupOperation <BsonDocument>(collectionNamespace, key, initial, reduceFunction, null, messageEncoderSettings);

            subject.MaxTime = TimeSpan.FromSeconds(1);
            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", collectionNamespace.CollectionName },
                      { "key", key },
                      { "$reduce", reduceFunction },
                      { "initial", initial }
                  } },
                { "maxTimeMS", 1000 }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_keyFunction_is_used(
            [Values(false, true)]
            bool isFilterNull)
        {
            var filter  = isFilterNull ? _filter : null;
            var subject = new GroupOperation <BsonDocument>(_collectionNamespace, _keyFunction, _initial, _reduceFunction, filter, _messageEncoderSettings);

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", _collectionNamespace.CollectionName },
                      { "$keyf", _keyFunction },
                      { "$reduce", _reduceFunction },
                      { "initial", _initial },
                      { "cond", filter, filter != null }
                  } }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var subject = new GroupOperation <BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "group", new BsonDocument
                  {
                      { "ns", _collectionNamespace.CollectionName },
                      { "key", _key },
                      { "$reduce", _reduceFunction },
                      { "initial", _initial }
                  } },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }