public void Test_IfThisThreadLocksAndTimesOutBeforePersistingThenThrowErrorWhenPersisting() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); cp.Surname = Guid.NewGuid().ToString(); IBOProp propDateTimeLocked = cp.Props["DateTimeLocked"]; int lockDuration = 15; //---------------Execute Test ---------------------- propDateTimeLocked.Value = DateTime.Now.AddMinutes(-1 * lockDuration - 1); UpdateDatabaseLockAsExpired(lockDuration); try { cp.Save(); Assert.Fail(); } //---------------Test Result ----------------------- catch (BusObjPessimisticConcurrencyControlException ex) { Assert.IsTrue( ex.Message.Contains( "The lock on the business object ContactPersonPessimisticLockingDB has a duration of 15 minutes and has been exceeded for the object")); } }
private static ContactPersonPessimisticLockingDB CreateSavedContactPersonPessimisticLocking() { ContactPersonPessimisticLockingDB.LoadDefaultClassDef(); ContactPersonPessimisticLockingDB cp = new ContactPersonPessimisticLockingDB(); cp.Surname = Guid.NewGuid().ToString(); TransactionCommitter tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); tc.AddBusinessObject(cp); tc.CommitTransaction(); return(cp); }
public void Test_EditContactPersonTwiceDoesNotCauseProblems() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); //---------------Execute Test ---------------------- cp.Surname = Guid.NewGuid().ToString(); cp.Surname = Guid.NewGuid().ToString(); //---------------Test Result ----------------------- //Should not raise an error since the lock duration has been exceeded. }
public void Test_MultipleSavesNoProblem() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); //---------------Execute Test ---------------------- cp.Surname = Guid.NewGuid().ToString(); cp.Save(); cp.Surname = Guid.NewGuid().ToString(); cp.Save(); //---------------Test Result ----------------------- }
public void Test_SurnameNotUpdatedToDBWhenUpdatingLockingProps() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); string surname = cp.Surname; //---------------Execute Test ---------------------- cp.Surname = Guid.NewGuid().ToString(); FixtureEnvironment.ClearBusinessObjectManager(); ContactPersonPessimisticLockingDB cp2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonPessimisticLockingDB>(cp.ID); Assert.AreEqual(surname, cp2.Surname); Assert.AreNotEqual(surname, cp.Surname); }
public void Test_NotLockedIfLockDurationExceeded() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); IConcurrencyControl concurrCntrl = cp.ConcurrencyControl(); //Create Lock concurrCntrl.CheckConcurrencyBeforeBeginEditing(); int lockDuration = 15; UpdateDatabaseLockAsExpired(lockDuration); //---------------Execute Test ---------------------- concurrCntrl.CheckConcurrencyBeforeBeginEditing(); //---------------Test Result ----------------------- //Should not raise an error since the lock duration has been exceeded. }
public void Test_ThrowErrorIfObjectDeletedPriorToBeginEdits() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); //---------------Execute Test ---------------------- ContactPerson.DeleteAllContactPeople(); try { IConcurrencyControl concurrCntrl = cp.ConcurrencyControl(); concurrCntrl.CheckConcurrencyBeforeBeginEditing(); Assert.Fail(); } //---------------Test Result ----------------------- catch (BusObjDeleteConcurrencyControlException ex) { Assert.IsTrue( ex.Message.Contains( "You cannot save the changes to 'ContactPersonPessimisticLockingDB', as another user has deleted the record")); } }
public void Test_ThrowErrorIfCheckConcurrencyBeforeEditingTwice() { //---------------Set up test pack------------------- ContactPersonPessimisticLockingDB cp = CreateSavedContactPersonPessimisticLocking(); //---------------Execute Test ---------------------- IConcurrencyControl concurrCntrl = cp.ConcurrencyControl(); concurrCntrl.CheckConcurrencyBeforeBeginEditing(); try { concurrCntrl.CheckConcurrencyBeforeBeginEditing(); Assert.Fail(); } //---------------Test Result ----------------------- catch (BusObjPessimisticConcurrencyControlException ex) { Assert.IsTrue( ex.Message.Contains( "You cannot begin edits on the 'ContactPersonPessimisticLockingDB', as another user has started edits and therefore locked to this record.")); } }
public void Test_WhenCleansUpObjectClearsItsLock() { //---------------Set up test pack------------------- FixtureEnvironment.ClearBusinessObjectManager(); var cp = CreateSavedContactPersonPessimisticLocking(); object value = cp.ID.GetAsValue(); //---------------Execute Test ---------------------- cp.Surname = Guid.NewGuid().ToString(); cp = new ContactPersonPessimisticLockingDB(); //so that garbage collector can work FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); //---------------Test Result ----------------------- FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); var cp2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectByValue <ContactPersonPessimisticLockingDB>(value); AssertIsNotLocked(cp2); }
private static void AssertIsNotLocked(ContactPersonPessimisticLockingDB cp) { Assert.IsFalse(Convert.ToBoolean(cp.BoPropLocked.Value)); }
private static ContactPersonPessimisticLockingDB CreateSavedContactPersonPessimisticLocking() { ContactPersonPessimisticLockingDB.LoadDefaultClassDef(); ContactPersonPessimisticLockingDB cp = new ContactPersonPessimisticLockingDB(); cp.Surname = Guid.NewGuid().ToString(); TransactionCommitter tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); tc.AddBusinessObject(cp); tc.CommitTransaction(); return cp; }
private static void AssertIsNotLocked(ContactPersonPessimisticLockingDB cp) { Assert.IsFalse(Convert.ToBoolean(cp.BoPropLocked.Value)); }
public void Test_WhenCleansUpObjectClearsItsLock() { //---------------Set up test pack------------------- FixtureEnvironment.ClearBusinessObjectManager(); var cp = CreateSavedContactPersonPessimisticLocking(); object value = cp.ID.GetAsValue(); //---------------Execute Test ---------------------- cp.Surname = Guid.NewGuid().ToString(); cp = new ContactPersonPessimisticLockingDB(); //so that garbage collector can work FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); //---------------Test Result ----------------------- FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); var cp2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectByValue<ContactPersonPessimisticLockingDB>(value); AssertIsNotLocked(cp2); }