This manager groups common logic for IBOColTabControl objects. Do not use this object in working code - rather call CreateBOColTabControl in the appropriate control factory. This Manager is an extract of common functionality required for the IBOColTabControl it is used to as part of the pattern to isolate the implementation of the actual BOColTabControl from the code using the BOColTabControl. This allows the developer to swap IBOColTabControls that support this interface without having to redevelop any code. Habanero uses this to isolate the UIframework so that a different framework can be implemented using these interfaces. This allows swapping in custom controls as well total other control libraries without modifying the app. This allows the Architecture to swap between Visual Web Gui and Windows or in fact between any UI framework and any other UI Framework.
 public void TestConstructor()
 {
     //---------------Set up test pack-------------------
     ITabControl tabControl = GetControlFactory().CreateTabControl();
     //---------------Execute Test ----------------------
     BOColTabControlManager colTabCtlMapper = new BOColTabControlManager(tabControl, GetControlFactory());
     //---------------Test Result -----------------------
     Assert.IsNotNull(colTabCtlMapper);
     Assert.IsNotNull(colTabCtlMapper.PageBoTable);
     Assert.IsNotNull(colTabCtlMapper.BoPageTable);
     Assert.AreSame(tabControl,colTabCtlMapper.TabControl);
     //---------------Tear down -------------------------
 }
        public void TestSetBusinessObjectControl()
        {
            //---------------Set up test pack-------------------
            ITabControl tabControl = GetControlFactory().CreateTabControl();
            BOColTabControlManager colTabCtlMapper = new BOColTabControlManager(tabControl, GetControlFactory());
            //---------------Execute Test ----------------------
            IBusinessObjectControl busControl = CreateBusinessObjectControl();
            colTabCtlMapper.BusinessObjectControl = busControl;

            //---------------Test Result -----------------------
            Assert.AreSame(busControl, colTabCtlMapper.BusinessObjectControl);
            //---------------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 TestSetCollection()
        {
            //---------------Set up test pack-------------------

            MyBO.LoadDefaultClassDef();
            ITabControl tabControl = GetControlFactory().CreateTabControl();
            BOColTabControlManager colTabCtlMapper = new BOColTabControlManager(tabControl, GetControlFactory());
            IBusinessObjectControl busControl = this.CreateBusinessObjectControl();
            colTabCtlMapper.BusinessObjectControl = busControl;
            //---------------Execute Test ----------------------
            BusinessObjectCollection<MyBO> myBoCol = new BusinessObjectCollection<MyBO>();
            myBoCol.Add(new MyBO());
            myBoCol.Add(new MyBO());
            myBoCol.Add(new MyBO());
            colTabCtlMapper.BusinessObjectCollection = myBoCol;
            //---------------Test Result -----------------------
            Assert.AreSame(myBoCol, colTabCtlMapper.BusinessObjectCollection);
            Assert.AreEqual(3, colTabCtlMapper.TabControl.TabPages.Count);
            //---------------Tear down -------------------------
        }
        public void TestConstructor()
        {
            //---------------Set up test pack-------------------
            ITabControl tabControl = CreateTabControl();
            IControlFactory controlFactory = GetControlFactory();
            //---------------Execute Test ----------------------
            BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
            //---------------Test Result -----------------------
            Assert.IsNotNull(selectorManager);
            Assert.AreSame(tabControl, selectorManager.TabControl);
//            Assert.AreSame(controlFactory, selectorManager.ControlFactory);

        }
 protected virtual BOColTabControlManager CreateBOTabControlManager(ITabControl tabControl)
 {
     IControlFactory controlFactory = GetControlFactory();
     BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
     selectorManager.BusinessObjectControl = GetBusinessObjectControl();
     return selectorManager;
 }
 protected virtual BOColTabControlManager GetselectorManager(out BusinessObjectControlCreatorDelegate creator)
 {
     IControlFactory controlFactory = GetControlFactory();
     ITabControl tabControl = controlFactory.CreateTabControl();
     BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
     creator = BusinessObjectControlCreator;
     selectorManager.BusinessObjectControlCreator = creator;
     return selectorManager;
 }
        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);
        }
 public void Test_WhenUsingCreator_SetUpBOTabColManagerWithDelegateForCreating_aBOControl()
 {
     //---------------Set up test pack-------------------
     ITabControl tabControl = CreateTabControl();
     IControlFactory controlFactory = GetControlFactory();
     BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
     BusinessObjectControlCreatorDelegate creator = BusinessObjectControlCreator;
     //---------------Assert Precondition----------------
     Assert.IsNull(selectorManager.BusinessObjectControlCreator);
     //---------------Execute Test ----------------------
     selectorManager.BusinessObjectControlCreator = creator;
     //---------------Test Result -----------------------
     Assert.IsNotNull(selectorManager.BusinessObjectControlCreator);
     Assert.AreEqual(creator, selectorManager.BusinessObjectControlCreator);
 }
 public void Test_Set_SelectedBusinessObject_BOColNull_ShouldRaiseError()
 {
     //---------------Set up test pack-------------------
     ITabControl tabControl = CreateTabControl();
     IControlFactory controlFactory = GetControlFactory();
     BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
     MyBO selectedBO = new MyBO();
     selectorManager.BusinessObjectControl = this.GetBusinessObjectControl();
     selectorManager.BusinessObjectCollection = null;
     //---------------Assert Precondition----------------
     Assert.IsNull(selectorManager.BusinessObjectCollection);
     Assert.IsNotNull(selectorManager.BusinessObjectControl);
     //---------------Execute Test ----------------------
     try
     {
         selectorManager.CurrentBusinessObject = selectedBO;
         Assert.Fail("expected Err");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         const string expectedMessage = "You cannot set the 'CurrentBusinessObject' for BOColTabControlManager since the BusinessObjectCollection has not been set";
         StringAssert.Contains(expectedMessage, ex.Message);
     }
 }
 public void Test_Set_SelectedBusinessObject()
 {
     //---------------Set up test pack-------------------
     ITabControl tabControl = CreateTabControl();
     IControlFactory controlFactory = GetControlFactory();
     BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
     MyBO selectedBO = new MyBO();
     BusinessObjectCollection<MyBO> myBoCol = new BusinessObjectCollection<MyBO>
                                                  {new MyBO(), selectedBO, new MyBO()};
     selectorManager.BusinessObjectControl = GetBusinessObjectControl();
     //---------------Execute Test ----------------------
     selectorManager.BusinessObjectCollection = myBoCol;
     selectorManager.CurrentBusinessObject = selectedBO;
     //---------------Test Result -----------------------
     Assert.AreEqual(selectedBO, selectorManager.CurrentBusinessObject);
 }
		public void Test_Set_CurrentBusinessObject_WhenUsingABusinessObjectControl_ShouldOnlySetBOOnce()
        {
            //---------------Set up test pack-------------------
            ITabControl tabControl = CreateTabControl();
            IControlFactory controlFactory = GetControlFactory();
			BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
			MyBO firstBo;
			BusinessObjectCollection<MyBO> myBoCol = GetMyBoCol_3Items(out firstBo);
        	var list = new List<IBusinessObject>();
        	var businessObjectControl = GetBusinessObjectControlSpy(list.Add);
        	selectorManager.BusinessObjectControl = businessObjectControl;
            selectorManager.BusinessObjectCollection = myBoCol;
			list.Clear();
			//---------------Assert Precondition----------------
			Assert.IsTrue(selectorManager.AutoSelectFirstItem);
			Assert.AreEqual(0, list.Count);
            //---------------Execute Test ----------------------
        	var newSelectedBo = myBoCol[1];
        	selectorManager.CurrentBusinessObject = newSelectedBo;
            //---------------Test Result -----------------------
			Assert.AreEqual(1, list.Count);
			Assert.AreEqual(newSelectedBo, list[0]);
        }
		public void Test_Set_Collection_WhenUsingABusinessObjectControl_ShouldSetToCurrentBO()
        {
            //---------------Set up test pack-------------------
            ITabControl tabControl = CreateTabControl();
            IControlFactory controlFactory = GetControlFactory();
			BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
			MyBO firstBo;
			BusinessObjectCollection<MyBO> myBoCol = GetMyBoCol_3Items(out firstBo);
        	var businessObjectControl = GetBusinessObjectControl();
        	selectorManager.BusinessObjectControl = businessObjectControl;
			selectorManager.AutoSelectFirstItem = true;
			//---------------Assert Precondition----------------
			Assert.IsTrue(selectorManager.AutoSelectFirstItem);
            //---------------Execute Test ----------------------
            selectorManager.BusinessObjectCollection = myBoCol;
            //---------------Test Result -----------------------
			Assert.AreSame(selectorManager.CurrentBusinessObject, businessObjectControl.BusinessObject);
        }
		public void Test_Set_Collection_ShouldPopulateTabs()
        {
            //---------------Set up test pack-------------------
            ITabControl tabControl = CreateTabControl();
            IControlFactory controlFactory = GetControlFactory();
            BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
            BusinessObjectCollection<MyBO> myBoCol = new BusinessObjectCollection<MyBO>
                                                         {new MyBO(), new MyBO(), new MyBO()};
            selectorManager.BusinessObjectControl = GetBusinessObjectControl();
            //---------------Execute Test ----------------------
            selectorManager.BusinessObjectCollection = myBoCol;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, selectorManager.BusinessObjectCollection.Count);
            Assert.AreEqual(3, selectorManager.TabControl.TabPages.Count);
        }
 	public void Test_Set_Collection_WhenBOControlNotSet_ShouldRaiseError()
 	{
 		//---------------Set up test pack-------------------
 		ITabControl tabControl = CreateTabControl();
 		IControlFactory controlFactory = GetControlFactory();
 		BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, controlFactory);
 		BusinessObjectCollection<MyBO> myBoCol = new BusinessObjectCollection<MyBO> { new MyBO(), new MyBO(), new MyBO() };
 		//---------------Assert Precondition----------------
 		Assert.IsNull(selectorManager.BusinessObjectCollection);
 		Assert.IsNull(selectorManager.BusinessObjectControl);
 		//---------------Execute Test ----------------------
 		try
 		{
 			selectorManager.BusinessObjectCollection = myBoCol;
 			Assert.Fail("expected Err");
 		}
 			//---------------Test Result -----------------------
 		catch (HabaneroDeveloperException ex)
 		{
 			const string expectedMessage = "You cannot set the 'BusinessObjectCollection' for BOColTabControlManager since the BusinessObjectControl has not been set";
 			StringAssert.Contains(expectedMessage, ex.Message);
 		}
 	}
		public void Test_Set_Collection_WithNull()
		{
			//---------------Set up test pack-------------------

			ITabControl tabControl = CreateTabControl();
			BOColTabControlManager selectorManager = new BOColTabControlManager(tabControl, GetControlFactory());
			selectorManager.BusinessObjectControl = GetBusinessObjectControl();
			//---------------Verify test pack-------------------
			//---------------Execute Test ----------------------
			selectorManager.BusinessObjectCollection = null;
			//---------------Verify Result -----------------------
			Assert.IsNull(selectorManager.BusinessObjectCollection);
			Assert.AreSame(tabControl, selectorManager.TabControl);
		}