Пример #1
0
        public void FastSerializer_Dictionary_Custom_ArgumentChecking()
        {
            var ser = FastJsonSerializerFactory.CreateSerializer <IDictionary <string, int> >(provider: null, FastJsonConcurrencyMode.SingleThreaded);

            Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(new NullableDictionary <string, int> {
                { null, 42 }
            }));
        }
Пример #2
0
 public Serialize()
 {
     _nucleusSerializer = FastJsonSerializerFactory.CreateSerializer <Person>(DefaultNameProvider.Instance, FastJsonConcurrencyMode.SingleThreaded);
     _jsonSerializer    = Newtonsoft.Json.JsonSerializer.CreateDefault();
     _person            = new Person {
         Name = "Bart", Age = 21
     };
 }
Пример #3
0
        public void FastSerializer_Any_ArgumentChecking()
        {
            var ser = FastJsonSerializerFactory.CreateSerializer <object>(provider: null, FastJsonConcurrencyMode.SingleThreaded);

            Assert.ThrowsException <NotSupportedException>(() => ser.Serialize(new int[1, 1]));
#if !NO_IO
            Assert.ThrowsException <NotSupportedException>(() => ser.Serialize(new int[1, 1], new System.IO.StringWriter()));
#endif
        }
Пример #4
0
        public void FastDeserializer_ArgumentChecking()
        {
            var des = FastJsonSerializerFactory.CreateDeserializer <int>(resolver: null, FastJsonConcurrencyMode.SingleThreaded);

            Assert.ThrowsException <ArgumentNullException>(() => des.Deserialize(default(string)));
#if !NO_IO
            Assert.ThrowsException <ArgumentNullException>(() => des.Deserialize(default(System.IO.TextReader)));
#endif
            Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize("42a"));

            Assert.ThrowsException <ArgumentNullException>(() => FastJsonSerializerFactory.CreateDeserializer <int>(resolver: null, settings: null));
        }
Пример #5
0
        private static void AssertDeserializeFails <T>(params string[] inputs)
        {
            var des = FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.SingleThreaded);

            foreach (var json in inputs)
            {
                Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize(json));

#if !NO_IO
                Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize(new System.IO.StringReader(json)));
#endif
            }
        }
Пример #6
0
        private static void AssertSerialize <T>(Asserts <T> asserts)
        {
            foreach (var ser in new[]
            {
                FastJsonSerializerFactory.CreateSerializer <T>(provider: null, FastJsonConcurrencyMode.SingleThreaded),
                FastJsonSerializerFactory.CreateSerializer <T>(provider: null, FastJsonConcurrencyMode.ThreadSafe),
            })
            {
                foreach (var kv in asserts)
                {
                    Assert.AreEqual(kv.Value, ser.Serialize(kv.Key));
                }

                if (asserts._null != null)
                {
                    Assert.AreEqual(asserts._null, ser.Serialize(default));
Пример #7
0
        public void FastSerializer_PersonWithParent_CycleDetection()
        {
            var ser = FastJsonSerializerFactory.CreateSerializer <PersonWithParent>(provider: null, FastJsonConcurrencyMode.SingleThreaded);

            var cyclic1 = new PersonWithParent();

            cyclic1.Parent = cyclic1;

            var cyclic2 = new PersonWithParent {
                Parent = new PersonWithParent()
            };

            cyclic2.Parent.Parent = cyclic2;

            Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(cyclic1));
            Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(cyclic2));
        }
Пример #8
0
        private static void AssertDeserialize <T>(Asserts <T> asserts, INameResolver resolver)
        {
            foreach (var des in new[]
            {
                FastJsonSerializerFactory.CreateDeserializer <T>(resolver, FastJsonConcurrencyMode.SingleThreaded),
                FastJsonSerializerFactory.CreateDeserializer <T>(resolver, FastJsonConcurrencyMode.ThreadSafe),
            })
            {
                foreach (var kv in asserts)
                {
                    Assert.AreEqual(kv.Value, des.Deserialize(kv.Key));

#if !NO_IO
                    Assert.AreEqual(kv.Value, des.Deserialize(new System.IO.StringReader(kv.Key)));
#endif
                }
            }
        }
Пример #9
0
        private static void AssertDeserialize <T>(Asserts <T> asserts, Func <T, T, bool> assert)
        {
            foreach (var des in new[]
            {
                FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.SingleThreaded),
                FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.ThreadSafe),
            })
            {
                foreach (var kv in asserts)
                {
                    Assert.IsTrue(assert(kv.Value, des.Deserialize(kv.Key)));

#if !NO_IO
                    Assert.IsTrue(assert(kv.Value, des.Deserialize(new System.IO.StringReader(kv.Key))));
#endif
                }
            }
        }
Пример #10
0
 private static object CreateSerializer <T>()
 {
     return(FastJsonSerializerFactory.CreateSerializer <T>(NameProvider.Instance, FastJsonConcurrencyMode.ThreadSafe));
 }
Пример #11
0
 public void FastSerializer_ArgumentChecking()
 {
     Assert.ThrowsException <ArgumentNullException>(() => FastJsonSerializerFactory.CreateSerializer <int>(provider: null, settings: null));
 }
Пример #12
0
 public Deserialize()
 {
     _nucleusDeserializer = FastJsonSerializerFactory.CreateDeserializer <Person>(DefaultNameResolver.Instance, FastJsonConcurrencyMode.SingleThreaded);
     _jsonDeserializer    = Newtonsoft.Json.JsonSerializer.CreateDefault();
     _json = "{ \"Name\": \"Bart\", \"Age\": 21 }";
 }
Пример #13
0
 public Deserializer()
 {
     _deserializer = FastJsonSerializerFactory.CreateDeserializer <T>(NameResolver.Instance, FastJsonConcurrencyMode.ThreadSafe);
 }
Пример #14
0
 public Serializer()
 {
     _serializer = FastJsonSerializerFactory.CreateSerializer <T>(NameProvider.Instance, FastJsonConcurrencyMode.ThreadSafe);
 }