Exemplo n.º 1
0
        public void DeSerializeInvalidDate()
        {
            var reader = Mock.Of <IBsonReader>();

            Mock.Get(reader).Setup(x => x.CurrentBsonType).Returns(BsonType.String);
            Mock.Get(reader).Setup(x => x.ReadString()).Returns("2019-12-32");
            var context = BsonDeserializationContext.CreateRoot(reader, null);

            var serializer = new DateSerializer();
            var date       = serializer.Deserialize(context);

            date.Should().Be(Date.MinValue);
        }
Exemplo n.º 2
0
        public void DeSerializeNumericType()
        {
            var reader = Mock.Of <IBsonReader>();

            Mock.Get(reader).Setup(x => x.CurrentBsonType).Returns(BsonType.Int32);
            var context = BsonDeserializationContext.CreateRoot(reader, null);

            var serializer = new DateSerializer();
            var date       = serializer.Deserialize(context);

            date.Should().Be(Date.MinValue);
            Mock.Get(reader).Verify(x => x.SkipValue());
        }
Exemplo n.º 3
0
        public void DeSerializeTimeStampType()
        {
            var testDate = new DateTimeOffset(2019, 12, 01, 8, 54, 26, TimeSpan.Zero);

            var reader = Mock.Of <IBsonReader>();

            Mock.Get(reader).Setup(x => x.CurrentBsonType).Returns(BsonType.Timestamp);
            Mock.Get(reader).Setup(x => x.ReadTimestamp()).Returns(testDate.ToUnixTimeMilliseconds);
            var context = BsonDeserializationContext.CreateRoot(reader, null);

            var serializer = new DateSerializer();
            var date       = serializer.Deserialize(context);

            date.Should().Be(new Date(2019, 12, 01));
        }