public void TestForDuplicateExistingObjects() { //create the first object ContactPerson myContact_1 = new ContactPerson(); //Edit first object and save myContact_1.Surname = "My Surname"; myContact_1.SetPropertyValue("PK2Prop1", "PK2Prop1Value1" + TestUtil.GetRandomString()); myContact_1.SetPropertyValue("PK2Prop2", "PK2Prop1Value2" + TestUtil.GetRandomString()); myContact_1.Save(); // //get the second new object from the object manager); ContactPerson myContact_2 = new ContactPerson(); myContact_2.SetPropertyValue("PK2Prop1", "PK2Prop1Value1 Two"); myContact_2.Surname = "My Surname two"; myContact_2.Save(); //set this new object to have the same // data as the already saved object myContact_2.SetPropertyValue("PK2Prop1", myContact_1.GetPropertyValue("PK2Prop1")); myContact_2.SetPropertyValue("PK2Prop2", myContact_1.GetPropertyValue("PK2Prop2")); try { myContact_2.Save(); Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDuplicateConcurrencyControlException ex) { StringAssert.Contains("A 'Contact Person' already exists with the same identifier", ex.Message); } }
public void TestMultipleUpdates_NoConcurrencyErrors() { _contactPersonUpdateConcurrency.Surname = "New Surname"; _contactPersonUpdateConcurrency.Save(); _contactPersonUpdateConcurrency.Surname = "New Surname 2"; _contactPersonUpdateConcurrency.Save(); _contactPersonUpdateConcurrency.Surname = "New Surname 3"; }
private static void CreateDeletedPersonTestPack() { ContactPerson myContact = new ContactPerson(); myContact.DateOfBirth = new DateTime(1980, 01, 22); myContact.FirstName = "Brad"; myContact.Surname = "Vincent2"; myContact.Save(); //save the object to the DB myContact.MarkForDelete(); myContact.Save(); }
public void TestForDuplicateNewObjectsSinglePropKeyNull() { //create the first object ContactPerson myContact_1 = new ContactPerson(); //Edit first object and save myContact_1.Surname = "My Surname SinglePropKeyNull"; myContact_1.SetPropertyValue("PK3Prop", null); // set the previous value to null myContact_1.Save(); // //get the second new object from the object manager ContactPerson myContact_2 = new ContactPerson(); //set this new object to have the same // data as the already saved object myContact_2.Surname = "My Surname SinglePropKeyNull"; myContact_2.SetPropertyValue("PK3Prop", myContact_1.GetPropertyValue("PK3Prop")); // set the previous value to null try { myContact_2.Save(); Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDuplicateConcurrencyControlException ex) { StringAssert.Contains("A 'Contact Person' already exists with the same identifier", ex.Message); } }
public void TestEditTwoInstancesContactPerson() { ContactPerson myContact = new ContactPerson(); myContact.DateOfBirth = new DateTime(1980, 01, 22); myContact.FirstName = "Brad"; myContact.Surname = "Vincent5"; myContact.Save(); //save the object to the DB IPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database Assert.AreEqual(id, myContact.ID); ContactPerson mySecondContactPerson = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPerson>(id); Assert.AreEqual(myContact.ID, mySecondContactPerson.ID); Assert.AreEqual(myContact.FirstName, mySecondContactPerson.FirstName); Assert.AreEqual(myContact.DateOfBirth, mySecondContactPerson.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.Surname = "New Surname"; Assert.AreEqual(myContact.Surname, mySecondContactPerson.Surname); }
public void Test_ReturnSameObjectFromBusinessObjectLoader() { //---------------Set up test pack------------------- //------------------------------Setup Test new Engine(); new Car(); ContactPerson originalContactPerson = new ContactPerson(); originalContactPerson.Surname = "FirstSurname"; originalContactPerson.Save(); FixtureEnvironment.ClearBusinessObjectManager(); //load second object from DB to ensure that it is now in the object manager ContactPerson myContact2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPerson> (originalContactPerson.ID); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- ContactPerson myContact3 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPerson> (originalContactPerson.ID); //---------------Test Result ----------------------- // Assert.AreNotSame(originalContactPerson, myContact3); Assert.AreSame(myContact2, myContact3); }
public void CreateTestPack() { SetupDBConnection(); new Engine(); new Address(); ContactPerson.DeleteAllContactPeople(); new Car(); CreateUpdatedContactPersonTestPack(); _contactPersonUpdateConcurrency = new ContactPerson(); _contactPersonUpdateConcurrency.Surname = "Update Concurrency"; _contactPersonUpdateConcurrency.Save(); _contactPBeginEditsConcurrency = new ContactPerson(); _contactPBeginEditsConcurrency.Surname = "BeginEdits Concurrency"; _contactPBeginEditsConcurrency.Save(); _contactPTestRefreshFromObjMan = new ContactPerson(); _contactPTestRefreshFromObjMan.Surname = "FirstSurname"; _contactPTestRefreshFromObjMan.Save(); new Engine(); CreateDeletedPersonTestPack(); CreateSaveContactPersonTestPack(); //Ensure that a fresh object is loaded from DB FixtureEnvironment.ClearBusinessObjectManager(); }
public void Test_ReturnSameObjectFromBusinessObjectLoader() { //---------------Set up test pack------------------- //------------------------------Setup Test new Engine(); new Car(); ContactPerson originalContactPerson = new ContactPerson(); originalContactPerson.Surname = "FirstSurname"; originalContactPerson.Save(); FixtureEnvironment.ClearBusinessObjectManager(); //load second object from DB to ensure that it is now in the object manager ContactPerson myContact2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPerson> (originalContactPerson.ID); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- ContactPerson myContact3 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPerson> (originalContactPerson.ID); //---------------Test Result ----------------------- // Assert.AreNotSame(originalContactPerson, myContact3); Assert.AreSame(myContact2, myContact3); }
public void TestStateAfterApplyEdit() { ContactPerson myContact = new ContactPerson(); myContact.Surname = "Test Surname"; myContact.Save(); Assert.IsFalse(myContact.Status.IsNew, "BO is still IsNew after being saved."); }
private void CreateSaveContactPersonTestPack() { _contactPTestSave = new ContactPerson(); _contactPTestSave.DateOfBirth = new DateTime(1980, 01, 22); _contactPTestSave.FirstName = "Brad"; _contactPTestSave.Surname = "Vincent1"; _contactPTestSave.Save(); //save the object to the DB }
private void CreateUpdatedContactPersonTestPack() { ContactPerson myContact = new ContactPerson(); myContact.DateOfBirth = new DateTime(1969, 01, 29); myContact.FirstName = "FirstName"; myContact.Surname = "Surname"; myContact.Save(); _updateContactPersonId = myContact.ID; }
public void CreateContactPersone() { ContactPerson cp = new ContactPerson(); cp.FirstName = "Jarosav"; cp.LastName = "Runcik"; cp.Email = "*****@*****.**"; cp.PhoneNumber = "+420 602 658 348"; cp.Save(); cp.Delete(); }
public void TestDeleteFlagsSetContactPerson() { ContactPerson myContact = new ContactPerson(); Assert.IsTrue(myContact.Status.IsNew); // this object is new myContact.DateOfBirth = new DateTime(1980, 01, 22); myContact.FirstName = "Brad"; myContact.Surname = "Vincent4"; 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); }
public void CreateOrder() { ContactPerson cp = new ContactPerson(); cp.FirstName = "Jarosav"; cp.LastName = "Runcik"; cp.Email = "*****@*****.**"; cp.PhoneNumber = "+420 602 658 348"; cp.Save(); PaperType paperType = new PaperType(); paperType.Color = System.Drawing.Color.Blue; paperType.Type = "Stitek"; paperType.Save(); Proofsheet proofsheet = new Proofsheet(); proofsheet.Time = DateTime.Now; proofsheet.Passed = true; proofsheet.Save(); try { Order order = new Order(); order.Contact = cp; order.Format = TiskarnaVosahlo.PaperFormats.GetFormat("A4"); order.PaperType = paperType; order.Proofsheet = proofsheet; order.Save(); order.Delete(); } finally { proofsheet.Delete(); paperType.Delete(); cp.Delete(); } }
public void TestObjectCompulsorySurnameNotSet() { //---------------Set up test pack------------------- ContactPerson myContact = new ContactPerson(); //---------------Execute Test ---------------------- try { myContact.Save(); Assert.Fail("Expected to throw an BusObjectInAnInvalidStateException"); } //---------------Test Result ----------------------- catch (BusObjectInAnInvalidStateException ex) { StringAssert.Contains("'ContactPerson.Surname' is a compulsory field and has no value", ex.Message); } }
public void TestObjectSurnameTooLong() { //---------------Set up test pack------------------- ContactPerson myContact = new ContactPerson(); myContact.Surname = "MyPropertyIsTooLongByFarThisWill Cause and Error in Bus object"; //---------------Execute Test ---------------------- try { myContact.Save(); Assert.Fail("Expected to throw an BusObjectInAnInvalidStateException"); } //---------------Test Result ----------------------- catch (BusObjectInAnInvalidStateException ex) { StringAssert.Contains("for property 'ContactPerson.Surname' is not valid for the rule 'ContactPerson-Surname'", ex.Message); } }
public void TestCreateBusinessObjectFromCollection() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); new Address(); new Engine(); new Car(); new ContactPerson(); BusinessObjectCollection <ContactPerson> col = new BusinessObjectCollection <ContactPerson>(); IBusinessObjectCreator boCreator = new DefaultBOCreator(col); //---------------Execute Test ---------------------- ContactPerson cp = (ContactPerson)boCreator.CreateBusinessObject(); cp.Surname = Guid.NewGuid().ToString("N"); cp.Save(); //---------------Test Result ----------------------- Assert.IsTrue(col.Contains(cp)); //---------------Tear Down ------------------------- }
public void TestLoadFromDatabaseAlwaysLoadsSameObject() { //---------------Set up test pack------------------- new Engine(); new Car(); ContactPerson originalContactPerson = new ContactPerson(); const string firstSurname = "FirstSurname"; originalContactPerson.Surname = firstSurname; originalContactPerson.Save(); IPrimaryKey origConactPersonID = originalContactPerson.ID; originalContactPerson = null; FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); //load second object from DB to ensure that it is now in the object manager ContactPerson loadedContactPerson1 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPerson>(origConactPersonID); //---------------Assert Precondition---------------- Assert.IsNull(originalContactPerson); Assert.AreEqual(firstSurname, loadedContactPerson1.Surname); Assert.AreNotSame(originalContactPerson, loadedContactPerson1); Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count); //---------------Execute Test ---------------------- ContactPerson loadedContactPerson2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPerson>(origConactPersonID); //---------------Test Result ----------------------- Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count); Assert.AreEqual(firstSurname, loadedContactPerson2.Surname); Assert.AreNotSame(originalContactPerson, loadedContactPerson2); Assert.AreSame(loadedContactPerson1, loadedContactPerson2); }
public int SaveContactPerson(ContactPerson model, int userID = 0) { try { model.tsUpdate = DateTime.Now; model.tsUpdateUserID = userID; if (model.ContactPersonID == 0) { model.tsInsert = DateTime.Now; model.tsInsertUserID = userID; } model.Save(); return(model.ContactPersonID); } catch (Exception ex) { string error = ""; CommonMethods.getError(ex, ref error); throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_08, error, CommonMethods.GetCurrentMethodName())); } }
public void TestLoadFromDatabaseAlwaysLoadsSameObject() { //---------------Set up test pack------------------- new Engine(); new Car(); ContactPerson originalContactPerson = new ContactPerson(); const string firstSurname = "FirstSurname"; originalContactPerson.Surname = firstSurname; originalContactPerson.Save(); IPrimaryKey origConactPersonID = originalContactPerson.ID; originalContactPerson = null; FixtureEnvironment.ClearBusinessObjectManager(); TestUtil.WaitForGC(); //load second object from DB to ensure that it is now in the object manager ContactPerson loadedContactPerson1 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPerson>(origConactPersonID); //---------------Assert Precondition---------------- Assert.IsNull(originalContactPerson); Assert.AreEqual(firstSurname, loadedContactPerson1.Surname); Assert.AreNotSame(originalContactPerson, loadedContactPerson1); Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count); //---------------Execute Test ---------------------- ContactPerson loadedContactPerson2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPerson>(origConactPersonID); //---------------Test Result ----------------------- Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count); Assert.AreEqual(firstSurname, loadedContactPerson2.Surname); Assert.AreNotSame(originalContactPerson, loadedContactPerson2); Assert.AreSame(loadedContactPerson1, loadedContactPerson2); }
public void TestForDuplicateNewObjects() { //create the first object ContactPerson myContact_1 = new ContactPerson(); //Edit first object and save myContact_1.FirstName = "My FirstName"; myContact_1.Surname = "My Surname"; myContact_1.SetPropertyValue("PK2Prop1", "PK2Prop1Value1" + TestUtil.GetRandomString()); myContact_1.SetPropertyValue("PK2Prop2", "PK2Prop1Value2" + TestUtil.GetRandomString()); myContact_1.Save(); // //get the second new object from the object manager; ContactPerson myContact_2 = new ContactPerson(); //set this new object to have the same // data as the already saved object myContact_2.Surname = "My Surname"; myContact_2.SetPropertyValue("PK2Prop1", myContact_1.GetPropertyValue("PK2Prop1")); myContact_2.SetPropertyValue("PK2Prop2", myContact_1.GetPropertyValue("PK2Prop2")); try { myContact_2.Save(); Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDuplicateConcurrencyControlException ex) { StringAssert.Contains("A 'Contact Person' already exists with the same identifier", ex.Message); } }
public void TestEditTwoInstancesContactPerson() { ContactPerson myContact = new ContactPerson(); myContact.DateOfBirth = new DateTime(1980, 01, 22); myContact.FirstName = "Brad"; myContact.Surname = "Vincent5"; myContact.Save(); //save the object to the DB IPrimaryKey id = myContact.ID; //Save the objectsID so that it can be loaded from the Database Assert.AreEqual(id, myContact.ID); ContactPerson mySecondContactPerson = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPerson>(id); Assert.AreEqual(myContact.ID, mySecondContactPerson.ID); Assert.AreEqual(myContact.FirstName, mySecondContactPerson.FirstName); Assert.AreEqual(myContact.DateOfBirth, mySecondContactPerson.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.Surname = "New Surname"; Assert.AreEqual(myContact.Surname, mySecondContactPerson.Surname); }