public void Serializer_Deserializes_Correctly()
        {
            var serializer = new JsonCacheSerializer();
            var instance = "{\"Age\":25,\"Birthday\":\"\\/Date(-62132724000000-0600)\\/\",\"Name\":\"Some Name\"}";
            var actual = serializer.Deserialize<SerializeType>(instance);

            Assert.AreEqual(25, actual.Age);
            Assert.AreEqual(new DateTime(1, 2, 3), actual.Birthday);
            Assert.AreEqual("Some Name", actual.Name);
        }
Exemple #2
0
        public void JsonSerializer_Primitives <T>(T value)
        {
            // arrange
            var serializer = new JsonCacheSerializer();

            // act
            var data   = serializer.Serialize(value);
            var result = serializer.Deserialize(data, typeof(T));

            result.Should().Be(value);
        }
Exemple #3
0
        public void JsonSerializer_Pocco()
        {
            // arrange
            var serializer = new JsonCacheSerializer();
            var item       = SerializerPoccoSerializable.Create();

            // act
            var data   = serializer.Serialize(item);
            var result = serializer.Deserialize(data, item.GetType());

            result.ShouldBeEquivalentTo(item);
        }
Exemple #4
0
        public void JsonSerializer_List()
        {
            // arrange
            var serializer = new JsonCacheSerializer();
            var items      = new List <SerializerPoccoSerializable>()
            {
                SerializerPoccoSerializable.Create(),
                SerializerPoccoSerializable.Create(),
                SerializerPoccoSerializable.Create()
            };

            // act
            var data   = serializer.Serialize(items);
            var result = serializer.Deserialize(data, items.GetType());

            result.ShouldBeEquivalentTo(items);
        }
Exemple #5
0
        public void TestJsonNet()
        {
            var rnd      = new Random();
            var utcNow   = DateTimeOffset.UtcNow;
            var userInfo = new object[]  // EFTableRow -> public object[] Values { get; set; }
            {
                $"User {rnd.Next(1, 100000)}",
                DateTime.UtcNow,
                null,
                1000,
                true,
                1,
                'C',
                utcNow,
                1.1M,
                1.3,
                1.2f,
                Guid.NewGuid(),
                TimeSpan.FromMinutes(1),
                2,
                new byte[] { 1, 2 },
                1,
                1,
                1
            };

            var jss = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                TypeNameHandling      = TypeNameHandling.Auto,
                Converters            = { new SpecialTypesConverter() }
            };
            var jcs      = new JsonCacheSerializer(jss, jss); // This is how the CacheManagerCore uses the Json.NET
            var json     = jcs.Serialize(userInfo);
            var userData = jcs.Deserialize(json, typeof(object[])) as object[];

            Assert.IsNotNull(userData);
            Assert.AreEqual(utcNow, userData[7]);
        }
Exemple #6
0
        public void TestJsonNet()
        {
            var rnd   = new Random();
            var user1 = new User
            {
                Name                = $"User {rnd.Next(1, 100000)}",
                AddDate             = DateTime.UtcNow,
                UpdateDate          = null,
                Points              = 1000,
                IsActive            = true,
                ByteValue           = 1,
                CharValue           = 'C',
                DateTimeOffsetValue = DateTimeOffset.UtcNow,
                DecimalValue        = 1.1M,
                DoubleValue         = 1.3,
                FloatValue          = 1.2f,
                GuidValue           = Guid.NewGuid(),
                TimeSpanValue       = TimeSpan.FromMinutes(1),
                ShortValue          = 2,
                ByteArrayValue      = new byte[] { 1, 2 },
                UintValue           = 1,
                UlongValue          = 1,
                UshortValue         = 1
            };

            var jss = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                TypeNameHandling      = TypeNameHandling.Auto,
                Converters            = { new SpecialTypesConverter() }
            };
            var jcs  = new JsonCacheSerializer(jss, jss);
            var json = jcs.Serialize(user1);
            var user = jcs.Deserialize(json, typeof(object));

            Assert.IsNotNull(user);
        }