Exemple #1
0
                            public void UT_InsGetDelSequence()
                            {
                                DO_User _user;

                                try {
                                    _user = new DO_User();
                                } catch (Exception e) {
                                    Assert.IsTrue(false, "some error trying to instantiate DO_User\n---\n{0}\n---", e.Message);
                                    return; // no need...
                                }
                                _user.Connection.Open();
                                _user.Connection.Transaction.Begin();



                                _user.Fields.Login         = "******";
                                _user.Fields.Password      = "******";
                                _user.Fields.SomeNullValue = 123;
                                // handle Constraints // ToDos: here!



                                _user.Connection.Transaction.Rollback();
                                _user.Connection.Transaction.Terminate();
                                _user.Connection.Close();
                                _user.Dispose(); _user = null;
                            }
Exemple #2
0
        public HowTo_UseTransactions_inDOs()
        {
            string _testid = DateTime.Now.Ticks.ToString();
            bool   _constraint;
            long   _iduser;
            long   _idgroup;


            DO_User _user = new DO_User();

            // before beginning a transaction we need to open the connection
            _user.Connection.Open();

            // beginning transaction
            _user.Connection.Transaction.Begin();

            // performing some operations on User Data Object
            _user.Fields.Login    = _testid;
            _user.Fields.Password = _testid;
            _iduser = _user.insObject(true, out _constraint);
            // handling constraint code should be added here

            // rollback transaction, we don't need such data in db, this is just an how to sample
            _user.Connection.Transaction.Rollback();

            // terminate transaction
            _user.Connection.Transaction.Terminate();

            // closing connection
            _user.Connection.Close();

            _user.Dispose(); _user = null;
        }
Exemple #3
0
        public void UT_Constraints()
        {
            string _testid = DateTime.Now.Ticks.ToString();
            bool   _constraint;

            for (int c = 0; c < UT0__utils.DBConnections.Length; c++)
            {
//Console.WriteLine("UT_Constraints: {0}", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]).ToString());

                UT0__utils.DBConnections[c].Open();
                UT0__utils.DBConnections[c].Transaction.Begin();
                DO_User _user = new DO_User(UT0__utils.DBConnections[c]);

                _user.Fields.Login    = _testid;
                _user.Fields.Password = _testid;
                _user.insObject(false, out _constraint);
                Assert.IsFalse(_constraint, "there should be no constraint problems");

                _user.clrObject();
                _user.Fields.Login    = _testid;
                _user.Fields.Password = _testid;
                _user.insObject(false, out _constraint);
                Assert.IsTrue(_constraint, "constraint problems expected and not found");

                _user.Dispose(); _user = null;
                UT0__utils.DBConnections[c].Transaction.Rollback();
                UT0__utils.DBConnections[c].Transaction.Terminate();
                UT0__utils.DBConnections[c].Close();
            }
        }
Exemple #4
0
        public HowTo_UseTransactions_betweenDOs_operations()
        {
            string _testid = DateTime.Now.Ticks.ToString();
            bool   _constraint;
            long   _iduser;
            long   _idgroup;

            // we need a shared connection between Data Objects
            DBConnection _con = DO__utils.DBConnection_createInstance(
                DO__utils.DBServerType,
                DO__utils.DBConnectionstring,
                string.Empty
                );

            // before beginning a transaction we need to open the connection
            _con.Open();

            // beginning transaction
            _con.Transaction.Begin();

            // sharing connection with User Data Object
            DO_User _user = new DO_User(_con);

            // performing some operations on User Data Object
            _user.Fields.Login    = _testid;
            _user.Fields.Password = _testid;
            _iduser = _user.insObject(true, out _constraint);
            // handling constraint code should be added here
            _user.Dispose(); _user = null;

            // sharing connection with Group Data Object
            DO_Group _group = new DO_Group(_con);

            // performing some operations on User Data Object
            _group.Fields.Name       = _testid;
            _idgroup                 = _group.insObject(true);
            _group.Dispose(); _group = null;

            // sharing connection with Group Data Object
            DO_UserGroup _usergroup = new DO_UserGroup(_con);

            // performing some operations on User Data Object
            _usergroup.Fields.IDGroup         = _idgroup;
            _usergroup.Fields.IDUser          = _iduser;
            _usergroup.Fields.Relationdate    = DateTime.Now;
            _usergroup.Fields.Defaultrelation = false;
            _usergroup.setObject(false);
            _usergroup.Dispose(); _usergroup = null;

            // rollback transaction, we don't need such data in db, this is just an how to sample
            _con.Transaction.Rollback();

            // terminate transaction
            _con.Transaction.Terminate();

            // closing connection
            _con.Close();

            _con.Dispose(); _con = null;
        }
Exemple #5
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();
                }
            }
        }
Exemple #6
0
        public void UT_Reflection_GetProperty()
        {
            long _initialvalue   = 123L;
            long _replacingvalue = 456L;

            DO_User _user = new DO_User();

            _user.Fields.IDUser = _initialvalue;
            //---
            PropertyInfo _iduser
                = typeof(SO0_User).GetProperty("IDUser");

            //---
            Assert.AreEqual(_initialvalue, (long)_iduser.GetValue(_user.Fields, null));
            _iduser.SetValue(
                _user.Fields,
                Convert.ChangeType(
                    _replacingvalue,
                    _iduser.PropertyType
                    ),
                null
                );
            Assert.AreEqual(_replacingvalue, (long)_iduser.GetValue(_user.Fields, null));
            //---
            _user.Dispose(); _user = null;

            #region             //oldstuff...
            //PropertyInfo[] properties = typeof(DO_User).GetProperties(
            //    BindingFlags.Public |
            //    BindingFlags.Instance
            //);
            //for (int p = 0; p < properties.Length; p++) {
            //    if (Attribute.IsDefined(
            //        properties[p],
            //        typeof(DOPropertyAttribute)
            //    )) {
            //        Assert.AreEqual("123", properties[p].GetValue(_user, null).ToString());
            //        properties[p].SetValue(
            //            _user,
            //            Convert.ChangeType(
            //                456,
            //                properties[p].PropertyType
            //            ),
            //            null
            //        );
            //        Assert.AreEqual("456", properties[p].GetValue(_user, null).ToString());
            //    }
            //}
            #endregion
        }
Exemple #7
0
        public SO_User getObject(
            long idUser_in,
            string login_in,
            out bool exists_out
            )
        {
            DO_User _do_user = new DO_User();

            exists_out = _do_user.getObject(idUser_in);
            SO_User _so_user_out = (SO_User)_do_user.Fields;

            _do_user.Dispose();

            return(_so_user_out);
        }
Exemple #8
0
        public void UT_PropertyNullAssignement()
        {
            //string _testid = DateTime.Now.Ticks.ToString();
            //bool _constraint;
            //long _iduser;

            DO_User _user = new DO_User();

            try {
                _user.Fields.Login = null;
            } catch {
                Assert.Fail("unexpected null assignement error!");
            }
            _user.Dispose(); _user = null;
        }
Exemple #9
0
        public void UT_bugPostgreSQL_noFunctionMatchesTheGivenNameAndArgumentTypes()
        {
            bool _contraint;
            long _iduser;
            long _idgroup;

            for (int c = 0; c < UT0__utils.DBConnections.Length; c++)
            {
//Console.WriteLine("UT_NullableFields: {0}", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]).ToString());

                UT0__utils.DBConnections[c].Open();
                UT0__utils.DBConnections[c].Transaction.Begin();

                #region _iduser = new DO_User(UT0__utils.DBConnections[c]).insObject(true);
                DO_User _user = new DO_User(UT0__utils.DBConnections[c]);
                _user.Fields.Login    = testid_;
                _user.Fields.Password = testid_;
                _iduser = _user.insObject(true, out _contraint);
                _user.Dispose(); _user = null;
                #endregion
                #region _idgroup = new DO_Group(UT0__utils.DBConnections[c]).insObject(true);
                DO_Group _group = new DO_Group(UT0__utils.DBConnections[c]);
                _group.Fields.Name       = testid_;
                _idgroup                 = _group.insObject(true);
                _group.Dispose(); _group = null;
                #endregion

                DO_UserGroup _usergroup = new DO_UserGroup(UT0__utils.DBConnections[c]);
                _usergroup.Fields.IDUser                 = _iduser;
                _usergroup.Fields.IDGroup                = _idgroup;
                _usergroup.Fields.Relationdate_isNull    = true;
                _usergroup.Fields.Defaultrelation_isNull = true;
                try {
                    _usergroup.setObject(true);
                } catch {
                    Assert.Fail(
                        "test error: 1 ({0})",
                        DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])
                        );
                }
                _usergroup.Dispose(); _usergroup = null;

                UT0__utils.DBConnections[c].Transaction.Rollback();
                UT0__utils.DBConnections[c].Transaction.Terminate();
                UT0__utils.DBConnections[c].Close();
            }
        }
Exemple #10
0
        public long insObject(
            SO_User user_in,
            bool selectIdentity_in,
            string login_in,
            out bool constraintExist_out
            )
        {
            long    _iduser;
            DO_User _user = new DO_User();

            _user.Fields = (SO_User)user_in;
            _iduser      = _user.insObject(
                selectIdentity_in,
                out constraintExist_out
                );
            _user.Dispose();

            return(_iduser);
        }
Exemple #11
0
        public SO_User[] Record_Open_byGroup(
            long IDGroup_search_in,
            int page_in,
            int page_numRecords_in,
            string login_in,
            out long recordLength_out
            )
        {
            SO_User[] _output;

            DO_User _do_user = new DO_User();

            if (
                (page_in > 0)
                &&
                (page_numRecords_in > 0)
                )
            {
                _do_user.Record.Open_byGroup(
                    IDGroup_search_in,
                    page_in,
                    page_numRecords_in
                    );
                recordLength_out = _do_user.Record.Count_byGroup(
                    IDGroup_search_in
                    );
            }
            else
            {
                _do_user.Record.Open_byGroup(
                    IDGroup_search_in
                    );
                recordLength_out = (long)_do_user.Record.Count;
            }
            _output = _do_user.Record.Serialize().SO_User;
            _do_user.Record.Close();
            _do_user.Dispose();

            return(_output);
        }
Exemple #12
0
        public string Login(
            string login_in,
            string password_in
            )
        {
            bool _validLogin;
            long _iduser = -1;

            DO_User _user = new DO_User();

            if (
                _user.getObject_byLogin(login_in)
                &&
                (_user.Fields.Password == password_in)
                )
            {
                _iduser = _user.Fields.IDUser;
            }
            _user.Dispose();

            return(_iduser.ToString());
        }
Exemple #13
0
        public void UT_hasChanges()
        {
            string _testid = DateTime.Now.Ticks.ToString();
            bool   _constraint;
            long   _iduser;

            DO_User _user = new DO_User();

            _user.Connection.Open();
            _user.Connection.Transaction.Begin();

            Assert.IsFalse(_user.Fields.hasChanges, "unexpected changes, object just instantiated and no changes have been made");
            _user.Fields.Login    = _testid;
            _user.Fields.Password = _testid;
            Assert.IsTrue(_user.Fields.hasChanges, "expected changes, changes have been made over object");
            _iduser = _user.insObject(true, out _constraint);
            Assert.IsFalse(_user.Fields.hasChanges, "unexpected changes, object state commited (insert) over data base");
            _user.Fields.Login    = _testid;
            _user.Fields.Password = _testid;
            Assert.IsFalse(_user.Fields.hasChanges, "unexpected changes, no real changes have been made");
            _user.Fields.Password = string.Empty;
            Assert.IsTrue(_user.Fields.hasChanges, "expected changes, real changes have been made");
            _user.updObject(false, out _constraint);
            Assert.IsFalse(_user.Fields.hasChanges, "unexpected changes, object state commited (update) over data base");
            _user.clrObject();
            Assert.IsTrue(_user.Fields.hasChanges, "expected changes, object state cleared");
            _user.getObject_byLogin(_testid);
            Assert.IsFalse(_user.Fields.hasChanges, "unexpected changes, object state sinchronized (select) with data base");
            _user.delObject();
            Assert.IsTrue(_user.Fields.hasChanges, "expected changes, object erased (delete on data base)");

            _user.Connection.Transaction.Rollback();
            _user.Connection.Transaction.Terminate();
            _user.Connection.Close();
            _user.Dispose(); _user = null;
        }
Exemple #14
0
        static void Main(string[] args)
        {
            //DO_UserGroup _usergroup_test = new DO_UserGroup(
            //    //new DBConnection(
            //    //    DBServerTypes.SQLServer,
            //    //    "server=127.0.0.1;uid=sa;pwd=passpub;database=OGen-NTier_UTs;"
            //    //)
            //);
            //_usergroup_test.IDGroup = 1;
            //_usergroup_test.IDUser = 1;
            //_usergroup_test.Relationdate_isNull = true;
            //_usergroup_test.Defaultrelation_isNull = true;
            //_usergroup_test.setObject(true);

            //OGen.NTier.UTs.lib.datalayer.UTs.UT__utils _ut_utils
            //    = new OGen.NTier.UTs.lib.datalayer.UTs.UT__utils();
            //_ut_utils.TestFixtureSetUp();
            //_ut_utils.UT_Check_DataObjects_integrity();
            //return;

            //OGen.NTier.UTs.lib.datalayer.UTs.UT_User _ut_user
            //    = new OGen.NTier.UTs.lib.datalayer.UTs.UT_User();
            //_ut_user.TestFixtureSetUp();
            //_ut_user.UT_hasChanges();
            //return;


            //OGen.NTier.UTs.lib.datalayer.UTs.UT_UserGroup
            //	_ut_usergroup = new OGen.NTier.UTs.lib.datalayer.UTs.UT_UserGroup();
            //_ut_usergroup.TestFixtureSetUp();
            //_ut_usergroup.UT_bugPostgreSQL_noFunctionMatchesTheGivenNameAndArgumentTypes();
            ////_ut_usergroup.UT_NullableFields();
            //return;


            //DO_Config _config_test = new DO_Config();
            //_config_test.Connection.Open();
            //_config_test.Connection.Transaction.Begin();
            //_config_test.Fields.Name = "test";
            //_config_test.Fields.Description = "test";
            //_config_test.Fields.Config = "test";
            //_config_test.Fields.Type = 1;
            //try {
            //	_config_test.setObject(true);
            //	Console.WriteLine("ok");
            //} catch {
            //	Console.WriteLine("ko");
            //}
            //_config_test.Connection.Transaction.Rollback();
            //_config_test.Connection.Transaction.Terminate();
            //_config_test.Connection.Close();
            //_config_test.Dispose();
            //return;



            const int _cycles = 50;

            DBConnection[] _cons = new DBConnection[] {
                #region new DBConnection(DBServerTypes.SQLServer, ...),
                DBConnectionsupport.CreateInstance(
                    DBServerTypes.SQLServer,

                    DBUtilssupport.GetInstance(DBServerTypes.SQLServer).ConnectionString.Build(
                        "127.0.0.1",
                        "sa",
                        "passpub",
                        "OGen-NTier_UTs"
                        )
                    ),
                #endregion
                #region new DBConnection(DBServerTypes.PostgreSQL, ...)
                DBConnectionsupport.CreateInstance(
                    DBServerTypes.PostgreSQL,
                    DBUtilssupport.GetInstance(DBServerTypes.PostgreSQL).ConnectionString.Build(
                        "127.0.0.1",
                        "postgres",
                        "passpub",
                        "OGen-NTier_UTs"
                        )
                    )
                #endregion
            };

            long _conter = 0L;
            for (int _compiled = 0; _compiled < 2; _compiled++)
            {
                for (int _con = 0; _con < _cons.Length; _con++)
                {
                    _cons[_con].Open();
                    _cons[_con].Transaction.Begin();
                    for (int _cached = 0; _cached < 2; _cached++)
                    {
                        DO_Config _config = new DO_Config(_cons[_con]);
                        #region _config.setObject();
                        _conter = DateTime.Now.Ticks;

                        for (int c = 0; c < _cycles; c++)
                        {
                            _config.Fields.Name   = c.ToString();
                            _config.Fields.Config = "DELETE THIS, IT IS A TEST";
                            _config.Fields.Type   = 2;
                            _config.setObject(true);
                        }

                        Console.WriteLine(
                            "setObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.Record.Open_...(false);
                        _conter = DateTime.Now.Ticks;

                        _config.Record.Open_all(false);
                        while (_config.Record.Read())
                        {
                            ;
                        }
                        _config.Record.Close();

                        Console.WriteLine(
                            "Record.Open()    \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.delObject();
                        _conter = DateTime.Now.Ticks;

                        _config.Record.Open_all(true);
                        while (_config.Record.Read())
                        {
                            if (_config.Fields.Config == "DELETE THIS, IT IS A TEST")
                            {
                                _config.delObject();
                            }
                        }
                        _config.Record.Close();

                        Console.WriteLine(
                            "delObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.getObject();
                        _conter = DateTime.Now.Ticks;

                        _config.Fields.Name   = "SomeIntConfig";
                        _config.Fields.Config = "1245";
                        _config.Fields.Type   = 4;
                        _config.setObject(true);

                        for (int c = 0; c < _cycles; c++)
                        {
                            _config.getObject("SomeIntConfig");
                        }

                        Console.WriteLine(
                            "getObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        _config.Dispose(); _config = null;
                        //---
                        DO_User _user = new DO_User(_cons[_con]);

                        #region _user.insObject();
                        _conter = DateTime.Now.Ticks;

                        for (int c = 0; c < _cycles; c++)
                        {
                            bool _constraint;
                            _user.Fields.Login    = c.ToString();
                            _user.Fields.Password = "******";
                            _user.insObject(true, out _constraint);
                        }

                        _user.Record.Open_all(true);
                        while (_user.Record.Read())
                        {
                            if (_user.Fields.Password == "DELETE THIS, IT IS A TEST")
                            {
                                _user.delObject();
                            }
                        }
                        _user.Record.Close();

                        Console.WriteLine(
                            "insObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion

                        _conter = DateTime.Now.Ticks;
                        for (int c = 0; c < _cycles; c++)
                        {
                            if (!_user.isObject_byLogin("fmonteiro"))
                            {
                                bool _constraint;
                                _user.Fields.Login    = "******";
                                _user.Fields.Password = "******";
                                _user.insObject(true, out _constraint);
                            }
                            _user.getObject_byLogin("fmonteiro");
                        }
                        Console.WriteLine(
                            "getObject_by()   \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );

                        _user.Dispose(); _user = null;
                    }
                    _cons[_con].Transaction.Rollback();
                    _cons[_con].Transaction.Terminate();
                    _cons[_con].Close();
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }
Exemple #15
0
        public void UT_NullableFields()
        {
            bool _contraint;
            long _iduser;
            long _idgroup;

            for (int c = 0; c < UT0__utils.DBConnections.Length; c++)
            {
//Console.WriteLine("UT_NullableFields: {0}", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]).ToString());

                UT0__utils.DBConnections[c].Open();
                UT0__utils.DBConnections[c].Transaction.Begin();

                #region _iduser = new DO_User(UT0__utils.DBConnections[c]).insObject(true);
                DO_User _user = new DO_User(UT0__utils.DBConnections[c]);
                _user.Fields.Login    = testid_;
                _user.Fields.Password = testid_;
                _iduser = _user.insObject(true, out _contraint);
                _user.Dispose(); _user = null;
                #endregion
                #region _idgroup = new DO_Group(UT0__utils.DBConnections[c]).insObject(true);
                DO_Group _group = new DO_Group(UT0__utils.DBConnections[c]);
                _group.Fields.Name       = testid_;
                _idgroup                 = _group.insObject(true);
                _group.Dispose(); _group = null;
                #endregion

                DO_UserGroup _usergroup = new DO_UserGroup(UT0__utils.DBConnections[c]);
                _usergroup.Fields.IDUser                 = _iduser;
                _usergroup.Fields.IDGroup                = _idgroup;
                _usergroup.Fields.Relationdate_isNull    = true;
                _usergroup.Fields.Defaultrelation_isNull = true;
                _usergroup.setObject(true);

                #region test1...
                _usergroup.clrObject();
                _usergroup.getObject(_iduser, _idgroup);
                Assert.IsTrue(_usergroup.Fields.Relationdate_isNull, "DO_UserGroup.Relationdate expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]));
                Assert.IsTrue(_usergroup.Fields.Defaultrelation_isNull, "DO_UserGroup.Defaultrelation expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]));
                #endregion
                #region test2...
                for (int i = 0; i < 2; i++)                   // test both fullmode and not
                {
                    _usergroup.Record.Open_byUser_Defaultrelation(
                        _iduser,
                        null,
                        (i == 0)                         // test both fullmode and not
                        );
                    while (_usergroup.Record.Read())
                    {
                        Assert.IsTrue(_usergroup.Fields.Relationdate_isNull, "DO_UserGroup.Relationdate expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]));
                        Assert.IsTrue(_usergroup.Fields.Defaultrelation_isNull, "DO_UserGroup.Defaultrelation expected to be nullable ({0})", DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c]));
                    }
                    _usergroup.Record.Close();
                }
                #endregion
                #region test3...
                Assert.IsTrue(
                    _usergroup.Record.hasObject_byUser_Defaultrelation(
                        _iduser,
                        _idgroup,
                        _iduser,
                        null
                        ),
                    "test error: 1 ({0})",
                    DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])
                    );
                Assert.AreEqual(
                    1L,
                    _usergroup.Record.Count_byUser_Defaultrelation(
                        _iduser,
                        null
                        ),
                    "test error: 2 ({0})",
                    DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])
                    );
                #endregion
                #region test4...
                DateTime _now = DateTime.Now;
                _usergroup.Record.Update_SomeUpdateTest_byUser_Defaultrelation(
                    _iduser,
                    null,
                    _now
                    );

                Assert.IsTrue(
                    _usergroup.Record.hasObject_byUser_Defaultrelation(
                        _iduser,
                        _idgroup,
                        _iduser,
                        _now
                        ),
                    "test error: 3 ({0})",
                    DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])
                    );
                Assert.AreEqual(
                    1L,
                    _usergroup.Record.Count_byUser_Defaultrelation(
                        _iduser,
                        _now
                        ),
                    "test error: 4 ({0})",
                    DBConnectionsupport.GetDBServerType(UT0__utils.DBConnections[c])
                    );
                #endregion

                _usergroup.Dispose(); _usergroup = null;

                UT0__utils.DBConnections[c].Transaction.Rollback();
                UT0__utils.DBConnections[c].Transaction.Terminate();
                UT0__utils.DBConnections[c].Close();
            }
        }
Exemple #16
0
        static void Main(string[] args)
        {
            IBO_Authentication _authentication;
            IBO_User           _user;
            string             _login;

            for (int _provider = 0; _provider < 3; _provider++)
            {
                switch (_provider)
                {
                case 0:
                    Console.WriteLine("--- remoting...");
                    _authentication
                        = new RC_Authentication(
                              "tcp://127.0.0.1:8085/OGen.NTier.UTs.distributedlayer.remoting.server.RS_Authentication.remoting"
                              //"http://127.0.0.1:8085/OGen.NTier.UTs.distributedlayer.remoting.server.RS_Authentication.soap"
                              );

                    _user
                        = new RC_User(
                              "tcp://127.0.0.1:8085/OGen.NTier.UTs.distributedlayer.remoting.server.RS_User.remoting"
                              //"http://127.0.0.1:8085/OGen.NTier.UTs.distributedlayer.remoting.server.RS_User.soap"
                              );
                    break;

                case 1:
                    Console.WriteLine("--- webservices...");
                    _authentication
                        = new WC_Authentication.WC_Authentication(
                              "http://127.0.0.1:2937/WS_Authentication.asmx"
                              );

                    _user
                        = new WC_User.WC_User(
                              "http://127.0.0.1:2937/WS_User.asmx"
                              );
                    break;

                default:
                    Console.WriteLine("--- direct assembly...");
                    _authentication
                        = new BC_Authentication(
                              );

                    _user
                        = new BC_User(
                              );
                    break;
                }

                Console.WriteLine(
                    "authentication string: {0}\n",
                    _login = _authentication.Login(
                        "fmonteiro",
                        "passpub"
                        )
                    );

                OGen.NTier.UTs.lib.datalayer.proxy.ISO_User _so_user
                    = new OGen.NTier.UTs.lib.datalayer.proxy.SO_User(
                          0L,
                          string.Format(
                              "login-{0}",
                              Guid.NewGuid().ToString()
                              ),
                          "password",
                          0
                          );
                _so_user.SomeNullValue_isNull = true;
                Console.WriteLine(
                    "IDUser: {0}; Login: {1}; Password: {2}; SomeNullValue: {3} (is null: {4})",
                    _so_user.IDUser,
                    _so_user.Login,
                    _so_user.Password,
                    _so_user.SomeNullValue,
                    _so_user.SomeNullValue_isNull
                    );

                long _iduser;
                bool _constraintExists;
                Console.WriteLine(
                    "IDUser: {0}; Constraint Exists: {1}",
                    _iduser = _user.insObject(
                        (SO_User)_so_user,
                        true,
                        _login,
                        out _constraintExists
                        ),
                    _constraintExists
                    );

                bool _exists;
                _so_user = _user.getObject(
                    _iduser,
                    _login,
                    out _exists
                    );
                Console.WriteLine(
                    "Exists: {5}; IDUser: {0}; Login: {1}; Password: {2}; SomeNullValue: {3} (is null: {4})",
                    _so_user.IDUser,
                    _so_user.Login,
                    _so_user.Password,
                    _so_user.SomeNullValue,
                    _so_user.SomeNullValue_isNull,
                    _exists
                    );

                long      _recordLength;
                SO_User[] _users = _user.Record_Open_byGroup(
                    3L,
                    1,
                    4,
                    _login,
                    out _recordLength
                    );
                Console.WriteLine(
                    "Record Length: {0}",
                    _recordLength
                    );
                for (int i = 0; i < _users.Length; i++)
                {
                    Console.WriteLine(
                        //"IDUser: {0}; Login: {1}",
                        "IDUser: {0}; Login: {1}; Password: {2}; SomeNullValue: {3} (is null: {4})",
                        _users[i].IDUser,
                        _users[i].Login,
                        _users[i].Password,
                        _users[i].SomeNullValue,
                        _users[i].SomeNullValue_isNull
                        );
                }

                _authentication.Logout();
            }
            return;



            //OGen.NTier.UTs.lib.businesslayer-2.0
            Assembly _assembly = Assembly.Load(
                                #if NET_1_1
                "OGen.NTier.UTs.lib.businesslayer-1.1"
                                #elif NET_2_0
                "OGen.NTier.UTs.lib.businesslayer-2.0"
                                #endif
                );

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

                    object[] _attibutes = _type.GetCustomAttributes(
                        typeof(BOClassAttribute),
                        true                        //false
                        );
                    if (
                        (_attibutes.Length > 0)
                        &&
                        (_type.Name.IndexOf("BO0_") != 0)
                        &&
                        (_type.Name.IndexOf("BBO0_") != 0)
                        )
                    {
                        Console.Write("{0};  ", _type.Name);

                        for (int c = 0; c < _attibutes.Length; c++)
                        {
                            BOClassAttribute _attribute
                                = (BOClassAttribute)_attibutes[c];
                            Console.WriteLine(
                                "name:{0};",
                                _attribute.Name
                                );

                            MethodInfo[] _methods = _type.GetMethods(
                                BindingFlags.Public |
                                BindingFlags.Instance
                                );
                            for (int m = 0; m < _methods.Length; m++)
                            {
                                if (Attribute.IsDefined(
                                        _methods[m],
                                        typeof(BOMethodAttribute)
                                        ))
                                {
                                    Attribute[] _attributes = Attribute.GetCustomAttributes(
                                        _methods[m],
                                        typeof(BOMethodAttribute),
                                        true
                                        );

                                    for (int a = 0; a < _attributes.Length; a++)
                                    {
                                        //if (_attributes[a].GetType() == typeof(BOMethodAttribute)) {
                                        BOMethodAttribute _propertyattribute
                                            = (BOMethodAttribute)_attributes[a];
                                        Console.WriteLine(
                                            "\tname:{0}; distribute:{1};",
                                            _propertyattribute.Name,
                                            _propertyattribute.Distribute
                                            );
                                        //}
                                    }
                                    Console.WriteLine(
                                        "\t.{0}:{1}.{2}(",
                                        _methods[m].Name,
                                        _methods[m].ReturnType.Namespace,
                                        _methods[m].ReturnType.Name
                                        );
                                    ParameterInfo[] _parameterinfo = _methods[m].GetParameters();
                                    for (int p = 0; p < _parameterinfo.Length; p++)
                                    {
                                        Console.WriteLine(
                                            "\t\tname:{0}; type:{1}; isOut:{2}; isByRef:{3}; isEnum:{4}; isClass:{5}; isValueType:{6}",
                                            _parameterinfo[p].Name,
                                            _parameterinfo[p].ParameterType,
                                            _parameterinfo[p].IsOut,
                                            _parameterinfo[p].ParameterType.IsByRef,
                                            _parameterinfo[p].ParameterType.IsEnum,
                                            _parameterinfo[p].ParameterType.IsClass,
                                            _parameterinfo[p].ParameterType.IsValueType
                                            );
                                    }
                                    Console.WriteLine("\t)");
                                }
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
            return;

            //DO_UserGroup _usergroup_test = new DO_UserGroup(
            //    //new DBConnection(
            //    //    DBServerTypes.SQLServer,
            //    //    "server=127.0.0.1;uid=sa;pwd=passpub;database=OGen-NTier_UTs;"
            //    //)
            //);
            //_usergroup_test.IDGroup = 1;
            //_usergroup_test.IDUser = 1;
            //_usergroup_test.Relationdate_isNull = true;
            //_usergroup_test.Defaultrelation_isNull = true;
            //_usergroup_test.setObject(true);

            //OGen.NTier.UTs.lib.datalayer.UTs.UT__utils _ut_utils
            //    = new OGen.NTier.UTs.lib.datalayer.UTs.UT__utils();
            //_ut_utils.TestFixtureSetUp();
            //_ut_utils.UT_Check_DataObjects_integrity();
            //return;

            //OGen.NTier.UTs.lib.datalayer.UTs.UT_User _ut_user
            //    = new OGen.NTier.UTs.lib.datalayer.UTs.UT_User();
            //_ut_user.TestFixtureSetUp();
            //_ut_user.UT_hasChanges();
            //return;


            //OGen.NTier.UTs.lib.datalayer.UTs.UT_UserGroup
            //	_ut_usergroup = new OGen.NTier.UTs.lib.datalayer.UTs.UT_UserGroup();
            //_ut_usergroup.TestFixtureSetUp();
            //_ut_usergroup.UT_bugPostgreSQL_noFunctionMatchesTheGivenNameAndArgumentTypes();
            ////_ut_usergroup.UT_NullableFields();
            //return;


            //DO_Config _config_test = new DO_Config();
            //_config_test.Connection.Open();
            //_config_test.Connection.Transaction.Begin();
            //_config_test.Fields.Name = "test";
            //_config_test.Fields.Description = "test";
            //_config_test.Fields.Config = "test";
            //_config_test.Fields.Type = 1;
            //try {
            //	_config_test.setObject(true);
            //	Console.WriteLine("ok");
            //} catch {
            //	Console.WriteLine("ko");
            //}
            //_config_test.Connection.Transaction.Rollback();
            //_config_test.Connection.Transaction.Terminate();
            //_config_test.Connection.Close();
            //_config_test.Dispose();
            //return;



            const int _cycles = 50;

            DBConnection[] _cons = new DBConnection[] {
                #region new DBConnection(DBServerTypes.SQLServer, ...),
                DBConnectionsupport.CreateInstance(
                    DBServerTypes.SQLServer,

                    DBUtilssupport.GetInstance(DBServerTypes.SQLServer).ConnectionString.Build(
                        "127.0.0.1",
                        "sa",
                        "passpub",
                        "OGen-NTier_UTs"
                        )
                    ),
                #endregion
                #region new DBConnection(DBServerTypes.PostgreSQL, ...)
                DBConnectionsupport.CreateInstance(
                    DBServerTypes.PostgreSQL,
                    DBUtilssupport.GetInstance(DBServerTypes.PostgreSQL).ConnectionString.Build(
                        "127.0.0.1",
                        "postgres",
                        "passpub",
                        "OGen-NTier_UTs"
                        )
                    )
                #endregion
                //#region new DBConnection(DBServerTypes.MySQL, ...)
                //, DBConnectionsupport.CreateInstance(
                //    DBServerTypes.MySQL,
                //    DBUtilssupport.GetInstance(DBServerTypes.MySQL).ConnectionString.Build(
                //        "127.0.0.1",
                //        "root",
                //        "passpub",
                //        "OGen-NTier_UTs"
                //    )
                //)
                //#endregion
            };

            long _conter = 0L;
            for (int _compiled = 0; _compiled < 2; _compiled++)
            {
                for (int _con = 0; _con < _cons.Length; _con++)
                {
                    _cons[_con].Open();
                    _cons[_con].Transaction.Begin();
                    for (int _cached = 0; _cached < 2; _cached++)
                    {
                        DO_Config _config = new DO_Config(_cons[_con]);
                        #region _config.setObject();
                        _conter = DateTime.Now.Ticks;

                        for (int c = 0; c < _cycles; c++)
                        {
                            _config.Fields.Name   = c.ToString();
                            _config.Fields.Config = "DELETE THIS, IT IS A TEST";
                            _config.Fields.Type   = 2;
                            _config.setObject(true);
                        }

                        Console.WriteLine(
                            "setObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.Record.Open_...(false);
                        _conter = DateTime.Now.Ticks;

                        _config.Record.Open_all();
                        while (_config.Record.Read())
                        {
                            ;
                        }
                        _config.Record.Close();

                        Console.WriteLine(
                            "Record.Open()    \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.delObject();
                        _conter = DateTime.Now.Ticks;

                        _config.Record.Open_all();
                        while (_config.Record.Read())
                        {
                            if (_config.Fields.Config == "DELETE THIS, IT IS A TEST")
                            {
                                _config.delObject();
                            }
                        }
                        _config.Record.Close();

                        Console.WriteLine(
                            "delObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        #region _config.getObject();
                        _conter = DateTime.Now.Ticks;

                        _config.Fields.Name   = "SomeIntConfig";
                        _config.Fields.Config = "1245";
                        _config.Fields.Type   = 4;
                        _config.setObject(true);

                        for (int c = 0; c < _cycles; c++)
                        {
                            _config.getObject("SomeIntConfig");
                        }

                        Console.WriteLine(
                            "getObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion
                        _config.Dispose(); _config = null;
                        //---
                        DO_User _do_user = new DO_User(_cons[_con]);

                        #region _do_user.insObject();
                        _conter = DateTime.Now.Ticks;

                        for (int c = 0; c < _cycles; c++)
                        {
                            bool _constraint;
                            _do_user.Fields.Login    = c.ToString();
                            _do_user.Fields.Password = "******";
                            _do_user.insObject(true, out _constraint);
                        }

                        _do_user.Record.Open_all();
                        while (_do_user.Record.Read())
                        {
                            if (_do_user.Fields.Password == "DELETE THIS, IT IS A TEST")
                            {
                                _do_user.delObject();
                            }
                        }
                        _do_user.Record.Close();

                        Console.WriteLine(
                            "insObject()      \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );
                        #endregion

                        _conter = DateTime.Now.Ticks;
                        for (int c = 0; c < _cycles; c++)
                        {
                            if (!_do_user.isObject_byLogin("fmonteiro"))
                            {
                                bool _constraint;
                                _do_user.Fields.Login    = "******";
                                _do_user.Fields.Password = "******";
                                _do_user.insObject(true, out _constraint);
                            }
                            _do_user.getObject_byLogin("fmonteiro");
                        }
                        Console.WriteLine(
                            "getObject_by()   \t{0}\tcached:{1}\tcompiled:{2}\t{3}",
                            DBConnectionsupport.GetDBServerType(_cons[_con]),
                            (_cached == 1),
                            (_compiled == 1),
                            (DateTime.Now.Ticks - _conter).ToString()
                            );

                        _do_user.Dispose(); _do_user = null;
                    }
                    _cons[_con].Transaction.Rollback();
                    _cons[_con].Transaction.Terminate();
                    _cons[_con].Close();
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }