Skip to content

Commit

Permalink
CSHARP-713: MongoDatabase.Eval doesn't send argument to server when t…
Browse files Browse the repository at this point in the history
…here is exactly one argument.
  • Loading branch information
rstam committed Mar 26, 2013
1 parent b252bcc commit 072aad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MongoDB.Driver/MongoDatabase.cs
Expand Up @@ -378,7 +378,7 @@ public virtual CommandResult DropCollection(string collectionName)
/// <returns>The result of evaluating the code.</returns> /// <returns>The result of evaluating the code.</returns>
public virtual BsonValue Eval(EvalFlags flags, BsonJavaScript code, params object[] args) public virtual BsonValue Eval(EvalFlags flags, BsonJavaScript code, params object[] args)
{ {
var argsArray = (args != null && args.Length > 1) ? new BsonArray(args) : null; var argsArray = (args != null && args.Length > 0) ? new BsonArray(args) : null;
var command = new CommandDocument var command = new CommandDocument
{ {
{ "$eval", code }, { "$eval", code },
Expand Down
20 changes: 18 additions & 2 deletions MongoDB.DriverUnitTests/MongoDatabaseTests.cs
Expand Up @@ -99,15 +99,31 @@ public void TestEvalNoArgsNoLock()
} }


[Test] [Test]
public void TestEvalWithArgs() public void TestEvalWithOneArg()
{
var code = "function(x) { return x + 1; }";
var result = _database.Eval(code, 1);
Assert.AreEqual(2, result.ToInt32());
}

[Test]
public void TestEvalWithOneArgNoLock()
{
var code = "function(x) { return x + 1; }";
var result = _database.Eval(EvalFlags.NoLock, code, 1);
Assert.AreEqual(2, result.ToInt32());
}

[Test]
public void TestEvalWithTwoArgs()
{ {
var code = "function(x, y) { return x / y; }"; var code = "function(x, y) { return x / y; }";
var result = _database.Eval(code, 6, 2); var result = _database.Eval(code, 6, 2);
Assert.AreEqual(3, result.ToInt32()); Assert.AreEqual(3, result.ToInt32());
} }


[Test] [Test]
public void TestEvalWithArgsNoLock() public void TestEvalWithTwoArgsNoLock()
{ {
var code = "function(x, y) { return x / y; }"; var code = "function(x, y) { return x / y; }";
var result = _database.Eval(EvalFlags.NoLock, code, 6, 2); var result = _database.Eval(EvalFlags.NoLock, code, 6, 2);
Expand Down

0 comments on commit 072aad4

Please sign in to comment.