public void SerializeAndDeserializeToTheSameObject(DateTimeOffset originalValue)
        {
            Serializer <DateTimeOffset> serializer = new DateTimeOffsetSerializer();

            byte[]         serializedValue   = serializer.Serialize(originalValue);
            DateTimeOffset deserializedValue = serializer.Deserialize(serializedValue);

            Assert.Equal(originalValue, deserializedValue);
        }
Beispiel #2
0
        public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            if (context.Reader.CurrentBsonType != BsonType.Null)
            {
                return(Helper.BuildDateTimeOffset(_serializer.Deserialize(context, args)));
            }

            context.Reader.ReadNull();

            return(Helper.DefaultDateTimeOffsetValue);
        }
Beispiel #3
0
        public void Deserialize_should_return_expected_result(string json, string expectedResult)
        {
            var x       = DateTimeOffset.Parse(expectedResult);
            var m       = BsonUtils.ToMillisecondsSinceEpoch(x.UtcDateTime);
            var subject = new DateTimeOffsetSerializer();

            DateTimeOffset result;

            using (var reader = new JsonReader(json))
            {
                reader.ReadStartDocument();
                reader.ReadName("x");
                var context = BsonDeserializationContext.CreateRoot(reader);
                result = subject.Deserialize(context);
                reader.ReadEndDocument();
            }

            result.Should().Be(DateTimeOffset.Parse(expectedResult));
        }
 /// <summary>
 /// Deserializes a value.
 /// </summary>
 /// <param name="context">The deserialization context.</param>
 /// <param name="args">The deserialization args.</param>
 /// <returns>A deserialized value.</returns>
 public override Timestamp Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(_serializer.Deserialize(context, args));
 }
        public void ShouldThrowIfDeserializingLessThanSixteenBytes(byte[] data)
        {
            Serializer <DateTimeOffset> serializer = new DateTimeOffsetSerializer();

            Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data));
        }
        public void ShouldThrowIfDeserializingNull()
        {
            Serializer <DateTimeOffset> serializer = new DateTimeOffsetSerializer();

            Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null));
        }