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_Create_WhenRelatedProp_ShouldCreateBOPropMapper() { //---------------Set up test pack------------------- const string propName = "Organisation.Name"; var bo = new ContactPersonTestBO(); //---------------Assert Precondition---------------- Assert.IsTrue(bo.Relationships.Contains("Organisation")); //---------------Execute Test ---------------------- IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName); //---------------Test Result ----------------------- Assert.IsInstanceOf <BOPropertyMapper>(propMapper); Assert.AreEqual(propName, propMapper.PropertyName); Assert.AreSame(bo, propMapper.BusinessObject); }
public void Test_Create_WhenReflectiveProp_WhenNotDefinedWithDash_ShouldCreateReflectivePropMapper() { //---------------Set up test pack------------------- const string propName = "ReflectiveProp"; var bo = new ContactPersonTestBO(); //---------------Assert Precondition---------------- var propertyInfo = ReflectionUtilities.GetPropertyInfo(bo.GetType(), propName); Assert.IsNotNull(propertyInfo); //---------------Execute Test ---------------------- IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName); //---------------Test Result ----------------------- Assert.IsInstanceOf <ReflectionPropertyMapper>(propMapper); Assert.AreEqual(propName, propMapper.PropertyName); Assert.AreSame(bo, propMapper.BusinessObject); }
public void Test_Create_WhenRelatedReflectiveProp_WithNullRelationship_ShouldCreateBOPropMapper() { //---------------Set up test pack------------------- const string propName = "Organisation.-Name-"; var bo = new ContactPersonTestBO(); bo.Organisation = null; //---------------Assert Precondition---------------- Assert.IsTrue(bo.Relationships.Contains("Organisation")); //---------------Execute Test ---------------------- IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName); //---------------Test Result ----------------------- Assert.IsInstanceOf <NullBOPropertyMapper>(propMapper); Assert.AreEqual(propName, propMapper.PropertyName); Assert.AreSame(bo, propMapper.BusinessObject); Assert.AreEqual("The 'Organisation' relationship of the 'ContactPersonTestBO' returned null, therefore the '-Name-' property could not be accessed.", propMapper.InvalidReason); }
public void Test_Create_WhenReflectiveProp_WhenReflectivePropNotExists_ShouldCreateReflectivePropMapper() { //---------------Set up test pack------------------- const string propName = "NonExistentReflectiveProp"; var bo = new ContactPersonTestBO(); //---------------Assert Precondition---------------- var propertyInfo = ReflectionUtilities.GetPropertyInfo(bo.GetType(), propName); Assert.IsNull(propertyInfo); //---------------Execute Test ---------------------- try { BOPropMapperFactory.CreateMapper(bo, propName); Assert.Fail("Expected to throw an InvalidPropertyException"); } //---------------Test Result ----------------------- catch (InvalidPropertyException ex) { StringAssert.Contains("The property 'NonExistentReflectiveProp' on 'ContactPersonTestBO' cannot be found", ex.Message); } }