public void RecoverNewObjectFromObjectManagerBeforeAndAfterPersist() { ContactPersonCompositeKey myContact = new ContactPersonCompositeKey(); myContact.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22)); myContact.SetPropertyValue("FirstName", "Brad"); myContact.SetPropertyValue("Surname", "Vincent"); myContact.SetPropertyValue("PK1Prop1", Guid.NewGuid()); myContact.SetPropertyValue("PK1Prop2", Guid.NewGuid()); IPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database myContact.Save(); //save the object to the DB // BOPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database Assert.AreEqual(id, myContact.ID); ContactPersonCompositeKey mySecondContactPerson = ContactPersonCompositeKey.GetContactPersonCompositeKey(id); Assert.IsTrue(ReferenceEquals(myContact, mySecondContactPerson)); Assert.AreEqual(myContact.ID, mySecondContactPerson.ID); Assert.AreEqual(myContact.GetPropertyValue("FirstName"), mySecondContactPerson.GetPropertyValue("FirstName")); Assert.AreEqual(myContact.GetPropertyValue("DateOfBirth"), mySecondContactPerson.GetPropertyValue("DateOfBirth")); //Change the MyContact's Surname see if mySecondContactPerson is changed. //this should change since the second contact person was obtained from object manager and // these should thus be the same instance. myContact.SetPropertyValue("Surname", "New Surname"); Assert.AreEqual(myContact.GetPropertyValue("Surname"), mySecondContactPerson.GetPropertyValue("Surname")); }
public void TestUpdateExistingContactPerson() { ContactPersonCompositeKey myContactPerson = ContactPersonCompositeKey.GetContactPersonCompositeKey(updateContactPersonID); myContactPerson.SetPropertyValue("FirstName", "NewFirstName"); myContactPerson.Save(); ContactPersonCompositeKey.ClearContactPersonCol(); //Reload the person and make sure that the changes have been made. ContactPersonCompositeKey myNewContactPerson = ContactPersonCompositeKey.GetContactPersonCompositeKey(updateContactPersonID); Assert.AreEqual("NewFirstName", myNewContactPerson.GetPropertyValue("FirstName"), "The firstName was not updated"); }
public void TestDeleteContactPerson() { //---------------Execute Test ---------------------- try { ContactPersonCompositeKey mySecondContactPerson = ContactPersonCompositeKey.GetContactPersonCompositeKey(mContactPDeleted.ID); Assert.Fail("Expected to throw an BusObjDeleteConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDeleteConcurrencyControlException ex) { StringAssert.Contains("the object you are trying to refresh has been deleted by another user", ex.Message); } }
public void TestSaveContactPerson() { //-----------------------------Setup Test Pack----------------------------- ContactPersonCompositeKey contactPTestSave = new ContactPersonCompositeKey(); contactPTestSave.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22)); contactPTestSave.SetPropertyValue("FirstName", "Brad"); contactPTestSave.SetPropertyValue("Surname", "Vincent"); contactPTestSave.SetPropertyValue("PK1Prop1", Guid.NewGuid()); contactPTestSave.SetPropertyValue("PK1Prop2", Guid.NewGuid()); contactPTestSave.Save(); //save the object to the DB FixtureEnvironment.ClearBusinessObjectManager(); WaitForGC(); //---------------------------Assert Precondition -------------------------- Assert.IsFalse(contactPTestSave.Status.IsNew); // this object is saved and thus no longer // new IPrimaryKey id = contactPTestSave.ID; //Save the objectsID so that it can be loaded from the Database Assert.AreEqual(id, contactPTestSave.ID); //--------------------------Execute --------------------------------------- ContactPersonCompositeKey secondContactPerson = ContactPersonCompositeKey.GetContactPersonCompositeKey(id); //-------------------------Assert Result ---------------------------------- Assert.AreNotSame(contactPTestSave, secondContactPerson); Assert.IsFalse(secondContactPerson.Status.IsNew); // this object is recovered from the DB // and is thus not new. // Assert.AreEqual(contactPTestSave.ID.ToString().ToUpper(), secondContactPerson.ID.ToString()); Assert.AreEqual(contactPTestSave.GetPropertyValue("FirstName"), secondContactPerson.GetPropertyValue("FirstName")); Assert.AreEqual(contactPTestSave.GetPropertyValue("DateOfBirth"), secondContactPerson.GetPropertyValue("DateOfBirth")); //For some reason doing this here old tests contactPTestSave.SetPropertyValue("FirstName", "Change FirstName"); Assert.IsFalse(contactPTestSave.GetPropertyValue("FirstName") == secondContactPerson.GetPropertyValue("FirstName")); }