public void Test_LoadingFromMultipleSources() { //---------------Set up test pack------------------- DataStoreInMemory dataStore1 = new DataStoreInMemory(); MyBO bo1 = CreateMyBO(dataStore1); BusinessObjectLoaderInMemory loader1 = new BusinessObjectLoaderInMemory(dataStore1); DataStoreInMemory dataStore2 = new DataStoreInMemory(); MyRelatedBo bo2 = CreateMyRelatedBO(dataStore2); BusinessObjectLoaderInMemory loader2 = new BusinessObjectLoaderInMemory(dataStore2); BusinessObjectLoaderInMemory defaultBusinessObjectLoader = new BusinessObjectLoaderInMemory(new DataStoreInMemory()); BusinessObjectLoaderMultiSource businessObjectLoaderMultiSource = new BusinessObjectLoaderMultiSource(defaultBusinessObjectLoader); //---------------Execute Test ---------------------- businessObjectLoaderMultiSource.AddBusinessObjectLoader(typeof(MyBO), loader1); businessObjectLoaderMultiSource.AddBusinessObjectLoader(typeof(MyRelatedBo), loader2); var loadedBo1 = businessObjectLoaderMultiSource.GetBusinessObject <MyBO>(bo1.ID); var loadedBo2 = businessObjectLoaderMultiSource.GetBusinessObject <MyRelatedBo>(bo2.ID); //---------------Tear down ------------------------- Assert.AreSame(loadedBo1, bo1); Assert.AreSame(loadedBo2, bo2); }
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); }
public void Test_SavingToMultipleSources() { //---------------Set up test pack------------------- DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataStoreInMemory dataStore2 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2); DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory()); dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1); dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); var bo1 = new MyBO(); var bo2 = new MyRelatedBo(); //---------------Execute Test ---------------------- ITransactionCommitter committer1 = dataAccessor.CreateTransactionCommitter(); committer1.AddBusinessObject(bo1); committer1.CommitTransaction(); ITransactionCommitter committer2 = dataAccessor.CreateTransactionCommitter(); committer2.AddBusinessObject(bo2); committer2.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsNotNull(dataStore1.Find <MyBO>(bo1.ID)); Assert.IsNotNull(dataStore2.Find <MyRelatedBo>(bo2.ID)); //---------------Tear down ------------------------- }
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); }
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)); }
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 void Test_Success_WhenAddingObjectsOfDifferentTypesWithSameDataAccessors() { //---------------Set up test pack------------------- IDataAccessor defaultDataAccessor = new DataAccessorInMemory(); DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); MyBO bo1 = new MyBO(); MyRelatedBo bo2 = new MyRelatedBo(); Dictionary <Type, IDataAccessor> dataAccessors = new Dictionary <Type, IDataAccessor>(); dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1); dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory1); //---------------Execute Test ---------------------- ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors); transactionCommitter1.AddBusinessObject(bo1); transactionCommitter1.AddBusinessObject(bo2); transactionCommitter1.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsNotNull(dataStore1.Find <MyBO>(bo1.ID)); Assert.IsNotNull(dataStore1.Find <MyRelatedBo>(bo2.ID)); //---------------Tear down ------------------------- }
public void Test_Create_WhenReflectiveProp_WithTwoRelationshipLevels_ShouldCreateReflectivePropMapper() { //---------------Set up test pack------------------- const string propName = "MyName"; var propNameWithDashes = string.Format("-{0}-", propName); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyBO(); var myRelatedBo = new MyRelatedBo(); bo.MyRelationship = myRelatedBo; bo.MyRelationship.MyRelationship = new MyBO(); var propertyPath = "MyRelationship.MyRelationship." + propNameWithDashes; //---------------Assert Precondition---------------- Assert.IsNotNull(ReflectionUtilities.GetPropertyInfo(bo.MyRelationship.MyRelationship.GetType(), propName)); //---------------Execute Test ---------------------- IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propertyPath); //---------------Test Result ----------------------- Assert.IsInstanceOf <ReflectionPropertyMapper>(propMapper); Assert.AreEqual(propName, propMapper.PropertyName); Assert.AreSame(bo.MyRelationship.MyRelationship, propMapper.BusinessObject); }
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); }
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); }
private MyRelatedBo CreateMyRelatedBO(DataStoreInMemory dataStore2) { MyRelatedBo.LoadClassDef(); TransactionCommitterInMemory committer2 = new TransactionCommitterInMemory(dataStore2); var bo2 = new MyRelatedBo(); committer2.AddBusinessObject(bo2); committer2.CommitTransaction(); return(bo2); }
public void BinaryExpression_WithRelationship_NotEquals_ShouldCreateCriteriaOnRelationshipFields() { //---------------Set up test pack------------------- MyBO.LoadClassDefWithAssociationRelationship(); MyRelatedBo.LoadClassDef(); var bo1 = new MyBO(); var expectedCriteria = new Criteria("MyRelationship.MyBoID", Criteria.ComparisonOp.NotEquals, bo1.ID.GetAsGuid()); //---------------Execute Test ---------------------- var criteria = Criteria.Expr <MyRelatedBo>(bo => bo.MyRelationship != bo1).Build(); //---------------Test Result ----------------------- Assert.AreEqual(expectedCriteria, criteria); }
public void Test_Criteria_OneProp_NullValue() { //--------------- Set up test pack ------------------ MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyRelatedBo myRelatedBo = new MyRelatedBo(); SingleRelationship<MyBO> relationship = myRelatedBo.Relationships.GetSingle<MyBO>("MyRelationship"); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- Criteria relCriteria = relationship.RelKey.Criteria; //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase("MyBoID IS NULL", relCriteria.ToString()); }
public void TestIndexer() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO)classDef.CreateNewBusinessObject(); //---------------Execute Test ---------------------- IRelationship relationship = bo1.Relationships["MyMultipleRelationship"]; //---------------Test Result ----------------------- Assert.IsNotNull(relationship); }
public void RelationshipType_ShouldBeSameAsRelationshipDefRelationshipType() { //---------------Set up test pack------------------- MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyBO(); var relationship = bo.Relationships["MyRelationship"]; var expectedRelationshipType = relationship.RelationshipDef.RelationshipType; //---------------Execute Test ---------------------- RelationshipType relationshipType = relationship.RelationshipType; //---------------Test Result ----------------------- Assert.AreEqual(expectedRelationshipType, relationshipType); }
public void Test_Criteria_OneProp_NullValue() { //--------------- Set up test pack ------------------ MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyRelatedBo myRelatedBo = new MyRelatedBo(); SingleRelationship <MyBO> relationship = myRelatedBo.Relationships.GetSingle <MyBO>("MyRelationship"); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- Criteria relCriteria = relationship.RelKey.Criteria; //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase("MyBoID IS NULL", relCriteria.ToString()); }
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 TestSetRelatedBusinessObject() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithRelationship(); IClassDef relatedClassDef = MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO)classDef.CreateNewBusinessObject(); MyRelatedBo relatedBo1 = (MyRelatedBo)relatedClassDef.CreateNewBusinessObject(); //---------------Execute Test ---------------------- bo1.Relationships.SetRelatedObject("MyRelationship", relatedBo1); //---------------Test Result ----------------------- Assert.AreSame(relatedBo1, bo1.Relationships.GetRelatedObject <MyRelatedBo>("MyRelationship")); Assert.AreSame(bo1.GetPropertyValue("RelatedID"), relatedBo1.GetPropertyValue("MyRelatedBoID")); }
protected void SetupClassDefs(object propValue) { ClassDef.ClassDefs.Clear(); IClassDef itsClassDef = MyBO.LoadClassDefWithRelationship(); IClassDef itsRelatedClassDef = MyRelatedBo.LoadClassDef(); itsMyBo = (MyBO)itsClassDef.CreateNewBusinessObject(); MyRelatedBo relatedBo = (MyRelatedBo)itsRelatedClassDef.CreateNewBusinessObject(); Guid myRelatedBoGuid = relatedBo.ID.GetAsGuid(); itsMyBo.SetPropertyValue("RelatedID", myRelatedBoGuid); relatedBo.SetPropertyValue("MyRelatedTestProp", propValue); itsMyBo.Save(); relatedBo.Save(); }
public void Test_IsOneToOne_WhenHasReverseRelationshipAndIsOneToMany_ShouldBeFalse() { //---------------Set up test pack------------------- var classDef = MyBO.LoadClassDefWithSingleRelationshipWithReverseRelationship(); var relationshipDef = classDef.RelationshipDefCol["MyRelationship"]; MyRelatedBo.LoadClassDefWithMultipleRelationshipBackToMyBo(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bool isOneToOne = relationshipDef.IsOneToOne; //---------------Test Result ----------------------- Assert.IsFalse(isOneToOne); }
public void CreateQueryField_WithRelatedClass() { //---------------Set up test pack------------------- var classDef = MyBO.LoadClassDefWithRelationship(); var relatedClassDef = MyRelatedBo.LoadClassDef(); const string relationshipName = "MyRelationship"; const string propertyName = "MyRelatedTestProp"; const string fullpropertyName = relationshipName + "." + propertyName; //---------------Execute Test ---------------------- var queryField = QueryBuilder.CreateQueryField(classDef, fullpropertyName); //---------------Test Result ----------------------- Assert.AreEqual(propertyName, queryField.PropertyName); Assert.AreEqual(propertyName, queryField.FieldName); Assert.AreEqual(new Source(relatedClassDef.ClassName), queryField.Source); }
public void Test_GetPropertyValue_WithDot() { ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadClassDefWithRelationship(); _itsRelatedClassDef = MyRelatedBo.LoadClassDef(); //MyBO bo1 = (MyBO)itsClassDef.CreateNewBusinessObject(connection); MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject(); MyRelatedBo relatedBo = (MyRelatedBo)_itsRelatedClassDef.CreateNewBusinessObject(); Guid myRelatedBoGuid = relatedBo.ID.GetAsGuid(); bo1.SetPropertyValue("RelatedID", myRelatedBoGuid); relatedBo.SetPropertyValue("MyRelatedTestProp", "MyValue"); BOMapper mapper = new BOMapper(bo1); Assert.AreEqual("MyValue", mapper.GetPropertyValueToDisplay("MyRelationship.MyRelatedTestProp")); }
public void TestSetOrderCriteria_AddsJoinToSource_OnlyOnce() { //---------------Set up test pack------------------- MyRelatedBo.LoadClassDefWithDifferentTableAndFieldNames(); IClassDef myBoClassdef = MyBO.LoadClassDefWithRelationship(); ISelectQuery selectQuery = QueryBuilder.CreateSelectQuery(myBoClassdef); IOrderCriteria orderCriteria = QueryBuilder.CreateOrderCriteria(myBoClassdef, "MyRelationship.MyRelatedTestProp, MyRelationship.MyRelatedTestProp2"); //---------------Execute Test ---------------------- selectQuery.OrderCriteria = orderCriteria; //---------------Test Result ----------------------- Assert.AreEqual(1, selectQuery.Source.Joins.Count); //---------------Tear Down ------------------------- }
public void TestGetMultiple() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO)classDef.CreateNewBusinessObject(); string relationshipName = "MyMultipleRelationship"; //---------------Execute Test ---------------------- IMultipleRelationship relationship = bo1.Relationships.GetMultiple(relationshipName); //---------------Test Result ----------------------- Assert.IsNotNull(relationship); Assert.AreEqual(relationshipName, relationship.RelationshipName); }
public void TestIsDirty_NotDirtyRelationship() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); MyBO.LoadClassDefWithAssociationRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo = new MyBO(); //---------------Assert Precondition---------------- Assert.IsFalse(bo.MyMultipleRelationship.IsDirty); //---------------Execute Test ---------------------- bool isDirty = bo.Relationships.IsDirty; //---------------Test Result ----------------------- Assert.IsFalse(isDirty, "Should be dirty since dirty Association relationships do make the RelationshipCol dirty"); }
public void Test_GetPropertyValueToDisplay_WhenRelatedVirtualPropertyValue_WithNullRelationship_ShouldReturnNullValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyRelatedBo(); bo.MyRelationship = null; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var mapper = CreateBOMapper(bo); var propertyValueToDisplay = mapper.GetPropertyValueToDisplay("MyRelationship.-MyName-"); //---------------Test Result ----------------------- Assert.IsNull(propertyValueToDisplay); }
public void Test_SetDisplayPropertyValue_WithRelatedVirtualPropName_ShouldSetPropValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyRelatedBo(); bo.MyRelationship = new MyBO(); var myNewValue = "MyNewValue"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var mapper = CreateBOMapper(bo); mapper.SetDisplayPropertyValue("MyRelationship.-MySettableVirtualProp-", myNewValue); //---------------Test Result ----------------------- Assert.AreEqual(myNewValue, bo.MyRelationship.MySettableVirtualProp); }
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); }
public void Test_ShouldThrowError_WhenAddingObjectsOfDifferentTypesWithDifferentDataAccessors() { //---------------Set up test pack------------------- IDataAccessor defaultDataAccessor = new DataAccessorInMemory(); DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataStoreInMemory dataStore2 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); MyBO bo1 = new MyBO(); MyRelatedBo bo2 = new MyRelatedBo(); Dictionary <Type, IDataAccessor> dataAccessors = new Dictionary <Type, IDataAccessor>(); dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1); dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory2); //---------------Execute Test ---------------------- try { ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors); transactionCommitter1.AddBusinessObject(bo1); transactionCommitter1.AddBusinessObject(bo2); transactionCommitter1.CommitTransaction(); Assert.Fail("Error should have occurred"); } catch (HabaneroDeveloperException ex) //---------------Test Result ----------------------- { Assert.IsNull(dataStore1.Find <MyBO>(bo1.ID)); Assert.IsNull(dataStore1.Find <MyRelatedBo>(bo2.ID)); Assert.IsNull(dataStore2.Find <MyBO>(bo1.ID)); Assert.IsNull(dataStore2.Find <MyRelatedBo>(bo2.ID)); StringAssert.Contains("MyRelatedBo", ex.DeveloperMessage); StringAssert.Contains("was added to a TransactionCommitterMultiSource which has been set up with a different source to this type", ex.DeveloperMessage); //correct } //---------------Tear down ------------------------- }
public void TestMissingRelationshipErrorMessageMultiple() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO)classDef.CreateNewBusinessObject(); //---------------Execute Test ---------------------- try { bo1.Relationships.GetRelatedCollection("WrongRelationshipName"); Assert.Fail("Expected to throw an RelationshipNotFoundException"); } //---------------Test Result ----------------------- catch (RelationshipNotFoundException ex) { StringAssert.Contains("The relationship WrongRelationshipName was not found on a BusinessObject of type Habanero.Test.MyBO", ex.Message); } }
public void TestInvalidRelationshipAccessSingle() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO)classDef.CreateNewBusinessObject(); //---------------Execute Test ---------------------- try { bo1.Relationships.GetRelatedCollection("MyRelationship"); Assert.Fail("Expected to throw an InvalidRelationshipAccessException"); } //---------------Test Result ----------------------- catch (InvalidRelationshipAccessException ex) { StringAssert.Contains("The 'single' relationship MyRelationship was accessed as a 'multiple' relationship (using GetRelatedCollection()).", ex.Message); } }
public void Test_SetDisplayPropertyValue_WithRelatedPropName_WhenNullRelationship_ShouldSetPropValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyRelatedBo(); bo.MyRelationship = null; var myNewValue = "MyNewValue"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var mapper = CreateBOMapper(bo); Assert.DoesNotThrow(() => { mapper.SetDisplayPropertyValue("MyRelationship.TestProp", myNewValue); }); //---------------Test Result ----------------------- }
public void Test_Create_WhenReflectiveProp_WithTwoRelationshipLevels_ShouldCreateReflectivePropMapper() { //---------------Set up test pack------------------- const string propName = "MyName"; var propNameWithDashes = string.Format("-{0}-", propName); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyBO(); var myRelatedBo = new MyRelatedBo(); bo.MyRelationship = myRelatedBo; bo.MyRelationship.MyRelationship = new MyBO(); var propertyPath = "MyRelationship.MyRelationship." + propNameWithDashes; //---------------Assert Precondition---------------- Assert.IsNotNull(ReflectionUtilities.GetPropertyInfo(bo.MyRelationship.MyRelationship.GetType(), propName)); //---------------Execute Test ---------------------- IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propertyPath); //---------------Test Result ----------------------- Assert.IsInstanceOf<ReflectionPropertyMapper>(propMapper); Assert.AreEqual(propName, propMapper.PropertyName); Assert.AreSame(bo.MyRelationship.MyRelationship, propMapper.BusinessObject); }
private MyRelatedBo CreateMyRelatedBO(DataStoreInMemory dataStore2) { MyRelatedBo.LoadClassDef(); TransactionCommitterInMemory committer2 = new TransactionCommitterInMemory(dataStore2); var bo2 = new MyRelatedBo(); committer2.AddBusinessObject(bo2); committer2.CommitTransaction(); return bo2; }
public void Test_UsingDataAccessorAssignedForType() { //---------------Set up test pack------------------- IDataAccessor defaultDataAccessor = new DataAccessorInMemory(); DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataStoreInMemory dataStore2 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); MyBO bo1 = new MyBO(); MyRelatedBo bo2 = new MyRelatedBo(); Dictionary<Type, IDataAccessor> dataAccessors = new Dictionary<Type, IDataAccessor>(); dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1); dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory2); //---------------Execute Test ---------------------- ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors); transactionCommitter1.AddBusinessObject(bo1); transactionCommitter1.CommitTransaction(); ITransactionCommitter transactionCommitter2 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors); transactionCommitter2.AddBusinessObject(bo2); transactionCommitter2.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsNotNull(dataStore1.Find<MyBO>(bo1.ID)); Assert.IsNull(dataStore2.Find<MyBO>(bo1.ID)); Assert.IsNotNull(dataStore2.Find<MyRelatedBo>(bo2.ID)); Assert.IsNull(dataStore1.Find<MyRelatedBo>(bo2.ID)); //---------------Tear down ------------------------- }
public void Test_ShouldThrowError_WhenAddingObjectsOfDifferentTypesWithDifferentDataAccessors() { //---------------Set up test pack------------------- IDataAccessor defaultDataAccessor = new DataAccessorInMemory(); DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataStoreInMemory dataStore2 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); MyBO bo1 = new MyBO(); MyRelatedBo bo2 = new MyRelatedBo(); Dictionary<Type, IDataAccessor> dataAccessors = new Dictionary<Type, IDataAccessor>(); dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1); dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory2); //---------------Execute Test ---------------------- try { ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors); transactionCommitter1.AddBusinessObject(bo1); transactionCommitter1.AddBusinessObject(bo2); transactionCommitter1.CommitTransaction(); Assert.Fail("Error should have occurred"); } catch (HabaneroDeveloperException ex) //---------------Test Result ----------------------- { Assert.IsNull(dataStore1.Find<MyBO>(bo1.ID)); Assert.IsNull(dataStore1.Find<MyRelatedBo>(bo2.ID)); Assert.IsNull(dataStore2.Find<MyBO>(bo1.ID)); Assert.IsNull(dataStore2.Find<MyRelatedBo>(bo2.ID)); StringAssert.Contains("MyRelatedBo", ex.DeveloperMessage); StringAssert.Contains("was added to a TransactionCommitterMultiSource which has been set up with a different source to this type", ex.DeveloperMessage); //correct } //---------------Tear down ------------------------- }
public void Test_SavingToMultipleSources() { //---------------Set up test pack------------------- DataStoreInMemory dataStore1 = new DataStoreInMemory(); DataStoreInMemory dataStore2 = new DataStoreInMemory(); DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1); DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2); DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory()); dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1); dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2); MyBO.LoadDefaultClassDef(); MyRelatedBo.LoadClassDef(); var bo1 = new MyBO(); var bo2 = new MyRelatedBo(); //---------------Execute Test ---------------------- ITransactionCommitter committer1 = dataAccessor.CreateTransactionCommitter(); committer1.AddBusinessObject(bo1); committer1.CommitTransaction(); ITransactionCommitter committer2 = dataAccessor.CreateTransactionCommitter(); committer2.AddBusinessObject(bo2); committer2.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsNotNull(dataStore1.Find<MyBO>(bo1.ID)); Assert.IsNotNull(dataStore2.Find<MyRelatedBo>(bo2.ID)); //---------------Tear down ------------------------- }
public void Test_SetDisplayPropertyValue_WithRelatedVirtualPropName_WhenNullRelationship_ShouldSetPropValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var bo = new MyRelatedBo(); bo.MyRelationship = null; var myNewValue = "MyNewValue"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var mapper = CreateBOMapper(bo); Assert.DoesNotThrow(() => { mapper.SetDisplayPropertyValue("MyRelationship.-MySettableVirtualProp-", myNewValue); }); //---------------Test Result ----------------------- }
public void Test_NewBusObject_Added() { //Test add new business object adds to created collection and sets the foreign key fields //---------------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); MyRelatedBo relatedBo = new MyRelatedBo(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- col.Add(relatedBo); //---------------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(1, col.Count); Assert.AreEqual(0, col.AddedBusinessObjects.Count); }
public void Test_IsDeletable_WhenSingle_WhenHasRelatedBO_WhenPreventDelete_WhenRelatedBOMarked4Delete_ShouldReturnTrue() { //---------------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"]; MyRelatedBo myRelatedBO = new MyRelatedBo(); relationship.SetRelatedObject(myRelatedBO); myRelatedBO.MarkForDelete(); //---------------Assert Precondition---------------- Assert.IsFalse(bo.Status.IsDeleted); Assert.IsFalse(bo.Status.IsNew); Assert.IsTrue(bo.Status.IsDirty); Assert.IsTrue(bo.Status.IsEditing); Assert.IsNotNull(relationship.GetRelatedObject()); Assert.AreEqual(DeleteParentAction.Prevent, relationship.DeleteParentAction); //---------------Execute Test ---------------------- string message; bool isDeletable = bo.IsDeletable(out message); //---------------Test Result ----------------------- Assert.IsTrue(isDeletable); }