Esempio n. 1
0
        /// <summary>Testing option input arguments</summary>
        private static void OptionTestArgs()
        {
            Console.Write("OptionTestArgs:");
            Options opt = null;
            try
            {
                new Options(null, "test_class");
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("namespaceName"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }
            
            try
            {
                opt = new Options("test", null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("className"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }
            
            opt = new Options("test", "test_class");
            try
            {
                opt.AddNamespace(null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("name"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddPropertyType(null, null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("property"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddPropertyType("abc", null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("typeName"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddConverter(null, null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("property"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddConverter("test", null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("function"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddClassAttribute(null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("attribute"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddAssembly(null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("assemblyName"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddPropertyAttributes(null, null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("propertyName"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            try
            {
                opt.AddPropertyAttributes("test", null);
                Console.WriteLine(Fail);
                return;
            }
            catch (ArgumentNullException ex)
            {
                if (!ex.Message.Contains("attributes"))
                {
                    Console.WriteLine(ex);
                    Console.WriteLine(Fail);
                    return;
                }
            }

            Console.WriteLine(Pass);
        }
Esempio n. 2
0
        /// <summary>Type mapping test</summary>
        private static void TypeMapTest()
        {
            Console.Write("TypeMapTest:");
            var obj = ObjectWrapper.CreateFrom(new { abc = "1" }, new Options("test", "testclass"));
            if (obj.GetField("abc").GetType().Name != "String")
            {
                Console.WriteLine(obj.GetField("abc").GetType().Name);
                Console.WriteLine(Fail);
                return;
            }

            Options opts = new Options("test", "test_class");
            opts.AddPropertyType("abc", "System.Int32");
            opts.AddConverter("abc", x => { return Convert.ToInt32(x); });
            obj = ObjectWrapper.CreateFrom(new { abc = "1" }, opts);
            if (obj.GetField("abc").GetType().Name != "Int32")
            {
                Console.WriteLine(obj.GetField("abc").GetType().Name);
                Console.WriteLine(Fail);
                return;
            }

            var serialized = Serializer.Serialize(obj.Instance);
            if (serialized != @"{""abc"":1}")
            {
                Console.WriteLine(serialized);
                Console.WriteLine(Fail);
                return;
            }

            Console.WriteLine(Pass);
        }
Esempio n. 3
0
        /// <summary>Option creation testing</summary>
        private static void OptionTest()
        {
            Console.Write("OptionTest:");
            Options opt = new Options("test", "test_class");
            opt.AddAssembly("System.Data.dll");
            opt.AddClassAttribute("[DataContract]");
            opt.AddPropertyAttributes("Something", new List<string>() { "[DataMember]" });
            opt.AddPropertyType("abc", "System.String");
            opt.AddConverter("abc", x => { return 1; });
            opt.AddNamespace("system.namespace");
            
            var props = opt.GetPropertyAttributes("someTHING");
            if (props.Count == 1 && props[0] == "[DataMember]")
            {
            }
            else
            {
                Console.WriteLine("Invalid property attributes");
                Console.WriteLine(Fail);
                return;
            }                        
            
            props = opt.GetPropertyAttributes("OTHER");
            if (props.Count != 0)
            {
                Console.WriteLine("Invalid property attributes, should be empty");
                Console.WriteLine(Fail);
                return;
            }
            
            var classAttributes = opt.GetClassAttributes();
            if (classAttributes.Count == 1 && classAttributes[0] == "[DataContract]")
            {
            }
            else
            {
                Console.WriteLine("Invalid class attributes");
                Console.WriteLine(Fail);
                return;
            }            
            
            var assemblies = opt.GetAssemblies();
            if (assemblies.Count == 1 && assemblies[0] == "System.Data.dll")
            {
            }
            else
            {
                Console.WriteLine("Invalid assembly set");
                Console.WriteLine(Fail);
                return;
            }
            
            if (opt.GetPropertyType("abc") != "System.String")
            {
                Console.WriteLine("Incorrect type");
                Console.WriteLine(Fail);
                return;
            }

            if (opt.GetPropertyType("xyz") != null)
            {
                Console.WriteLine("Type shouldn't be set");
                Console.WriteLine(Fail);
                return;
            }

            if (opt.GetConverter("abc") == null)
            {
                Console.WriteLine("Incorrect converter");
                Console.WriteLine(Fail);
                return;
            }

            if (opt.GetConverter("xyz") != null)
            {
                Console.WriteLine("Converter shouldn't be set");
                Console.WriteLine(Fail);
                return;
            }

            var names = opt.GetNamespaces();
            if (names.Length != 1 || names[0] != "system.namespace")
            {
                Console.WriteLine("Incorrect namespace set");
                Console.WriteLine(Fail);
                return;
            }

            Console.WriteLine(Pass);
        }