Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CSHARP-562: Change GetDocumentId in BsonDocumentSerializer to always …

…return an instance of BsonValue.
  • Loading branch information...
commit cf64c559a5ee451fed75064208dc2b8e88cbbc85 1 parent c25e484
rstam authored
View
14 MongoDB.Bson/Serialization/Serializers/BsonDocumentSerializer.cs
@@ -119,21 +119,11 @@ public static BsonDocumentSerializer Instance
BsonElement idElement;
if (bsonDocument.TryGetElement("_id", out idElement))
{
- // TODO: in a future release we will always return a BsonValue (GetDocumentId is not supposed to transform Id values in any way)
- // we're returning the raw value in 1.4.2 to remain temporarily backward compatible with 1.4.0 and earlier
-#pragma warning disable 618
- id = idElement.Value.RawValue;
-#pragma warning restore
- if (id == null)
- {
- id = idElement.Value;
- }
+ id = idElement.Value;
idGenerator = BsonSerializer.LookupIdGenerator(id.GetType());
if (idGenerator == null)
{
- // note: in 1.4.2 this code isn't yet used because if the RawValue was a Guid then the GuidIdGenerator was found
- // but once we start returning BsonValue like we should this code will start being used
var idBinaryData = id as BsonBinaryData;
if (idBinaryData != null && (idBinaryData.SubType == BsonBinarySubType.UuidLegacy || idBinaryData.SubType == BsonBinarySubType.UuidStandard))
{
@@ -144,7 +134,7 @@ public static BsonDocumentSerializer Instance
else
{
id = null;
- idGenerator = ObjectIdGenerator.Instance; // TODO: in a future release we will return an instance of BsonObjectIdGenerator
+ idGenerator = BsonObjectIdGenerator.Instance;
}
idNominalType = typeof(BsonValue);
View
4 MongoDB.BsonUnitTests/Jira/CSharp446Tests.cs
@@ -36,8 +36,8 @@ public void TestGetDocumentId()
Type nominalType;
IIdGenerator idGenerator;
Assert.IsTrue(((IBsonIdProvider)BsonDocumentSerializer.Instance).GetDocumentId(document, out id, out nominalType, out idGenerator));
- Assert.IsInstanceOf<int>(id); // TODO: in a future release id will be an instance of BsonInt32
- Assert.AreEqual(1, (int)id);
+ Assert.IsInstanceOf<BsonInt32>(id);
+ Assert.AreEqual(new BsonInt32(1), id);
Assert.AreEqual(typeof(BsonValue), nominalType);
Assert.IsNull(idGenerator);
}
View
12 MongoDB.BsonUnitTests/ObjectModel/BsonDocumentTests.cs
@@ -416,8 +416,8 @@ public void TestGetDocumentId()
Type nominalType;
IIdGenerator idGenerator;
Assert.IsTrue(((IBsonIdProvider)BsonDocumentSerializer.Instance).GetDocumentId(document, out id, out nominalType, out idGenerator));
- Assert.IsInstanceOf<int>(id); // TODO: in a future release id will be an instance of BsonInt32
- Assert.AreEqual(1, id);
+ Assert.IsInstanceOf<BsonInt32>(id);
+ Assert.AreEqual(new BsonInt32(1), id);
Assert.AreEqual(typeof(BsonValue), nominalType);
Assert.IsNull(idGenerator);
}
@@ -430,10 +430,10 @@ public void TestGetDocumentIdWhenIdIsGuid()
Type nominalType;
IIdGenerator idGenerator;
Assert.IsTrue(((IBsonIdProvider)BsonDocumentSerializer.Instance).GetDocumentId(document, out id, out nominalType, out idGenerator));
- Assert.IsInstanceOf<Guid>(id); // TODO: in a future release id will be an instance of BsonBinaryData
- Assert.AreEqual(Guid.Empty, id);
+ Assert.IsInstanceOf<BsonBinaryData>(id);
+ Assert.AreEqual(new BsonBinaryData(Guid.Empty), id);
Assert.AreEqual(typeof(BsonValue), nominalType);
- Assert.IsInstanceOf<GuidGenerator>(idGenerator); // TODO: in a future release idGenerator will be an instance of BsonBinaryDataGuidGenerator
+ Assert.IsInstanceOf<BsonBinaryDataGuidGenerator>(idGenerator);
}
[Test]
@@ -446,7 +446,7 @@ public void TestGetDocumentIdWhenIdIsMissing()
Assert.IsTrue(((IBsonIdProvider)BsonDocumentSerializer.Instance).GetDocumentId(document, out id, out nominalType, out idGenerator));
Assert.IsNull(id);
Assert.AreEqual(typeof(BsonValue), nominalType);
- Assert.IsInstanceOf<ObjectIdGenerator>(idGenerator); // TODO: in a future release idGenerator will be an instance of BsonObjectIdGenerator
+ Assert.IsInstanceOf<BsonObjectIdGenerator>(idGenerator);
}
[Test]
Please sign in to comment.
Something went wrong with that request. Please try again.