public void Read_ShouldLoadObjectsAsSaved()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore = new DataStoreInMemory();
            var savedBo = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);
            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var writeStream = GetStreamForDataStore(savedDataStore);
            var reader = new DataStoreInMemoryXmlReader();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedDataStore = reader.Read(writeStream);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
            IBusinessObject loadedBo;
            var success = loadedDataStore.AllObjects.TryGetValue(savedBo.MyBoID.GetValueOrDefault(), out loadedBo);
            Assert.IsTrue(success);
            Assert.IsNotNull(loadedBo);
            Assert.IsInstanceOf(typeof(MyBO), loadedBo);
            var loadedMyBo = (MyBO)loadedBo;
            Assert.AreNotSame(savedBo, loadedMyBo);

            Assert.IsFalse(loadedBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedBo.Status.IsDeleted, "Should not be Deleted");
            Assert.IsFalse(loadedBo.Status.IsDirty, "Should not be Dirty");
            Assert.IsFalse(loadedBo.Status.IsEditing, "Should not be Editing");
        }
Пример #2
0
        public void Read_ShouldLoadObjectsAsSaved()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore       = new DataStoreInMemory();
            var savedBo              = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);

            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var writeStream = GetStreamForDataStore(savedDataStore);
            var reader      = new DataStoreInMemoryXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedDataStore = reader.Read(writeStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
            IBusinessObject loadedBo;
            var             success = loadedDataStore.AllObjects.TryGetValue(savedBo.MyBoID.GetValueOrDefault(), out loadedBo);

            Assert.IsTrue(success);
            Assert.IsNotNull(loadedBo);
            Assert.IsInstanceOf(typeof(MyBO), loadedBo);
            var loadedMyBo = (MyBO)loadedBo;

            Assert.AreNotSame(savedBo, loadedMyBo);

            Assert.IsFalse(loadedBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedBo.Status.IsDeleted, "Should not be Deleted");
            Assert.IsFalse(loadedBo.Status.IsDirty, "Should not be Dirty");
            Assert.IsFalse(loadedBo.Status.IsEditing, "Should not be Editing");
        }
        public void Read_ShouldLoadObjectsAsNew()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore       = new DataStoreInMemory();
            var savedBo              = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);

            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var stream    = GetStreamForDataStore(savedDataStore);
            var xmlReader = GetXmlReader(stream);
            var reader    = new BusinessObjectXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(xmlReader);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();

            Assert.AreEqual(1, businessObjects.Count);
            var loadedMyBo = (MyBO)businessObjects[0];

            Assert.AreNotSame(savedBo, loadedMyBo);
            Assert.IsTrue(loadedMyBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedMyBo.Status.IsDeleted, "Should not be Deleted");
        }
        public void Test_CreateDisplayValueDictionary_NoSort()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();

            myBO1.Save();
            MyBO myBO2 = new MyBO();

            myBO2.Save();
            MyBO myBO3 = new MyBO();

            myBO3.Save();
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO>();

            myBOs.LoadAll();
            //--------------- Test Preconditions ----------------

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

            //--------------- Test Result -----------------------
            Assert.AreEqual(3, dictionary.Count);
            Assert.IsTrue(dictionary.ContainsValue(myBO1.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO2.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO3.ID.ToString()));
        }
        public void Test_Refresh_WithDuplicateObjectsInPersistedCollection_ShouldThrowHabaneroDeveloperException()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            MyBO bo = new MyBO();

            bo.Save();
            BusinessObjectCollection <MyBO> collection = new BusinessObjectCollection <MyBO>();

            collection.Load("MyBoID = '" + bo.MyBoID + "'", "");
            collection.PersistedBusinessObjects.Add(bo);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, collection.PersistedBusinessObjects.Count);
            Assert.AreSame(collection.PersistedBusinessObjects[0], collection.PersistedBusinessObjects[1]);
            //---------------Execute Test ----------------------
            try
            {
                collection.Refresh();
                //---------------Test Result -----------------------
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <HabaneroDeveloperException>(ex, "Should have thrown a HabaneroDeveloperException because of the duplicate item in the PersistedBusinessObjects collection");
                StringAssert.Contains("A duplicate Business Object was found in the persisted objects collection of the BusinessObjectCollection during a reload", ex.Message);
                StringAssert.Contains("MyBO", ex.Message);
                StringAssert.Contains(bo.MyBoID.Value.ToString("B"), ex.Message);
            }
        }
Пример #6
0
        public void Test_MarkForDelete_WhenMultiple_WhenDerefenceRelated_WhenHasRelatedBO_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            ReflectionUtilities.SetPropertyValue(bo.Status, "IsDeleted", true);
            MyRelatedBo   myRelatedBO  = bo.MyMultipleRelationship.CreateBusinessObject();
            IRelationship relationship = bo.Relationships["MyMultipleRelationship"];

            ((RelationshipDef)relationship.RelationshipDef).DeleteParentAction = DeleteParentAction.DereferenceRelated;

            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsFalse(myRelatedBO.Status.IsDeleted);
            Assert.AreEqual(1, bo.MyMultipleRelationship.Count);
            Assert.AreEqual(DeleteParentAction.DereferenceRelated, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            relationship.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsFalse(myRelatedBO.Status.IsDeleted);
        }
Пример #7
0
        public void TestInitGrid_LoadsCustomColumnType()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = MyBO.LoadClassDefWithDateTimeParameterFormat();
            IEditableGridControl grid        = GetControlFactory().CreateEditableGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef  uiDef     = classDef.UIDefCol["default"];
            IUIGrid uiGridDef = uiDef.UIGrid;

            Type customColumnType = typeof(CustomDataGridViewColumnVWG);

            uiGridDef[2].GridControlTypeName     = customColumnType.Name; //"CustomDataGridViewColumn";
            uiGridDef[2].GridControlAssemblyName = "Habanero.Faces.Test.VWG";
            AddControlToForm(grid);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);
            //---------------Test Result -----------------------
            Assert.AreEqual(6, grid.Grid.Columns.Count);
            IDataGridViewColumn column3 = grid.Grid.Columns[3];

            Assert.AreEqual("TestDateTime", column3.Name);
            Assert.IsInstanceOf(typeof(IDataGridViewColumn), column3);
            AssertGridColumnTypeAfterCast(column3, customColumnType);
        }
Пример #8
0
        public void TestVWGRowIsRefreshed()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase    gridBase = GetGridBaseWith_4_Rows(out col);
            const string propName = "TestProp";
            const int    rowIndex = 1;
            MyBO         bo       = col[rowIndex];

            AddControlToForm(gridBase);

            //---------------verify preconditions---------------
            object cellValue = GetCellValue(rowIndex, gridBase, propName);

            //DataGridViewCell cell;

            Assert.AreEqual(bo.GetPropertyValue(propName), cellValue);

            //---------------Execute Test ----------------------
            bo.SetPropertyValue(propName, "UpdatedValue");
            bo.Save();
            //---------------Test Result -----------------------
            //gridBase.SelectedBusinessObject = bo;

            //cell = GetCell(rowIndex, propName, gridBase);
            cellValue = GetCellValue(rowIndex, gridBase, propName);
            Assert.AreEqual("UpdatedValue", cellValue);
        }
Пример #9
0
        public void Test_ControlMapperStrategy_RemoveBOPropHandlers()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            var          strategyWin = new ControlMapperStrategyWin();
            var          tb          = _factory.CreateTextBox();
            const string testprop    = "TestProp";
            var          stubMapper  = new ControlMapperStub(tb, testprop, false, _factory);
            var          bo          = new MyBO();
            var          prop        = bo.Props[testprop];
            const string origvalue   = "origValue";

            prop.Value = origvalue;
            stubMapper.BusinessObject = bo;


            const string newValue = "New value";

            //--------------Assert PreConditions----------------
            Assert.AreNotEqual(newValue, tb.Text);
            Assert.AreEqual(origvalue, prop.Value, "The text box value is set from the prop due to the fact that the BOPropHandler is on the ControlMapperStrategy");
            Assert.AreEqual(origvalue, tb.Text, "The text box value is set from the prop due to the fact that the BOPropHandler is on the ControlMapperStrategy");
            //---------------Execute Test ----------------------
            strategyWin.RemoveCurrentBOPropHandlers(stubMapper, prop);
            prop.Value = newValue;
            //---------------Test Result -----------------------
            Assert.AreNotEqual(newValue, tb.Text, "Updating the prop should not update the textbox since the handler has been removed");
            Assert.AreEqual(origvalue, tb.Text);
            Assert.AreEqual(newValue, prop.Value, "The text box value is not changed when the prop has changed due the the BOPropHandler being removed");
        }
        public void TestGridFiringItemSelected()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            IReadOnlyGridControl readOnlyGridControl = GetControlFactory().CreateReadOnlyGridControl();

            DisposeOnTearDown(readOnlyGridControl);
            BusinessObjectCollection <MyBO> myBOS = new BusinessObjectCollection <MyBO>();

            myBOS.Add(new MyBO());
            MyBO bo = new MyBO();

            myBOS.Add(bo);
            myBOS.Add(new MyBO());

            readOnlyGridControl.SetBusinessObjectCollection(myBOS);
            bool gridItemSelected = false;

            readOnlyGridControl.Grid.SelectedBusinessObject  = null;
            readOnlyGridControl.Grid.BusinessObjectSelected += (delegate { gridItemSelected = true; });

            //---------------Execute Test ----------------------
            readOnlyGridControl.Grid.SelectedBusinessObject = bo;

            //---------------Test Result -----------------------
            Assert.IsTrue(gridItemSelected);
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
        public void Test_RemoveFromBOCol_WhenNotIsSelected_ShouldNotFireBusinessObjectSelectedEvent()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            var listBox = CreateListBox();
            var manager = CreateListBoxCollectionManager(listBox);

            MyBO.LoadDefaultClassDef();
            var myBoCol       = new BusinessObjectCollection <MyBO>();
            var toBeRemovedBo = new MyBO();

            myBoCol.Add(new MyBO());
            myBoCol.Add(toBeRemovedBo);
            myBoCol.Add(new MyBO());
            manager.BusinessObjectCollection = myBoCol;
            IBusinessObject boFromSelectedEvent  = null;
            bool            boSelectedEventFired = false;

            manager.BusinessObjectSelected += (sender, args) =>
            {
                boFromSelectedEvent  = args.BusinessObject;
                boSelectedEventFired = true;
            };
            //---------------Assert Precondition----------------
            Assert.AreNotSame(toBeRemovedBo, manager.SelectedBusinessObject);
            Assert.IsNull(boFromSelectedEvent);
            Assert.IsFalse(boSelectedEventFired);
            //---------------Execute Test ----------------------
            manager.BusinessObjectCollection.Remove(toBeRemovedBo);
            //---------------Test Result -----------------------
            Assert.IsFalse(boSelectedEventFired);
        }
Пример #13
0
        public void Test_WhenUsingCreator_WhenSetBOCol_ShouldCreateTabPageWithControlFromCreator()
        {
            //---------------Set up test pack-------------------
            BusinessObjectControlCreatorDelegate creator;
            BOColTabControlManager selectorManager = GetselectorManager(out creator);
            MyBO expectedBO = new MyBO();
            BusinessObjectCollection <MyBO> myBoCol = new BusinessObjectCollection <MyBO>
            {
                expectedBO
            };

            //---------------Assert Precondition----------------
            Assert.IsNotNull(selectorManager.BusinessObjectControlCreator);
            Assert.AreEqual(creator, selectorManager.BusinessObjectControlCreator);
            Assert.AreEqual(0, selectorManager.TabControl.TabPages.Count);
            //---------------Execute Test ----------------------
            selectorManager.BusinessObjectCollection = myBoCol;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, selectorManager.TabControl.TabPages.Count);
            ITabPage page = selectorManager.TabControl.TabPages[0];

            Assert.AreEqual(1, page.Controls.Count);
            IControlHabanero boControl = page.Controls[0];

            Assert.IsInstanceOf(TypeOfBusinessObjectControl(), boControl);
            IBusinessObjectControl businessObjectControl = (IBusinessObjectControl)boControl;

            Assert.AreSame(expectedBO, businessObjectControl.BusinessObject);
            Assert.AreSame(boControl, selectorManager.BusinessObjectControl);
        }
Пример #14
0
        public void Test_SetDisplayPropertyValue_WithRelatedPropName_ShouldSetPropValue()
        {
            //---------------Set up test pack-------------------
            const string underlyingPropName = "MyRelatedTestProp";
            const string propName           = "MyRelationship." + underlyingPropName;

            ClassDef.ClassDefs.Clear();

            var myBOClassDef    = MyBO.LoadClassDefWithRelationship();
            var relatedClassDef = MyRelatedBo.LoadClassDef();

            MyBO        myBO        = (MyBO)myBOClassDef.CreateNewBusinessObject();
            MyRelatedBo myRelatedBo = (MyRelatedBo)relatedClassDef.CreateNewBusinessObject();

            myBO.Relationships.SetRelatedObject("MyRelationship", myRelatedBo);
            BOMapper boMapper         = new BOMapper(myBO);
            var      initialPropValue = RandomValueGen.GetRandomString();

            myRelatedBo.SetPropertyValue(underlyingPropName, initialPropValue);
            //---------------Assert Precondition----------------
            Assert.AreEqual(initialPropValue, myRelatedBo.GetPropertyValue(underlyingPropName));
            //---------------Execute Test ----------------------
            var expectedPropValue = RandomValueGen.GetRandomString();

            boMapper.SetDisplayPropertyValue(propName, expectedPropValue);
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropValue, myRelatedBo.GetPropertyValue(underlyingPropName));
        }
Пример #15
0
        public void Test_WhenChangeTabIndex_ShouldNotRecreateTheBOControl()
        {
            //---------------Set up test pack-------------------
            BusinessObjectControlCreatorDelegate creator;
            BOColTabControlManager selectorManager = GetselectorManager(out creator);

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

            selectorManager.BusinessObjectCollection = myBoCol;
            ITabPage firstTabPage = selectorManager.TabControl.TabPages[0];
            IBusinessObjectControl firstBOControl = (IBusinessObjectControl)firstTabPage.Controls[0];
            ITabPage secondTabPage = selectorManager.TabControl.TabPages[1];
            IBusinessObjectControl secondBOControl = (IBusinessObjectControl)secondTabPage.Controls[0];

            //---------------Assert Precondition----------------
            Assert.AreSame(secondBO, secondBOControl.BusinessObject);
            Assert.AreSame(firstBOControl, selectorManager.BusinessObjectControl);
            Assert.AreEqual(2, selectorManager.TabControl.TabPages.Count);
            Assert.AreEqual(0, selectorManager.TabControl.SelectedIndex);
            //---------------Execute Test ----------------------
            selectorManager.CurrentBusinessObject = secondBO;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, selectorManager.TabControl.SelectedIndex);
            Assert.AreSame(secondBOControl, secondTabPage.Controls[0]);
            Assert.AreSame(secondBOControl, selectorManager.BusinessObjectControl);
        }
        public void Test_BOIsValid_WhenBORuleIsNotValid_ShouldBeNotValid()
        {
            //---------------Set up test pack-------------------
            var bo = new MyBO();
            var ruleStub = new BusinessObjectRuleStub(false) {Message = TestUtil.GetRandomString()};
            string msg;
            IList<IBOError> msgList;
            //---------------Assert Precondition----------------
            Assert.IsFalse(ruleStub.IsValid());

            Assert.IsTrue(bo.Status.IsValid());
            Assert.IsTrue(bo.Status.IsValid(out msg));
            Assert.IsTrue(bo.Status.IsValid(out msgList));
            //---------------Execute Test ----------------------
            bo = new MyBO();
            bo.AddBusinessRule(ruleStub);
            //---------------Test Result -----------------------
            Assert.IsFalse(bo.Status.IsValid());
            Assert.IsFalse(bo.Status.IsValid(out msg));
            Assert.IsFalse(bo.Status.IsValid(out msgList));
            Assert.AreEqual(1, msgList.Count);
            TestUtil.AssertStringNotEmpty(msg, "msg");
            IBOError error = msgList[0];
            Assert.AreEqual(error.Level, ErrorLevel.Error);
            Assert.AreSame(bo, error.BusinessObject);
            IList<IBOError> warningList;
            Assert.IsTrue(bo.Status.HasWarnings(out warningList));
            Assert.AreEqual(1, warningList.Count);
            Assert.AreSame(bo, warningList[0].BusinessObject);
        }
        public void Read_MultipleObjects()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore = new DataStoreInMemory();
            var bo1            = new MyBO();
            var bo2            = new Car();

            savedDataStore.Add(bo1);
            savedDataStore.Add(bo2);
            var stream    = GetStreamForDataStore(savedDataStore);
            var xmlReader = GetXmlReader(stream);
            var reader    = new BusinessObjectXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(xmlReader);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();

            Assert.AreEqual(2, businessObjects.Count);
            Assert.IsNotNull(businessObjects.Find(o => o.ID.Equals(bo1.ID)));
            Assert.IsNotNull(businessObjects.Find(o => o.ID.Equals(bo2.ID)));
        }
Пример #18
0
        public void Test_SetBusinessObject_BusinessObjectSelectEvent_FiresAndReturnsAValidBO()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGrid editableGrid          = GetControlFactory().CreateEditableGrid();

            AddControlToForm(editableGrid);
            SetupGridColumnsForMyBo(editableGrid);
            editableGrid.BusinessObjectCollection = col;
            IBusinessObject boFromEvent = null;
            bool            eventFired  = false;

            editableGrid.BusinessObjectSelected += delegate(object sender, BOEventArgs e)
            {
                eventFired  = true;
                boFromEvent = e.BusinessObject;
            };
            MyBO myBO = col[2];

            //---------------Execute Test ----------------------
            editableGrid.SelectedBusinessObject = myBO;
            //---------------Test Result -----------------------
            Assert.AreEqual(col.Count + 1, editableGrid.Rows.Count, "should be 4 item 1 adding item");
            Assert.AreSame(myBO, editableGrid.SelectedBusinessObject);
            Assert.IsTrue(eventFired);
            Assert.AreEqual(myBO, boFromEvent);
        }
Пример #19
0
        public void Test_Read_WhenWrittenWithListOfKeyValuePairs_ShouldStillReturnEquivalentConcurrentDictionary()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefsNoUIDef();
            var myBo            = new MyBO();
            var businessObjects = new List <KeyValuePair <Guid, IBusinessObject> > {
                new KeyValuePair <Guid, IBusinessObject>(myBo.ID.GetAsGuid(), myBo)
            };
            var writeStream = new MemoryStream();

            new BinaryFormatter().Serialize(writeStream, businessObjects);
            BORegistry.BusinessObjectManager = new BusinessObjectManager();
            var loadedDataStore = new DataStoreInMemory();

            writeStream.Seek(0, SeekOrigin.Begin);
            var reader = new DataStoreInMemoryBinaryReader(writeStream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, businessObjects.Count);
            //---------------Execute Test ----------------------
            loadedDataStore.AllObjects = reader.Read();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
        }
Пример #20
0
        public void Test_ControlMapperStrategy_AddBOPropHandlers()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            var          strategyWin = new ControlMapperStrategyWin();
            var          factory     = new Habanero.Faces.Win.ControlFactoryWin();
            var          tb          = factory.CreateTextBox();
            const string testprop    = "TestProp";
            var          stubMapper  = new ControlMapperStub(tb, testprop, false, factory);
            var          bo          = new MyBO();
            var          prop        = bo.Props[testprop];
            const string origvalue   = "origValue";

            prop.Value = origvalue;
            stubMapper.BusinessObject = bo;
            strategyWin.RemoveCurrentBOPropHandlers(stubMapper, prop);

            //--------------Assert PreConditions----------------
            Assert.AreEqual(origvalue, tb.Text);

            //---------------Execute Test ----------------------
            strategyWin.AddCurrentBOPropHandlers(stubMapper, prop);
            const string newValue = "New value";

            prop.Value = newValue;

            //---------------Test Result -----------------------
            Assert.AreEqual(newValue, tb.Text);
        }
        public void Test_LoadingFromMultipleSources()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();

            MyBO.LoadDefaultClassDef();
            TransactionCommitterInMemory committer1 = new TransactionCommitterInMemory(dataStore1);
            var bo1 = new MyBO();
            committer1.AddBusinessObject(bo1);
            committer1.CommitTransaction();

            MyRelatedBo.LoadClassDef();
            TransactionCommitterInMemory committer2 = new TransactionCommitterInMemory(dataStore2);
            var bo2 = new MyRelatedBo();
            committer2.AddBusinessObject(bo2);
            committer2.CommitTransaction();

            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);

            //---------------Execute Test ----------------------
            
            //---------------Test Result -----------------------
            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
            dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1);
            dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2);
            var loadedBo1 = dataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(bo1.ID);
            var loadedBo2 = dataAccessor.BusinessObjectLoader.GetBusinessObject<MyRelatedBo>(bo2.ID);
            //---------------Tear down -------------------------

            Assert.AreSame(loadedBo1, bo1);
            Assert.AreSame(loadedBo2, bo2);
        }
Пример #22
0
        public override void TestSetSelectedBO_WhenGridHasObjectIDButBOColNotHasObject_ShouldSetBO()
        {
            //This is a fairly specific situation but can occur when you are using
            // a CachedBindingList or a paginaged BindingList where the BOCol that the
            // grid has reference to does not have any BusinessObjects.
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_SavedObjects();

            IGridBase gridBase = CreateGridBaseStub();

            gridBase.GridLoader = new CustomDelegateLoaderClass(col).GridLoaderDelegateLoadFromDiffCol;
            SetupGridColumnsForMyBo(gridBase);
            gridBase.BusinessObjectCollection = new BusinessObjectCollection <MyBO>();
            //---------------Assert Preconditions---------------
            Assert.IsNull(gridBase.DataSetProvider);
            Assert.IsNotNull(gridBase.DataSource);
            col.Refresh();
            Assert.AreEqual(4, col.Count);
            Assert.AreEqual(4, gridBase.RowCount);
            //---------------Execute Test ----------------------
            var expectedSelectedBo = col[2];

            gridBase.SelectedBusinessObject = expectedSelectedBo;
            var actualSelectedBO = gridBase.SelectedBusinessObject;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedSelectedBo, actualSelectedBO);
        }
Пример #23
0
        public void Test_Read()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefsNoUIDef();
            DataStoreInMemory savedDataStore = new DataStoreInMemory();

            savedDataStore.Add(new MyBO());
            MemoryStream writeStream             = new MemoryStream();
            DataStoreInMemoryBinaryWriter writer = new DataStoreInMemoryBinaryWriter(writeStream);

            writer.Write(savedDataStore);
            BORegistry.BusinessObjectManager = new BusinessObjectManager();
            DataStoreInMemory loadedDataStore = new DataStoreInMemory();

            writeStream.Seek(0, SeekOrigin.Begin);
            DataStoreInMemoryBinaryReader reader = new DataStoreInMemoryBinaryReader(writeStream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            loadedDataStore.AllObjects = reader.Read();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
        }
Пример #24
0
        public void Test_AddClicked_RowAddedAfterPostEditActionCalled()
        {
            //---------------Set up test pack-------------------
            //Get Grid with 4 items
            BusinessObjectCollection <MyBO> col;
            IReadOnlyGridControl            readOnlyGridControl = GetGridWith_4_Rows(out col, true);
            //AddControlToForm(readOnlyGridControl);
            IButton button  = readOnlyGridControl.Buttons["Add"];
            MyBO    myNewBo = null;
            PostObjectEditDelegate editorPostEditAction = null;

            readOnlyGridControl.BusinessObjectEditor = new DelegatedBusinessObjectEditor <MyBO>(
                delegate(MyBO obj, string uiDefName, PostObjectEditDelegate postEditAction)
            {
                myNewBo = obj;
                editorPostEditAction = postEditAction;
                return(true);
            });
            button.PerformClick();
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(editorPostEditAction);
            Assert.IsNotNull(myNewBo);
            Assert.AreEqual(4, readOnlyGridControl.Grid.Rows.Count);
            //---------------Execute Test ----------------------
            editorPostEditAction(myNewBo, true);
            //---------------Test Result -----------------------
            Assert.AreEqual(5, readOnlyGridControl.Grid.Rows.Count);
        }
        public void TestAddRowP_RowValueDBNull_VirtualProp_NUll_ShouldNotRaiseException_FIXBUG()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithUIAllDataTypes();

            classDef.UIDefCol["default"].UIGrid.Add(new UIGridColumn("VirtualProp", "-TestProp-", typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));
            BusinessObjectCollection <MyBO> boCollection = new BusinessObjectCollection <MyBO>();

            _dataSetProvider = new EditableDataSetProvider(boCollection);
            BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject());

            itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid);

            //--------------Assert PreConditions----------------
            Assert.AreEqual(0, boCollection.Count);
            Assert.AreEqual(0, boCollection.PersistedBusinessObjects.Count, "Should be no created items to start");
            //            Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start");

            //---------------Execute Test ----------------------
            itsTable.Rows.Add(new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value });
            //---------------Test Result -----------------------
            Assert.IsFalse(itsTable.Rows[0].HasErrors);
            //Behaviour has been changed to persist the business object
            Assert.AreEqual
                (1, boCollection.PersistedBusinessObjects.Count,
                "Adding a row to the table should use the collection to create the object");
            //            Assert.AreEqual
            //                (1, boCollection.CreatedBusinessObjects.Count,
            //                 "Adding a row to the table should use the collection to create the object");
            Assert.AreEqual(1, boCollection.Count, "Adding a row to the table should add a bo to the main collection");
        }
Пример #26
0
        public void Acceptance_Read_WhenCalledWithPropertyReadExceptions_ShouldSetReadResultSuccessfulFalseAndMessage_Bug1336()
        {
            //---------------Set up test pack-------------------
            var classDef = LoadMyBOClassDefsWithNoUIDefs();
            var bo       = new MyBO {
                TestProp = "characters"
            };
            var propDef = classDef.PropDefcol["TestProp"];

            classDef.PropDefcol.Remove(propDef);
            var propDefWithDifferentType = propDef.Clone();

            // Change type to force property read exception
            propDefWithDifferentType.PropertyType = typeof(int);
            classDef.PropDefcol.Add(propDefWithDifferentType);
            var toStream = GetStreamForBusinessObject(bo);
            var reader   = new ObjectTreeXmlReader();

            //---------------Assert Precondition----------------
            Assert.IsNull(reader.ReadResult);
            //---------------Execute Test ----------------------
            var businessObjects = reader.Read(toStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, businessObjects.Count());
            Assert.IsNotNull(reader.ReadResult);
            Assert.IsFalse(reader.ReadResult.Successful);
            StringAssert.Contains("An error occured when attempting to set property 'MyBO.TestProp'.", reader.ReadResult.Message);
        }
Пример #27
0
        public override void Test_SetDateToGridCustomFormat_LoadViaCollection()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadClassDefWithDateTime();
            IDataGridViewColumn             column;
            const string                    requiredFormat = "dd.MMM.yyyy";
            IGridBase                       gridBase       = CreateGridBaseWithDateCustomFormatCol(out column, requiredFormat);
            BusinessObjectCollection <MyBO> col            = new BusinessObjectCollection <MyBO>();
            MyBO         bo           = new MyBO();
            const string dateTimeProp = "TestDateTime";
            DateTime     expectedDate = DateTime.Now;

            bo.SetPropertyValue(dateTimeProp, expectedDate);
            col.Add(bo);
            //--------------Assert PreConditions----------------
            Assert.AreEqual(expectedDate, bo.GetPropertyValue(dateTimeProp));
            Assert.AreEqual(1, gridBase.ColumnCount);
            Assert.AreEqual(dateTimeProp, gridBase.Columns[0].Name);
            Assert.AreEqual(dateTimeProp, gridBase.Columns[0].DataPropertyName);
            //---------------Execute Test ----------------------
            gridBase.BusinessObjectCollection = col;
            //---------------Test Result -----------------------
            IDataGridViewCell dataGridViewCell = gridBase.Rows[0].Cells[0];

            Assert.AreEqual(expectedDate.ToString(requiredFormat), dataGridViewCell.FormattedValue);
        }
Пример #28
0
        public void Test_IsDeletable_WhenDeleteAction_EQ_DeleteRelated_WhenHasRelatedObject_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            IRelationship relationship = bo.Relationships["MyMultipleRelationship"];

            SetDeleteRelatedAction(relationship, DeleteParentAction.DeleteRelated);
            bo.MyMultipleRelationship.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsFalse(bo.Status.IsDeleted);
            Assert.AreEqual(1, bo.MyMultipleRelationship.Count);
            Assert.AreEqual(DeleteParentAction.DeleteRelated, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            string message;
            bool   isDeletable = relationship.IsDeletable(out message);

            //---------------Test Result -----------------------
            Assert.IsTrue(isDeletable);
        }
Пример #29
0
        public void TestSetupColumnAsCheckBoxType()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWith_Grid_1CheckBoxColumn();
            IBusinessObjectCollection colBOs = GetCol_BO_1CheckboxItem(classDef);
            IEditableGrid             grid   = GetControlFactory().CreateEditableGrid();
            IDataGridViewColumn       dataGridViewColumnSetup = GetControlFactory().CreateDataGridViewCheckBoxColumn();

            SetupGridColumnsForMyBo(grid, dataGridViewColumnSetup);

            //--------------Assert PreConditions----------------
            Assert.AreEqual(1, grid.Columns.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            IUIGrid uiGridDef = classDef.UIDefCol["default"].UIGrid;

            Assert.IsNotNull(uiGridDef);
            Assert.AreEqual(1, uiGridDef.Count);

            //---------------Execute Test ----------------------
#pragma warning disable 618,612// maintained test for backward compatibility testing
            grid.SetBusinessObjectCollection(colBOs);
#pragma warning restore 618,612
            //---------------Test Result -----------------------
            IDataGridViewColumn dataGridViewColumn = grid.Columns[0];
            AssertIsCheckBoxColumnType(dataGridViewColumn);
            //---------------Tear Down -------------------------
        }
Пример #30
0
        public void Test_MarkForDelete_WhenSingle_WhenDeleteRelated_WhenHasRelatedBO_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            ReflectionUtilities.SetPropertyValue(bo.Status, "IsDeleted", true);
            ISingleRelationship relationship = (ISingleRelationship)bo.Relationships["MyRelationship"];
            MyRelatedBo         myRelatedBO  = new MyRelatedBo();

            relationship.SetRelatedObject(myRelatedBO);
            SetDeleteRelatedAction(relationship, DeleteParentAction.DeleteRelated);


            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsFalse(myRelatedBO.Status.IsDeleted);
            Assert.IsNotNull(relationship.GetRelatedObject());
            Assert.AreEqual(DeleteParentAction.DeleteRelated, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            relationship.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsTrue(myRelatedBO.Status.IsDeleted);
        }
Пример #31
0
        public void Test_Set_BusinessObjectCollection_SetupColumnAsCheckBoxType()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWith_Grid_1CheckBoxColumn();
            IBusinessObjectCollection colBOs = GetCol_BO_1CheckboxItem(classDef);
            IEditableGrid             grid   = GetControlFactory().CreateEditableGrid();
            IDataGridViewColumn       dataGridViewColumnSetup = GetControlFactory().CreateDataGridViewCheckBoxColumn();

            SetupGridColumnsForMyBo(grid, dataGridViewColumnSetup);

            //--------------Assert PreConditions----------------
            Assert.AreEqual(1, grid.Columns.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            IUIGrid uiGridDef = classDef.UIDefCol["default"].UIGrid;

            Assert.IsNotNull(uiGridDef);
            Assert.AreEqual(1, uiGridDef.Count);

            //---------------Execute Test ----------------------
            grid.BusinessObjectCollection = colBOs;
            //---------------Test Result -----------------------
            IDataGridViewColumn dataGridViewColumn = grid.Columns[0];

            AssertIsCheckBoxColumnType(dataGridViewColumn);
            //---------------Tear Down -------------------------
        }
Пример #32
0
        public void Test_IsDeletable_WhenSingle_WhenDeleteAction_EQ_PreventDelete_WhenHasRelated_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            SingleRelationship <MyRelatedBo> relationship = (SingleRelationship <MyRelatedBo>)bo.Relationships["MyRelationship"];

            relationship.SetRelatedObject(new MyRelatedBo());
            //---------------Assert Precondition----------------
            Assert.IsFalse(bo.Status.IsDeleted);
            Assert.IsNotNull(relationship.GetRelatedObject());
            Assert.AreEqual(DeleteParentAction.Prevent, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            string message;
            bool   isDeletable = relationship.IsDeletable(out message);

            //---------------Test Result -----------------------
            Assert.IsFalse(isDeletable);
        }
        public override void Test_Set_SelectedBusinessObject_ItemNotInList_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 = new MyBO();
            //---------------Test Result -----------------------
            Assert.AreEqual(ActualIndex(2), colSelector.NoOfItems, "The blank item");
            Assert.IsNull(colSelector.SelectedBusinessObject);
            Assert.AreEqual
                (1, SelectedIndex(colSelector),
                "This does not make sense with a collapsible panel similar to a boTabcontrol");
        }
Пример #34
0
 public void TestLink()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     string testValue = TestUtil.GetRandomString();
     //---------------Execute Test ----------------------
     new PropertyLink<string, string>(bo, "TestProp", "TestProp2", delegate(string input) { return input; });
     bo.TestProp = testValue;
     //---------------Test Result -----------------------
     Assert.AreEqual(testValue, bo.TestProp2);
 }
Пример #35
0
 public void TestLink_DoesntChangeDestinationIfAlreadySet()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     string testValue = TestUtil.GetRandomString();
     const string prop2Value = "my set value";
     bo.TestProp2 = prop2Value;
     //---------------Execute Test ----------------------
     new PropertyLink<string, string>(bo, "TestProp", "TestProp2", delegate(string input) { return input; });
     bo.TestProp = testValue;
     //---------------Test Result -----------------------
     Assert.AreEqual(prop2Value, bo.TestProp2);
 }
Пример #36
0
        public void Test_Criteria_OneProp()
        {
            //--------------- Set up test pack ------------------
            MyBO.LoadClassDefWithRelationship();
            MyRelatedBo.LoadClassDef();
            MyBO myBO = new MyBO();
            MultipleRelationship<MyRelatedBo> relationship = myBO.Relationships.GetMultiple<MyRelatedBo>("MyMultipleRelationship");
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            Criteria relCriteria = relationship.RelKey.Criteria;
            //--------------- Test Result -----------------------
            StringAssert.AreEqualIgnoringCase("MyBoID = '" + myBO.MyBoID.Value.ToString("B") + "'", relCriteria.ToString());
        }
 public void Test_UsingDefaultBusinessObjectLoader()
 {
     //---------------Set up test pack-------------------
     DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
     ITransactionCommitter committer = dataAccessor.CreateTransactionCommitter();
     MyBO.LoadDefaultClassDef();
     var bo1 = new MyBO();
     committer.AddBusinessObject(bo1);
     committer.CommitTransaction();
     //---------------Execute Test ----------------------
     var loadedBo1 = dataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(bo1.ID);
     //---------------Test Result -----------------------
     Assert.AreSame(loadedBo1, bo1);
     //---------------Tear down -------------------------
 }
 public void Test_DefaultDataAccessor_OneObject()
 {
     //---------------Set up test pack-------------------
     DataStoreInMemory dataStore = new DataStoreInMemory();
     IDataAccessor defaultDataAccessor = new DataAccessorInMemory(dataStore);
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     //---------------Execute Test ----------------------
     ITransactionCommitter transactionCommitter = new TransactionCommitterMultiSource(defaultDataAccessor, new Dictionary<Type, IDataAccessor>());
     transactionCommitter.AddBusinessObject(bo);
     transactionCommitter.CommitTransaction();
     //---------------Test Result -----------------------
     Assert.IsNotNull(dataStore.Find<MyBO>(bo.ID));
     //---------------Tear down -------------------------
 }
        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();
        }
Пример #40
0
        public void Test_Constructor()
        {
            //--------------- Set up test pack ------------------
            const string message = "message";
            const ErrorLevel errorLevel = ErrorLevel.Error;
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            IBusinessObject bo = new MyBO();
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            BOError boError = new BOError(message, errorLevel);
            //--------------- Test Result -----------------------

            Assert.AreEqual(message, boError.Message);
            Assert.AreEqual(errorLevel, boError.Level);

        }
        public void Test_CreateBusinessObject_AddedToTheCollection()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefWithRelationship();
            MyRelatedBo.LoadClassDef();
            MyBO bo = new MyBO();
            IMultipleRelationship rel = bo.Relationships.GetMultiple("MyMultipleRelationship");
            RelatedBusinessObjectCollection<MyRelatedBo> col = new RelatedBusinessObjectCollection<MyRelatedBo>(rel);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            MyRelatedBo relatedBo = col.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(bo.MyBoID, relatedBo.MyBoID, "The foreign key should eb set");
            Assert.IsTrue(relatedBo.Status.IsNew);
            Assert.AreEqual(1, col.CreatedBusinessObjects.Count, "The created BOs should be added");
            Assert.AreEqual(0, col.AddedBusinessObjects.Count);
            Assert.AreEqual(1, col.Count);
        }
Пример #42
0
 public void Test_SerialiseBusinessObject()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     MyBO.LoadClassDefs_OneProp();
     BusinessObject myBO = new MyBO();
     const string dataFile = _dataFileName;
     File.Delete(dataFile);
     
     // Construct a BinaryFormatter and use it 
     // to serialize the data to the stream.
     BinaryFormatter formatter = new BinaryFormatter();
     //---------------Assert Precondition----------------
     AssertFileDoesNotExist(dataFile);
     //---------------Execute Test ----------------------
     // Serialize the BO.
     using (FileStream fs = new FileStream(dataFile, FileMode.Create))
     {
         formatter.Serialize(fs, myBO);
     }
     //---------------Test Result -----------------------
     AssertFileHasBeenCreated(dataFile);
 }
        public void TestAddRowCreatesBusinessObjectThroughCollection()
        {
            SetupTestData();
            //---------------Set up test pack-------------------
            BusinessObjectCollection<MyBO> boCollection = new BusinessObjectCollection<MyBO>();
            MyBO bo = new MyBO();
            bo.SetPropertyValue("TestProp", "bo1prop1");
            bo.SetPropertyValue("TestProp2", "s1");
            bo.Save();
            boCollection.Add(bo);

            MyBO bo2 = new MyBO();
            bo2.SetPropertyValue("TestProp", "bo2prop1");
            bo2.SetPropertyValue("TestProp2", "s2");
            bo2.Save();
            boCollection.Add(bo2);

            _dataSetProvider = new EditableDataSetProvider(boCollection);
            BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject());

            itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid);


            //--------------Assert PreConditions----------------            
            Assert.AreEqual(2, boCollection.Count);
            Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start");

            //---------------Execute Test ----------------------
            itsTable.Rows.Add(new object[] {null, "bo3prop1", "bo3prop2"});

            //---------------Test Result -----------------------
            Assert.AreEqual
                (1, boCollection.CreatedBusinessObjects.Count,
                 "Adding a row to the table should use the collection to create the object");
            //Assert.AreEqual(2, boCollection.Count, "Adding a row to the table should not add a bo to the main collection");
            Assert.AreEqual(3, boCollection.Count, "Adding a row to the table should add a bo to the main collection");
        }
        public void Read_ShouldLoadObjectsAsNew_WhenNotInExistingDataStore()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore = new DataStoreInMemory();
            var savedBo = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);
            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var writeStream = GetStreamForDataStore(savedDataStore);
            var reader = new ObjectTreeXmlReader();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(writeStream);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();
            Assert.AreEqual(1, businessObjects.Count);
            var loadedMyBo = (MyBO)businessObjects[0];
            Assert.AreNotSame(savedBo, loadedMyBo);

            Assert.IsTrue(loadedMyBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedMyBo.Status.IsDeleted, "Should not be Deleted");
        }
        public void Test_BOIsValid_WhenBORuleIsValid_ShouldBeValid()
        {
            //---------------Set up test pack-------------------
            MyBO bo = new MyBO();
            BusinessObjectRuleStub ruleStub = new BusinessObjectRuleStub();
            string msg;
            IList<IBOError> msgList;

            //---------------Assert Precondition----------------
            Assert.IsTrue(ruleStub.IsValid());

            Assert.IsTrue(bo.Status.IsValid());
            Assert.IsTrue(bo.Status.IsValid(out msg));
            Assert.IsTrue(bo.Status.IsValid(out msgList));
            //---------------Execute Test ----------------------
            bo.AddBusinessRule(ruleStub);
            //---------------Test Result -----------------------
            Assert.IsTrue(bo.Status.IsValid());
            Assert.IsTrue(bo.Status.IsValid(out msg));
            Assert.IsTrue(bo.Status.IsValid(out msgList));
            Assert.AreEqual(0,msgList.Count);
            TestUtil.AssertStringEmpty(msg, "msg");
            Assert.IsFalse(bo.Status.HasWarnings(out msgList));
        }
Пример #46
0
 public void Test_Instantiate_NewObjectIdRemainsAfterCancelEdit()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     string testPropDefault = TestUtil.GetRandomString();
     MyBO.LoadDefaultClassDefWithDefault(testPropDefault);
     MyBO bo = new MyBO();
     Guid id = bo.MyBoID.GetValueOrDefault();
     //-------------Assert Preconditions -------------
     //---------------Execute Test ----------------------
     bo.CancelEdits();
     //---------------Test Result -----------------------
     Assert.AreEqual(id, bo.MyBoID);
 }
Пример #47
0
		public void Test_SetPropertyDisplayValue_WithIntString_ShouldBeAbleGetString()
		{
			//---------------Set up test pack-------------------

			ClassDef.ClassDefs.Clear();
			MyBO.LoadDefaultClassDef();
			var testBo = new MyBO();
			var boMapper = new BOMapper(testBo);
			const string propName = "TestProp";
			boMapper.SetDisplayPropertyValue(propName, "7");
			//---------------Assert Precondition----------------
			Assert.AreEqual("7", boMapper.GetPropertyValueToDisplay(propName).ToString());
			//---------------Execute Test ----------------------
			boMapper.SetDisplayPropertyValue(propName, "3");
			//---------------Test Result -----------------------
			Assert.AreEqual("3", boMapper.GetPropertyValueToDisplay(propName).ToString());
			Assert.AreEqual("3", testBo.TestProp);
		}
 public void Test_CreateBusinessObject_OnlyFiresOneAddedEvent()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     MyBO.LoadClassDefWithRelationship();
     MyRelatedBo.LoadClassDef();
     MyBO bo = new MyBO();
     IMultipleRelationship rel = bo.Relationships.GetMultiple("MyMultipleRelationship");
     RelatedBusinessObjectCollection<MyRelatedBo> col = (RelatedBusinessObjectCollection<MyRelatedBo>)rel.BusinessObjectCollection;
     int addedEventCount = 0;
     col.BusinessObjectAdded += (sender, e) => addedEventCount++;
     //---------------Assert Precondition----------------
     Assert.AreEqual(0, addedEventCount);
     //---------------Execute Test ----------------------
     col.CreateBusinessObject();
     //---------------Test Result -----------------------
     Assert.AreEqual(1, addedEventCount);
 }
Пример #49
0
 public void TestInstantiate()
 {
     ClassDef.ClassDefs.Clear();
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     bo.GetPropertyValueString("TestProp");
 }
Пример #50
0
 public void Test_InitialiseProp_ValidBusinessObject()
 {
     //---------------Set up test pack-------------------
     BOProp boProp = new BOProp(_propDef);
     MyBO bo = new MyBO();
     //---------------Assert Precondition----------------
     Assert.IsNull(boProp.Value);
     //---------------Execute Test ----------------------
     boProp.InitialiseProp(bo);
     //---------------Test Result -----------------------
     Assert.IsNotNull(boProp.Value);
     Assert.IsTrue(boProp.Value is Guid, "Value should be a guid");
     Assert.AreEqual(bo.MyBoID, boProp.Value);
 }
Пример #51
0
 public void Test_InitialiseProp_InValidBusinessObject()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     MyBO.LoadDefaultClassDef_CompulsoryField_TestProp();
     BOProp boProp = new BOProp(_propDef);
     MyBO bo = new MyBO();
     //bo.SetPropertyValue("MyBoID", null);
     //---------------Assert Precondition----------------
     Assert.IsNull(boProp.Value);
     //---------------Execute Test ----------------------
     boProp.InitialiseProp(bo);
     //---------------Test Result -----------------------
     Assert.IsNotNull(boProp.Value);
     Assert.IsTrue(boProp.Value is Guid, "Value should be a guid");
     Assert.AreEqual(bo.MyBoID, boProp.Value);
 }
Пример #52
0
 public void Test_Instantiate_NewObjectIdIsBackedUp()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     string testPropDefault = TestUtil.GetRandomString();
     MyBO.LoadDefaultClassDefWithDefault(testPropDefault);
     //-------------Assert Preconditions -------------
     //---------------Execute Test ----------------------
     MyBO bo = new MyBO();
     //---------------Test Result -----------------------
     Assert.AreEqual(bo.MyBoID, bo.Props["MyBoID"].PersistedPropertyValue);
     Assert.IsTrue(bo.Props["MyBoID"].IsObjectNew);
 }
Пример #53
0
 public void Test_BusinessObject_WhenSetAgainToSameBo_ShouldNotThrowError()
 {
     //---------------Set up test pack-------------------
     IPropDef propDef = CreateTestPropPropDef();
     BOProp boProp = new BOProp(propDef);
     ClassDef.ClassDefs.Clear();
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     boProp.BusinessObject = bo;
     //---------------Assert Precondition----------------
     Assert.AreSame(bo, boProp.BusinessObject);
     //---------------Execute Test ----------------------
     Exception exception = null;
     try
     {
         boProp.BusinessObject = bo;
     } catch(Exception ex)
     {
         exception = ex;
     }
     //---------------Test Result -----------------------
     Assert.IsNull(exception);
     Assert.AreSame(bo, boProp.BusinessObject);
 }
Пример #54
0
 public void Test_BusinessObject_WhenSetAgain_ShouldThrowError()
 {
     //---------------Set up test pack-------------------
     IPropDef propDef = CreateTestPropPropDef();
     BOProp boProp = new BOProp(propDef);
     ClassDef.ClassDefs.Clear();
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     boProp.BusinessObject = bo;
     //---------------Assert Precondition----------------
     Assert.AreSame(bo, boProp.BusinessObject);
     //---------------Execute Test ----------------------
     try
     {
         boProp.BusinessObject = new MyBO();
         Assert.Fail("Expected to throw a HabaneroDeveloperException");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         StringAssert.Contains("Once a BOProp has been assigned to a BusinessObject it cannot be assigned to another BusinessObject.", ex.DeveloperMessage);
     }
 }
Пример #55
0
 public void Test_BusinessObject_SetAndGet()
 {
     //---------------Set up test pack-------------------
     IPropDef propDef = CreateTestPropPropDef();
     BOProp boProp = new BOProp(propDef);
     ClassDef.ClassDefs.Clear();
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     //---------------Assert Precondition----------------
     Assert.IsNull(boProp.BusinessObject);
     //---------------Execute Test ----------------------
     boProp.BusinessObject = bo;
     //---------------Test Result -----------------------
     Assert.AreSame(bo, boProp.BusinessObject);
 }
Пример #56
0
		public void TestGetLookupListDoesntExist()
		{
			ClassDef.ClassDefs.Clear();
			_itsClassDef = MyBO.LoadClassDefWithNoLookup();
			MyBO bo = new MyBO();
			BOMapper mapper = new BOMapper(bo);
			Assert.AreEqual(0, mapper.GetLookupList("TestProp").Count);
		}
Пример #57
0
        public void Test_IsValid_Valid_EmptyErrorDescriptions()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            MyBO myBO = new MyBO();
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            IList<IBOError> errors;
            bool isValid = myBO.Status.IsValid(out errors);
            //--------------- Test Result -----------------------
            Assert.IsTrue(isValid);
            Assert.AreEqual(0, errors.Count);
        }
Пример #58
0
        public void Test_IsValid_Errors()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef_CompulsoryField_TestProp();
            MyBO myBO = new MyBO();
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            IList<IBOError> errors;
            bool isValid = myBO.Status.IsValid(out errors);
            //--------------- Test Result -----------------------
            Assert.IsFalse(isValid);
            Assert.AreEqual(1, errors.Count);
            StringAssert.Contains("Test Prop' is a compulsory field and has no value", errors[0].Message);
            Assert.AreEqual(ErrorLevel.Error, errors[0].Level);
            Assert.AreSame(myBO, errors[0].BusinessObject);
        }
Пример #59
0
        public void Test_IsValueValid_ValueInLookupList_Guid()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            MyBO.LoadDefaultClassDef();
            PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null) ;
            MyBO validBusinessObject = new MyBO {TestProp = "ValidValue"};
            validBusinessObject.Save();
            propDef.LookupList = new BusinessObjectLookupList(typeof(MyBO));
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            string errMsg = "";
            bool valid = propDef.IsValueValid(validBusinessObject.ID.GetAsGuid(), ref errMsg);

            //---------------Test Result -----------------------
            Assert.AreEqual("", errMsg);
            Assert.IsTrue(valid);
        }
Пример #60
0
        public void Test_GetPropertyValueToDisplay_WhenRelatedVirtualPropertyValue_WithManyLevels_ShouldReturnRelatedValue()
	    {
	        //---------------Set up test pack-------------------
			ClassDef.ClassDefs.Clear();
		    MyBO.LoadClassDefWithRelationship();
		    MyRelatedBo.LoadClassDef();
	        var bo = new MyBO();
	        bo.MyRelationship = new MyRelatedBo();
            bo.MyRelationship.MyRelationship = new MyBO();
            bo.MyRelationship.MyRelationship.MyRelationship = new MyRelatedBo();
            bo.MyRelationship.MyRelationship.MyRelationship.MyRelationship = new MyBO();
	        //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var mapper = CreateBOMapper(bo);
            var propertyValueToDisplay = mapper.GetPropertyValueToDisplay("MyRelationship.MyRelationship.MyRelationship.MyRelationship.-MyName-");
	        //---------------Test Result -----------------------
	        Assert.AreEqual("MyNameIsMyBo", propertyValueToDisplay);
	    }