public void CreateCommand_should_return_expected_result()
        {
            var function       = new BsonJavaScript("return 1");
            var subject        = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "$eval", function }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_noLock_is_provided()
        {
            var function = new BsonJavaScript("return 1");
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            subject.NoLock = true;
            var expectedResult = new BsonDocument
            {
                { "$eval", function },
                { "nolock", true }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_maxTime_is_provided()
        {
            var function = new BsonJavaScript("return 1");
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            subject.MaxTime = TimeSpan.FromSeconds(1);
            var expectedResult = new BsonDocument
            {
                { "$eval", function },
                { "maxTimeMS", 1000.0 }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_args_are_provided()
        {
            var function = new BsonJavaScript("return 1");
            var subject  = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);
            var args     = new BsonValue[] { 1, 2, 3 };

            subject.Args = args;
            var expectedResult = new BsonDocument
            {
                { "$eval", function },
                { "args", new BsonArray(args) }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var function = new BsonJavaScript("return 1");
            var subject  = new EvalOperation(_adminDatabaseNamespace, function, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };
            var expectedResult = new BsonDocument
            {
                { "$eval", function },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            var result = subject.CreateCommand();

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