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);
        }
Пример #2
0
        public void Test_BOPropUpdated_WhenBONotInComboBox_ShouldNotRaiseError_FixBug()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            IBusinessObjectCollection col;
            IBOColSelectorControl     boColSelector = GetSelectorWith_4_Rows(out col);
            const string propName = "TestProp";
            const int    rowIndex = 1;
            MyBO         bo       = (MyBO)col[rowIndex];

            boColSelector.BusinessObjectCollection = col;
            IBOComboBoxSelector selector = ((IBOComboBoxSelector)boColSelector);
            string origStringValue       = selector.GetItemText(bo);

            selector.ComboBox.Items.Remove(bo);
            //---------------Assert Precondition----------------
            Assert.AreEqual(bo.ToString(), origStringValue);
            Assert.AreEqual(4, selector.ComboBox.Items.Count);
            //---------------Execute Test ----------------------
            const string newPropValue = "NewValue";

            bo.SetPropertyValue(propName, newPropValue);
            bo.Save();
            //---------------Test Result -----------------------
            string newBoItemText = selector.GetItemText(bo);

            Assert.AreNotEqual(origStringValue, newBoItemText);
            Assert.AreEqual(newPropValue + " - " + bo.MyBoID, newBoItemText);
        }
Пример #3
0
        public void TestEditItemFromCollectionUpdatesItemInSelector()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            IBusinessObjectCollection col;
            IBOColSelectorControl     boColSelector = GetSelectorWith_4_Rows(out col);
            const string propName = "TestProp";
            const int    rowIndex = 1;
            MyBO         bo       = (MyBO)col[rowIndex];

            boColSelector.BusinessObjectCollection = col;
            string origStringValue = ((IBOComboBoxSelector)boColSelector).GetItemText(bo);

            //---------------Verify precondition----------------
            Assert.AreEqual(bo.ToString(), origStringValue);
            //---------------Execute Test ----------------------
            const string newPropValue = "NewValue";

            bo.SetPropertyValue(propName, newPropValue);
            bo.Save();
            //---------------Test Result -----------------------
            string newStringValue = ((IBOComboBoxSelector)boColSelector).GetItemText(bo);

            Assert.AreNotEqual(origStringValue, newStringValue);
            Assert.AreEqual(newPropValue + " - " + bo.MyBoID, newStringValue);
        }
Пример #4
0
        public void Test_WhenUsingCreator_WhenBusinessObejctRemovedToCollection_ShouldRemoveTab()
        {
            ITabControl            tabControl            = CreateTabControl();
            IControlFactory        controlFactory        = GetControlFactory();
            BOColTabControlManager selectorManager       = new BOColTabControlManager(tabControl, controlFactory);
            BusinessObjectControlCreatorDelegate creator = BusinessObjectControlCreator;

            selectorManager.BusinessObjectControlCreator = creator;

            MyBO removedBo = new MyBO();
            BusinessObjectCollection <MyBO> myBoCol = new BusinessObjectCollection <MyBO> {
                removedBo, new MyBO(), new MyBO()
            };

            selectorManager.BusinessObjectCollection = myBoCol;
            bool             pageRemovedEventFired = false;
            TabPageEventArgs ex = null;

            selectorManager.TabPageRemoved += (sender, e) =>
            {
                pageRemovedEventFired = true;
                ex = e;
            };
            ITabPage         tabPage = selectorManager.TabControl.TabPages[0];
            IControlHabanero boControlToBeRemoved = tabPage.Controls[0];

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, selectorManager.TabControl.TabPages.Count);
            Assert.IsFalse(pageRemovedEventFired);
            //---------------Execute Test ----------------------
            selectorManager.BusinessObjectCollection.Remove(removedBo);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, selectorManager.TabControl.TabPages.Count);

            Assert.AreEqual(removedBo.ToString(), tabPage.Text);
            Assert.AreEqual(removedBo.ToString(), tabPage.Name);
            Assert.AreEqual(1, tabPage.Controls.Count);

            Assert.IsTrue(pageRemovedEventFired);
            Assert.IsNotNull(ex);
            Assert.AreSame(tabPage, ex.TabPage);
            Assert.AreSame(boControlToBeRemoved, ex.BOControl);
        }
Пример #5
0
        public void Test_BusinessObjectAddedToCollection()
        {
            ITabControl            tabControl      = CreateTabControl();
            BOColTabControlManager selectorManager = CreateBOTabControlManager(tabControl);
            MyBO addedBo = new MyBO();
            BusinessObjectCollection <MyBO> myBoCol = new BusinessObjectCollection <MyBO>
            {
                new MyBO(), new MyBO(), new MyBO()
            };

            selectorManager.BusinessObjectCollection = myBoCol;
            //---------------Assert Precondition----------------
            Assert.AreEqual(3, selectorManager.TabControl.TabPages.Count);
            //---------------Execute Test ----------------------
            selectorManager.BusinessObjectCollection.Add(addedBo);
            //---------------Test Result -----------------------
            Assert.AreEqual(4, selectorManager.TabControl.TabPages.Count);
            Assert.AreEqual(addedBo.ToString(), selectorManager.TabControl.TabPages[3].Text);
            Assert.AreEqual(addedBo.ToString(), selectorManager.TabControl.TabPages[3].Name);
        }
Пример #6
0
        public void Test_WhenUsingCreator_WhenBusinessObejctAddedToCollection_ShouldAddTab_CorrectName()
        {
            BusinessObjectControlCreatorDelegate creator;
            IBOColTabControl boColTabControl = CreateBOTabControlWithControlCreator(out creator);

            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 ----------------------
            MyBO addedBo = new MyBO();

            boColTabControl.BusinessObjectCollection.Add(addedBo);
            addedBo.TestProp = TestUtil.GetRandomString();
            //---------------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);
        }
Пример #7
0
        public void Test_EditUnselectedItemFromCollection_UpdatesItemInCombo_DoesNotSelectItem_WithBlank()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();

            DisposeOnTearDown(cmbox);
            IControlFactory            controlFactory  = GetControlFactory();
            ComboBoxCollectionSelector selectorManager = new ComboBoxCollectionSelector(cmbox, controlFactory, false);

            DisposeOnTearDown(selectorManager);
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO> {
                { new MyBO(), new MyBO() }
            };

            selectorManager.SetCollection(myBOs);
            MyBO   myBO         = myBOs[1];
            string origToString = myBO.ToString();
            Guid   newValue     = Guid.NewGuid();
            int    index        = cmbox.Items.IndexOf(myBO);

            //---------------Assert precondition----------------
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.AreEqual(-1, 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(-1, cmbox.SelectedIndex);
//            Assert.AreNotEqual(origToString, cmbox.Text);
//            Assert.AreEqual(newToString, cmbox.Text);
        }
        public void Setup()
        {
            ClassDef.ClassDefs.Clear();
            FixtureEnvironment.SetupInMemoryDataAccessor();
            FixtureEnvironment.SetupNewIsolatedBusinessObjectManager();
            MyBO.LoadClassDefsNoUIDef();
            _propDefGuid = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
            _validBusinessObject = new MyBO { TestProp = "ValidValue" };
            _collection = new BusinessObjectCollection<MyBO> { _validBusinessObject };
            _validLookupValue = _validBusinessObject.ToString();

            _propDefGuid.LookupList = new BusinessObjectLookupListStub(typeof(MyBO), _collection);
            _validBusinessObjectNotInList = new MyBO { TestProp = "AnotherValue" };
            ClassDef.ClassDefs.Clear();
        }
Пример #9
0
        public void Test_CancelEditsItemFromCollection_UpdatesItemInCombo()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            IComboBox cmbox = GetControlFactory().CreateComboBox();

            DisposeOnTearDown(cmbox);
            IControlFactory            controlFactory  = GetControlFactory();
            ComboBoxCollectionSelector selectorManager = new ComboBoxCollectionSelector(cmbox, controlFactory)
            {
                IncludeBlankItem = false
            };

            DisposeOnTearDown(selectorManager);
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO> {
                { new MyBO(), new MyBO() }
            };

            selectorManager.SetCollection(myBOs);
            MyBO myBO     = myBOs[0];
            Guid newValue = Guid.NewGuid();
            int  index    = cmbox.Items.IndexOf(myBO);

            cmbox.SelectedIndex = index;
            myBO.MyBoID         = newValue;
            myBO.Save();
            //---------------Assert precondition----------------
            Assert.AreEqual(2, cmbox.Items.Count);
            Assert.AreEqual(0, cmbox.SelectedIndex);
            Assert.AreSame(myBO, cmbox.Items[index]);
            Assert.AreEqual(index, cmbox.SelectedIndex);
            //---------------Execute Test ----------------------
            myBO.MyBoID = Guid.NewGuid();
            myBO.CancelEdits();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, cmbox.SelectedIndex);
            Assert.AreEqual(index, cmbox.SelectedIndex);
            Assert.AreSame(myBO, cmbox.Items[index]);
            string newToString = myBO.ToString();

            Assert.AreEqual(newToString, cmbox.Items[index].ToString());
        }
Пример #10
0
        public void TestInitialLayout()
        {
            //---------------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);

            //---------------Execute Test ----------------------
            boColTabControl.BusinessObjectCollection = myBoCol;

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boColTabControl.TabControl.TabPages[0].Controls.Count);
            Assert.AreSame(busControl, boColTabControl.TabControl.TabPages[0].Controls[0]);
            Assert.AreEqual(DockStyle.Fill, busControl.Dock);
            Assert.AreEqual(firstBo.ToString(), boColTabControl.TabControl.TabPages[0].Text);
        }
        public void Test_CreateDisplayValueDictionary_WhenToStringIsNull_ShouldNotRaiseError()
        {
            //--------------- Set up test pack ------------------
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();

            myBO1.SetToString(null);
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO> {
                myBO1
            };

            //--------------- Test Preconditions ----------------
            Assert.IsNull(myBO1.ToString());
            //--------------- Execute Test ----------------------
            Dictionary <string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);

            //--------------- Test Result -----------------------
            Assert.AreEqual(1, dictionary.Count);
        }
 public void Test_CreateDisplayValueDictionary_WhenToStringIsNull_ShouldNotRaiseError()
 {
     //--------------- Set up test pack ------------------
     MyBO.LoadDefaultClassDef();
     MyBO.DeleteAllMyBos();
     FixtureEnvironment.ClearBusinessObjectManager();
     TestUtil.WaitForGC();
     MyBO myBO1 = new MyBO();
     myBO1.SetToString(null);
     BusinessObjectCollection<MyBO> myBOs = new BusinessObjectCollection<MyBO> {myBO1};
     //--------------- Test Preconditions ----------------
     Assert.IsNull(myBO1.ToString());
     //--------------- Execute Test ----------------------
     Dictionary<string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);
     //--------------- Test Result -----------------------
     Assert.AreEqual(1, dictionary.Count);
 }
 public void TestPropertyValueToDisplay_BusinessObjectLookupList_NotInList()
 {
     MyBO.LoadDefaultClassDef();
     IBusinessObject businessObject = GetBusinessObjectStub();
     BOProp boProp = (BOProp) businessObject.Props[_propDefGuid.PropertyName];
     MyBO bo1 = new MyBO {TestProp = "PropValue"};
     string expectedPropValueToDisplay = bo1.ToString();
     object expctedID = bo1.MyBoID;
     bo1.Save();
     PropDef propDef = (PropDef) boProp.PropDef;
     //---------------Assert Precondition----------------
     Assert.AreEqual(typeof (Guid), propDef.PropertyType);
     Assert.IsNull(boProp.Value);
     Assert.IsFalse(bo1.Status.IsNew);
     //---------------Execute Test ----------------------
     boProp.Value = expctedID;
     //---------------Test Result -----------------------
     Assert.AreEqual(expctedID, boProp.Value);
     Assert.AreEqual(expectedPropValueToDisplay, boProp.PropertyValueToDisplay);
 }