private static MultipleRelationship<ContactPersonTestBO> GetCompositionRelationship(out BusinessObjectCollection<ContactPersonTestBO> cpCol, OrganisationTestBO organisationTestBO) { MultipleRelationship<ContactPersonTestBO> compositionRelationship = organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople"); RelationshipDef relationshipDef = (RelationshipDef)compositionRelationship.RelationshipDef; relationshipDef.RelationshipType = RelationshipType.Composition; cpCol = compositionRelationship.BusinessObjectCollection; return compositionRelationship; }
public void Test_RootNodeBusinessObject() { //---------------Set up test pack------------------- TreeViewWin treeView = new TreeViewWin(); TreeViewController treeViewController = new TreeViewController(treeView); OrganisationTestBO organisationTestBO = new OrganisationTestBO(); treeViewController.LoadTreeView(organisationTestBO); //-------------Assert Preconditions ------------- Assert.AreEqual(1, treeView.Nodes.Count); //---------------Execute Test ---------------------- IBusinessObject businessObject = treeViewController.RootNodeBusinessObject; //---------------Test Result ----------------------- Assert.AreSame(organisationTestBO, businessObject); }
public void Test_LoadSingleBO_NoChildren() { //---------------Set up test pack------------------- TreeViewWin treeView = new TreeViewWin(); TreeViewController treeViewController = new TreeViewController(treeView); OrganisationTestBO organisationTestBO = new OrganisationTestBO(); //-------------Assert Preconditions ------------- Assert.AreEqual(0, treeView.Nodes.Count); //---------------Execute Test ---------------------- treeViewController.LoadTreeView(organisationTestBO); //---------------Test Result ----------------------- Assert.AreEqual(1, treeView.Nodes.Count); ITreeNode node = treeView.Nodes[0]; Assert.AreEqual(organisationTestBO.ToString(), node.Text); Assert.AreEqual(0, node.Nodes.Count); }
public void Test_AddRow_WhenVirtualProp_ShouldAddBOWithRelatedVirtualPropSet() { //---------------Set up test pack------------------- RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; AddressTestBO.LoadDefaultClassDef(); var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); BusinessObjectCollection <ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection <ContactPersonTestBO>(); OrganisationTestBO organisation = new OrganisationTestBO(); UIGrid uiGrid = new UIGrid(); new UIDef("fdafdas", new UIForm(), uiGrid) { ClassDef = contactPersonClassDef }; const string propertyName = "-Organisation-"; uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS); DataTable table = dataSetProvider.GetDataTable(uiGrid); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(0, table.Rows.Count); Assert.AreEqual(0, contactPersonTestBOS.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, organisation }); //---------------Test Result ----------------------- Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, contactPersonTestBOS.Count); Assert.AreSame(organisation, table.Rows[0][propertyName]); Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation); }
public void TestFindAll_ClassDef_NullCriteria() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); OrganisationTestBO.LoadDefaultClassDef(); DataStoreInMemory dataStore = new DataStoreInMemory(); DateTime now = DateTime.Now; ContactPersonTestBO cp1 = new ContactPersonTestBO { DateOfBirth = now }; dataStore.Add(cp1); dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); //---------------Execute Test ---------------------- IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), null); //---------------Test Result ----------------------- Assert.AreEqual(1, col.Count); Assert.Contains(cp1, col); Assert.IsNull(col.SelectQuery.Criteria); }
public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingPropertyOnRelatedBO_ShouldChangeProperty() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerPropertyName = "Name"; const string propertyName = "Organisation." + innerPropertyName; BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propertyName); boPropertyMapper.BusinessObject = contactPersonTestBO; OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO(); //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject); Assert.AreSame(oldOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = newOrganisationTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject); Assert.AreSame(newOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property); }
public void Test_UpdateRelatedObject_ShouldRaiseEvent() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(); ISingleRelationship relationship = (ISingleRelationship)contactPersonTestBO.Relationships["Organisation"]; bool eventCalled = false; IRelKey key = relationship.RelKey; IRelProp relProp = key[0]; relProp.PropValueUpdated += delegate { eventCalled = true; }; //---------------Assert Precondition---------------- Assert.IsTrue(contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation").OwningBOHasForeignKey); Assert.IsFalse(eventCalled); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = organisationTestBO; //---------------Test Result ----------------------- Assert.IsTrue(eventCalled); }
public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingRelationshipOnRelatedBO_ShouldFireRelationshipChangedEvent() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO(); bool eventFired = false; boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true; //---------------Assert Precondition---------------- Assert.IsFalse(eventFired); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = newOrganisationTestBO; //---------------Test Result ----------------------- Assert.IsTrue(eventFired); }
public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingRelationshipOnRelatedBO_ShouldChangeRelationship() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO(); //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(oldOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = newOrganisationTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(newOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); }
public void Test_AddRow_WhenMultipleLevelProp_ShouldAddBOWithRelatedPropSet() { //---------------Set up test pack------------------- RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; ClassDef.ClassDefs.Clear(); AddressTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson(); BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses; OrganisationTestBO organisation = new OrganisationTestBO(); UIGrid uiGrid = new UIGrid(); const string propertyName = "ContactPersonTestBO.OrganisationID"; uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses); DataTable table = dataSetProvider.GetDataTable(uiGrid); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(0, table.Rows.Count); Assert.AreEqual(0, addresses.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, organisation.OrganisationID }); //---------------Test Result ----------------------- Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, addresses.Count); Assert.AreEqual(organisation.OrganisationID.ToString(), table.Rows[0][propertyName].ToString()); Assert.AreEqual(organisation.OrganisationID, contactPersonTestBO.OrganisationID); recordingExceptionNotifier.RethrowRecordedException(); }
public void TestFind_UsingGuidCriteria_Untyped() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO { Surname = Guid.NewGuid().ToString("N") }; cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID; cp.Save(); DataStoreInMemory dataStore = new DataStoreInMemory(); dataStore.Add(cp); Criteria criteria = new Criteria("OrganisationID", Criteria.ComparisonOp.Equals, cp.OrganisationID); //---------------Execute Test ---------------------- ContactPersonTestBO loadedCP = (ContactPersonTestBO)dataStore.Find(typeof(ContactPersonTestBO), criteria); //---------------Test Result ----------------------- Assert.AreSame(cp.ID, loadedCP.ID); }
public void Test_SimpleLookup_Create_SetsUpKeyLookupList_BO_PrimaryKeyNotSet() { //---------------Set up test pack------------------- OrganisationTestBO.LoadDefaultClassDef_WithSingleRelationship(); OrganisationTestBO bo = new OrganisationTestBO {OrganisationID = null}; BusinessObjectCollection<OrganisationTestBO> collectionBO = new BusinessObjectCollection<OrganisationTestBO> {bo}; //---------------Assert Precondition---------------- Assert.IsNull(bo.ID.GetAsValue()); //---------------Execute Test ---------------------- try { BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub (typeof (OrganisationTestBO), collectionBO) {PropDef = _propDefGuid}; businessObjectLookupList.GetIDValueLookupList(); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { string developerMessage = string.Format ("A business object of '{0}' is being added to a lookup list for {1} it " + "does not have a value for its primary key set", _propDefGuid.PropertyTypeName, _propDefGuid.PropertyName); StringAssert.Contains(developerMessage, ex.DeveloperMessage); } }
public void Test3LayerDeleteRelated() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorDB(); OrganisationTestBO.LoadDefaultClassDef(); AddressTestBO address; var contactPersonTestBO = CreateContactPersonWithOneAddress(out address); var org = new OrganisationTestBO(); contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID); org.Save(); contactPersonTestBO.Save(); //---------------Assert Precondition---------------- Assert.AreEqual(1,org.ContactPeople.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.Count); Assert.AreEqual(1, org.Relationships.Count); Assert.IsTrue(org.Relationships.Contains("ContactPeople")); Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["ContactPeople"].DeleteParentAction); //---------------Execute Test ---------------------- //IBusinessObjectCollection colContactPeople = org.Relationships["ContactPeople"].GetRelatedBusinessObjectCol(); //ContactPersonTestBO loadedCP = (ContactPersonTestBO)colContactPeople[0]; //IBusinessObjectCollection colAddresses = loadedCP.Relationships["Addresses"].GetRelatedBusinessObjectCol(); //Address loadedAdddress = (Address)colAddresses[0]; org.MarkForDelete(); TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); committer.AddBusinessObject(org); committer.CommitTransaction(); //---------------Test Result ----------------------- //Assert.AreSame(contactPersonTestBO, loadedCP); //Assert.AreSame(address, loadedAdddress); AssertBusinessObjectNotInDatabase(org); AssertBusinessObjectNotInDatabase(contactPersonTestBO); AssertBusinessObjectNotInDatabase(address); BOTestUtils.AssertBOStateIsValidAfterDelete(org); BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO); BOTestUtils.AssertBOStateIsValidAfterDelete(address); }
public void Test_LoadSingleBO_OneChild_Expanded() { //---------------Set up test pack------------------- TreeViewWin treeView = new TreeViewWin(); TreeViewController treeViewController = new TreeViewController(treeView); OrganisationTestBO organisationTestBO = new OrganisationTestBO {Name = TestUtil.GetRandomString()}; ContactPersonTestBO contactPersonTestBO = organisationTestBO.ContactPeople.CreateBusinessObject(); contactPersonTestBO.Surname = TestUtil.GetRandomString(); //-------------Assert Preconditions ------------- Assert.AreEqual(0, treeView.Nodes.Count); //---------------Execute Test ---------------------- treeViewController.LoadTreeView(organisationTestBO, 2); //---------------Test Result ----------------------- Assert.AreEqual(1, treeView.Nodes.Count); ITreeNode node = treeView.Nodes[0]; Assert.AreEqual(organisationTestBO.ToString(), node.Text); Assert.AreEqual(1, node.Nodes.Count); ITreeNode relationshipNode = node.Nodes[0]; Assert.AreEqual("ContactPeople", relationshipNode.Text); Assert.AreEqual(1, relationshipNode.Nodes.Count); ITreeNode childNode = relationshipNode.Nodes[0]; Assert.AreEqual(contactPersonTestBO.ToString(), childNode.Text); }
public void Test3LayerLoadRelated() { //---------------Set up test pack------------------- FixtureEnvironment.ClearBusinessObjectManager(); ContactPersonTestBO.DeleteAllContactPeople(); ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorDB(); OrganisationTestBO.LoadDefaultClassDef(); TestUtil.WaitForGC(); AddressTestBO address; var tableNameExt = CreateContactPersonAndAddressTables(); var contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, tableNameExt); var org = new OrganisationTestBO(); contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID); org.Save(); contactPersonTestBO.Save(); //---------------Assert Preconditions -------------- Assert.AreEqual(3, BusinessObjectManager.Instance.Count); //---------------Execute Test ---------------------- var colContactPeople = org.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople").BusinessObjectCollection; var loadedCP = colContactPeople[0]; var colAddresses = loadedCP.Relationships.GetMultiple<AddressTestBO>("Addresses").BusinessObjectCollection; Assert.Greater(colAddresses.Count, 0, "There should be at least one Address"); var loadedAdddress = colAddresses[0]; //---------------Test Result ----------------------- Assert.AreEqual(3, BusinessObjectManager.Instance.Count); Assert.AreEqual(1, colAddresses.Count); Assert.AreSame(contactPersonTestBO, loadedCP); Assert.AreSame(address, loadedAdddress); }
public void Test_ChangeRelatedBO_WhenSetToNull_HavingPropertyOnRelatedBO_ShouldChangePropertyToNull() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerPropertyName = "Name"; const string propertyName = "Organisation." + innerPropertyName; BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propertyName); boPropertyMapper.BusinessObject = contactPersonTestBO; //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject); Assert.AreSame(oldOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = null; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject); Assert.IsNull(boPropertyMapper.Property); }
public void TestIsMatch_NonNullGuidValue_Equals_NullMatchValue_ShouldNotMatch() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); OrganisationTestBO organisationTestBO = new OrganisationTestBO(); cp.OrganisationID = organisationTestBO.OrganisationID; Criteria nameCriteria = new Criteria("OrganisationID", Criteria.ComparisonOp.Equals, null); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- bool isMatch = nameCriteria.IsMatch(cp, false); //---------------Test Result ----------------------- Assert.IsFalse(isMatch, "The object should not be a match since it does not match the criteria given."); }
public void Test3LayerLoadRelated() { //---------------Set up test pack------------------- BusinessObjectManager.Instance.ClearLoadedObjects(); ContactPersonTestBO.DeleteAllContactPeople(); BORegistry.DataAccessor = new DataAccessorDB(); OrganisationTestBO.LoadDefaultClassDef(); TestUtil.WaitForGC(); Address address; ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address); OrganisationTestBO org = new OrganisationTestBO(); contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID); org.Save(); contactPersonTestBO.Save(); //---------------Assert Preconditions -------------- Assert.AreEqual(3, BusinessObjectManager.Instance.Count); //---------------Execute Test ---------------------- IBusinessObjectCollection colContactPeople = org.Relationships["ContactPeople"].GetRelatedBusinessObjectCol(); ContactPersonTestBO loadedCP = (ContactPersonTestBO) colContactPeople[0]; IBusinessObjectCollection colAddresses = loadedCP.Relationships["Addresses"].GetRelatedBusinessObjectCol(); Address loadedAdddress = (Address) colAddresses[0]; //---------------Test Result ----------------------- Assert.AreEqual(3, BusinessObjectManager.Instance.Count); Assert.AreEqual(1, colAddresses.Count); Assert.AreSame(contactPersonTestBO, loadedCP); Assert.AreSame(address, loadedAdddress); }
public static OrganisationTestBO CreateSavedOrganisation() { OrganisationTestBO bo = new OrganisationTestBO(); bo.Save(); return bo; }
public void Test_ChangeRelatedBO_WhenSetToNull_HavingRelationshipOnRelatedBO_ShouldChangeRelationshipToNull() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(oldOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = null; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); }
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_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 Test_SelectButtonWhenClicked_ShouldApplyBusinessObjectChanges(bool enableEditing) { //---------------Set up test pack------------------- GetClassDefs(); IControlFactory controlFactory = GetControlFactory(); ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory); const string propName = "OrganisationID"; ExtendedTextBoxMapperSpy mapperSpy = new ExtendedTextBoxMapperSpy( extendedTextBoxWin, propName, true, controlFactory); mapperSpy.EnableEditing = enableEditing; ContactPersonTestBO contactPersonTestBo = new ContactPersonTestBO(); mapperSpy.BusinessObject = contactPersonTestBo; var expectedSelectedBO = new OrganisationTestBO(); //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBo, mapperSpy.BusinessObject); Assert.IsNull(contactPersonTestBo.OrganisationID); //---------------Execute Test ---------------------- mapperSpy.CallSetupPopupForm(); mapperSpy.SetSelectedBusinessObject(expectedSelectedBO); mapperSpy.CallSelectClick(); //---------------Test Result ----------------------- Assert.IsNotNull(contactPersonTestBo.OrganisationID); Assert.AreSame(expectedSelectedBO, contactPersonTestBo.Organisation); }
public void Test_LoadSingleBO_OneChildRelationship_Expanded() { //---------------Set up test pack------------------- TreeViewWin treeView = new TreeViewWin(); TreeViewController treeViewController = new TreeViewController(treeView); OrganisationTestBO organisationTestBO = new OrganisationTestBO(); //-------------Assert Preconditions ------------- Assert.AreEqual(0, treeView.Nodes.Count); //---------------Execute Test ---------------------- treeViewController.LoadTreeView(organisationTestBO, 1); //---------------Test Result ----------------------- Assert.AreEqual(1, treeView.Nodes.Count); ITreeNode node = treeView.Nodes[0]; Assert.AreEqual(organisationTestBO.ToString(), node.Text); Assert.AreEqual(1, node.Nodes.Count); ITreeNode relationshipNode = node.Nodes[0]; Assert.AreEqual("ContactPeople", relationshipNode.Text); }
public void TestPreventDelete_ThreeLevels() { //---------------Set up test pack------------------- AddressTestBO address; ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_PreventDelete(out address); OrganisationTestBO.LoadDefaultClassDef(); OrganisationTestBO org = new OrganisationTestBO(); contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID); org.Save(); contactPersonTestBO.Save(); //org.MarkForDelete(); //TransactionCommitterDB committer = new TransactionCommitterDB(); //committer.AddBusinessObject(org); //---------------Execute Test ---------------------- try { //committer.CommitTransaction(); org.MarkForDelete(); Assert.Fail(); } //---------------Test Result ----------------------- catch (BusObjDeleteException ex) { Assert.IsNotNull(ex.InnerException, "BusObjDeleteException should have an inner exception with more information"); StringAssert.Contains("as the IsDeletable is set to false for the object", ex.InnerException.Message); StringAssert.Contains("since it is related to 1 Business Objects via the Addresses relationship", ex.Message); } finally { CleanupObjectFromDatabase(address); CleanupObjectFromDatabase(contactPersonTestBO); CleanupObjectFromDatabase(org); } }
public void Test3LayerDeleteRelated_WithDeletedObjectChildAndGrandchild() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress(); AddressTestBO address; var contactPersonTestBO = CreateContactPersonWithOneAddress(out address); var org = new OrganisationTestBO(); contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID); org.Save(); contactPersonTestBO.Save(); address.OrganisationID = org.OrganisationID; address.Save(); org.MarkForDelete(); TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); committer.AddBusinessObject(org); //---------------Assert Precondition---------------- //Assert.AreEqual(1, org.ContactPeople.Count); Assert.AreEqual(0, org.ContactPeople.Count); Assert.AreEqual(1, org.ContactPeople.MarkedForDeleteBusinessObjects.Count); Assert.AreEqual(0, ((IMultipleRelationship) org.Relationships["Addresses"]).BusinessObjectCollection.Count); Assert.AreEqual(1, ((IMultipleRelationship) org.Relationships["Addresses"]).BusinessObjectCollection.MarkedForDeleteBusinessObjects.Count); Assert.AreEqual(0, contactPersonTestBO.Addresses.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.MarkedForDeleteBusinessObjects.Count); Assert.AreEqual(2, org.Relationships.Count); Assert.IsTrue(org.Relationships.Contains("ContactPeople")); Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["ContactPeople"].DeleteParentAction); Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["Addresses"].DeleteParentAction); //---------------Execute Test ---------------------- committer.CommitTransaction(); //---------------Test Result ----------------------- BOTestUtils.AssertBOStateIsValidAfterDelete(org); BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO); BOTestUtils.AssertBOStateIsValidAfterDelete(address); AssertBusinessObjectNotInDatabase(org); AssertBusinessObjectNotInDatabase(contactPersonTestBO); AssertBusinessObjectNotInDatabase(address); }
public virtual void Test_AddBOToCol_ShouldUpdateItems() { //---------------Set up test pack------------------- IComboBox cmbox = CreateComboBox(); BusinessObjectCollection<OrganisationTestBO> boCol; RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(cmbox, out boCol); OrganisationTestBO newBO = new OrganisationTestBO(); //---------------Assert Precondition---------------- Assert.AreEqual(1, boCol.Count); Assert.AreEqual(2, mapper.Control.Items.Count); //---------------Execute Test ---------------------- boCol.Add(newBO); //---------------Test Result ----------------------- Assert.AreEqual(2, boCol.Count); Assert.AreEqual(3, mapper.Control.Items.Count); }
public void Test_AddRow_WhenMultipleLevelProp_ShouldAddBOWithRelatedPropSet() { //---------------Set up test pack------------------- RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; ClassDef.ClassDefs.Clear(); AddressTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson(); BusinessObjectCollection<AddressTestBO> addresses = contactPersonTestBO.Addresses; OrganisationTestBO organisation = new OrganisationTestBO(); UIGrid uiGrid = new UIGrid(); const string propertyName = "ContactPersonTestBO.OrganisationID"; uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses); DataTable table = dataSetProvider.GetDataTable(uiGrid); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(0, table.Rows.Count); Assert.AreEqual(0, addresses.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, organisation.OrganisationID }); //---------------Test Result ----------------------- Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, addresses.Count); Assert.AreEqual(organisation.OrganisationID.ToString(), table.Rows[0][propertyName].ToString()); Assert.AreEqual(organisation.OrganisationID, contactPersonTestBO.OrganisationID); recordingExceptionNotifier.RethrowRecordedException(); }
public void TestFindAll_UsingClassDef_BUGFIX_ShouldBeThreadsafe(string aaa) { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); OrganisationTestBO.LoadDefaultClassDef(); var dataStore = new DataStoreInMemory(); var now = DateTime.Now; var cp1 = new ContactPersonTestBO { DateOfBirth = now, Surname = TestUtil.GetRandomString() }; cp1.Save(); dataStore.Add(cp1); var cp2 = new ContactPersonTestBO { DateOfBirth = now, Surname = TestUtil.GetRandomString() }; cp2.Save(); dataStore.Add(cp2); //var criteria = MockRepository.GenerateStub<Criteria>("DateOfBirth", Criteria.ComparisonOp.Equals, now); //criteria.Stub(o => o.IsMatch(Arg<IBusinessObject>.Is.Anything)).WhenCalled(invocation => //{ // Thread.Sleep(100); // invocation.ReturnValue = true; //}).Return(true); var criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); for (int i1 = 0; i1 < 1000; i1++) { dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); } var threads = new List <Thread>(); threads.Add(new Thread(() => { for (int i1 = 0; i1 < 1000; i1++) { dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); } })); var exceptions = new List <Exception>(); threads.Add(new Thread(() => { try { for (int i = 0; i < 10; i++) { dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), criteria); } } catch (Exception ex) { exceptions.Add(ex); } })); //---------------Execute Test ---------------------- threads.AsParallel().ForAll(thread => thread.Start()); threads.AsParallel().ForAll(thread => thread.Join()); //Assert.DoesNotThrow(() => //{ //var col = dataStore.FindAll(ClassDef.Get<ContactPersonTestBO>(), criteria); //thread.Join(); //}); //---------------Test Result ----------------------- if (exceptions.Count > 0) { Assert.Fail("Has an Exception: " + exceptions[0].ToString()); } }
private ContactPersonTestBO CreateUnsavedContactPerson(OrganisationTestBO organisation) { ContactPersonTestBO contactPersonTestBO = organisation.ContactPeople.CreateBusinessObject(); contactPersonTestBO.FirstName = TestUtil.GetRandomString(); contactPersonTestBO.Surname = TestUtil.GetRandomString(); return contactPersonTestBO; }
public void Test_AddRow_WhenVirtualProp_ShouldAddBOWithRelatedVirtualPropSet() { //---------------Set up test pack------------------- RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; AddressTestBO.LoadDefaultClassDef(); var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); BusinessObjectCollection<ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection<ContactPersonTestBO>(); OrganisationTestBO organisation = new OrganisationTestBO(); UIGrid uiGrid = new UIGrid(); new UIDef("fdafdas", new UIForm(), uiGrid) {ClassDef = contactPersonClassDef}; const string propertyName = "-Organisation-"; uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS); DataTable table = dataSetProvider.GetDataTable(uiGrid); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(0, table.Rows.Count); Assert.AreEqual(0, contactPersonTestBOS.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, organisation }); //---------------Test Result ----------------------- Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, contactPersonTestBOS.Count); Assert.AreSame(organisation, table.Rows[0][propertyName]); Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation); }
public void Test_NonAutoLoading_SetPerson_WithUnsavedOrganisation_ShouldNotRemoveOrganisation_FIXBUG() { //---------------Set up test pack------------------- ComboBoxWinStub cmbox = new ComboBoxWinStub(); BusinessObjectCollection<OrganisationTestBO> boCol; RelationshipComboBoxMapper mapper = new RelationshipComboBoxMapper(cmbox, "Organisation", false, GlobalUIRegistry.ControlFactory); boCol = GetBoColWithOneItem(); mapper.BusinessObjectCollection = boCol; mapper.BusinessObject = new ContactPersonTestBO(); OrganisationTestBO testBO = new OrganisationTestBO(); ContactPersonTestBO person = CreateCPWithRelatedOrganisation(testBO); //---------------Assert Precondition---------------- Assert.False(boCol.Contains(testBO)); Assert.AreSame(testBO, person.Organisation); Assert.IsNotNull(person.Organisation); Assert.IsTrue(person.Organisation.Status.IsNew); //---------------Execute Test ---------------------- mapper.BusinessObject = person; //---------------Test Result ----------------------- Assert.IsNotNull(person.Organisation); }
protected static ContactPersonTestBO CreateCPWithRelatedOrganisation(OrganisationTestBO organisationTestBO) { ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson(); person.Organisation = organisationTestBO; return person; }