public void TestGetBusinessObjectByIDInt_CriteriaString_Untyped() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef classDef = BOWithIntID.LoadClassDefWithIntID(); BOWithIntID bo = new BOWithIntID { IntID = TestUtil.GetRandomInt() }; bo.Save(); BORegistry.BusinessObjectManager = new BusinessObjectManagerSpy();//Ensures a new BOMan is created and used for each test //---------------Execute Test ---------------------- BOWithIntID bo1 = (BOWithIntID)BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject (classDef, string.Format("IntID = {0}", bo.IntID)); //---------------Test Result ----------------------- Assert.IsNotNull(bo1); BOWithIntID bo2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <BOWithIntID>(bo1.ID); Assert.AreSame(bo1, bo2); }
public void TestGetBusinessObjectByIDInt_ByCriteriaObject() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BOWithIntID.LoadClassDefWithIntID(); BOWithIntID bo = new BOWithIntID { IntID = TestUtil.GetRandomInt() }; bo.Save(); BORegistry.BusinessObjectManager = new BusinessObjectManagerSpy();//Ensures a new BOMan is created and used for each test Criteria criteria = new Criteria("IntID", Criteria.ComparisonOp.Equals, bo.IntID.ToString()); //---------------Execute Test ---------------------- BOWithIntID bo1 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <BOWithIntID>(criteria); //---------------Test Result ----------------------- Assert.IsNotNull(bo1); BOWithIntID bo2 = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <BOWithIntID>(bo1.ID); Assert.AreSame(bo1, bo2); }
public void Test_GetBusinessObjectFromObjectManager_IdInObjectManager_ButWrongType() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); BOWithIntID.LoadClassDefWithIntID(); BOWithIntID_DifferentType.LoadClassDefWithIntID(); PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); BOWithIntID expectedBO = new BOWithIntID { IntID = 3, TestField = "ValidValue" }; expectedBO.Save(); propDef.LookupList = new BusinessObjectLookupList(typeof(BOWithIntID_DifferentType)); //---------------Assert Precondition---------------- Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count); //---------------Execute Test ---------------------- IBusinessObject returnedBO = propDef.GetlookupBusinessObjectFromObjectManager(expectedBO.IntID); //---------------Test Result ----------------------- Assert.IsNull(returnedBO); }
public void Test_GetBusinessObjectFromObjectManager() { //---------------Set up test pack------------------- FixtureEnvironment.ClearBusinessObjectManager(); ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); BOWithIntID.LoadClassDefWithIntID(); PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null); BOWithIntID expectedBO = new BOWithIntID { IntID = 3, TestField = "ValidValue" }; expectedBO.Save(); propDef.LookupList = new BusinessObjectLookupList(typeof(BOWithIntID)); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBusinessObject returnedBO = propDef.GetlookupBusinessObjectFromObjectManager(expectedBO.IntID); //---------------Test Result ----------------------- Assert.AreSame(expectedBO, returnedBO ); }
public void Test_IsValueValid_ValueInLookupList_Int() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); BORegistry.DataAccessor = new DataAccessorInMemory(); BOWithIntID.LoadClassDefWithIntID(); PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null) ; BOWithIntID validBusinessObject = new BOWithIntID { IntID = 3, TestField = "ValidValue" }; validBusinessObject.Save(); propDef.LookupList = new BusinessObjectLookupList(typeof(BOWithIntID)); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- string errMsg = ""; bool valid = propDef.IsValueValid(validBusinessObject.IntID, ref errMsg); //---------------Test Result ----------------------- Assert.AreEqual("", errMsg); Assert.IsTrue(valid); }
public void Test_TwoObjectTypesWithTheSameIDField_EdidtedToHaveTheSamevalue_ResetOneInRelationships_WDuplicateID() { //--------------- Set up test pack ------------------ const int id = 3; BOWithIntID boWithIntID = new BOWithIntID { IntID = id }; BOWithIntID_DifferentType boWithIntID_DifferentType = new BOWithIntID_DifferentType { IntID = id }; boWithIntID_DifferentType.IntID = boWithIntID.IntID; SingleRelationship<BOWithIntID> parentRelationship = (SingleRelationship<BOWithIntID>)boWithIntID.Relationships["MyParentBOWithInt"]; //--------------- Test Preconditions ---------------- Assert.AreEqual(2, BORegistry.BusinessObjectManager.Count); Assert.IsNull(parentRelationship.GetRelatedObject()); Assert.AreEqual(boWithIntID.IntID, boWithIntID_DifferentType.IntID); //--------------- Execute Test ---------------------- BOWithIntID childBOWithID = new BOWithIntID { IntID = 4 }; SingleRelationship<BOWithIntID> childRelationship = (SingleRelationship<BOWithIntID>)childBOWithID.Relationships["MyChildBoWithInt"]; childRelationship.SetRelatedObject(boWithIntID); //--------------- Test Result ----------------------- Assert.AreSame(childBOWithID ,parentRelationship.GetRelatedObject()); Assert.AreSame(boWithIntID, childRelationship.GetRelatedObject()); Assert.AreEqual(parentRelationship.GetReverseRelationship(childBOWithID), childRelationship); }