Beispiel #1
0
        public void FullMatchString()
        {
            string s       = "Testing";
            string pattern = @"^Testing$";

            StringAssert.FullMatch(s, pattern);
        }
        public void PrimitivesAliasedByDefault()
        {
            Serializer s      = GetSerializer();
            string     result = s.Serialize <object>(1);

            StringAssert.FullMatch(result, @"\s*\(int\)\s*1\s*");
            int i = (int)s.Deserialize <object>(result);

            Assert.AreEqual(1, i, "Deserialize");
        }
        public void AliasedOpenGenericType()
        {
            Serializer s = GetSerializer();

            s.Settings.TypeAliases.Add(typeof(Dictionary <,>), "dictionary");
            string result = s.Serialize <object>(new Dictionary <string, int>());

            StringAssert.FullMatch(result, @"\s*\(dictionary<string,int>\)\s*\{\s*\}\s*");
            Dictionary <string, int> targetDictionary = s.Deserialize <Dictionary <string, int> >(result);

            Assert.AreEqual(0, targetDictionary.Count, "Deserialize");
        }
        public void AliasedGenericArgument()
        {
            Serializer s = GetSerializer();

            s.Settings.TypeAliases.Add(typeof(ArrayList), "array");
            string result = s.Serialize <object>(new List <ArrayList>());

            StringAssert.FullMatch(result, @"\s*\(System\.Collections\.Generic\.List<array>\)\s*\[\s*\]\s*");
            List <ArrayList> targetList = s.Deserialize <List <ArrayList> >(result);

            Assert.AreEqual(0, targetList.Count, "Deserialize");
        }
        public void NonGenericClass()
        {
            Serializer s = GetSerializer();

            s.Settings.TypeAliases.Add(typeof(ArrayList), "array");
            string result = s.Serialize <object>(new ArrayList());

            StringAssert.FullMatch(result, @"\s*\(array\)\s*\[\s*\]\s*");
            ArrayList targetList = s.Deserialize <ArrayList>(result);

            Assert.AreEqual(0, targetList.Count, "Deserialize");
        }
        public void EmptyArrayTest()
        {
            List <int> source = new List <int>();
            Serializer s      = new Serializer();

            s.Settings.IsCompact = true;
            string result = s.Serialize(source);

            StringAssert.FullMatch(result, @"\s*\[\s*\]\s*");
            List <int> target = s.Deserialize <List <int> >(result);

            Assert.AreEqual(0, target.Count, "List count");
        }
        public void AssemblyAliasTest()
        {
            Serializer    s      = GetSerializer();
            MockValueType source = new MockValueType(9, 6);

            s.Settings.TypeAliases.Assemblies.Add(typeof(MockValueType).Assembly);
            string result = s.Serialize <object>(source);

            StringAssert.FullMatch(result, @"\s*\(JsonExSerializerTests\.Mocks\.MockValueType\)\s*{""X"":9, ""Y"":6}");
            MockValueType target = s.Deserialize <MockValueType>(result);

            Assert.AreEqual(source, target, "Deserialize");
        }
        public void EmptyObjectTest()
        {
            Dictionary <string, int> source = new Dictionary <string, int>();
            Serializer s = new Serializer();

            s.Settings.IsCompact = true;
            string result = s.Serialize(source);

            StringAssert.FullMatch(result, @"\s*\{\s*\}\s*");
            Dictionary <string, int> target = s.Deserialize <Dictionary <string, int> >(result);

            Assert.AreEqual(0, target.Count, "Dictionary count");
        }
        public void SingleItemArrayTest()
        {
            List <int> source = new List <int>();
            Serializer s      = new Serializer();

            s.Settings.IsCompact = true;
            source.Add(5);
            string result = s.Serialize(source);

            StringAssert.FullMatch(result, @"\s*\[\s*5\s*\]\s*");
            List <int> target = s.Deserialize <List <int> >(result);

            Assert.AreEqual(1, target.Count, "List count");
            Assert.AreEqual(5, target[0], "single item");
        }
        public void SingleItemObjectTest()
        {
            Dictionary <string, int> source = new Dictionary <string, int>();
            Serializer s = new Serializer();

            s.Settings.IsCompact = true;
            source["first"]      = 1;
            string result = s.Serialize(source);

            StringAssert.FullMatch(result, @"\s*\{\s*""first""\s*:\s*1\s*\}\s*");
            Dictionary <string, int> target = s.Deserialize <Dictionary <string, int> > (result);

            Assert.AreEqual(1, target.Count, "Dictionary count");
            Assert.AreEqual(1, target["first"], "Dictionary item");
        }