public void TestStrictSerialization() { var serializer = new JsonCacheSerializer(); Assert.Throws <InvalidOperationException>(() => serializer.Serialize(new CustomEntity { Id = 10 }), "Non standard types should be registered explicitly"); }
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); }
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); }
public void Serializer_Serializes_Correctly() { var serializer = new JsonCacheSerializer(); var instance = new SerializeType { Age = 25, Birthday = new DateTime(1, 2, 3), Name = "Some Name", }; var expected = "{\"Age\":25,\"Birthday\":\"\\/Date(-62132724000000-0600)\\/\",\"Name\":\"Some Name\"}"; var actual = serializer.Serialize(instance); Assert.AreEqual(expected, actual); }
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); }
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]); }
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); }