-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for Offset. * Fix assertions in tests for deserialized values. * Update README.md Co-authored-by: Greg Lincoln <greg@greglincoln.com>
- Loading branch information
Showing
10 changed files
with
84 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using NodaTime; | ||
using NodaTime.Text; | ||
|
||
namespace MongoDb.Bson.NodaTime | ||
{ | ||
public class OffsetSerializer : PatternSerializer<Offset> | ||
{ | ||
public OffsetSerializer() : base(OffsetPattern.GeneralInvariant) | ||
{ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using FluentAssertions; | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization; | ||
using NodaTime; | ||
using System; | ||
using Xunit; | ||
|
||
namespace MongoDb.Bson.NodaTime.Tests | ||
{ | ||
public class OffsetSerializerTests | ||
{ | ||
static OffsetSerializerTests() | ||
{ | ||
BsonSerializer.RegisterSerializer(new OffsetSerializer()); | ||
} | ||
|
||
[Fact] | ||
public void CanConvertValue() | ||
{ | ||
var obj = new Test { Offset = Offset.FromHours(4) }; | ||
obj.ToTestJson().Should().Contain("'Offset' : '+04'"); | ||
|
||
var deserialized = BsonSerializer.Deserialize<Test>(obj.ToBson()); | ||
deserialized.Offset.Should().Be(obj.Offset); | ||
} | ||
|
||
[Fact] | ||
public void ThrowsWhenValueIsInvalid() | ||
{ | ||
Assert.Throws<FormatException>(() => BsonSerializer.Deserialize<Test>(new BsonDocument(new BsonElement("Duration", "bleh")))); | ||
} | ||
|
||
[Fact] | ||
public void CanParseNullable() | ||
{ | ||
BsonSerializer.Deserialize<Test>(new BsonDocument(new BsonElement("OffsetNullable", BsonNull.Value))).OffsetNullable.Should().BeNull(); | ||
} | ||
|
||
private class Test | ||
{ | ||
public Offset Offset { get; set; } | ||
public Offset? OffsetNullable { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters