private static void SetupSelectorWithTestPackCollection(ComboBoxCollectionSelector selectorManager, bool includeBlankItems) { MyBO.LoadDefaultClassDef(); selectorManager.IncludeBlankItem = includeBlankItems; BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO> { { new MyBO(), new MyBO() } }; selectorManager.SetCollection(myBOs); }
public void TearDown() { BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>(); shapes.LoadAll(); Shape[] shapesClone = shapes.ToArray(); foreach (Shape shape in shapesClone) { shape.MarkForDelete(); } shapes.SaveAll(); //Shape shape = BOLoader.Instance.GetBusinessObject<Shape>( // "ShapeName = 'MyShape' OR ShapeName = 'MyShapeChanged'"); //if (shape != null) //{ // shape.MarkForDelete(); // shape.Save(); //} //CircleNoPrimaryKey circle = BOLoader.Instance.GetBusinessObject<CircleNoPrimaryKey>( // "ShapeName = 'Circle' OR ShapeName = 'CircleChanged'"); //if (circle != null) //{ // circle.MarkForDelete(); // circle.Save(); //} //FilledCircleInheritsCircleNoPK filledCircle = BOLoader.Instance.GetBusinessObject<FilledCircleInheritsCircleNoPK>( // "ShapeName = 'FilledCircle' OR ShapeName = 'FilledCircleChanged'"); //if (filledCircle != null) //{ // filledCircle.MarkForDelete(); // filledCircle.Save(); //} }
protected MultipleRelationship<ContactPersonTestBO> GetRelationship( out OrganisationTestBO organisationTestBO, out BusinessObjectCollection<ContactPersonTestBO> cpCol) { RelationshipCol relationships; return GetRelationship(out organisationTestBO, out relationships, out cpCol); }
protected MultipleRelationship<ContactPersonTestBO> GetRelationship( OrganisationTestBO organisationTestBO, out BusinessObjectCollection<ContactPersonTestBO> cpCol) { var relationship = GetRelationship(organisationTestBO); cpCol = relationship.BusinessObjectCollection; return relationship; }
private static MultipleRelationship<ContactPersonTestBO> GetAggregateRelationship(OrganisationTestBO organisationTestBO, out BusinessObjectCollection<ContactPersonTestBO> cpCol) { MultipleRelationship<ContactPersonTestBO> aggregateRelationship = organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople"); RelationshipDef relationshipDef = (RelationshipDef) aggregateRelationship.RelationshipDef; relationshipDef.RelationshipType = RelationshipType.Aggregation; cpCol = aggregateRelationship.BusinessObjectCollection; return aggregateRelationship; }
public void Test_BusinessObjectEdited_ShouldRefreshTheValueInTheList() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); var listBox = GetControlFactory().CreateListBox(); var manager = CreateListBoxCollectionManager(listBox); var boToBeUpdated = new MyBO(); var myBoCol = new BusinessObjectCollection<MyBO> {new MyBO(), boToBeUpdated }; manager.BusinessObjectCollection = myBoCol; manager.Control.SelectedItem = boToBeUpdated; var initialListBoxDisplayText = manager.Control.Text; var initialBOToString = boToBeUpdated.ToString(); //---------------Assert Precondition---------------- Assert.AreEqual(2, manager.Control.Items.Count); Assert.AreSame(boToBeUpdated, manager.Control.Items[1]); Assert.AreEqual(initialBOToString, initialListBoxDisplayText); //---------------Execute Test ---------------------- boToBeUpdated.TestProp = GetRandomString(); boToBeUpdated.Save(); //---------------Test Result ----------------------- var updatedListBoxDisplayText = manager.Control.Text; var updatedBOToString = boToBeUpdated.ToString(); Assert.AreNotEqual(initialListBoxDisplayText, updatedListBoxDisplayText); Assert.AreNotEqual(initialBOToString, updatedBOToString); Assert.AreEqual(updatedBOToString, updatedListBoxDisplayText); }
public void TestBusinessObjectControlHasDifferentBOWhenTabChanges() { //---------------Set up test pack------------------- IBOColTabControl boColTabControl = GetControlFactory().CreateBOColTabControl(); IBusinessObjectControl busControl = GetBusinessObjectControlStub(); boColTabControl.BusinessObjectControl = busControl; BusinessObjectCollection<MyBO> myBoCol = new BusinessObjectCollection<MyBO>(); MyBO firstBo = new MyBO(); myBoCol.Add(firstBo); myBoCol.Add(new MyBO()); MyBO thirdBO = new MyBO(); myBoCol.Add(thirdBO); boColTabControl.BusinessObjectCollection = myBoCol; //---------------Assert Precondition---------------- Assert.AreEqual(firstBo, boColTabControl.BusinessObjectControl.BusinessObject); //---------------Execute Test ---------------------- boColTabControl.TabControl.SelectedIndex = 2; //---------------Test Result ----------------------- Assert.AreNotSame(firstBo, boColTabControl.BusinessObjectControl.BusinessObject); Assert.AreEqual(thirdBO, boColTabControl.BusinessObjectControl.BusinessObject); }
public void InitialiseCollection() { _boCol = new BusinessObjectCollection<MultiPropBO>(); _boCol.Add((MultiPropBO)_classDef.CreateNewBusinessObject()); _boCol.Add((MultiPropBO)_classDef.CreateNewBusinessObject()); //_boCol.Add((MultiPropBO)_classDef.CreateNewBusinessObject()); //_boCol.Add((MultiPropBO)_classDef.CreateNewBusinessObject()); }
public static void AssertAllCollectionsHaveNoItems(BusinessObjectCollection<ContactPersonTestBO> cpCol) { Assert.AreEqual(0, cpCol.Count); Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count); Assert.AreEqual(0, cpCol.RemovedBusinessObjects.Count); Assert.AreEqual(0, cpCol.PersistedBusinessObjects.Count); Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count); Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count); }
public static BusinessObjectCollection GetHierarchicalData(int? parentId) { List<BusinessObject> result = GetData().FindAll(obj => obj.ParentID == parentId); BusinessObjectCollection ret = new BusinessObjectCollection(); ret.Clear(); ret.AddRange(result); return ret; }
public static BusinessObjectCollection GetData(int categoryId) { List<BusinessObject> result = GetData().FindAll(obj => obj.CategoryID == categoryId); BusinessObjectCollection ret = new BusinessObjectCollection(); ret.Clear(); ret.AddRange(result); return ret; }
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 static void AssertOneObjectInCurrentPersistedCollectionOnly (BusinessObjectCollection<ContactPersonTestBO> cpCol) { Assert.AreEqual(1, cpCol.Count); Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count); Assert.AreEqual(0, cpCol.RemovedBusinessObjects.Count); Assert.AreEqual(1, cpCol.PersistedBusinessObjects.Count); Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count); Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count); }
protected void CreateDirtyChildren(BusinessObjectCollection<ContactPersonTestBO> cpCol, out ContactPersonTestBO existingChild, out ContactPersonTestBO editedChild, out ContactPersonTestBO deletedChild, out ContactPersonTestBO createdChildWithEdits, out ContactPersonTestBO createdChild) { createdChild = CreateCreatedChild(cpCol); createdChildWithEdits = CreateCreatedChildWithEdits(cpCol); existingChild = CreateExistingChild(cpCol); editedChild = CreateEditedChild(cpCol); deletedChild = CreateDeletedChild(cpCol); }
public void Test_BindBusinessObjectCollection_ToListBox_ShouldAddToControlList() { //---------------Set up test pack------------------- var lstBox = new ListBox(); var selectorBinder = new HabaneroSelectorControlBinder<FakeBo, ListBox>(lstBox); var businessObjectCollection = new BusinessObjectCollection<FakeBo>(); businessObjectCollection.CreateBusinessObject(); //---------------Assert Precondition---------------- Assert.AreEqual(0, lstBox.Items.Count); //---------------Execute Test ---------------------- selectorBinder.SetBusinessObjectCollection(businessObjectCollection); //---------------Test Result ----------------------- Assert.AreEqual(1, lstBox.Items.Count, "The business object collection's items should be in list"); }
public void TestFixtureSetup() { //Code that is executed before any test is run in this class. If multiple tests // are executed then it will still only be called once. ClassDef.ClassDefs.Clear(); BOWithIntID.LoadClassDefWithIntID(); _propDef_int = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null); _validBusinessObject = new BOWithIntID {TestField = _validLookupValue}; _validIntID = 3; _validBusinessObject.IntID = _validIntID; _collection_IntId = new BusinessObjectCollection<BOWithIntID> {_validBusinessObject}; _propDef_int.LookupList = new BusinessObjectLookupListStub(typeof (BOWithIntID), _collection_IntId); }
public override void Test_SelectedBusinessObject_ReturnsNullIfNoItemSelected() { //---------------Set up test pack------------------- IBOColSelectorControl colSelector = CreateSelector(); MyBO myBO = new MyBO(); BusinessObjectCollection<MyBO> collection = new BusinessObjectCollection<MyBO> { myBO }; colSelector.BusinessObjectCollection = collection; colSelector.SelectedBusinessObject = null; //---------------Assert Precondition---------------- Assert.AreEqual(collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and one other"); //---------------Execute Test ---------------------- IBusinessObject selectedBusinessObject = colSelector.SelectedBusinessObject; //---------------Test Result ----------------------- Assert.IsNull(selectedBusinessObject); }
public void TestSetCollection_EmptyCollection() { //---------------Set up test pack------------------- ListViewCollectionManager cntrl = CreateDefaultListVievController(); BusinessObjectCollection<MyBO> col = new BusinessObjectCollection<MyBO>(); //---------------Execute Test ---------------------- cntrl.SetCollection(col); //---------------Test Result ----------------------- Assert.AreEqual(0, cntrl.ListView.Items.Count); //UIDef uiDef = GetDefaultUIDef(cntrl); //Assert.AreEqual(uiDef.GetUIGridProperties().Count, cntrl.ListView.Columns.Count);//There are 8 columns in the collection BO //Assert.IsNull(gridBase.SelectedBusinessObject); //---------------Tear Down ------------------------- }
public void TestCreateTestTabControlCollectionController() { //---------------Set up test pack------------------- BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO> {{new MyBO(), new MyBO()}}; ITabControl tabControl = CreateTabControl(); BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, GetControlFactory()); selectorManager.BusinessObjectControl = GetBusinessObjectControl(); //---------------Verify test pack------------------- //---------------Execute Test ---------------------- selectorManager.BusinessObjectCollection = myBOs; //---------------Verify Result ----------------------- Assert.AreEqual(myBOs, selectorManager.BusinessObjectCollection); Assert.AreSame(tabControl, selectorManager.TabControl); //---------------Tear Down ------------------------- }
public void Test_CreateTestComboBoxCollectionController() { //---------------Set up test pack------------------- MyBO.LoadClassDefWithBoolean(); BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO> {{new MyBO(), new MyBO()}}; IComboBox cmb = GetControlFactory().CreateComboBox(); DisposeOnTearDown(cmb); ComboBoxCollectionSelector selector = new ComboBoxCollectionSelector(cmb, GetControlFactory()); DisposeOnTearDown(selector); //---------------Verify test pack------------------- //---------------Execute Test ---------------------- selector.SetCollection(myBOs); //---------------Verify Result ----------------------- Assert.AreEqual(myBOs, selector.BusinessObjectCollection); Assert.AreSame(cmb,selector.Control); //---------------Tear Down ------------------------- }
public void TestSetCollectionOnGrid_EmptyCollection() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); var col = new BusinessObjectCollection<MyBO>(); var gridBase = CreateGridBaseStub(); SetupGridColumnsForMyBo(gridBase); //---------------Execute Test ---------------------- #pragma warning disable 618,612 gridBase.SetBusinessObjectCollection(col); #pragma warning restore 618,612 //---------------Test Result ----------------------- Assert.AreEqual(0, gridBase.Rows.Count); //Assert.AreEqual(classDef.PropDefcol.Count, myGridBase.Columns.Count);//There are 8 columns in the collection BO Assert.IsNull(gridBase.SelectedBusinessObject); //---------------Tear Down ------------------------- }
public void TestSetBOCollection() { //---------------Set up test pack------------------- IComboBox cmbox = GetControlFactory().CreateComboBox(); const string propName = "SampleLookupID"; CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName); Sample bo = new Sample(); IBusinessObjectCollection col = new BusinessObjectCollection<Sample> {bo}; //---------------Assert Precondition --------------- Assert.AreEqual(0, cmbox.Items.Count); //---------------Execute Test ---------------------- mapper.BusinessObjectCollection = col; //---------------Test Result ----------------------- Assert.AreEqual(2, cmbox.Items.Count, "The Sample item and the blank"); Assert.AreSame(typeof (string), cmbox.Items[0].GetType(), "First Item should be blank"); Assert.IsTrue(cmbox.Items.Contains(bo), "Second Item should be the Business Object"); }
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 override void Test_Set_SelectedBusinessObject_Null_SetsItemNull() { //---------------Set up test pack------------------- IBOColSelectorControl colSelector = CreateSelector(); MyBO myBO = new MyBO(); MyBO myBO2 = new MyBO(); BusinessObjectCollection<MyBO> collection = new BusinessObjectCollection<MyBO> { myBO, myBO2 }; colSelector.BusinessObjectCollection = collection; SetSelectedIndex(colSelector, ActualIndex(1)); //---------------Assert Precondition---------------- Assert.AreEqual(collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and others"); Assert.AreEqual(ActualIndex(1), SelectedIndex(colSelector)); Assert.AreEqual(myBO2, colSelector.SelectedBusinessObject); //---------------Execute Test ---------------------- colSelector.SelectedBusinessObject = null; //---------------Test Result ----------------------- Assert.IsNull(colSelector.SelectedBusinessObject); Assert.AreEqual(-1, SelectedIndex(colSelector)); }
public override void Test_RemoveBOToCol_UpdatesItems() { //---------------Set up test pack------------------- IBOColSelectorControl colSelector = CreateSelector(); MyBO myBO = new MyBO(); MyBO newMyBO = new MyBO(); BusinessObjectCollection<MyBO> collection = new BusinessObjectCollection<MyBO> {myBO, newMyBO}; colSelector.BusinessObjectCollection = collection; //---------------Assert Precondition---------------- Assert.AreEqual (collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and one other"); Assert.AreSame(myBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0))); Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(1))); //---------------Execute Test ---------------------- collection.Remove(myBO); //---------------Test Result ----------------------- Assert.AreEqual(ActualNumberOfRows(1), colSelector.NoOfItems, "The blank item and one other"); Assert.AreSame(newMyBO, colSelector.GetBusinessObjectAtRow(ActualIndex(0))); }
public void Test_SelectedBusinessObject_BlankItemSelected_ReturnsNull() { //---------------Set up test pack------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); Car car = new Car(); BusinessObjectCollection<Car> collection = new BusinessObjectCollection<Car> { car }; selector.BusinessObjectCollection = collection; SetSelectedIndex(selector, -1); //---------------Assert Precondition---------------- Assert.AreEqual(2, selector.NoOfItems, "The blank item and one other"); Assert.AreEqual(-1, SelectedIndex(selector)); Assert.AreEqual(null, selector.SelectedValue); //---------------Execute Test ---------------------- SetSelectedIndex(selector, 0); //---------------Test Result ----------------------- Assert.AreEqual(0, SelectedIndex(selector)); Assert.AreEqual("", selector.SelectedValue); Assert.IsNull(selector.SelectedBusinessObject); }
public void Test_AddMethod() { //---------------Set up test pack------------------- //ContactPersonTestBO.LoadDefaultClassDef(); BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>(); ContactPersonTestBO myBO = new ContactPersonTestBO(); _businessObjectCollectionTestHelper.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- Assert.AreEqual(0, cpCol.Count); Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count); _businessObjectCollectionTestHelper.AssertAddedEventNotFired(); //---------------Execute Test ---------------------- cpCol.Add(myBO); //---------------Test Result ----------------------- Assert.AreEqual(1, cpCol.Count, "One object should be in the cpCollection"); BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndCreatedCollection(cpCol); _businessObjectCollectionTestHelper.AssertAddedEventFired(); Assert.AreEqual(myBO, cpCol[0], "Added object should be in the cpCollection"); }
[Test] // Ensures that a class can be successfully saved public void Test_SaveCar() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- Car car = TestUtilsCar.CreateUnsavedValidCar(); //---------------Assert Precondition---------------- Assert.IsTrue(car.Status.IsNew); BusinessObjectCollection<Car> col = new BusinessObjectCollection<Car>(); col.LoadAll(); Assert.AreEqual(0, col.Count); //---------------Execute Test ---------------------- car.Save(); //---------------Test Result ----------------------- Assert.IsFalse(car.Status.IsNew); col.LoadAll(); Assert.AreEqual(1, col.Count); }
public void TestCreateTestListBoxCollectionController() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithBoolean(); BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO>(); MyBO myBO1 = new MyBO(); MyBO myBO2 = new MyBO(); myBOs.Add(myBO1, myBO2); IListBox cmb = CreateListBox(); var selector = CreateListBoxCollectionManager(cmb); //---------------Verify test pack------------------- //---------------Execute Test ---------------------- selector.SetCollection(myBOs); //---------------Verify Result ----------------------- Assert.AreEqual(myBOs, selector.Collection); Assert.AreSame(cmb, selector.Control); //---------------Tear Down ------------------------- }
[Test] // Ensures that a class can be successfully saved public void Test_SaveSteeringWheel() { CheckIfTestShouldBeIgnored(); //---------------Set up test pack------------------- SteeringWheel steeringWheel = TestUtilsSteeringWheel.CreateUnsavedValidSteeringWheel(); //---------------Assert Precondition---------------- Assert.IsTrue(steeringWheel.Status.IsNew); BusinessObjectCollection<SteeringWheel> col = new BusinessObjectCollection<SteeringWheel>(); col.LoadAll(); Assert.AreEqual(0, col.Count); //---------------Execute Test ---------------------- steeringWheel.Save(); //---------------Test Result ----------------------- Assert.IsFalse(steeringWheel.Status.IsNew); col.LoadAll(); Assert.AreEqual(1, col.Count); }
public void Test_EditUnselectedItemFromCollection_UpdatesItemInCombo_DoesNotSelectItem() { //---------------Set up test pack------------------- var cmbox = GetControlFactory().CreateComboBox(); DisposeOnTearDown(cmbox); var controlFactory = GetControlFactory(); var selectorManager = new ComboBoxCollectionSelector(cmbox, controlFactory) { IncludeBlankItem = false }; DisposeOnTearDown(selectorManager); MyBO.LoadDefaultClassDef(); var myBOs = new BusinessObjectCollection <MyBO> { { new MyBO(), new MyBO() } }; selectorManager.SetCollection(myBOs); var myBO = myBOs[1]; var origToString = myBO.ToString(); var newValue = Guid.NewGuid(); var index = cmbox.Items.IndexOf(myBO); //---------------Assert precondition---------------- Assert.AreEqual(2, cmbox.Items.Count); Assert.AreEqual(0, cmbox.SelectedIndex); Assert.AreSame(myBO, cmbox.Items[index]); Assert.AreEqual(origToString, cmbox.Items[index].ToString()); Assert.AreNotEqual(index, cmbox.SelectedIndex); //---------------Execute Test ---------------------- myBO.MyBoID = newValue; //---------------Test Result ----------------------- string newToString = myBO.ToString(); Assert.AreNotEqual(origToString, newToString); Assert.AreEqual(0, cmbox.SelectedIndex); }
public void Test_WhenUsingCreator_WhenBusinessObejctAddedToCollection_ShouldAddTab() { BusinessObjectControlCreatorDelegate creator; IBOColTabControl boColTabControl = CreateBOTabControlWithControlCreator(out creator); MyBO addedBo = new MyBO(); BusinessObjectCollection <MyBO> myBoCol = new BusinessObjectCollection <MyBO> { new MyBO(), new MyBO(), new MyBO() }; boColTabControl.BusinessObjectCollection = myBoCol; bool pageAddedEventFired = false; TabPageEventArgs ex = null; boColTabControl.TabPageAdded += (sender, e) => { pageAddedEventFired = true; ex = e; }; //---------------Assert Precondition---------------- Assert.AreEqual(3, boColTabControl.TabControl.TabPages.Count); Assert.IsFalse(pageAddedEventFired); //---------------Execute Test ---------------------- boColTabControl.BusinessObjectCollection.Add(addedBo); //---------------Test Result ----------------------- Assert.AreEqual(4, boColTabControl.TabControl.TabPages.Count); ITabPage tabPage = boColTabControl.TabControl.TabPages[3]; Assert.AreEqual(addedBo.ToString(), tabPage.Text); Assert.AreEqual(addedBo.ToString(), tabPage.Name); Assert.AreEqual(1, tabPage.Controls.Count); IControlHabanero boControl = tabPage.Controls[0]; Assert.IsTrue(pageAddedEventFired); Assert.IsNotNull(ex); Assert.AreSame(tabPage, ex.TabPage); Assert.AreSame(boControl, ex.BOControl); }
public void TestSerialiseDeserialiseBusinessObjectCollection_CreatedBusObjAreIncluded() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); Structure.Car.LoadDefaultClassDef(); OrganisationPerson.LoadDefaultClassDef(); Person.LoadDefaultClassDef(); BusinessObjectCollection <Person> originalPeople = new BusinessObjectCollection <Person>(); originalPeople.CreateBusinessObject(); originalPeople.CreateBusinessObject(); IFormatter formatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); FixtureEnvironment.ClearBusinessObjectManager(); //---------------Assert PreConditions--------------- Assert.AreEqual(2, originalPeople.CreatedBusinessObjects.Count); Assert.AreEqual(2, originalPeople.Count); //---------------Execute Test ---------------------- formatter.Serialize(memoryStream, originalPeople); memoryStream.Seek(0, SeekOrigin.Begin); BusinessObjectCollection <Person> deserialisedPeople = (BusinessObjectCollection <Person>)formatter.Deserialize(memoryStream); //---------------Test Result ----------------------- Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count); Assert.AreEqual(originalPeople.CreatedBusinessObjects.Count, deserialisedPeople.CreatedBusinessObjects.Count); Assert.AreEqual(originalPeople.PersistedBusinessObjects.Count, deserialisedPeople.PersistedBusinessObjects.Count); Assert.AreEqual(originalPeople.AddedBusinessObjects.Count, deserialisedPeople.AddedBusinessObjects.Count); Assert.AreEqual(originalPeople.RemovedBusinessObjects.Count, deserialisedPeople.RemovedBusinessObjects.Count); Assert.AreEqual(originalPeople.MarkedForDeleteBusinessObjects.Count, deserialisedPeople.MarkedForDeleteBusinessObjects.Count); AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[0], originalPeople.CreatedBusinessObjects[0]); AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[1], originalPeople.CreatedBusinessObjects[1]); }
public override void Test_Set_SelectedBusinessObject_SetsItem() { //---------------Set up test pack------------------- IBOColSelectorControl colSelector = CreateSelector(); MyBO myBO = new MyBO(); MyBO myBO2 = new MyBO(); BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO> { myBO, myBO2 }; colSelector.BusinessObjectCollection = collection; SetSelectedIndex(colSelector, ActualIndex(0)); //---------------Assert Precondition---------------- Assert.AreEqual (collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and others"); // Assert.AreEqual(ActualIndex(1), SelectedIndex(selector)); Assert.AreSame(myBO, colSelector.SelectedBusinessObject); //---------------Execute Test ---------------------- colSelector.SelectedBusinessObject = myBO2; //---------------Test Result ----------------------- Assert.AreSame(myBO2, colSelector.SelectedBusinessObject); Assert.AreEqual(ActualIndex(1), SelectedIndex(colSelector)); }
protected static BusinessObjectCollection <MyBO> CreateCollectionWith_4_Objects() { MyBO cp = new MyBO(); cp.TestProp = "b"; cp.Save(); MyBO cp2 = new MyBO(); cp2.TestProp = "d"; cp2.Save(); MyBO cp3 = new MyBO(); cp3.TestProp = "c"; cp3.Save(); MyBO cp4 = new MyBO(); cp4.TestProp = "a"; cp4.Save(); BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>(); col.Add(cp, cp2, cp3, cp4); return(col); }
public virtual void Test_SelectedBusinessObject_Null_DoesNothing() { //---------------Set up test pack------------------- //The control is being swapped out // onto each tab i.e. all the tabs use the Same BusinessObjectControl // setting the selected Bo to null is therefore not a particularly // sensible action on a BOTabControl.t up test pack------------------- ITabControl tabControl = CreateTabControl(); BOColTabControlManager selectorManager = CreateBOTabControlManager(tabControl); MyBO myBO = new MyBO(); BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO> { myBO }; selectorManager.BusinessObjectCollection = collection; selectorManager.CurrentBusinessObject = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBusinessObject selectedBusinessObject = selectorManager.CurrentBusinessObject; //---------------Test Result ----------------------- Assert.IsNotNull(selectedBusinessObject); }
public void TestRemoveRelatedObject_PersistBOToDataStore() { //-----Create Test pack--------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); AddressTestBO address; ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString()); //-----Assert Precondition------------------ Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.Count); //-----Run tests---------------------------- BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses; addresses.Remove(address); address.Save(); ////-----Test results------------------------- Assert.AreEqual(0, addresses.RemovedBusinessObjects.Count); Assert.AreEqual(0, addresses.Count); Assert.AreEqual(0, addresses.PersistedBusinessObjects.Count); }
public void TestAddMethod_RestoreBusinessObject() { //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- myBO.CancelEdits(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); }
public void Test_SetComboBoxCollection_IncludeBlank_True() { //---------------Set up test pack------------------- var cmbox = GetControlFactory().CreateComboBox(); DisposeOnTearDown(cmbox); var controlFactory = GetControlFactory(); var selectorManager = new ComboBoxCollectionSelector(cmbox, controlFactory); DisposeOnTearDown(selectorManager); MyBO.LoadDefaultClassDef(); var firstBo = new MyBO(); var myBoCol = new BusinessObjectCollection <MyBO> { firstBo, new MyBO(), new MyBO() }; //---------------Execute Test ---------------------- selectorManager.SetCollection(myBoCol); //---------------Test Result ----------------------- Assert.AreSame(firstBo, selectorManager.SelectedBusinessObject); Assert.AreEqual(4, cmbox.Items.Count); }
public void TestAddMethod_Refresh_LoadWithCriteria_BusinessObject() { //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); cpCol.Load("Surname='bbb'", ""); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("aaa"); cpCol.Add(myBO); _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- cpCol.Refresh(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); }
public void Test_BusinessObjectEdited_WhenMultiSelected_ShouldRemainMultiSelected() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); var listBox = GetControlFactory().CreateListBox(); var manager = CreateListBoxCollectionManager(listBox); var boToBeUpdated = new MyBO(); var myBoCol = new BusinessObjectCollection <MyBO> { new MyBO(), boToBeUpdated }; manager.BusinessObjectCollection = myBoCol; manager.Control.SetSelected(1, true); //---------------Assert Precondition---------------- Assert.IsTrue(manager.Control.SelectedItems.Contains(boToBeUpdated)); //---------------Execute Test ---------------------- boToBeUpdated.TestProp = GetRandomString(); boToBeUpdated.Save(); //---------------Test Result ----------------------- Assert.IsTrue(manager.Control.SelectedItems.Contains(boToBeUpdated), "Should still be multi selected"); }
public void Test_MarkForDelete_Added_AddBo() { //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB"); cpCol.Add(myBO); myBO.MarkForDelete(); _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- cpCol.Add(myBO); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); }
public void Test_SetCollection() { //---------------Set up test pack------------------- IEditableGridControl gridControl = GetControlFactory().CreateEditableGridControl(); MyBO.LoadDefaultClassDef(); IClassDef def = ClassDef.ClassDefs[typeof(MyBO)]; gridControl.Initialise(def); BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>(); //--------------Assert PreConditions---------------- //---------------Execute Test ---------------------- gridControl.Grid.BusinessObjectCollection = col; //---------------Test Result ----------------------- Assert.IsFalse(gridControl.Grid.ReadOnly); Assert.IsTrue(gridControl.Grid.AllowUserToAddRows); Assert.IsTrue(gridControl.Grid.AllowUserToDeleteRows); Assert.AreEqual(1, gridControl.Grid.Rows.Count); //---------------Tear Down ------------------------- }
public void Test_MarkForDelete_Added_RefreshAll() { //---------------Set up test pack------------------- ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); cpCol.Load(new Criteria("Surname", Criteria.ComparisonOp.Equals, TestUtil.GetRandomString()), ""); cpCol.Add(myBO); myBO.MarkForDelete(); _businessObjectCollectionTestHelper.RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); //---------------Execute Test ---------------------- cpCol.Refresh(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedAndRemovedEventsNotFired(); }
public void SaveConfig(string[] name, int rolepkid) { Session session = new Session(); try { session.BeginTransaction(); BusinessObjectCollection rolemenucollection = new BusinessObjectCollection("RoleMenu"); rolemenucollection.SessionInstance = session; BusinessFilter filter = new BusinessFilter("RoleMenu"); filter.AddFilterItem("FK_Role", rolepkid.ToString(), Operation.Equal, FilterType.NumberType, AndOr.AND); filter.AddFilterItem("IsValid", "1", Operation.Equal, FilterType.NumberType, AndOr.AND); rolemenucollection.AddFilter(filter); rolemenucollection.DeleteFilter(); for (int index = 0; index < name.Length; index++) { RoleMenu rolemenu = new RoleMenu(); rolemenu.SessionInstance = session; rolemenu.FK_Menu.Value = int.Parse(name[index].ToString()); rolemenu.FK_Role.Value = rolepkid; rolemenu.CreateUser.Value = GlobalFacade.SystemContext.GetContext().UserID; rolemenu.ModifyUser.Value = GlobalFacade.SystemContext.GetContext().UserID; rolemenu.CreateTime.Value = DateTime.Now; rolemenu.ModifyTime.Value = DateTime.Now; rolemenu.IsValid.Value = true; rolemenu.Insert(); } session.Commit(); BusinessRule.SystemManage.OperationLog opLog = new BusinessRule.SystemManage.OperationLog(); opLog.WriteOperationLog("界面权限管理", "配置界面权限"); } catch { session.Rollback(); } }
public void SaveRegionConfig(string[] name, int rolepkid) { Session session = new Session(); try { session.BeginTransaction(); BusinessObjectCollection regioncollection = new BusinessObjectCollection("RoleDataPermission"); regioncollection.SessionInstance = session; BusinessFilter filter = new BusinessFilter("RoleDataPermission"); filter.AddFilterItem("FK_Role", rolepkid.ToString(), Operation.Equal, FilterType.NumberType, AndOr.AND); filter.AddFilterItem("Type", Convert.ToString((int)DictionaryType.Region), Operation.Equal, FilterType.NumberType, AndOr.AND); regioncollection.AddFilter(filter); regioncollection.DeleteFilter(); for (int index = 0; index < name.Length; index++) { BusinessMapping.RoleDataPermission regionright = new RoleDataPermission(); regionright.SessionInstance = session; regionright.FK_Role.Value = rolepkid; regionright.Type.Value = 1; regionright.FK_Dictionary.Value = int.Parse(name[index].ToString()); regionright.CreateUser.Value = SystemContext.GetContext().UserID; regionright.ModifyUser.Value = SystemContext.GetContext().UserID; regionright.CreateTime.Value = regionright.ModifyTime.Value = DateTime.Now; regionright.Insert(); } session.Commit(); OperationLog opLog = new OperationLog(); opLog.WriteOperationLog("数据权限管理", "配置数据权限"); } catch { session.Rollback(); } }
public void Test_ResetParent_PersistedChild() { //The Tyre may however be transferred from one car to another. //---------------Set up test pack------------------- OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); BusinessObjectCollection <ContactPersonTestBO> cpCol; GetAggregateRelationship(organisationTestBO, out cpCol); ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject(); contactPerson.Surname = TestUtil.GetRandomString(); contactPerson.FirstName = TestUtil.GetRandomString(); contactPerson.Save(); OrganisationTestBO alternateOrganisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); //---------------Assert Precondition---------------- util.AssertOneObjectInCurrentPersistedCollection(cpCol); Assert.IsFalse(contactPerson.Status.IsNew); Assert.AreSame(contactPerson.Organisation, organisationTestBO); // Assert.AreEqual(0, cpAltCol.Count); //---------------Execute Test ---------------------- contactPerson.Organisation = alternateOrganisationTestBO; //---------------Test Result ----------------------- Assert.AreEqual(0, cpCol.Count); Assert.IsFalse(cpCol.Contains(contactPerson)); util.AssertOneObjectInRemovedAndPersisted(cpCol); MultipleRelationship <ContactPersonTestBO> relationship = alternateOrganisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople"); BusinessObjectCollection <ContactPersonTestBO> cpAltCol = relationship.BusinessObjectCollection; Assert.AreSame(contactPerson.Organisation, relationship.OwningBO); Assert.AreSame(alternateOrganisationTestBO, contactPerson.Organisation); util.AssertOneObjectInCurrentAndAddedCollection(cpAltCol); }
public void Test_ShowGridAndBOEditorControlWinOnClick() { //--------------- Set up test pack ------------------ BusinessObjectCollection <OrganisationTestBO> organisationTestBOS = CreateSavedOrganisationTestBOSCollection(); IControlFactory controlFactory = GetControlFactory(); IExtendedComboBox extendedComboBox = CreateExtendedComboBox(); const string propName = "OrganisationID"; ExtendedComboBoxMapper mapper = new ExtendedComboBoxMapper( extendedComboBox, propName, true, controlFactory); mapper.BusinessObject = new ContactPersonTestBO(); // mapper.RelatedBusinessObject = OrganisationTestBO.CreateSavedOrganisation(); //--------------- Test Preconditions ---------------- Assert.IsNull(mapper.PopupForm); //--------------- Execute Test ---------------------- //extendedComboBox.Button.PerformClick(); mapper.ShowPopupForm(); //--------------- Test Result ----------------------- Assert.IsNotNull(mapper.PopupForm); IFormHabanero form = mapper.PopupForm; Assert.AreEqual(800, form.Width); Assert.AreEqual(600, form.Height); Assert.AreEqual(1, form.Controls.Count); Assert.AreEqual(DockStyle.Fill, form.Controls[0].Dock); Assert.IsInstanceOf(typeof(IBOGridAndEditorControl), form.Controls[0]); IBOGridAndEditorControl andBOGridAndEditorControlWin = (IBOGridAndEditorControl)form.Controls[0]; //Assert.AreSame(mapper.BusinessObject, BOGridAndEditorControlWin.BOEditorControlWin.BusinessObject); Assert.IsTrue(andBOGridAndEditorControlWin.GridControl.IsInitialised); IBusinessObjectCollection collection = andBOGridAndEditorControlWin.GridControl.Grid.BusinessObjectCollection; Assert.IsNotNull(collection); Assert.AreEqual(organisationTestBOS.Count, collection.Count); Assert.AreEqual(organisationTestBOS.Count, mapper.LookupList.Count); }
/// <summary> /// Loads the List as DataSource for PivotGridControl /// </summary> private void LoadList() { this.Target.ItemSource = null; this.Target.ResetPivotData(); this.Target.ItemSource = BusinessObjectCollection.GetList(200); this.Target.PivotRows.Add(new PivotItem() { FieldMappingName = "Fruit", FieldHeader = "Fruit", TotalHeader = "Total" }); this.Target.PivotRows.Add(new PivotItem() { FieldMappingName = "Color", FieldHeader = "Color", TotalHeader = "Total" }); this.Target.PivotColumns.Add(new PivotItem() { FieldMappingName = "Shape", FieldHeader = "Shape", TotalHeader = "Total" }); this.Target.PivotColumns.Add(new PivotItem() { FieldMappingName = "Even", FieldHeader = "Even", TotalHeader = "Total" }); this.Target.PivotCalculations.Add(new PivotComputationInfo() { FieldName = "Count", FieldHeader = "Count", SummaryType = SummaryType.DoubleTotalSum }); this.Target.PivotCalculations.Add(new PivotComputationInfo() { FieldName = "Section", FieldHeader = "Section", SummaryType = SummaryType.DoubleTotalSum }); this.Target.PivotCalculations.Add(new PivotComputationInfo() { FieldName = "Weight", FieldHeader = "Weight", SummaryType = SummaryType.DoubleTotalSum }); }
public void TestSerialiseDeserialiseBusinessObjectCollection() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); Structure.Car.LoadDefaultClassDef(); OrganisationPerson.LoadDefaultClassDef(); Person.LoadDefaultClassDef(); BusinessObjectCollection <Person> originalPeople = new BusinessObjectCollection <Person>(); Person person1 = Person.CreateSavedPerson(); originalPeople.Add(person1); Person person2 = Person.CreateSavedPerson(); originalPeople.Add(person2); Person person3 = Person.CreateSavedPerson(); originalPeople.Add(person3); IFormatter formatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); FixtureEnvironment.ClearBusinessObjectManager(); //---------------Execute Test ---------------------- formatter.Serialize(memoryStream, originalPeople); memoryStream.Seek(0, SeekOrigin.Begin); BusinessObjectCollection <Person> deserialisedPeople = (BusinessObjectCollection <Person>)formatter.Deserialize(memoryStream); //---------------Test Result ----------------------- Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count); Assert.AreNotSame(originalPeople, deserialisedPeople); AssertPersonsAreEqual(deserialisedPeople[0], originalPeople[0]); AssertPersonsAreEqual(deserialisedPeople[1], originalPeople[1]); AssertPersonsAreEqual(deserialisedPeople[2], originalPeople[2]); }
public virtual void TestRejectChanges() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); IClassDef classDef1 = MyBO.LoadDefaultClassDef(); MyBO myBO = new MyBO(); string originalValue = TestUtil.GetRandomString(); myBO.TestProp = originalValue; myBO.Save(); IFormHabanero frm; IStaticDataEditor editor = CreateEditorOnForm(out frm); IEditableGridControl gridControl = (IEditableGridControl)editor.Controls[0]; editor.AddSection(TestUtil.GetRandomString()); string itemName1 = TestUtil.GetRandomString(); editor.AddItem(itemName1, classDef1); editor.SelectItem(itemName1); //---------------Execute Test ---------------------- gridControl.Grid.SelectedBusinessObject = myBO; string newValue = TestUtil.GetRandomString(); gridControl.Grid.CurrentRow.Cells["TestProp"].Value = newValue; bool result = editor.RejectChanges(); //---------------Test Result ----------------------- Assert.IsTrue(result); BusinessObjectCollection <MyBO> collection = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <MyBO>(""); Assert.AreEqual(1, collection.Count); Assert.AreEqual(originalValue, myBO.TestProp); Assert.IsFalse(myBO.Status.IsDirty); //---------------Tear Down ------------------------- TearDownForm(frm); }
public void Test_EditDataTable_ToDBNull_EditsBo() { //---------------Set up test pack------------------- BusinessObjectCollection <MyBO> col = null; IDataSetProvider dataSetProvider = GetDataSetProviderWithCollection(ref col); BOMapper mapper = new BOMapper(col.ClassDef.CreateNewBusinessObject()); DataTable table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); MyBO bo1 = col[0]; // const string updatedvalue = "UpdatedValue"; const string columnName = "TestProp"; object origionalPropValue = bo1.GetPropertyValue(columnName); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(4, table.Rows.Count); Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(origionalPropValue, table.Rows[0][columnName]); //---------------Execute Test ---------------------- table.Rows[0][columnName] = DBNull.Value; //---------------Test Result ----------------------- Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(DBNull.Value, table.Rows[0][columnName]); Assert.AreEqual(null, bo1.GetPropertyValue(columnName)); }
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 Test_CreatedBo_Remove() { //If you remove a created business object that is not yet persisted then //-- remove from the restored and saved event. //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(); Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count); ContactPersonTestBO createdCp = cpCol.CreateBusinessObject(); createdCp.Surname = BOTestUtils.RandomString; RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- Assert.IsTrue(cpCol.Contains(createdCp)); AssertTwoCurrentObjects_OnePsersisted_OneCreated(cpCol); //---------------Execute Test ---------------------- cpCol.Remove(createdCp); //---------------Test Result ----------------------- Assert.IsFalse(cpCol.Contains(createdCp)); AssertOneObjectInCurrentAndPersistedCollection(cpCol); AssertRemovedEventFired(); AssertAddedEventNotFired(); }
public void Test_RemoveCreatedBo_DeregistersForSaveEvent() { //If you remove a created business object that is not yet persisted then //-- remove from the restored and saved event. //-- when the object is saved it should be independent of the collection. //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO(); ContactPersonTestBO createdCp = cpCol.CreateBusinessObject(); createdCp.Surname = BOTestUtils.RandomString; cpCol.Remove(createdCp); RegisterForAddedAndRemovedEvents(cpCol); //---------------Assert Precondition---------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsFalse(cpCol.Contains(createdCp)); //---------------Execute Test ---------------------- createdCp.Save(); //---------------Test Result ----------------------- AssertOneObjectInCurrentAndPersistedCollection(cpCol); Assert.IsFalse(cpCol.Contains(createdCp)); AssertAddedAndRemovedEventsNotFired(); }
/// <summary> /// 获取行政区列表 /// </summary> /// <param name="totalCount">记录总数</param> /// <param name="pageSize">页大小(一次取出的记录数)</param> /// <param name="pageIndex">页码(1开始)</param> /// <param name="obType">排续类型</param> /// <param name="subfilter">筛选条件对象</param> /// <returns>结果集</returns> public DataTable GetDistrictList(out int totalCount, int pageSize, int pageIndex, Common.OrderByType obType, BusinessFilter subfilter) { BusinessRule.BaseData.Region rule = new Region(); Wicresoft.Session.Session session = new Wicresoft.Session.Session(); BusinessObjectCollection boc = new BusinessObjectCollection("District"); boc.SessionInstance = session; BusinessFilter filter = new BusinessFilter("District"); filter.AddFilterItem("IsValid", "1", Operation.Equal, FilterType.NumberType, AndOr.AND); filter.AddCustomerFilter("District.FK_Dictionary IN (" + rule.GetAuthorizedCitiesPKID(GlobalFacade.SystemContext.GetContext().UserID) + ")", AndOr.AND); if (subfilter != null) { filter.AddFilter(subfilter, AndOr.AND); } boc.AddFilter(filter); DataSet ds = boc.GetPagedRecords(pageIndex, pageSize, "PKID", (obType == Common.OrderByType.ASC)?true:false); totalCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]); return(ds.Tables[1]); }
public override void Test_Set_SelectedBusinessObject_Null_SetsItemNull() { //---------------Set up test pack------------------- IBOColSelectorControl colSelector = CreateSelector(); MyBO myBO = new MyBO(); MyBO myBO2 = new MyBO(); BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO> { myBO, myBO2 }; colSelector.BusinessObjectCollection = collection; // SetSelectedIndex(selector, ActualIndex(1)); colSelector.SelectedBusinessObject = myBO2; //---------------Assert Precondition---------------- Assert.AreEqual (collection.Count + NumberOfLeadingBlankRows(), colSelector.NoOfItems, "The blank item and others"); Assert.AreEqual(ActualIndex(1), SelectedIndex(colSelector)); Assert.AreEqual(myBO2, colSelector.SelectedBusinessObject); //---------------Execute Test ---------------------- colSelector.SelectedBusinessObject = null; //---------------Test Result ----------------------- Assert.IsNull(colSelector.SelectedBusinessObject); Assert.AreEqual(1, SelectedIndex(colSelector), "This does not make sense with a collapsible panel similar to a boTabcontrol"); }
public void Test_CreateDisplayValueDictionary_WhenThreeBOsWithSameToStringAndTwoWithAnotherToString_WhenOrdered_ShouldAddIncrementedNumberToToString() { //---------------Set up test pack------------------- //---------NNB person.ToString returns the Surname.----------------- var person = new ContactPersonTestBO { Surname = "A" }; var personBB1 = new ContactPersonTestBO { Surname = "BB" }; var person2 = new ContactPersonTestBO { Surname = "A" }; var personBB2 = new ContactPersonTestBO { Surname = "BB" }; var person3 = new ContactPersonTestBO { Surname = "A" }; var col = new BusinessObjectCollection <ContactPersonTestBO> { person, personBB1, person2, personBB2, person3 }; //---------------Assert Precondition---------------- Assert.AreEqual(5, col.Count); //---------------Execute Test ---------------------- var displayValueDictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(col, true, Convert.ToString); //---------------Test Result ----------------------- Assert.AreEqual(5, displayValueDictionary.Count); Assert.Contains("A", displayValueDictionary.Keys, "The first person in the list returns its ToString"); Assert.Contains("A(2)", displayValueDictionary.Keys, "The second person in the list returns its ToString plus 2"); Assert.Contains("A(3)", displayValueDictionary.Keys, "The third person in the list returns its ToString plus 3"); Assert.Contains("BB", displayValueDictionary.Keys, ""); Assert.Contains("BB(2)", displayValueDictionary.Keys, ""); }
// /// <summary> // /// 返回所有城市的对象集合 // /// </summary> // /// <returns></returns> // public BusinessObjectCollection GetAllCities() // { // BusinessFilter filter = new BusinessFilter("Dictionary"); // filter.AddFilterItem("IsValid", "1", Operation.Equal, FilterType.NumberType, AndOr.AND); // filter.AddFilterItem("Type", Convert.ToInt32(SystemManage.DictionaryType.Region).ToString(), Operation.Equal, FilterType.NumberType, AndOr.AND); // filter.AddFilterItem("Level", SystemManage.Level.City, Operation.Equal, FilterType.NumberType, AndOr.AND); // // BusinessObjectCollection boc = new BusinessObjectCollection("Dictionary"); // boc.SessionInstance = new Session(); // boc.AddFilter(filter); // boc.Query(); // return boc; // } /// <summary> /// 选出所有中心 /// </summary> /// <param name="totalCount"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="obType"></param> /// <param name="filter"></param> /// <returns></returns> public DataTable GetCenterList(out int totalCount, int pageSize, int pageIndex, Common.OrderByType obType, BusinessFilter filter) { Common commonRule = new Common(); BusinessFilter flt = new BusinessFilter("Dictionary"); flt.AddFilterItem("IsValid", "1", Operation.Equal, FilterType.NumberType, AndOr.AND); flt.AddFilterItem("Level", SystemManage.Level.Center, Operation.Equal, FilterType.NumberType, AndOr.AND); flt.AddFilter(filter, AndOr.AND); // Add Data Permission // flt.AddFilter(GetAuthorizedCenterFilter(GlobalFacade.SystemContext.GetContext().UserID), AndOr.AND); BusinessObjectCollection boc = new BusinessObjectCollection("Dictionary"); boc.SessionInstance = new Session(); boc.AddFilter(flt); DataSet ds = boc.GetPagedRecords(pageIndex, pageSize, "PKID", (obType == Common.OrderByType.ASC) ? true : false); totalCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]); return(ds.Tables[1]); }
public void TestRefreshCollectionRefreshesNonDirtyObjects() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorDB(); ContactPersonTestBO.DeleteAllContactPeople(); SetupDefaultContactPersonBO(); var col = new BusinessObjectCollection <ContactPersonTestBO>(); var cp1 = ContactPersonTestBO.CreateSavedContactPerson(); FixtureEnvironment.ClearBusinessObjectManager(); ContactPersonTestBO.CreateSavedContactPerson(); ContactPersonTestBO.CreateSavedContactPerson(); col.LoadAll(); var newSurname = Guid.NewGuid().ToString(); cp1.Surname = newSurname; cp1.Save(); var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID); //--------------------Assert Preconditions---------- Assert.IsFalse(col.Contains(cp1)); Assert.AreEqual(3, col.Count); Assert.AreEqual(newSurname, cp1.Surname); Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname); Assert.IsFalse(cp1.Status.IsDirty); //---------------Execute Test ---------------------- BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col); //---------------Test Result ----------------------- Assert.AreEqual(3, col.Count); Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname); }