public void Setup() { ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); }
public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_UsingRelationship_DoesReloadFromDB() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); IBusinessObjectCollection collection = organisationTestBO.ContactPeople; DateTime?initialTimeLastLoaded = collection.TimeLastLoaded; //---------------Assert Precondition---------------- Assert.IsNotNull(collection.TimeLastLoaded); Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded); Assert.AreEqual(0, collection.Count); MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)organisationTestBO.Relationships["ContactPeople"]; Assert.AreEqual(0, relationship.TimeOut); //---------------Execute Test ---------------------- ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject(); contactPerson.Surname = TestUtil.GetRandomString(); contactPerson.FirstName = TestUtil.GetRandomString(); contactPerson.Save(); TestUtil.Wait(100); IBusinessObjectCollection secondCollectionCall = organisationTestBO.ContactPeople; //---------------Test Result ----------------------- Assert.AreSame(collection, secondCollectionCall); Assert.IsNotNull(secondCollectionCall.TimeLastLoaded); Assert.AreEqual(1, secondCollectionCall.Count); Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded); }
public void TestColIsInstantiatedButNotLoaded() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef(); IClassDef contactPersonClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); RelKeyDef keyDef = new RelKeyDef(); keyDef.Add(new RelPropDef(contactPersonClassDef.PropDefcol["OrganisationID"], "OrganisationID")); MultipleRelationshipDef def = new MultipleRelationshipDef (TestUtil.GetRandomString(), typeof(ContactPersonTestBO), keyDef, false, "", DeleteParentAction.DoNothing); OrganisationTestBO organisation = new OrganisationTestBO(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IMultipleRelationship rel = (IMultipleRelationship)def.CreateRelationship(organisation, organisation.Props); //---------------Test Result ----------------------- IBusinessObjectCollection collection = rel.BusinessObjectCollection; Assert.IsNotNull(collection); Assert.AreEqual(0, collection.Count); Assert.AreSame(contactPersonClassDef, collection.ClassDef); Assert.IsNotNull(collection.SelectQuery.Criteria); Assert.IsNotNull(collection.SelectQuery.Criteria.Field); Assert.AreEqual("OrganisationID", collection.SelectQuery.Criteria.Field.PropertyName); Assert.IsNotNull(collection.SelectQuery.Criteria.Field.Source); Assert.AreEqual("ContactPersonTestBO", collection.SelectQuery.Criteria.Field.Source.Name); Assert.AreEqual(organisation.OrganisationID.Value, collection.SelectQuery.Criteria.FieldValue); Assert.IsInstanceOf(typeof(ContactPersonTestBO), collection.CreateBusinessObject()); }
public void Test_LoadMultiplerelationship_TimeOutNotExceeded_DoesNotReloadFromDB() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); RelationshipDef relationshipDef = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"]; IMultipleRelationship rel = new MultipleRelationship <ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 30000); IBusinessObjectCollection collection = rel.BusinessObjectCollection; DateTime?initialTimeLastLoaded = collection.TimeLastLoaded; //---------------Assert Precondition---------------- Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded); Assert.AreEqual(0, collection.Count); //---------------Execute Test ---------------------- ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject(); contactPerson.Surname = TestUtil.GetRandomString(); contactPerson.FirstName = TestUtil.GetRandomString(); contactPerson.Save(); TestUtil.Wait(100); IBusinessObjectCollection secondCollectionCall = rel.BusinessObjectCollection; //---------------Test Result ----------------------- Assert.AreSame(collection, secondCollectionCall); Assert.AreEqual(0, secondCollectionCall.Count); Assert.AreEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded); }
public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_UsingRelationship_DoesResetTheTimeLastLoaded() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); RelationshipDef relationshipDef = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"]; //IMultipleRelationship rel = new MultipleRelationship<ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 0); IBusinessObjectCollection collection = organisationTestBO.ContactPeople; DateTime?initialTimeLastLoaded = collection.TimeLastLoaded; //---------------Assert Precondition---------------- Assert.IsNotNull(collection.TimeLastLoaded); Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded); //---------------Execute Test ---------------------- TestUtil.Wait(100); IBusinessObjectCollection secondCollectionCall = organisationTestBO.ContactPeople; //---------------Test Result ----------------------- Assert.AreSame(collection, secondCollectionCall); Assert.IsNotNull(secondCollectionCall.TimeLastLoaded); Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded); }
public void TestGetReverseRelationship_ReverseRelationshipSpecifiedButNotFound() { //---------------Set up test pack------------------- OrganisationTestBO.LoadDefaultClassDef(); IClassDef cpClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); string reverseRelationshipName = TestUtil.GetRandomString(); cpClassDef.RelationshipDefCol["Organisation"].ReverseRelationshipName = reverseRelationshipName; OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation(); ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson(); SingleRelationship <OrganisationTestBO> organisationRel = contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation"); //---------------Execute Test ---------------------- try { organisationRel.GetReverseRelationship(organisation); Assert.Fail("Should have failed since a reverse relationship was specified that didn't exist."); } catch (HabaneroDeveloperException ex) { StringAssert.Contains( string.Format( "The relationship 'Organisation' on class 'ContactPersonTestBO' has a reverse relationship defined ('{0}')", reverseRelationshipName), ex.Message); } }
public void Test_ItemsShowingInComboBox() { //--------------- Set up test pack ------------------ ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); contactPersonTestBO.Surname = TestUtil.GetRandomString(); contactPersonTestBO.FirstName = TestUtil.GetRandomString(); OrganisationTestBO.LoadDefaultClassDef(); OrganisationTestBO.CreateSavedOrganisation(); OrganisationTestBO.CreateSavedOrganisation(); IControlFactory controlFactory = GetControlFactory(); ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory); const string propName = "OrganisationID"; ExtendedTextBoxMapper mapper = new ExtendedTextBoxMapper( extendedTextBoxWin, propName, true, controlFactory); //--------------- Test Preconditions ---------------- Assert.IsNull(mapper.BusinessObject); Assert.IsNull(mapper.BusinessObject); //--------------- Execute Test ---------------------- mapper.BusinessObject = contactPersonTestBO; //--------------- Test Result ----------------------- Assert.AreSame(contactPersonTestBO, mapper.BusinessObject); Assert.AreSame(contactPersonTestBO, mapper.BusinessObject); // Assert.AreEqual(2, mapper.LookupList.Count); }
public override void Test_ApplyChangesToBusinessObject_WhenNewItemIsSelected_WhenSet_WhenRelationshipIsLevelsDeep_ShouldUpdateRelatedBusinessObjectWithSelectedValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); AddressTestBO.LoadDefaultClassDef(); const string relationshipName = "ContactPersonTestBO.Organisation"; var mapper = GetMapperBoColHasOneItem(relationshipName); var cmbox = mapper.Control; var boCol = (BusinessObjectCollection <OrganisationTestBO>)mapper.BusinessObjectCollection; var person = new ContactPersonTestBO { Organisation = boCol[0] }; var addressTestBO = new AddressTestBO { ContactPersonTestBO = person }; var newOrganisation = new OrganisationTestBO(); newOrganisation.Save(); mapper.BusinessObject = addressTestBO; //---------------Assert Precondition---------------- Assert.AreSame(addressTestBO, mapper.BusinessObject); Assert.AreSame(person.Organisation, cmbox.SelectedItem); Assert.AreNotSame(person.Organisation, newOrganisation); //---------------Execute Test ---------------------- cmbox.SelectedItem = newOrganisation; Assert.AreSame(newOrganisation, cmbox.SelectedItem, "Selected Item should be set."); mapper.ApplyChangesToBusinessObject(); //---------------Test Result ----------------------- Assert.AreSame(newOrganisation, cmbox.SelectedItem); Assert.AreSame(newOrganisation, person.Organisation); }
public void Test_CreateMultipleRelationshipDef_Association() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadDefaultClassDef(); RelPropDef relPropDef = new RelPropDef(ClassDef.Get <OrganisationTestBO>().PropDefcol["OrganisationID"], "OrganisationID"); RelKeyDef relKeyDef = new RelKeyDef(); relKeyDef.Add(relPropDef); const int expectedTimeout = 550; MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO", "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Association, expectedTimeout); OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation(); //---------------Assert Precondition---------------- Assert.AreEqual(expectedTimeout, relationshipDef.TimeOut); //---------------Execute Test ---------------------- MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)relationshipDef.CreateRelationship(organisation, organisation.Props); //---------------Test Result ----------------------- Assert.AreEqual(expectedTimeout, relationship.TimeOut); Assert.AreEqual(InsertParentAction.InsertRelationship, relationship.RelationshipDef.InsertParentAction); }
public void Test_UpdateSqlStatement() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson(); OrganisationTestBO organisationTestBO = new OrganisationTestBO(); SingleRelationship <OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation"); singleRelationship.SetRelatedObject(organisationTestBO); IRelationship relationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople"); //TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship); var generator = CreateUpdateStatementGenerator(contactPersonTestBO, DatabaseConfig.MySql); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- var sql = generator.GenerateForRelationship(relationship, contactPersonTestBO); //---------------Test Result ----------------------- var sqlStatements = sql.ToList(); Assert.AreEqual(1, sqlStatements.Count); Assert.AreEqual("UPDATE `contact_person` SET `OrganisationID` = ?Param0 WHERE `ContactPersonID` = ?Param1", sqlStatements[0].Statement.ToString()); Assert.AreEqual(organisationTestBO.OrganisationID.Value.ToString("B").ToUpper(), sqlStatements[0].Parameters[0].Value); Assert.AreEqual(contactPersonTestBO.ContactPersonID.ToString("B").ToUpper(), sqlStatements[0].Parameters[1].Value); }
public void SetupTest() { //Runs every time that any testmethod is executed ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); BORegistry.DataAccessor = new DataAccessorInMemory(); }
//[Test] //public void Test_ShowGridAndBOEditorControlWinWithSuperClassDef_DatabaseLookupList() //{ // //--------------- Set up test pack ------------------ // ClassDef.ClassDefs.Clear(); // OrganisationTestBO.LoadDefaultClassDef(); // ContactPersonTestBO.LoadDefaultClassDefWithPersonTestBOSuperClass(); // PersonTestBO.LoadDefaultClassDefWithTestOrganisationBOLookup_DatabaseLookupList(); // IControlFactory controlFactory = GetControlFactory(); // IExtendedComboBox extendedComboBox = CreateExtendedComboBox(); // const string propName = "OrganisationID"; // ExtendedComboBoxMapper mapper = new ExtendedComboBoxMapper( // extendedComboBox, propName, true, controlFactory); // DatabaseConfig databaseConfig = TestUtil.GetDatabaseConfig(); // DatabaseConnection.CurrentConnection = databaseConfig.GetDatabaseConnection(); // mapper.BusinessObject = new ContactPersonTestBO(); // // mapper.RelatedBusinessObject = OrganisationTestBO.CreateSavedOrganisation(); // //--------------- Test Preconditions ---------------- // Assert.IsNull(mapper.PopupForm); // //--------------- Execute Test ---------------------- // //extendedComboBox.Button.PerformClick(); // mapper.SetupPopupForm(); // //--------------- Test Result ----------------------- // Assert.IsNotNull(mapper.PopupForm); //} private static BusinessObjectCollection <OrganisationTestBO> CreateSavedOrganisationTestBOSCollection() { OrganisationTestBO.LoadDefaultClassDef(); BusinessObjectCollection <OrganisationTestBO> organisationTestBOS = new BusinessObjectCollection <OrganisationTestBO>(); organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation()); organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation()); organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation()); organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation()); return(organisationTestBOS); }
private static BusinessObjectCollection <OrganisationTestBO> CreateSavedOrganisationTestBOsCollection() { OrganisationTestBO.LoadDefaultClassDef(); BusinessObjectCollection <OrganisationTestBO> organisationTestBOs = new BusinessObjectCollection <OrganisationTestBO> { OrganisationTestBO.CreateSavedOrganisation(), OrganisationTestBO.CreateSavedOrganisation(), OrganisationTestBO.CreateSavedOrganisation(), OrganisationTestBO.CreateSavedOrganisation() }; return(organisationTestBOs); }
protected static IClassDef GetCustomClassDef() { ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDef_NoOrganisationRelationship(); IClassDef classDef = OrganisationTestBO.LoadDefaultClassDef(); IUIGrid originalGridDef = classDef.UIDefCol["default"].UIGrid; UIGrid extraGridDef = ((UIGrid)originalGridDef).Clone(); extraGridDef.Remove(extraGridDef[extraGridDef.Count - 1]); UIDef extraUIDef = new UIDef(CUSTOM_UIDEF_NAME, new UIForm(), extraGridDef); UIDef gridWithNoForm = new UIDef(GRID_WITHNOFORM, null, extraGridDef); classDef.UIDefCol.Add(extraUIDef); return(classDef); }
public void Test_CreateMultipleRelationshipWithTimeout() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); RelationshipDef relationshipDef = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"]; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IMultipleRelationship rel = new MultipleRelationship <ContactPersonTestBO> (organisationTestBO, relationshipDef, organisationTestBO.Props, 30000); //---------------Test Result ----------------------- Assert.IsTrue(true, "Should not give an error when constructing"); }
public void Test_CanDeleteParentWithNewChildren() { //--------------- Set up test pack ------------------ ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); organisationTestBO.ContactPeople.CreateBusinessObject(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- organisationTestBO.MarkForDelete(); organisationTestBO.Save(); //--------------- Test Result ----------------------- Assert.IsTrue(organisationTestBO.Status.IsDeleted); }
public void TestSetupComboBoxFromClassDef_SetsItemsInComboBox() { //---------------Set up test pack------------------- IClassDef classDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); ContactPerson.DeleteAllContactPeople(); OrganisationTestBO.ClearAllFromDB(); OrganisationTestBO.CreateSavedOrganisation(); OrganisationTestBO.CreateSavedOrganisation(); ContactPersonTestBO.CreateSavedContactPersonNoAddresses(); TestUtil.WaitForGC(); BusinessObjectCollection <ContactPersonTestBO> col = new BusinessObjectCollection <ContactPersonTestBO>(); col.LoadAll(); IEditableGridControl gridControl = GetControlFactory().CreateEditableGridControl(); GridInitialiser gridInitialiser = new GridInitialiser(gridControl, GetControlFactory()); //--------------Assert PreConditions---------------- Assert.AreEqual(0, gridControl.Grid.Columns.Count); Assert.AreEqual(1, classDef.UIDefCol.Count); const string uiDefName = "default"; IUIGrid uiGridDef = classDef.UIDefCol[uiDefName].UIGrid; Assert.IsNotNull(uiGridDef); Assert.AreEqual(1, uiGridDef.Count); Assert.AreEqual(1, col.Count); Assert.AreEqual(2, BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <OrganisationTestBO> ("").Count); //---------------Execute Test ---------------------- gridInitialiser.InitialiseGrid(classDef, uiDefName); //---------------Test Result ----------------------- Assert.AreEqual(2, gridControl.Grid.Columns.Count, "Should have ID column and should have comboBoxColumn"); IDataGridViewColumn dataGridViewColumn = gridControl.Grid.Columns[1]; AssertIsComboBoxColumnType(dataGridViewColumn); AssertComboBoxItemCount(dataGridViewColumn, 3); }
public void Test_GetIBOGridAndEditorControl_ShouldReturnEditorOnForm() { //---------------Set up test pack------------------- OrganisationTestBO.LoadDefaultClassDef(); IControlFactory controlFactory = GetControlFactory(); ExtendedComboBoxWin extendedComboBox = new ExtendedComboBoxWin(controlFactory); const string propName = "OrganisationID"; var mapper = new ExtendedComboBoxMapperSpy( extendedComboBox, propName, true, controlFactory); mapper.BusinessObject = new ContactPersonTestBO(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- mapper.ShowPopupForm(); var boGridAndEditorControl = mapper.CallGetIBOGridAndEditorControl(); //---------------Test Result ----------------------- IFormHabanero form = mapper.PopupForm; Assert.AreSame(boGridAndEditorControl, form.Controls[0]); }