private static ContactPersonOptimisticLockingVersionNumberDB CreateSavedCntactPersonOptimisticLockingVersionNumberDB()
        {
            ContactPersonOptimisticLockingVersionNumberDB.LoadDefaultClassDef();
            ContactPersonOptimisticLockingVersionNumberDB contactPersonOptimisticLockingVersionNumberDB;

            contactPersonOptimisticLockingVersionNumberDB         = new ContactPersonOptimisticLockingVersionNumberDB();
            contactPersonOptimisticLockingVersionNumberDB.Surname = Guid.NewGuid().ToString();
            contactPersonOptimisticLockingVersionNumberDB.Save();
            AddObjectToDelete(contactPersonOptimisticLockingVersionNumberDB);
            return(contactPersonOptimisticLockingVersionNumberDB);
        }
        public void TestLockingVersionNumber_DoesNotCauseProblemsWithMultipleSaves()
        {
            //---------------Set up test pack-------------------
            //Create object in DB

            ContactPersonOptimisticLockingVersionNumberDB.LoadDefaultClassDef();
            ContactPersonOptimisticLockingVersionNumberDB contactPerson = new ContactPersonOptimisticLockingVersionNumberDB();

            contactPerson.Surname = Guid.NewGuid().ToString();
            AddObjectToDelete(contactPerson);
            contactPerson.Save();
            //---------------Execute Test ----------------------
            //Edit first object and persist to the database.
            contactPerson.Surname = Guid.NewGuid().ToString();
            contactPerson.Save();
        }
        public void TestLockingVersionNumber_OnBeginEdit()
        {
            //---------------Set up test pack-------------------
            //Create object in DB

            ContactPersonOptimisticLockingVersionNumberDB.LoadDefaultClassDef();
            ContactPersonOptimisticLockingVersionNumberDB contactPerson = new ContactPersonOptimisticLockingVersionNumberDB
            {
                Surname = Guid.NewGuid().ToString()
            };

            AddObjectToDelete(contactPerson);
            contactPerson.Save();
            //Clear object manager
            FixtureEnvironment.ClearBusinessObjectManager();
            //Load second object from DB
            ContactPersonOptimisticLockingVersionNumberDB duplicateContactPerson =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonOptimisticLockingVersionNumberDB>(contactPerson.ID);

            AddObjectToDelete(duplicateContactPerson);

            //---------------Execute Test ----------------------
            //Edit first object and persist to the database.
            contactPerson.Surname = Guid.NewGuid().ToString();
            contactPerson.Save();
            //Begin Edit on second object
            try
            {
                duplicateContactPerson.FirstName = Guid.NewGuid().ToString();
                Assert.Fail("Should throw error");
            }
            //---------------Test Result -----------------------
            //Raise Exception that the object has been edited since
            // the user last edited.
            catch (BusObjBeginEditConcurrencyControlException ex)
            {
                Assert.IsTrue(ex.Message.Contains("You cannot Edit 'ContactPersonOptimisticLockingVersionNumberDB', as another user has edited this record"));
            }
        }