public void Test_AddedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves_DB_CompositeKey()
        {
            //---------------Set up test pack-------------------
            TestUsingDatabase.SetupDBDataAccessor();
            Car car = new Car();

            car.Save();

            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();

            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.PK1Prop2 = TestUtil.GetRandomString();
            contactPerson.Save();

            contactPerson.GetCarsDriven().Add(car);

            //---------------Assert PreConditions---------------
            Assert.AreEqual(contactPerson.PK1Prop1, car.DriverFK1);
            Assert.AreEqual(contactPerson.PK1Prop2, car.DriverFK2);

            //---------------Execute Test ----------------------
            contactPerson.Save();
            FixtureEnvironment.ClearBusinessObjectManager();
            Car loadedCar = Broker.GetBusinessObject <Car>(car.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(contactPerson.PK1Prop1, loadedCar.DriverFK1);
            Assert.AreEqual(contactPerson.PK1Prop2, loadedCar.DriverFK2);
        }
Пример #2
0
        public void TestCompositeKeyObject()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            //Ther are two datastores so that you can manually add an item to a datastore without
            // the save effecting the datastore you are testing.
            DataStoreInMemory dataStore      = new DataStoreInMemory();
            DataStoreInMemory otherDataStore = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(otherDataStore);
            new Car();
            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();

            contactPerson.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
            //---------------Execute Test ----------------------
            dataStore.Add(contactPerson);
            //In the save process the ID is updated to the persisted field values, so the hash of the ID changes
            // this is why the object is removed and re-added to the BusinessObjectManager (to ensure the dictionary
            // of objects is hashed on the correct, updated value.
            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
        }
Пример #3
0
        public void TestDeleteFlagsSetContactPerson()
        {
            ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();

            Assert.IsTrue(myContact.Status.IsNew); // this object is new
            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());

            myContact.Save();                       //save the object to the DB
            Assert.IsFalse(myContact.Status.IsNew); // this object is saved and thus no longer
            // new
            Assert.IsFalse(myContact.Status.IsDeleted);

            IPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database

            Assert.AreEqual(id, myContact.ID);
            myContact.MarkForDelete();
            Assert.IsTrue(myContact.Status.IsDeleted);
            myContact.Save();
            Assert.IsTrue(myContact.Status.IsDeleted);
            Assert.IsTrue(myContact.Status.IsNew);
        }
Пример #4
0
        public void Test_ChangePrimaryKeyForCompositeKey_UpdatedObjectMan()
        {
            //---------------Set up test pack-------------------
            ContactPersonCompositeKey.LoadClassDefs();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            ContactPersonCompositeKey cp = new ContactPersonCompositeKey();

            cp.PK1Prop1 = TestUtil.CreateRandomString();
            cp.PK1Prop2 = TestUtil.CreateRandomString();
            cp.Save();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.AreSame(cp, boMan[cp.ID]);

            //---------------Execute Test ----------------------
            cp.PK1Prop1 = TestUtil.CreateRandomString();
            cp.PK1Prop2 = TestUtil.CreateRandomString();
            cp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId()));
            Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
Пример #5
0
        private void CreateDeletedPersonTestPack()
        {
            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());
            myContact.Save(); //save the object to the DB
            myContact.MarkForDelete();
            myContact.Save();

            mContactPDeleted = myContact;
        }
Пример #6
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"));
        }
Пример #7
0
 private void CreateSaveContactPersonTestPack()
 {
     mContactPTestSave = new ContactPersonCompositeKey();
     mContactPTestSave.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22));
     mContactPTestSave.SetPropertyValue("FirstName", "Brad");
     mContactPTestSave.SetPropertyValue("Surname", "Vincent");
     mContactPTestSave.SetPropertyValue("PK1Prop1", Guid.NewGuid());
     mContactPTestSave.SetPropertyValue("PK1Prop2", Guid.NewGuid());
     mContactPTestSave.Save(); //save the object to the DB
 }
Пример #8
0
 private void CreateSaveContactPersonTestPack()
 {
     mContactPTestSave = new ContactPersonCompositeKey();
     mContactPTestSave.SetPropertyValue("DateOfBirth", new DateTime(1980, 01, 22));
     mContactPTestSave.SetPropertyValue("FirstName", "Brad");
     mContactPTestSave.SetPropertyValue("Surname", "Vincent");
     mContactPTestSave.SetPropertyValue("PK1Prop1", Guid.NewGuid());
     mContactPTestSave.SetPropertyValue("PK1Prop2", Guid.NewGuid());
     mContactPTestSave.Save(); //save the object to the DB
 }
Пример #9
0
        public void Test_HashCode_CompositeKey_Edited()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            new Car();
            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();

            contactPerson.Save();
            object originalHashCodeAfterSave = contactPerson.ID.GetHashCode();

            //---------------Execute Test ----------------------
            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.Save();
            object hashCodeAfterSecondSaving = contactPerson.ID.GetHashCode();

            //---------------Test Result -----------------------
            Assert.AreEqual(originalHashCodeAfterSave, hashCodeAfterSecondSaving);
        }
Пример #10
0
        private void CreateUpdatedContactPersonTestPack()
        {
            ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();

            myContact.SetPropertyValue("DateOfBirth", new DateTime(1969, 01, 29));
            myContact.SetPropertyValue("FirstName", "FirstName");
            myContact.SetPropertyValue("Surname", "Surname");
            myContact.SetPropertyValue("PK1Prop1", Guid.NewGuid());
            myContact.SetPropertyValue("PK1Prop2", Guid.NewGuid());
            myContact.Save();
            updateContactPersonID = myContact.ID;
        }
Пример #11
0
        public void ChangeObjectPrimaryKeyAndThenCreateNewObjectWithPreviousPrimaryKey()
        {
            ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();

            myContact.SetPropertyValue("Surname", "Vincent");
            Guid prop_1_ID = Guid.NewGuid();
            Guid prop_2_ID = Guid.NewGuid();

            myContact.SetPropertyValue("PK1Prop1", prop_1_ID.ToString());
            myContact.SetPropertyValue("PK1Prop2", prop_2_ID.ToString());
            myContact.Save();
            //modify the primary key
            myContact.SetPropertyValue("PK1Prop1", prop_1_ID + "1");
            myContact.SetPropertyValue("PK1Prop1", prop_1_ID + "1");
            myContact.Save();

            ContactPersonCompositeKey myContactTwo = new ContactPersonCompositeKey();

            myContactTwo.SetPropertyValue("Surname", "Vincent 2");
            myContactTwo.SetPropertyValue("PK1Prop1", prop_1_ID.ToString());
            myContactTwo.SetPropertyValue("PK1Prop2", prop_2_ID.ToString());
            myContactTwo.Save();
        }
Пример #12
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");
        }
Пример #13
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"));
        }
Пример #14
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);
            }
        }
        public void Test_UpdateSqlStatement_CompositeKey()
        {
            //---------------Set up test pack-------------------
            TestUsingDatabase.SetupDBDataAccessor();
            Car car = new Car();

            car.Save();

            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();

            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.PK1Prop2 = TestUtil.GetRandomString();
            contactPerson.Save();

            contactPerson.GetCarsDriven().Add(car);

            SingleRelationship <ContactPersonCompositeKey> singleRelationship = car.Relationships.GetSingle <ContactPersonCompositeKey>("Driver");

            singleRelationship.SetRelatedObject(contactPerson);
            IRelationship relationship = contactPerson.Relationships.GetMultiple <Car>("Driver");
            var           generator    = CreateUpdateStatementGenerator(car, DatabaseConfig.MySql);
            //---------------Assert PreConditions---------------

            //---------------Execute Test ----------------------
            var sql = generator.GenerateForRelationship(relationship, car);
            //---------------Test Result -----------------------
            var sqlStatements = sql.ToList();

            Assert.AreEqual(1, sqlStatements.Count);
            Assert.AreEqual("UPDATE `car_table` SET `Driver_FK1` = ?Param0, `Driver_FK2` = ?Param1 WHERE `CAR_ID` = ?Param2", sqlStatements[0].Statement.ToString());
            Assert.AreEqual(contactPerson.PK1Prop1, sqlStatements[0].Parameters[0].Value);
            Assert.AreEqual(contactPerson.PK1Prop2, sqlStatements[0].Parameters[1].Value);
            Assert.AreEqual(car.CarID.ToString("B").ToUpper(), sqlStatements[0].Parameters[2].Value);

            //---------------Tear Down -------------------------
        }
Пример #16
0
        public void Test_ChangePrimaryKeyForCompositeKey_UpdatedObjectMan()
        {
            //---------------Set up test pack-------------------
            ContactPersonCompositeKey.LoadClassDefs();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            ContactPersonCompositeKey cp = new ContactPersonCompositeKey();
            cp.PK1Prop1 = TestUtil.CreateRandomString();
            cp.PK1Prop2 = TestUtil.CreateRandomString();
            cp.Save();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.AreSame(cp, boMan[cp.ID]);

            //---------------Execute Test ----------------------
            cp.PK1Prop1 = TestUtil.CreateRandomString();
            cp.PK1Prop2 = TestUtil.CreateRandomString();
            cp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId()));
            Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
        public void Test_UpdateSqlStatement_CompositeKey()
        {
            //---------------Set up test pack-------------------
            TestUsingDatabase.SetupDBDataAccessor();
            Car car = new Car();
            car.Save();

            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();
            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.PK1Prop2 = TestUtil.GetRandomString();
            contactPerson.Save();

            contactPerson.GetCarsDriven().Add(car);

            SingleRelationship<ContactPersonCompositeKey> singleRelationship = car.Relationships.GetSingle<ContactPersonCompositeKey>("Driver");
            singleRelationship.SetRelatedObject(contactPerson);
            IRelationship relationship = contactPerson.Relationships.GetMultiple<Car>("Driver");
            var generator = CreateUpdateStatementGenerator(car, DatabaseConfig.MySql);
            //---------------Assert PreConditions--------------- 

            //---------------Execute Test ----------------------
            var sql = generator.GenerateForRelationship(relationship, car);
            //---------------Test Result -----------------------
            var sqlStatements = sql.ToList();
            Assert.AreEqual(1, sqlStatements.Count);
            Assert.AreEqual("UPDATE `car_table` SET `Driver_FK1` = ?Param0, `Driver_FK2` = ?Param1 WHERE `CAR_ID` = ?Param2", sqlStatements[0].Statement.ToString());
            Assert.AreEqual(contactPerson.PK1Prop1, sqlStatements[0].Parameters[0].Value);
            Assert.AreEqual(contactPerson.PK1Prop2, sqlStatements[0].Parameters[1].Value);
            Assert.AreEqual(car.CarID.ToString("B").ToUpper(), sqlStatements[0].Parameters[2].Value);

            //---------------Tear Down -------------------------                  
        }
Пример #18
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"));
        }
Пример #19
0
        public void ChangeObjectPrimaryKeyAndThenCreateNewObjectWithPreviousPrimaryKey()
        {
            ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();
            myContact.SetPropertyValue("Surname", "Vincent");
            Guid prop_1_ID = Guid.NewGuid();
            Guid prop_2_ID = Guid.NewGuid();
            myContact.SetPropertyValue("PK1Prop1", prop_1_ID.ToString());
            myContact.SetPropertyValue("PK1Prop2", prop_2_ID.ToString());
            myContact.Save();
            //modify the primary key
            myContact.SetPropertyValue("PK1Prop1", prop_1_ID + "1");
            myContact.SetPropertyValue("PK1Prop1", prop_1_ID + "1");
            myContact.Save();

            ContactPersonCompositeKey myContactTwo = new ContactPersonCompositeKey();
            myContactTwo.SetPropertyValue("Surname", "Vincent 2");
            myContactTwo.SetPropertyValue("PK1Prop1", prop_1_ID.ToString());
            myContactTwo.SetPropertyValue("PK1Prop2", prop_2_ID.ToString());
            myContactTwo.Save();
        }
Пример #20
0
        public void TestDeleteFlagsSetContactPerson()
        {
            ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();
            Assert.IsTrue(myContact.Status.IsNew); // this object is new
            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());

            myContact.Save(); //save the object to the DB
            Assert.IsFalse(myContact.Status.IsNew); // this object is saved and thus no longer
            // new
            Assert.IsFalse(myContact.Status.IsDeleted);

            IPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database
            Assert.AreEqual(id, myContact.ID);
            myContact.MarkForDelete();
            Assert.IsTrue(myContact.Status.IsDeleted);
            myContact.Save();
            Assert.IsTrue(myContact.Status.IsDeleted);
            Assert.IsTrue(myContact.Status.IsNew);
        }
Пример #21
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);
            }
        }
Пример #22
0
        private void CreateDeletedPersonTestPack()
        {
            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());
            myContact.Save(); //save the object to the DB
            myContact.MarkForDelete();
            myContact.Save();

            mContactPDeleted = myContact;
        }
Пример #23
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"));
        }
Пример #24
0
 private void CreateUpdatedContactPersonTestPack()
 {
     ContactPersonCompositeKey myContact = new ContactPersonCompositeKey();
     myContact.SetPropertyValue("DateOfBirth", new DateTime(1969, 01, 29));
     myContact.SetPropertyValue("FirstName", "FirstName");
     myContact.SetPropertyValue("Surname", "Surname");
     myContact.SetPropertyValue("PK1Prop1", Guid.NewGuid());
     myContact.SetPropertyValue("PK1Prop2", Guid.NewGuid());
     myContact.Save();
     updateContactPersonID = myContact.ID;
 }
        public void Test_ChangePrimaryKeyForCompositeKey_ChangeSecondOne_DoesNotUpdatedObjectMan()
        {
            //---------------Set up test pack-------------------
            ContactPersonCompositeKey.LoadClassDefs();
            var boMan = BusinessObjectManager.Instance;

            var cp = new ContactPersonCompositeKey
                                               {
                                                   PK1Prop1 = TestUtil.GetRandomString(),
                                                   PK1Prop2 = TestUtil.GetRandomString()
                                               };
            cp.Save();
            cp.PK1Prop1 = TestUtil.GetRandomString();
            var origIdCurrentValue = cp.ID.ObjectID;

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(origIdCurrentValue));
            Assert.AreSame(cp, boMan[cp.ID]);

            //---------------Execute Test ----------------------
            cp.PK1Prop2 = TestUtil.GetRandomString();

            //---------------Test Result -----------------------
            Assert.AreEqual(origIdCurrentValue, cp.ID.ObjectID);
            Assert.AreEqual(origIdCurrentValue, cp.ID.PreviousObjectID);
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.ObjectID));
            Assert.AreSame(cp, boMan[cp.ID.ObjectID]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
        public void Test_ChangePrimaryKeyForCompositeKey_ChangeSecondOne_UpdatedObjectMan_ExplicitAdd()
        {
            //---------------Set up test pack-------------------
            ContactPersonCompositeKey.LoadClassDefs();
            var boMan = BusinessObjectManager.Instance;

            var cp = new ContactPersonCompositeKey
                                               {
                                                   PK1Prop1 = TestUtil.GetRandomString(),
                                                   PK1Prop2 = TestUtil.GetRandomString()
                                               };
            cp.Save();
            boMan.ClearLoadedObjects();
            boMan.Add(cp);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.AreSame(cp, boMan[cp.ID]);

            //---------------Execute Test ----------------------
            cp.PK1Prop1 = TestUtil.GetRandomString();
            cp.PK1Prop2 = TestUtil.GetRandomString();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.ObjectID));
            Assert.AreSame(cp, boMan[cp.ID.ObjectID]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
        public void Test_SaveForCompositeKey_UpdatedObjectMan()
        {
            //---------------Set up test pack-------------------
            ContactPersonCompositeKey.LoadClassDefs();
            IBusinessObjectManager boMan = new BusinessObjectManager();
            BORegistry.BusinessObjectManager = boMan;
            var cp = new ContactPersonCompositeKey
                                               {
                                                   PK1Prop1 = TestUtil.GetRandomString(),
                                                   PK1Prop2 = TestUtil.GetRandomString()
                                               };

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);

            //---------------Execute Test ----------------------
            cp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.ObjectID));
            Assert.AreSame(cp, boMan[cp.ID.ObjectID]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
Пример #28
0
 public void TestCompositeKeyObject()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     //Ther are two datastores so that you can manually add an item to a datastore without
     // the save effecting the datastore you are testing.
     DataStoreInMemory dataStore = new DataStoreInMemory();
     DataStoreInMemory otherDataStore = new DataStoreInMemory();
     BORegistry.DataAccessor = new DataAccessorInMemory(otherDataStore);
     new Car();
     ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();
     contactPerson.Save();
     //---------------Assert Precondition----------------
     Assert.IsFalse(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
     //---------------Execute Test ----------------------
     dataStore.Add(contactPerson);
     //In the save process the ID is updated to the persisted field values, so the hash of the ID changes
     // this is why the object is removed and re-added to the BusinessObjectManager (to ensure the dictionary
     // of objects is hashed on the correct, updated value.
     contactPerson.PK1Prop1 = TestUtil.GetRandomString();
     contactPerson.Save();  
     //---------------Test Result -----------------------
     Assert.IsTrue(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
 }