Skip to content

Commit f2e4a38

Browse files
committed
fixed bug with Code property and added tests.
1 parent 2cb7e09 commit f2e4a38

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

MongoDB.Driver/CommandResults/CommandResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CommandResult(IMongoCommand command, BsonDocument response)
5555
/// </summary>
5656
public int? Code
5757
{
58-
get { return _response.GetValue("code", null).AsNullableInt32; }
58+
get { return _response.GetValue("code", BsonNull.Value).AsNullableInt32; }
5959
}
6060

6161
/// <summary>

MongoDB.DriverUnitTests/CommandResults/CommandResultTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ public void Setup()
3333
_database = Configuration.TestDatabase;
3434
}
3535

36+
[Test]
37+
public void TestCodeMissing()
38+
{
39+
var command = new CommandDocument("invalid", 1);
40+
var document = new BsonDocument();
41+
var result = new CommandResult(command, document);
42+
43+
Assert.IsFalse(result.Code.HasValue);
44+
}
45+
46+
[Test]
47+
public void TestCode()
48+
{
49+
var command = new CommandDocument("invalid", 1);
50+
var document = new BsonDocument("code", 18);
51+
var result = new CommandResult(command, document);
52+
53+
Assert.IsTrue(result.Code.HasValue);
54+
Assert.AreEqual(18, result.Code);
55+
}
56+
3657
[Test]
3758
public void TestOkMissing()
3859
{

0 commit comments

Comments
 (0)