public void CollectionNamespace_should_get_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            var result = subject.CollectionNamespace;

            result.Should().BeSameAs(_collectionNamespace);
        }
        public void JavaScriptMode_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings);
            var value   = true;

            subject.JavaScriptMode = value;
            var result = subject.JavaScriptMode;

            result.Should().Be(value);
        }
        public void Limit_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings);
            var value   = 1L;

            subject.Limit = value;
            var result = subject.Limit;

            result.Should().Be(value);
        }
Exemplo n.º 4
0
        public void MaxTime_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings);
            var value   = TimeSpan.FromSeconds(1.5);

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

            result.Should().Be(value);
        }
Exemplo n.º 5
0
        public void Sort_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings);
            var value   = new BsonDocument("sort", 1);

            subject.Sort = value;
            var result = subject.Sort;

            result.Should().Be(value);
        }
        public void FinalizeFunction_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings);
            var value   = new BsonJavaScript("finalize");

            subject.FinalizeFunction = value;
            var result = subject.FinalizeFunction;

            result.Should().BeSameAs(value);
        }
Exemplo n.º 7
0
        public void Filter_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = new BsonDocument("filter", 1);

            subject.Filter = value;
            var result = subject.Filter;

            result.Should().BeSameAs(value);
        }
Exemplo n.º 8
0
        public void Verbose_should_get_and_set_value(
            [Values(null, false, true)]
            bool?value)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.Verbose = value;
            var result = subject.Verbose;

            result.Should().Be(value);
        }
        public void CollectionNamespace_should_get_value(
            [Values("a", "b")]
            string collectionName)
        {
            var collectionNamespace = new CollectionNamespace(_collectionNamespace.DatabaseNamespace, collectionName);
            var subject = new FakeMapReduceOperation(collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            var result = subject.CollectionNamespace;

            result.Should().BeSameAs(collectionNamespace);
        }
Exemplo n.º 10
0
        public void MapFunction_should_get_value(
            [Values("a", "b")]
            string code)
        {
            var mapFunction = new BsonJavaScript(code);
            var subject     = new FakeMapReduceOperation(_collectionNamespace, mapFunction, _reduceFunction, _messageEncoderSettings);

            var result = subject.MapFunction;

            result.Should().BeSameAs(mapFunction);
        }
        public void CreateCommand_should_throw_when_Collation_is_provided_but_not_supported()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

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

            exception.Should().BeOfType <NotSupportedException>();
        }
Exemplo n.º 12
0
        public void Limit_should_get_and_set_value(
            [Values(null, 0L, 1L)]
            long?value)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.Limit = value;
            var result = subject.Limit;

            result.Should().Be(value);
        }
Exemplo n.º 13
0
        public void CollectionNamespace_should_get_value(
            [Values("a", "b")]
            string collectionName)
        {
            var collectionNamespace = new CollectionNamespace(_collectionNamespace.DatabaseNamespace, collectionName);
            var subject             = new FakeMapReduceOperation(collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            var result = subject.CollectionNamespace;

            result.Should().BeSameAs(collectionNamespace);
        }
        public void MaxTime_get_and_set_should_work(
            [Values(-10000, 0, 1, 10000, 99999)] long maxTimeTicks)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

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

            result.Should().Be(value);
        }
Exemplo n.º 15
0
        public void FinalizeFunction_should_get_and_set_value(
            [Values(null, "a", "b")]
            string code)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = code == null ? null : new BsonJavaScript(code);

            subject.FinalizeFunction = value;
            var result = subject.FinalizeFunction;

            result.Should().BeSameAs(value);
        }
Exemplo n.º 16
0
        public void MaxTime_should_get_and_set_value(
            [Values(null, 1, 2)]
            int?seconds)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;

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

            result.Should().Be(value);
        }
Exemplo n.º 17
0
        public void Sort_should_get_and_set_value(
            [Values(null, "{ x : 1 }", "{ x : -1 }")]
            string valueString)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.Sort = value;
            var result = subject.Sort;

            result.Should().Be(value);
        }
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-10001, -9999, -1)] long maxTimeTicks)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _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");
        }
Exemplo n.º 19
0
        public void Collation_should_get_and_set_value(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value   = locale == null ? null : new Collation(locale);

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

            result.Should().BeSameAs(value);
        }
        public void Collation_should_get_and_set_value(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = locale == null ? null : new Collation(locale);

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

            result.Should().BeSameAs(value);
        }
Exemplo n.º 21
0
        public void JavaScriptMode_should_get_and_set_value(
            [Values(null, false, true)]
            bool?value)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

#pragma warning disable 618
            subject.JavaScriptMode = value;
            var result = subject.JavaScriptMode;
#pragma warning restore 618

            result.Should().Be(value);
        }
Exemplo n.º 22
0
        public void CreateCommand_should_return_the_expected_result()
        {
            var subject        = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void constructor_should_initialize_instance()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.FinalizeFunction.Should().BeNull();
            subject.JavaScriptMode.Should().NotHaveValue();
            subject.Limit.Should().NotHaveValue();
            subject.MapFunction.Should().BeSameAs(_mapFunction);
            subject.MaxTime.Should().NotHaveValue();
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            subject.Filter.Should().BeNull();
            subject.ReduceFunction.Should().BeSameAs(_reduceFunction);
            subject.Scope.Should().BeNull();
            subject.Sort.Should().BeNull();
            subject.Verbose.Should().NotHaveValue();
        }
Exemplo n.º 24
0
        public void constructor_should_initialize_instance()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.FinalizeFunction.Should().BeNull();
            subject.JavaScriptMode.Should().NotHaveValue();
            subject.Limit.Should().NotHaveValue();
            subject.MapFunction.Should().BeSameAs(_mapFunction);
            subject.MaxTime.Should().NotHaveValue();
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            subject.Filter.Should().BeNull();
            subject.ReduceFunction.Should().BeSameAs(_reduceFunction);
            subject.Scope.Should().BeNull();
            subject.Sort.Should().BeNull();
            subject.Verbose.Should().NotHaveValue();
        }
        public void CreateCommand_should_return_the_expected_result()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "mapReduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) }
            };

            result.Should().Be(expectedResult);
        }
Exemplo n.º 26
0
        public void CreateCommand_should_return_the_expected_result_when_JavaScriptMode_is_provided()
        {
            var javaScriptMode = true;
            var subject        = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                JavaScriptMode = javaScriptMode
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "jsMode", javaScriptMode }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
Exemplo n.º 27
0
        public void CreateCommand_should_return_the_expected_result_when_MaxTime_is_provided()
        {
            var maxTime = TimeSpan.FromSeconds(1.5);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "maxTimeMS", 1500.0 }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Verbose_is_provided()
        {
            var verbose = true;
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Verbose = verbose
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "verbose", verbose }
            };

            var result = subject.CreateCommand(new SemanticVersion(3, 0, 0));

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_FinalizeFunction_is_provided()
        {
            var finalizeFunction = new BsonJavaScript("finalize");
            var subject          = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                FinalizeFunction = finalizeFunction
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "finalize", finalizeFunction }
            };

            var result = subject.CreateCommand(new SemanticVersion(3, 0, 0));

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Scope_is_provided()
        {
            var scope   = new BsonDocument("scope", 1);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _query, _messageEncoderSettings)
            {
                Scope = scope
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "query", _query },
                { "scope", scope }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Limit_is_provided(
            [Values(null, 1L, 2L)]
            long?limit)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Limit = limit
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "limit", () => limit.Value, limit.HasValue }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_FinalizeFunction_is_provided(
            [Values(null, "a", "b")]
            string code)
        {
            var finalizeFunction = code == null ? null : new BsonJavaScript(code);
            var subject          = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                FinalizeFunction = finalizeFunction
            };
            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "finalize", finalizeFunction, finalizeFunction != null }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Verbose_is_provided(
            [Values(null, false, true)]
            bool?verbose)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Verbose = verbose
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "verbose", () => verbose.Value, verbose.HasValue }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "mapReduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
        public void Sort_should_get_and_set_value(
            [Values(null, "{ x : 1 }", "{ x : -1 }")]
            string valueString)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.Sort = value;
            var result = subject.Sort;

            result.Should().Be(value);
        }
        public void CreateCommand_should_return_the_expected_result_when_MaxTime_is_provided(
            [Values(null, 1, 2)]
            int? seconds)
        {
            var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "maxTimeMS", () => seconds.Value * 1000, seconds.HasValue }
            };
            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Verbose_is_provided(
            [Values(null, false, true)]
            bool? verbose)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Verbose = verbose
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "verbose", () => verbose.Value, verbose.HasValue }
            };
            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Verbose_is_provided()
        {
            var verbose = true;
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Verbose = verbose
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "verbose", verbose }
            };

            var result = subject.CreateCommand(new SemanticVersion(3, 0, 0));

            result.Should().Be(expectedResult);
        }
        public void MapFunction_should_get_value(
            [Values("a", "b")]
            string code)
        {
            var mapFunction = new BsonJavaScript(code);
            var subject = new FakeMapReduceOperation(_collectionNamespace, mapFunction, _reduceFunction, _messageEncoderSettings);

            var result = subject.MapFunction;

            result.Should().BeSameAs(mapFunction);
        }
        public void JavaScriptMode_should_get_and_set_value(
            [Values(null, false, true)]
            bool? value)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.JavaScriptMode = value;
            var result = subject.JavaScriptMode;

            result.Should().Be(value);
        }
        public void MaxTime_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = TimeSpan.FromSeconds(1.5);

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

            result.Should().Be(value);
        }
        public void Sort_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = new BsonDocument("sort", 1);

            subject.Sort = value;
            var result = subject.Sort;

            result.Should().Be(value);
        }
        public void FinalizeFunction_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = new BsonJavaScript("finalize");

            subject.FinalizeFunction = value;
            var result = subject.FinalizeFunction;

            result.Should().BeSameAs(value);
        }
        public void CreateCommand_should_return_the_expected_result_when_Collation_is_provided(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var collation = locale == null ? null : new Collation(locale);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Collation = collation
            };

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

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "collation", () => collation.ToBsonDocument(), collation != null }
            };
            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_MaxTime_is_provided()
        {
            var maxTime = TimeSpan.FromSeconds(1.5);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "maxTimeMS", 1500.0 }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_JavaScriptMode_is_provided()
        {
            var javaScriptMode = true;
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                JavaScriptMode = javaScriptMode
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "jsMode", javaScriptMode }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_FinalizeFunction_is_provided()
        {
            var finalizeFunction = new BsonJavaScript("finalize");
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                FinalizeFunction = finalizeFunction
            };
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "finalize", finalizeFunction }
            };

            var result = subject.CreateCommand(new SemanticVersion(3, 0, 0));

            result.Should().Be(expectedResult);
        }
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-1, 0)]
            int seconds)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = TimeSpan.FromSeconds(seconds);

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

            var argumentOutOfRangeException = exception.Should().BeOfType<ArgumentOutOfRangeException>().Subject;
            argumentOutOfRangeException.ParamName.Should().Be("value");
        }
        public void Verbose_should_get_and_set_value()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = true;

            subject.Verbose = value;
            var result = subject.Verbose;

            result.Should().Be(value);
        }
        public void MaxTime_should_get_and_set_value(
            [Values(null, 1, 2)]
            int? seconds)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;

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

            result.Should().Be(value);
        }
        public void CreateCommand_should_return_the_expected_result_when_FinalizeFunction_is_provided(
            [Values(null, "a", "b")]
            string code)
        {
            var finalizeFunction = code == null ? null : new BsonJavaScript(code);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                FinalizeFunction = finalizeFunction
            };
            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "finalize", finalizeFunction, finalizeFunction != null }
            };
            result.Should().Be(expectedResult);
        }
        public void Limit_should_get_and_set_value(
            [Values(null, 0L, 1L)]
            long? value)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);

            subject.Limit = value;
            var result = subject.Limit;

            result.Should().Be(value);
        }
        public void CreateCommand_should_return_the_expected_result()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "mapreduce", "collectionName" },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void FinalizeFunction_should_get_and_set_value(
            [Values(null, "a", "b")]
            string code)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            var value = code == null ? null : new BsonJavaScript(code );

            subject.FinalizeFunction = value;
            var result = subject.FinalizeFunction;

            result.Should().BeSameAs(value);
        }
        public void CreateCommand_should_return_the_expected_result_when_Limit_is_provided(
            [Values(null, 1L, 2L)]
            long? limit)
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Limit = limit
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "limit", () => limit.Value, limit.HasValue }
            };
            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Sort_is_provided(
            [Values(null, "{ x : 1 }", "{ x : -1 }")]
            string sortString)
        {
            var sort = sortString == null ? null : BsonDocument.Parse(sortString);
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Sort = sort
            };

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "mapreduce", _collectionNamespace.CollectionName },
                { "map", _mapFunction },
                { "reduce", _reduceFunction },
                { "out", new BsonDocument("fake", 1) },
                { "sort", sort, sort != null }
            };
            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_throw_when_Collation_is_provided_but_not_supported()
        {
            var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

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

            exception.Should().BeOfType<NotSupportedException>();
        }