public void Test_UsingGivenDatabaseConnection_Delete()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            MyBO.LoadDefaultClassDef();
            MyBO bo = new MyBO();

            bo.Save();
            bo.MarkForDelete();
            DatabaseConnection.CurrentConnection = null;

            //---------------Assert preconditions---------------
            Assert.AreNotSame(_databaseConnection, DatabaseConnection.CurrentConnection);
            //---------------Execute Test ----------------------
            TransactionalBusinessObjectDB transactional = new TransactionalBusinessObjectDB(bo, _databaseConnection);
            SqlStatement sqlStatement = (SqlStatement)transactional.GetPersistSql().FirstOrDefault();

            //---------------Test Result -----------------------
            Assert.AreSame(_databaseConnection, sqlStatement.Connection);
            //---------------Tear down -------------------------
        }
        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");
        }
        protected static BusinessObjectCollection <MyBO> CreateCollectionWith_4_Objects()
        {
            MyBO cp = new MyBO();

            cp.TestProp = "b";
            cp.Save();
            MyBO cp2 = new MyBO();

            cp2.TestProp = "d";
            cp2.Save();
            MyBO cp3 = new MyBO();

            cp3.TestProp = "c";
            cp3.Save();
            MyBO cp4 = new MyBO();

            cp4.TestProp = "a";
            cp4.Save();
            BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>();

            col.Add(cp, cp2, cp3, cp4);
            return(col);
        }
        public void Test_BusinessObjectEdited_WhenMultiSelected_ShouldRemainMultiSelected()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            var listBox       = GetControlFactory().CreateListBox();
            var manager       = CreateListBoxCollectionManager(listBox);
            var boToBeUpdated = new MyBO();
            var myBoCol       = new BusinessObjectCollection <MyBO> {
                new MyBO(), boToBeUpdated
            };

            manager.BusinessObjectCollection = myBoCol;

            manager.Control.SetSelected(1, true);
            //---------------Assert Precondition----------------
            Assert.IsTrue(manager.Control.SelectedItems.Contains(boToBeUpdated));
            //---------------Execute Test ----------------------
            boToBeUpdated.TestProp = GetRandomString();
            boToBeUpdated.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(manager.Control.SelectedItems.Contains(boToBeUpdated), "Should still be multi selected");
        }
        public void 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");
        }
Beispiel #6
0
        public virtual void TestRejectChanges()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            IClassDef classDef1     = MyBO.LoadDefaultClassDef();
            MyBO      myBO          = new MyBO();
            string    originalValue = TestUtil.GetRandomString();

            myBO.TestProp = originalValue;
            myBO.Save();
            IFormHabanero        frm;
            IStaticDataEditor    editor      = CreateEditorOnForm(out frm);
            IEditableGridControl gridControl = (IEditableGridControl)editor.Controls[0];

            editor.AddSection(TestUtil.GetRandomString());
            string itemName1 = TestUtil.GetRandomString();

            editor.AddItem(itemName1, classDef1);
            editor.SelectItem(itemName1);

            //---------------Execute Test ----------------------
            gridControl.Grid.SelectedBusinessObject = myBO;
            string newValue = TestUtil.GetRandomString();

            gridControl.Grid.CurrentRow.Cells["TestProp"].Value = newValue;
            bool result = editor.RejectChanges();

            //---------------Test Result -----------------------
            Assert.IsTrue(result);
            BusinessObjectCollection <MyBO> collection = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <MyBO>("");

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(originalValue, myBO.TestProp);
            Assert.IsFalse(myBO.Status.IsDirty);
            //---------------Tear Down -------------------------
            TearDownForm(frm);
        }
        public void Read_ShouldUpdatedExistingObject_WhenFoundInDataAccessor()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var newBo = new MyBO {
                TestProp = "characters"
            };
            var stream = GetStreamForBusinessObject(newBo);

            newBo.TestProp = "oldvalue";
            newBo.Save();
            var reader = new ObjectTreeXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual("oldvalue", newBo.TestProp);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(stream);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();

            Assert.AreEqual(1, businessObjects.Count);
            Assert.AreSame(newBo, businessObjects[0]);
            Assert.AreEqual("characters", newBo.TestProp);
        }
Beispiel #8
0
        public void Test_MarkForDelete_WhenSingle_WhenDeleteRelated_WhenNotHasRelatedBO_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"];

            SetDeleteRelatedAction(relationship, DeleteParentAction.DeleteRelated);
            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsNull(relationship.GetRelatedObject());
            Assert.AreEqual(DeleteParentAction.DeleteRelated, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            relationship.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(bo.Status.IsDeleted);
        }
Beispiel #9
0
        public void Test_IsDeletable_WhenSingle_WhenDeleteAction_EQ_PreventDelete_WhenNotHasRelated_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();
            SingleRelationship <MyRelatedBo> relationship = (SingleRelationship <MyRelatedBo>)bo.Relationships["MyRelationship"];

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

            //---------------Test Result -----------------------
            Assert.IsTrue(isDeletable);
        }
        public void TestLoadingRelatedObjectWithSingleTableInheritance()
        {
            //---------------Set up test pack-------------------
            DatabaseConnection.CurrentConnection.ExecuteRawSql(
                "delete from filledcircle_table; delete from circle_table; delete from shape_table");
            //MyBO has a relationship to Shape. Shape potentially has a circle for single table inheritance.
            MyBO.LoadClassDefWithShape_SingleTableInheritance_Relationship();

            MyBO bo = new MyBO();
            CircleNoPrimaryKey circle = new CircleNoPrimaryKey();
            circle.Radius = 5;
            circle.ShapeName = "MyShape";
            circle.Save();
            bo.SetPropertyValue("ShapeID", circle.ShapeID);
            bo.Save();

            FixtureEnvironment.ClearBusinessObjectManager();

            //---------------Execute Test ----------------------
            bo = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(bo.ID);
            Shape shape = bo.Shape;

            //---------------Test Result -----------------------
            Assert.AreSame(typeof (CircleNoPrimaryKey), shape.GetType());
            Assert.IsFalse(shape.Status.IsNew);
            Assert.IsFalse(shape.Status.IsDeleted);
            Assert.IsFalse(shape.Status.IsEditing);
            Assert.IsFalse(shape.Status.IsDirty);
            Assert.IsTrue(shape.Status.IsValid());
        }
        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 TestButtonsControl_ClickSaveAcceptsChanges()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            //---------------Clean from previous tests----------
            const string originalText = "testsavechanges";
            const string newText      = "testsavechanges_edited";
            Criteria     criteria     = new Criteria("TestProp", Criteria.ComparisonOp.Equals, originalText);
//            MyBO oldBO1 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(criteria);
//            if (oldBO1 != null)
//            {
//                oldBO1.MarkForDelete();
//                oldBO1.Save();
//            }
//            MyBO oldBO2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(criteria);
//            if (oldBO2 != null)
//            {
//                oldBO2.MarkForDelete();
//                oldBO2.Save();
//            }

            MyBO bo = new MyBO {
                TestProp = originalText
            };

            bo.Save();

            BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO> {
                bo, new MyBO {
                    TestProp = "SomeText"
                }
            };

            IEditableGridControl gridControl = GetControlFactory().CreateEditableGridControl();

            AddControlToForm(gridControl.Grid);
            SetupGridColumnsForMyBo(gridControl.Grid);
            gridControl.Grid.BusinessObjectCollection = col;
            //---------------Assert Precondition----------------
            Assert.AreEqual(3, gridControl.Grid.Rows.Count);
            Assert.AreEqual(originalText, gridControl.Grid.Rows[0].Cells[1].Value);
            criteria = new Criteria("TestProp", Criteria.ComparisonOp.Equals, newText);
            MyBO nullBO = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <MyBO>(criteria);

//            MyBO nullBO = BOLoader.Instance.GetBusinessObject<MyBO>("TestProp='" + newText + "'");
            Assert.IsNull(nullBO);
            //---------------Execute Test ----------------------
            gridControl.Grid.Rows[0].Cells[1].Value = newText;
            //---------------Assert Precondition----------------
            Assert.AreEqual(newText, gridControl.Grid.Rows[0].Cells[1].Value);
            gridControl.Grid.SelectedBusinessObject = col[1];
            //---------------Execute Test ----------------------
            gridControl.Buttons["Save"].PerformClick();
            //---------------Test Result -----------------------
            Assert.AreEqual(newText, gridControl.Grid.Rows[0].Cells[1].Value);
            criteria = new Criteria("TestProp", Criteria.ComparisonOp.Equals, newText);
            MyBO savedBO = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <MyBO>(criteria);

//            MyBO savedBO = BOLoader.Instance.GetBusinessObject<MyBO>("TestProp='" + newText + "'");
            Assert.IsNotNull(savedBO);
            //---------------Tear Down--------------------------
            savedBO.MarkForDelete();
            savedBO.Save();
        }
 public void Read_ShouldUpdatedExistingObject_WhenFoundInDataAccessor()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var newBo = new MyBO { TestProp = "characters" };
     var stream = GetStreamForBusinessObject(newBo);
     newBo.TestProp = "oldvalue";
     newBo.Save();
     var reader = new ObjectTreeXmlReader();
     //---------------Assert Precondition----------------
     Assert.AreEqual("oldvalue", newBo.TestProp);
     //---------------Execute Test ----------------------
     var loadedObjects = reader.Read(stream);
     //---------------Test Result -----------------------
     var businessObjects = loadedObjects.ToList();
     Assert.AreEqual(1, businessObjects.Count);
     Assert.AreSame(newBo, businessObjects[0]);
     Assert.AreEqual("characters", newBo.TestProp);
 }
        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").ToUpper(), ex.Message);
            }

        }
Beispiel #15
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);
        }
Beispiel #16
0
        public void TestIsMatch_UsingCurrentValue()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefWithBoolean();
            MyBO bo = new MyBO();
            bo.TestBoolean = false;
            bo.Save();

            bo.TestBoolean = true;
            Criteria criteria = new Criteria("TestBoolean", Criteria.ComparisonOp.Equals, true);

            //--------------- Execute Test ----------------------
            bool isMatch = criteria.IsMatch(bo, false);
            //--------------- Test Result -----------------------
            Assert.IsTrue(isMatch, "The object should be a match since its current values match the criteria given.");
        }
 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);
 }