Beispiel #1
0
        public HowTo_Read_and_Write_to_DataObject_Properties()
        {
            DO_User _user = new DO_User();

            _user.Fields.IDUser   = 123;
            _user.Fields.Login    = "******";
            _user.Fields.Password = "******";

            PropertyInfo[] _properties = typeof(DO_User).GetProperties(
                BindingFlags.Public |
                BindingFlags.Instance
                );
            for (int _prop = 0; _prop < _properties.Length; _prop++)
            {
                if (Attribute.IsDefined(
                        _properties[_prop],
                        typeof(DOPropertyAttribute)
                        ))
                {
                    Console.Write(
                        "{0}: ",
                        _properties[_prop].Name
                        );
                    Attribute[] _attributes = Attribute.GetCustomAttributes(
                        _properties[_prop]
                        //, typeof(DOPropertyAttribute)
                        //, true
                        );
                    for (int _att = 0; _att < _attributes.Length; _att++)
                    {
                        //if (_attributes[_att].GetType() == typeof(DOPropertyAttribute)) {
                        DOPropertyAttribute _attribute = (DOPropertyAttribute)_attributes[_att];
                        Console.Write(
                            "name:{0};  isPK:{1};  isIdentity:{2};  DefaultValue:{3};  ",
                            _attribute.Name,
                            _attribute.isPK,
                            _attribute.isIdentity,
                            _attribute.DefaultValue
                            );
                        //}
                    }
                    Console.Write(
                        "value: {0}; ",
                        _properties[_prop].GetValue(_user, null)
                        );
                    _properties[_prop].SetValue(
                        _user,
                        Convert.ChangeType(
                            456,
                            _properties[_prop].PropertyType
                            ),
                        null
                        );
                    Console.WriteLine(
                        "new value: {0}", _properties[_prop].GetValue(_user, null)
                        );
                    Console.WriteLine();
                }
            }
        }
Beispiel #2
0
        public void UT_Reflection_GetCustomAttribute()
        {
            Assert.IsTrue(Attribute.IsDefined(typeof(SO0_User).GetProperty("IDUser"), typeof(DOPropertyAttribute)));

            DOPropertyAttribute _att = (DOPropertyAttribute)Attribute.GetCustomAttribute(
                typeof(SO0_User).GetProperty("IDUser"),
                typeof(DOPropertyAttribute),
                true
                );

            Assert.AreEqual("IDUser", _att.Name);
            Assert.IsTrue(_att.isPK);
            Assert.IsTrue(_att.isIdentity);
        }
Beispiel #3
0
        public HowTo_Read_DataObject_Property_Attributes()
        {
            DOPropertyAttribute _attribute = (DOPropertyAttribute)Attribute.GetCustomAttribute(
                typeof(DO_User).GetProperty("IDUser"),
                typeof(DOPropertyAttribute),
                true
                );

            Console.WriteLine(
                "name:{0};  isPK:{1};  isIdentity:{2};  DefaultValue:{3};",
                _attribute.Name,
                _attribute.isPK,
                _attribute.isIdentity,
                _attribute.DefaultValue
                );
            Console.WriteLine();
        }
Beispiel #4
0
        public void UT_Check_DataObjects_integrity()
        {
            bool _found_Config          = false;
            bool _found_vUserGroup      = false;
            int  _found_Config_Name     = 0;
            int  _found_Config_Config   = 0;
            int  _found_Config_Datatype = 0;
            bool _virtualTable_hasPK    = false;

            Assembly _assembly = Assembly.Load("OGen.NTier.UTs.lib.datalayer");

            Assert.IsTrue((_assembly != null), "couldn't load OGen.NTier.UTs.lib.datalayer assembly");
            if (_assembly != null)
            {
                Type[] _types = _assembly.GetTypes();
                for (int _tp = 0; _tp < _types.Length; _tp++)
                {
                    Type _type = (Type)_types[_tp];

                    object[] _doclassattributes = _type.GetCustomAttributes(
                        typeof(DOClassAttribute),
                        true                        //false
                        );
                    if (
                        (_doclassattributes.Length > 0)
                        &&
                        (_type.Name.IndexOf("DO0_") != 0)
                        )
                    {
                        for (int _catt = 0; _catt < _doclassattributes.Length; _catt++)
                        {
                            DOClassAttribute _classattribute = (DOClassAttribute)_doclassattributes[_catt];

                            PropertyInfo[] _properties = _type.GetProperties(
                                BindingFlags.Public |
                                BindingFlags.Instance
                                );
                            for (int _prop = 0; _prop < _properties.Length; _prop++)
                            {
                                if (Attribute.IsDefined(
                                        _properties[_prop],
                                        typeof(DOPropertyAttribute)
                                        ))
                                {
                                    Attribute[] _attributes = Attribute.GetCustomAttributes(
                                        _properties[_prop]
                                        );
                                    for (int _att = 0; _att < _attributes.Length; _att++)
                                    {
                                        DOPropertyAttribute _propertyattribute = (DOPropertyAttribute)_attributes[_att];

                                        Assert.AreEqual(_properties[_prop].Name, _propertyattribute.Name, "\"{0}\" != \"{1}\" ??", _properties[_prop].Name, _propertyattribute.Name);

                                        switch (_classattribute.Name)
                                        {
                                        case "Config": {
                                            if (!_found_Config)
                                            {
                                                _found_Config = true;
                                                Assert.IsTrue(_classattribute.isConfig, "DO_Config shouldn't have isConfig attribute set to false");
                                                Assert.IsFalse(_classattribute.isVirtualTable, "DO_Config shouldn't have isVirtualTable attribute set to true");
                                            }
                                            if (_classattribute.isConfig)
                                            {
                                                if (_propertyattribute.isConfig_Name)
                                                {
                                                    _found_Config_Name++;
                                                }
                                                if (_propertyattribute.isConfig_Config)
                                                {
                                                    _found_Config_Config++;
                                                }
                                                if (_propertyattribute.isConfig_Datatype)
                                                {
                                                    _found_Config_Datatype++;
                                                }
                                            }
                                            break;
                                        }

                                        case "vUserGroup": {
                                            if (!_found_vUserGroup)
                                            {
                                                _found_vUserGroup = true;
                                                Assert.IsFalse(_classattribute.isConfig, "DO_vUserGroup shouldn't have isConfig attribute set to true");
                                                Assert.IsTrue(_classattribute.isVirtualTable, "DO_vUserGroup shouldn't have isVirtualTable attribute set to false");
                                            }
                                            if ((!_virtualTable_hasPK) && (_classattribute.isVirtualTable) && (_propertyattribute.isPK))
                                            {
                                                _virtualTable_hasPK = true;
                                            }
                                            break;
                                        }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Assert.IsTrue(_found_Config, "couldn't find: DO_Config");
            Assert.IsTrue(_found_vUserGroup, "couldn't find: DO_vUserGroup");
            Assert.AreEqual(1, _found_Config_Name, "DO_Config isConfig_Name properties: {0}, expected 1", _found_Config_Name);
            Assert.AreEqual(1, _found_Config_Config, "DO_Config isConfig_Config properties: {0}, expected 1", _found_Config_Config);
            Assert.AreEqual(1, _found_Config_Datatype, "DO_Config isConfig_Datatype properties: {0}, expected 1", _found_Config_Datatype);
            Assert.IsTrue(_virtualTable_hasPK, "couldn't find any PKs fields at DO_vUserGroup");
        }
Beispiel #5
0
        public HowTo_List_DataObjects()
        {
            Assembly _assembly = Assembly.Load("OGen.NTier.UTs.lib.datalayer");

            if (_assembly != null)
            {
                Type[] _types = _assembly.GetTypes();
                for (int _tp = 0; _tp < _types.Length; _tp++)
                {
                    Type _type = (Type)_types[_tp];

                    object[] _doclassattributes = _type.GetCustomAttributes(
                        typeof(DOClassAttribute),
                        true                        //false
                        );
                    if (
                        (_doclassattributes.Length > 0)
                        &&
                        (_type.Name.IndexOf("DO0_") != 0)
                        )
                    {
                        Console.Write("{0};  ", _type.Name);
                        for (int _catt = 0; _catt < _doclassattributes.Length; _catt++)
                        {
                            DOClassAttribute _classattribute = (DOClassAttribute)_doclassattributes[_catt];
                            Console.WriteLine(
                                "name: {0};  isVirtualTable: {1};  isConfig: {2};  ",
                                _classattribute.Name,
                                _classattribute.isVirtualTable,
                                _classattribute.isConfig
                                );

                            PropertyInfo[] _properties = _type.GetProperties(
                                BindingFlags.Public |
                                BindingFlags.Instance
                                );
                            for (int _prop = 0; _prop < _properties.Length; _prop++)
                            {
                                if (Attribute.IsDefined(
                                        _properties[_prop],
                                        typeof(DOPropertyAttribute)
                                        ))
                                {
                                    Console.Write(
                                        "\t{0}: ",
                                        _properties[_prop].Name
                                        );
                                    Attribute[] _attributes = Attribute.GetCustomAttributes(
                                        _properties[_prop]
                                        //, typeof(DOPropertyAttribute)
                                        //, true
                                        );
                                    //Console.WriteLine("Name \t isPK \t isIdentity \t DefaultValue \t \t \t \t isBool");
                                    for (int _att = 0; _att < _attributes.Length; _att++)
                                    {
                                        //if (_attributes[_att].GetType() == typeof(DOPropertyAttribute)) {
                                        DOPropertyAttribute _propertyattribute = (DOPropertyAttribute)_attributes[_att];
                                        Console.Write(
                                            "name:{0};  isPK:{1};  isIdentity:{2};  isText:{3};",
                                            _propertyattribute.Name,
                                            _propertyattribute.isPK,
                                            _propertyattribute.isIdentity,
                                            //att3.DefaultValue,
                                            //att3.isConfig_Name,
                                            //att3.isConfig_Config,
                                            //att3.isConfig_Datatype,
                                            _propertyattribute.isText
                                            );
                                        //}
                                    }
                                    Console.WriteLine();
                                }
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
        }