Skip to content

Commit

Permalink
Merge commit '36b2a5441105b27055592023270c250a1b57ee30' into uri
Browse files Browse the repository at this point in the history
  • Loading branch information
rstam committed Mar 30, 2012
2 parents f52c26d + 36b2a54 commit de5d75c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Bson/Serialization/Serializers/NetPrimitiveSerializers.cs
Expand Up @@ -1980,7 +1980,7 @@ public static UriSerializer Instance
bsonReader.ReadNull();
return null;
case BsonType.String:
return new Uri(bsonReader.ReadString());
return new Uri(bsonReader.ReadString(), UriKind.RelativeOrAbsolute);
default:
var message = string.Format("Cannot deserialize Uri from BsonType {0}.", bsonType);
throw new FileFormatException(message);
Expand All @@ -2006,7 +2006,7 @@ public static UriSerializer Instance
}
else
{
bsonWriter.WriteString(((Uri)value).AbsoluteUri);
bsonWriter.WriteString(((Uri)value).OriginalString);
}
}
}
Expand Down
Expand Up @@ -1786,14 +1786,30 @@ public void TestHttp()
V = new Uri("http://www.cnn.com")
};
var json = obj.ToJson();
var expected = "{ 'V' : 'http://www.cnn.com/' }".Replace("'", "\"");
var expected = "{ 'V' : 'http://www.cnn.com' }".Replace("'", "\"");
Assert.AreEqual(expected, json);

var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}

[Test]
public void TestRelative()
{
var obj = new TestClass
{
V = new Uri("/relative/page.html", UriKind.RelativeOrAbsolute)
};
var json = obj.ToJson();
var expected = "{ 'V' : '/relative/page.html' }".Replace("'", "\"");
Assert.AreEqual(expected, json);

var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}

[Test]
public void TestMongoDB()
{
Expand Down

0 comments on commit de5d75c

Please sign in to comment.