예제 #1
0
        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"));
        }
예제 #2
0
        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"));
        }
예제 #3
0
        public void SaveNewObjectWithDuplicatePrimaryKey()
        {
            //---------------Set up test pack-------------------
            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
            FixtureEnvironment.ClearBusinessObjectManager();
            //			BOPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database
            Assert.AreEqual(id, myContact.ID);

            ContactPersonCompositeKey mySecondContactPerson =
                new ContactPersonCompositeKey();

            mySecondContactPerson.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22));
            mySecondContactPerson.SetPropertyValue("FirstName", "Brad");
            mySecondContactPerson.SetPropertyValue("Surname", "Vincent");
            mySecondContactPerson.SetPropertyValue("PK1Prop1", myContact.GetPropertyValue("PK1Prop1"));
            mySecondContactPerson.SetPropertyValue("PK1Prop2", myContact.GetPropertyValue("PK1Prop2"));

            //---------------Execute Test ----------------------
            try
            {
                mySecondContactPerson.Save();
                Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException");
            }
            //---------------Test Result -----------------------
            catch (BusObjDuplicateConcurrencyControlException ex)
            {
                StringAssert.Contains("A 'Contact Person Composite Key' already exists with the same identifier", ex.Message);
            }
        }
예제 #4
0
        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");
        }
예제 #5
0
        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"));
        }
예제 #6
0
        public void SaveNewObjectWithDuplicatePrimaryKey()
        {
            //---------------Set up test pack-------------------
            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
            FixtureEnvironment.ClearBusinessObjectManager();
            //			BOPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database
            Assert.AreEqual(id, myContact.ID);

            ContactPersonCompositeKey mySecondContactPerson =
                new ContactPersonCompositeKey();
            mySecondContactPerson.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22));
            mySecondContactPerson.SetPropertyValue("FirstName", "Brad");
            mySecondContactPerson.SetPropertyValue("Surname", "Vincent");
            mySecondContactPerson.SetPropertyValue("PK1Prop1", myContact.GetPropertyValue("PK1Prop1"));
            mySecondContactPerson.SetPropertyValue("PK1Prop2", myContact.GetPropertyValue("PK1Prop2"));

            //---------------Execute Test ----------------------
            try
            {
                mySecondContactPerson.Save();
                Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException");
            }
                //---------------Test Result -----------------------
            catch (BusObjDuplicateConcurrencyControlException ex)
            {
                StringAssert.Contains("A 'Contact Person Composite Key' already exists with the same identifier", ex.Message);
            }
        }
예제 #7
0
        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"));
        }