public void Test_Map_WhenHasMultipleReverseRel_ShouldReturnRel_WithReverseRelNameSet() { //For the BusinessObject 'FakeBOWithUndefinableSingleRel' //If the Related Type (in this case 'FakeBOWithSingleAndMultipleRelToSameType') // for the Relatiosnhip 'MySingleRelWithOneToManyAttribute' // and has a Multiple Reverse Relationship 'MyMultipleRevRel' // then it should create the Relationship //---------------Set up test pack------------------- var classType = typeof(FakeBOWithUndefinableSingleRel); var reverseClassType = typeof(FakeBOWithSingleAndMultipleRelToSameType); const string expectedPropName = "MySingleRelWithOneToManyAttribute"; var propertyInfo = classType.GetProperty(expectedPropName); PropertyWrapper propWrapper = propertyInfo.ToPropertyWrapper(); //---------------Assert Precondition---------------- classType.AssertPropertyExists(expectedPropName); propertyInfo.AssertIsOfType(reverseClassType); var reversePropInfo = reverseClassType.GetProperty("MySingleRevRel"); Assert.IsNotNull(reversePropInfo); reversePropInfo.AssertIsOfType <FakeBOWithUndefinableSingleRel>(); Assert.IsTrue(propWrapper.HasMultipleReverseRelationship); Assert.IsTrue(propWrapper.HasAttribute <AutoMapManyToOneAttribute>()); //---------------Execute Test ---------------------- var relationshipDef = propertyInfo.MapManyToOne(); //---------------Test Result ----------------------- Assert.IsNotNull(relationshipDef); Assert.AreEqual("MyMultipleRevRel", relationshipDef.ReverseRelationshipName); }
public static void AssertHasAttribute <T>(this PropertyInfo propertyInfo) where T : class { PropertyWrapper propertyWrapper = propertyInfo.ToPropertyWrapper(); Assert.IsTrue(propertyWrapper.HasAttribute <T>() , propertyWrapper.Name + string.Format(" does not have a '{0}' attribute", typeof(T))); }
public void Test_Map_WhenNoReverseRelationship_NoAttributes_ShouldReturnRel_WithConventionMultipleReverseRel() { //---------------Set up test pack------------------- const string expectedPropName = "MySingleRelationship"; var type = typeof(FakeBOWithSingleRel); PropertyInfo propertyInfo = type.GetProperty(expectedPropName); PropertyWrapper propWrapper = propertyInfo.ToPropertyWrapper(); //---------------Assert Precondition---------------- propertyInfo.AssertIsOfType <IBusinessObject>(); Assert.IsFalse(propWrapper.HasSingleReverseRelationship); Assert.IsFalse(propWrapper.HasMultipleReverseRelationship); Assert.IsFalse(propWrapper.HasAttribute <AutoMapManyToOneAttribute>()); Assert.IsFalse(propWrapper.HasAttribute <AutoMapOneToOneAttribute>()); //---------------Execute Test ---------------------- var relationshipDef = propertyInfo.MapManyToOne(); //---------------Test Result ----------------------- Assert.IsNotNull(relationshipDef); Assert.AreEqual("FakeBOWithSingleRels", relationshipDef.ReverseRelationshipName); }
public void Test_Map_WhenHasOneToOneAttribute_ShouldReturnNull() { //---------------Set up test pack------------------- var classType = typeof(FakeBOWithOneToOneAttribute); const string expectedPropName = "MySingleRelationship"; var propertyInfo = classType.GetProperty(expectedPropName); PropertyWrapper propWrapper = propertyInfo.ToPropertyWrapper(); //---------------Assert Precondition---------------- classType.AssertPropertyExists(expectedPropName); propertyInfo.AssertIsOfType <IBusinessObject>(); propWrapper.HasAttribute <AutoMapOneToOneAttribute>(); //---------------Execute Test ---------------------- var relationshipDef = propertyInfo.MapManyToOne(); //---------------Test Result ----------------------- Assert.IsNull(relationshipDef); }
public void Test_Map_WhenHasAttributeDeclareRevRelName_ShouldReturnRel_WithDeclaredRevRelName() { //---------------Set up test pack------------------- const string expectedPropName = "MySingleRelationship"; var type = typeof(FakeBOWithSingleAttributeDeclaredRevRel); const string reverseRelName = "AttributeRevRelName"; PropertyInfo propertyInfo = type.GetProperty(expectedPropName); PropertyWrapper propWrapper = propertyInfo.ToPropertyWrapper(); //---------------Assert Precondition---------------- Assert.IsTrue(propWrapper.IsSingleRelationship); Assert.IsFalse(propWrapper.HasSingleReverseRelationship); Assert.IsFalse(propWrapper.HasMultipleReverseRelationship); Assert.IsTrue(propWrapper.HasAttribute <AutoMapManyToOneAttribute>()); //---------------Execute Test ---------------------- var relationshipDef = propertyInfo.MapManyToOne(); //---------------Test Result ----------------------- Assert.IsNotNull(relationshipDef); Assert.AreEqual(reverseRelName, relationshipDef.ReverseRelationshipName); }