public void ModelContextThreadTests()
        {
            List <Thread> ts = new List <Thread>();

            // update NumDependents to 10, the therads below update the employee NumDependents to 1,2,3,4 but we roll them back
            // at the end of the test , after all theads have finished, we make sure that NumDependents is 10 for all emplloyees
            DBUtils.Current().executeSQLWithParams("update employee set NumDependents=10");
            int employeeCount = EmployeeDataUtils.findList("NumDependents=10").Count();

            Assert.AreEqual(4, employeeCount);

            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));
            ts.Add(new Thread(ModelContextConcurrencyTest));

            int i = 0;

            ts.ForEach(x => x.Start(i++));
            ts.ForEach(x => x.Join());

            employeeCount = EmployeeDataUtils.findList("NumDependents=10").Count();
            Assert.AreEqual(4, employeeCount);
            // at the end of the test , after all theads have finished, we make sure
            // that NumDependents is 10 for all emplloyees  since we set it at line 33 and all threads
            // rollback

            // the test below removed.  Never suceeeded but connection count is correct if you
            // do a select from database. Threading issues?
            //Assert.AreEqual(connectionCount, this.getConnectionCount(),
            //	"Expected connection count to be starting connection");
        }
        /// <summary>
        /// Called by the threadTests above.
        /// Tests transactions, with update and select statements
        /// </summary>
        private void ModelContextConcurrencyTest(object x)
        {
            TestContext.WriteLine("--->NumDependents:{0}, DBUtils: {1}", x, DBUtils.Current().GetHashCode().ToString());
            int employeeCount = DBUtils.Current().getLngValue("select count(*) from employee");

            ModelContext.beginTrans();
            try {
                List <Employee> empls = EmployeeDataUtils.findList();

                // update NumDependents to x
                empls.ForEach(em => em.PrNumDependents = Convert.ToInt32(x));
                empls.ForEach(em => ModelContext.Current.saveModelObject(em));

                using (IDataReader rs = DBUtils.Current().getDataReaderWithParams(
                           "select employeeid, address from employee where NumDependents=?", x)) {
                    Assert.IsFalse(rs.IsClosed);
                    Assert.IsTrue(rs.Read());
                }
                int employeeCount2 = DBUtils.Current().getLngValue("select count(*) from employee where NumDependents=?", Convert.ToInt32(x));
                Assert.AreEqual(
                    employeeCount2, employeeCount);
            } finally {
                ModelContext.rollbackTrans();
            }
        }
        public void testModelContextModelObjectUpdateAndRead()
        {
            ModelContext.beginTrans();
            try {
                Assert.AreEqual(ModelContext.CurrentDBUtils.GetHashCode(), DBUtils.Current().GetHashCode(),
                                "Expected same connection");

                Assert.AreEqual(true, ModelContext.CurrentDBUtils.inTrans,
                                "Expected connection to be in transaction");

                Employee e = ModelContext.Current.loadModelObject <Employee>(1);
                e.PrAddress = "nikoy theofanous 3a, nicosia - testObjectRead";
                ModelContext.Current.saveModelObject(e);

                e = ModelContext.Current.loadModelObject <Employee>(1);
                Assert.AreEqual(e.PrAddress, "nikoy theofanous 3a, nicosia - testObjectRead");

                e = EmployeeDataUtils.findOne("address=?", "nikoy theofanous 3a, nicosia - testObjectRead");
                Assert.IsNotNull(e);

                Assert.AreEqual(e.PrAddress, "nikoy theofanous 3a, nicosia - testObjectRead");
            } finally {
                ModelContext.rollbackTrans();
            }

            Employee e2 = EmployeeDataUtils.findOne("address=?", "nikoy theofanous 3a, nicosia - testObjectRead");

            Assert.IsNull(e2);
        }
        public void testVBNetUpdateOfParentIds()
        {
            ModelContext.beginTrans();
            try {
                Employee employee = EmployeeDataUtils.findByKey(1);
                NUnit.Framework.Assert.IsNotNull(employee);
                employee.loadObjectHierarchy();
                employee.PrEmployeeRankId = 1; // set to "president"
                EmployeeDataUtils.saveEmployee(employee);

                employee = EmployeeDataUtils.findByKey(1);                                                                              // reload from db
                employee.loadObjectHierarchy();
                NUnit.Framework.Assert.IsTrue(employee.PrEmployeeRankId == 1, "Employee must be PrEmployeeRankId=1");                   // president
                NUnit.Framework.Assert.IsTrue(employee.PrRank.PrRankId == 1, "Employee PrRank related object must be of PrRankId = 1"); // president

                employee.PrEmployeeRankId = 2;                                                                                          // modify to "Associate Consultant"
                NUnit.Framework.Assert.IsTrue(employee.PrEmployeeRankId == 2, "Employee must be PrEmployeeRankId=2");
                NUnit.Framework.Assert.IsTrue(employee.PrRank.PrRankId == 2, "Employee PrRank related object must be of PrRankId =2");
                EmployeeDataUtils.saveEmployee(employee);

                employee = EmployeeDataUtils.findByKey(1); // reload from db
                NUnit.Framework.Assert.IsTrue(employee.PrEmployeeRankId == 2, "Employee must be PrEmployeeRankId=2");
            } finally {
                ModelContext.rollbackTrans();
            }
        }
Exemple #5
0
        public void testModelObjectUpdateReadWithDataUtils()
        {
            DBUtils.Current().beginTrans();
            try {
                Employee e = EmployeeDataUtils.findByKey(1);
                e.PrAddress = "nikoy theofanous 3a, nicosia - testObjectRead";
                EmployeeDataUtils.saveEmployee(e);

                e = EmployeeDataUtils.findByKey(1);
                Assert.AreEqual(e.PrAddress, "nikoy theofanous 3a, nicosia - testObjectRead");

                e = EmployeeDataUtils.findOne("address=?", "nikoy theofanous 3a, nicosia - testObjectRead");
                Assert.IsNotNull(e);

                Assert.AreEqual(e.PrAddress, "nikoy theofanous 3a, nicosia - testObjectRead");
            } finally {
                DBUtils.Current().rollbackTrans();
            }


            Employee e2 = EmployeeDataUtils.findOne("address=?", "nikoy theofanous 3a, nicosia - testObjectRead");

            Assert.IsNull(e2);
        }
        public void createOracletestRecords()
        {
            ModelContext.Current.config.DoCascadeDeletes = true;
            ModelContext.beginTrans();
            ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(EmployeeValidator));

            try {
                Employee e = EmployeeFactory.Create();
                e.PrDepartment = DepartmentFactory.Create();
                e.PrDepartment.PrDepartmentName = "My New Dept";
                e.PrDepartment.PrLocationId     = LocationDataUtils.findList()[0].PrLocationId;

                e.PrFirstName   = "test";
                e.PrLastName    = "Lastname";
                e.PrSALARY      = 100m;
                e.PrEMAIL       = "*****@*****.**";
                e.PrPhoneNumber = "1030045";
                e.PrHireDate    = new DateTime(DateTime.Now.Year, 1, 1);
                e.PrJobId       = JobDataUtils.findList()[0].PrJobId;

                e.PrTrainingHistoryAdd(EmployeeTrainingHistoryFactory.Create());
                EmployeeTrainingHistory emplProj = e.PrTrainingHistoryGetAt(0);
                emplProj.PrDateFrom = new DateTime(DateTime.Now.Year, 3, 1);
                emplProj.PrDateTo   = new DateTime(DateTime.Now.Year, 6, 1);

                emplProj.PrTrainingCourse           = TrainingCourseFactory.Create();
                emplProj.PrTrainingCourse.PrCODE    = "X1";
                emplProj.PrTrainingCourse.PrDescrEn = "New Course";
                emplProj.PrTrainingCourse.PrDescrGr = "Νέο";
                Assert.IsTrue(e.isNew);
                Assert.IsTrue(e.isDirty);
                Assert.IsTrue(e.NeedsSave);

                // 3 ways to persist to database
                // method 1: use ModelContext.Current().save

                Assert.IsTrue(e.CreateDate == null, "Before save, created date is null");
                Assert.IsTrue(e.UpdateDate == null, "Before save, UpdateDate is not null");
                ModelContext.Current.saveModelObject(e);
                Assert.IsTrue(e.PrPhoneNumber == "12345XX", "12345XX value in PrPhoneNumber is Proof that validator was called");
                Assert.IsTrue(e.CreateDate != null, "Before save, created date is not null");
                Assert.IsTrue(e.UpdateDate != null, "Before save, UpdateDate is not null");
                Assert.IsTrue(e.CreateUser != null, "Before save, CreateUser date is not null");
                Assert.IsTrue(e.UpdateUser != null, "Before save, UpdateUser is not null");
                //Assert.IsTrue(e.UpdateDate.Value.Ticks == e.CreateDate.Value.Ticks, "update date = create date after saving new");
                Assert.IsTrue(e.UpdateUser == e.CreateUser, "update date = create date after saving new");

                long x = e.PrEmployeeId;
                Assert.IsFalse(e.isNew, "After save, model object isNew property must return false");
                Assert.IsFalse(e.isDirty, "After save to db, model object isDirty property must return false");

                e = EmployeeDataUtils.findByKey(x);

                Assert.IsNotNull(e, "New employee not found");

                Assert.IsFalse(e.isNew, "After load from db, model object isNew property returns false");
                Assert.IsFalse(e.isDirty, "After load from db, model object isDirty property returns false");

                Assert.AreEqual(e.PrDepartment.PrDepartmentName, "My New Dept");
                Assert.AreEqual(e.PrSALARY, 100m);
                Assert.AreEqual(e.PrLastName, "Lastname");
                Assert.AreEqual(e.PrPhoneNumber, "12345XX");
                Assert.AreEqual(e.PrHireDate, new DateTime(2015, 1, 1));
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 1);
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course");

                //change some values on child and parent objects
                e.PrTrainingHistoryGetAt(0).PrDateTo = new DateTime(DateTime.Now.Year, 6, 1);
                e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn = "New Course Updated"; // here we are updating parent record of child object of employee!
                Assert.IsTrue(e.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true");
                Assert.IsFalse(e.isDirty, "After changing parent or child obejcts values, e.isDirty must be false since we did not change anything on the Model Object");

                // method 2: call [ModelObject]DataUtils.save
                EmployeeDataUtils.saveEmployee(e);
                //Assert.IsTrue(e.UpdateDate > e.CreateDate, "after update of record, update must be date > create date ");
                // note that above test cannot be sucess since save is happening too fast

                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrPhoneNumber = "XXXXX";
                Assert.IsTrue(e.NeedsSave, "After changing value, e.NeedsSave must be true");
                Assert.IsTrue(e.isDirty, "After changing value e.isDirty must be true");

                // method 3: call [ModelObject]dbMapper.save
                new EmployeeDBMapper().saveEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrPhoneNumber, "XXXXX");
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrTrainingHistoryClear();
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked after call to clear");
                EmployeeDataUtils.saveEmployee(e);

                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked, after reloading from db");

                EmployeeDataUtils.deleteEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.IsNull(e, "New employee must have been deleted!");

                // now let's test string primary key
                Country et = CountryFactory.Create();
                et.PrCountryName = "A Description";
                et.PrCountryId   = "XX";

                Country et1 = CountryFactory.Create();
                et1.PrCountryName = "A Description 1";
                et1.PrCountryId   = "Y7";

                Country et2 = CountryFactory.Create();
                et2.PrCountryName = "A Description 2";
                et2.PrCountryId   = "H8";

                CountryDataUtils.saveCountry(et, et1, et2);

                et2 = CountryDataUtils.findByKey("H8");
                Assert.IsNotNull(et2, "New Country must have been created!");
                et1 = CountryDataUtils.findByKey("Y7");
                Assert.IsNotNull(et1, "New Country must have been created!");
            } finally {
                ModelContext.rollbackTrans();
            }
        }
        public void testVBNetSerializationAndDeserialization()
        {
            ModelContext.beginTrans();
            try {
                DateTime hireDate = new DateTime(DateTime.Now.Year, 1, 1);
                Employee employee = EmployeeFactory.Create();
                employee.PrEmployeeName           = "test employee";
                employee.PrSalary                 = 100m;
                employee.PrSSINumber              = "1030045";
                employee.PrTelephone              = "2234455";
                employee.PrHireDate               = hireDate;
                employee.PrIsActive               = true;
                employee.PrEmployeeInfo           = EmployeeInfoFactory.Create();
                employee.PrEmployeeInfo.PrAddress = "some address";
                employee.PrEmployeeInfo.PrSalary  = 300.0M;

                // test parent object
                employee.PrRank        = EmployeeRankFactory.Create();
                employee.PrRank.PrRank = "Test me";

                employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create());
                EmployeeProject emplProj = employee.PrEmployeeProjectGetAt(0);
                emplProj.PrAssignDate            = new DateTime(DateTime.Now.Year, 3, 1);
                emplProj.PrEndDate               = new DateTime(DateTime.Now.Year, 6, 1);
                emplProj.PrEPProjectId           = 1;
                emplProj.PrProject               = ProjectFactory.Create();
                emplProj.PrProject.PrProjectName = "MyProject 1";

                employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create());
                EmployeeProject emplProj2 = employee.PrEmployeeProjectGetAt(1);
                emplProj2.PrAssignDate            = new DateTime(DateTime.Now.Year, 3, 1);
                emplProj2.PrEndDate               = new DateTime(DateTime.Now.Year, 6, 1);
                emplProj2.PrEPProjectId           = 2;
                emplProj2.PrProject               = ProjectFactory.Create();
                emplProj2.PrProject.PrProjectName = "MyProject 2";

                string output = JsonConvert.SerializeObject(employee);

                //JavaScriptSerializer jss = new JavaScriptSerializer();
                //object d = jss.Deserialize<object>(output);
                Employee employee2 = JsonConvert.DeserializeObject <Employee>(output);

                NUnit.Framework.Assert.AreEqual(2, employee2.PrEmployeeProjects.ToList().Count, "Expected 2 projects after desirialize");
                NUnit.Framework.Assert.IsTrue(employee2.PrEmployeeInfo != null,
                                              "Expected employee info not null after desirialize");

                NUnit.Framework.Assert.IsTrue(employee2.PrRank != null,
                                              "Expected employee Rank not null after desirialize");

                EmployeeDataUtils.saveEmployee(employee2);
                long x = (long)employee2.Id;

                employee2 = EmployeeDataUtils.findByKey(x);
                NUnit.Framework.Assert.IsNotNull(employee2);
                NUnit.Framework.Assert.AreEqual(2, employee2.PrEmployeeProjects.ToList().Count, "Expected 2 projects after save");
                NUnit.Framework.Assert.IsTrue(employee2.PrRank != null,
                                              "Expected employee Rank not null after save");
                NUnit.Framework.Assert.IsTrue(employee2.PrEmployeeInfo != null,
                                              "Expected employee info not null after save");
            } finally {
                ModelContext.rollbackTrans();
            }
        }
        public void testVBNetCreateRecords()
        {
            ModelContext.Current.config.DoCascadeDeletes = true;
            ModelContext.beginTrans();
            ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(CsharpEmployeeValidator));
            DateTime hireDate = new DateTime(DateTime.Now.Year + 10, 1, 1);

            try {
                EmployeeRank er = EmployeeRankFactory.Create();
                er.PrRank = "My New Rank";

                Employee employee = EmployeeFactory.Create();
                NUnit.Framework.Assert.IsTrue(employee is IAuditable, "Empoyee must implement IAuditable");

                employee.PrRank         = er;
                employee.PrEmployeeName = "test employee";
                employee.PrSalary       = 100m;
                employee.PrSSINumber    = "1030045";
                employee.PrTelephone    = "2234455";
                employee.PrHireDate     = hireDate;
                employee.PrIsActive     = true;

                Guid g = Guid.NewGuid();
                employee.PrSampleGuidField = g;
                employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create());
                EmployeeProject emplProj = employee.PrEmployeeProjectGetAt(0);
                emplProj.PrAssignDate            = new DateTime(DateTime.Now.Year + 10, 3, 1);
                emplProj.PrEndDate               = new DateTime(DateTime.Now.Year + 10, 6, 1);
                emplProj.PrEPProjectId           = 1;
                emplProj.PrProject               = ProjectFactory.Create();
                emplProj.PrProject.PrProjectName = "MyProject";

                NUnit.Framework.Assert.IsTrue(employee.isNew);
                NUnit.Framework.Assert.IsTrue(employee.isDirty);
                NUnit.Framework.Assert.IsTrue(employee.NeedsSave);

                // 3 ways to persist to database
                // method 1: use ModelContext.Current().save

                NUnit.Framework.Assert.IsTrue(employee.CreateDate == null, "Before save, created date is null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate == null, "Before save, UpdateDate is not null");

                ModelContext.Current.saveModelObject(employee);

                NUnit.Framework.Assert.IsTrue(employee.PrSSINumber == "12345XX", "12345XX value in PrSSINumber is Proof that validator was called");
                NUnit.Framework.Assert.IsTrue(employee.CreateDate != null, "Before save, created date is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate != null, "Before save, UpdateDate is not null");
                NUnit.Framework.Assert.IsTrue(employee.CreateUser != null, "Before save, CreateUser date is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateUser != null, "Before save, UpdateUser is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate.GetValueOrDefault().ToString("dd/MM/yyyy") == employee.CreateDate.GetValueOrDefault().ToString("dd/MM/yyyy"), "update date = create date after saving new");
                NUnit.Framework.Assert.IsTrue(employee.UpdateUser == employee.CreateUser, "update date = create date after saving new");

                long x = (long)employee.Id;
                NUnit.Framework.Assert.IsFalse(employee.isNew, "After save, model object isNew property must return false");
                NUnit.Framework.Assert.IsFalse(employee.isDirty, "After save to db, model object isDirty property must return false");

                employee = EmployeeDataUtils.findByKey(x);

                NUnit.Framework.Assert.IsNotNull(employee, "New employee not found");

                NUnit.Framework.Assert.IsFalse(employee.isNew, "After load from db, model object isNew property returns false");
                NUnit.Framework.Assert.IsFalse(employee.isDirty, "After load from db, model object isDirty property returns false");
                NUnit.Framework.Assert.AreEqual(employee.PrSampleGuidField, g);
                NUnit.Framework.Assert.AreEqual(employee.PrRank.PrRank, "My New Rank");
                NUnit.Framework.Assert.AreEqual(employee.PrSalary, 100m);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeName, "test employee");
                NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "12345XX");
                NUnit.Framework.Assert.AreEqual(employee.PrHireDate, hireDate);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 1);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject");

                //change some values on child and parent objects
                employee.PrEmployeeProjectGetAt(0).PrEndDate = new DateTime(DateTime.Now.Year + 10, 6, 1);
                employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName = "MyProject Updated"; // here we are updating parent record of child object of employee!
                NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true");
                NUnit.Framework.Assert.IsFalse(employee.isDirty, "After changing parent or child obejcts values, e.isDirty must be false since we did not change anything on the Model Object");

                // method 2: call [ModelObject]DataUtils.save
                EmployeeDataUtils.saveEmployee(employee);

                var lst = EmployeeDataUtils.findList("hiredate between ? and ?", new DateTime(DateTime.Now.Year + 10, 1, 1), new DateTime(DateTime.Now.Year + 10, 12, 1));
                NUnit.Framework.Assert.AreEqual(1, lst.Count);
                employee = EmployeeDataUtils.findByKey(x);

                //NUnit.Framework.Assert.IsTrue(e.UpdateDate > e.CreateDate, "after update of record, update must be date > create date ");
                // note that above test cannot be sucess since save is happening too fast

                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1));
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!");

                employee.PrSSINumber              = "XXXXX";
                employee.PrEmployeeInfo           = EmployeeInfoFactory.Create();
                employee.PrEmployeeInfo.PrAddress = "2 nikoy thefanous street";
                employee.PrEmployeeInfo.PrSalary  = 3000;

                NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing value, e.NeedsSave must be true");
                NUnit.Framework.Assert.IsTrue(employee.isDirty, "After changing value e.isDirty must be true");

                // method 3: call [ModelObject]dbMapper.save
                new EmployeeDBMapper().save(employee);
                employee = EmployeeDataUtils.findByKey(x);
                NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "XXXXX");
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1));
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!");

                employee.PrEmployeeProjectsClear();
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 0, "Expected to have no Projects linked after call to clear");
                EmployeeDataUtils.saveEmployee(employee);

                employee = EmployeeDataUtils.findByKey(x);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 0, "Expected to have no Projects linked, after reloading from db");

                List <Employee> empls = EmployeeDataUtils.findList("EmployeeName={0} and Salary between {1} and {2} and HireDate={3}", "test employee", 0, 100, hireDate);
                NUnit.Framework.Assert.IsTrue(empls.Count > 0, "Employee Count not the expected!");

                EmployeeDataUtils.deleteEmployee(employee);
                employee = EmployeeDataUtils.findByKey(x);
                NUnit.Framework.Assert.IsNull(employee, "New employee must have been deleted!");

                // now let's test string primary key
                EmployeeType et = EmployeeTypeFactory.Create();
                et.PrEmployeeType     = "A Description";
                et.PrEmployeeTypeCode = "XX";

                EmployeeType et1 = EmployeeTypeFactory.Create();
                et1.PrEmployeeType     = "A Description 1";
                et1.PrEmployeeTypeCode = "XX1";

                EmployeeType et2 = EmployeeTypeFactory.Create();
                et2.PrEmployeeType     = "A Description 2";
                et2.PrEmployeeTypeCode = "XX2";

                EmployeeTypeDataUtils.saveEmployeeType(et, et1, et2);

                et2 = EmployeeTypeDataUtils.findByKey("XX2");
                NUnit.Framework.Assert.IsNotNull(et2, "New employeetype must have been created!");
                et1 = EmployeeTypeDataUtils.findByKey("XX1");
                NUnit.Framework.Assert.IsNotNull(et1, "New employeetype must have been created!");

                Project p = ProjectFactory.Create();
                p.PrIsActive      = true;
                p.PrProjectTypeId = ModelLibVBGenCode.EnumProjectType.EXTERNAL;
                p.PrProjectName   = "Test";
                ProjectDataUtils.saveProject(p);
                long pid = p.PrProjectId;
                p = ProjectDataUtils.findByKey(pid);
                NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!");
                NUnit.Framework.Assert.AreEqual(p.PrProjectTypeId, ModelLibVBGenCode.EnumProjectType.EXTERNAL);

                p.PrProjectTypeId = null; // test null value to enumaration
                ProjectDataUtils.saveProject(p);
                p = ProjectDataUtils.findByKey(pid);
                NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!");
                NUnit.Framework.Assert.IsNull(p.PrProjectTypeId, "project type id must be null after saved to the db, instead got value:" + p.PrProjectTypeId);

                List <Employee>    elst = EmployeeDataUtils.findList();
                EmployeeEvaluation ep   = EmployeeEvaluationFactory.Create();
                ep.PrEmployeeId     = elst[0].PrEmployeeId;
                ep.PrEvaluatorId    = elst[1].PrEmployeeId;
                ep.PrEvaluationDate = hireDate;
                EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep); // insert
                NUnit.Framework.Assert.IsTrue(ep.PrEmployeeEvaluationId > 0);
                long eid = ep.PrEmployeeEvaluationId;

                EmployeeEvaluation ep2 = EmployeeEvaluationDataUtils.findByKey(eid);
                NUnit.Framework.Assert.IsNotNull(ep2);
                NUnit.Framework.Assert.AreEqual(ep, ep2);
                ep2.PrEvaluationDate = new DateTime(hireDate.Year, hireDate.Month + 1, 1);
                EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep2);   // update

                EmployeeEvaluationDataUtils.deleteEmployeeEvaluation(ep2); //delete
                ep2 = EmployeeEvaluationDataUtils.findByKey(eid);
                NUnit.Framework.Assert.IsNull(ep2);

                Bank alphaBank = BankDataUtils.findOne("bankcode='09'");
                if (alphaBank == null)
                {
                    alphaBank            = BankFactory.Create();
                    alphaBank.PrBankCode = "09";
                    alphaBank.PrBankName = "ALPHA Bank";
                    BankDataUtils.saveBank(alphaBank);
                }

                Account pa = AccountDataUtils.findOne("Account='ALPHA'");
                if ((pa == null))
                {
                    pa                                     = AccountFactory.Create();
                    pa.PrAccount                           = "ALPHA";
                    pa.PrDescription                       = "ALPHA TEST";
                    pa.PrAccountTypeid                     = 1;
                    pa.PrBankaccnumber                     = "000000000004";
                    pa.PrBankAccountInfo                   = AccountBankInfoFactory.Create();
                    pa.PrBankAccountInfo.PrBankId          = alphaBank.PrBANKID;
                    pa.PrBankAccountInfo.PrCompanyName     = "UNIT TESTS LTD";
                    pa.PrBankAccountInfo.PrCompanyBankCode = "111";
                    AccountDataUtils.saveAccount(pa);
                }
            } finally {
                ModelContext.rollbackTrans();
            }
        }