public void Test_GetRelatedPropName_WhenRelatedClassHasAttributeDeclaredIdProp_ShouldUseDeclaredIDPropName() { //---------------Set up test pack------------------- SetFakeNameConvention(); var classType = typeof(FakeBOAttributePKAndPKNaming); PropertyInfo propertyInfo = classType.GetProperty("MyMultipleRevRel"); string expectedRelatedPropName = classType.ToTypeWrapper().GetPKPropName(); //---------------Assert Precondition---------------- Assert.AreEqual("PublicGuidProp", expectedRelatedPropName); //---------------Execute Test ---------------------- OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propertyInfo); var relatedPropName = autoMapper.GetRelatedPropName(); //---------------Test Result ----------------------- Assert.AreEqual(expectedRelatedPropName, relatedPropName); }
public void Test_GetRelatatedPropName_WhenStdNamingPropAndRelDeclaredProp_ShouldReturnDeclaredPropName() { //---------------Set up test pack------------------- var classType = typeof(FakeBOAttributePKAndPKNaming); const string expectedPropName = "MyMultipleRevRel2"; PropertyInfo propertyInfo = classType.GetProperty(expectedPropName); PropertyWrapper propertyWrapper = propertyInfo.ToPropertyWrapper(); OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propertyInfo); //---------------Assert Precondition---------------- classType.AssertPropertyExists(expectedPropName); propertyInfo.AssertIsMultipleRelationship(); Assert.IsTrue(propertyWrapper.HasSingleReverseRelationship, "There is no reverse single rel"); PropertyWrapper reverseRelPropInfo = propertyWrapper.GetSingleReverseRelPropInfos()[0]; string expectedRelatedPropName = reverseRelPropInfo.Name + "ID"; //---------------Execute Test ---------------------- var relatedPropName = autoMapper.GetRelatedPropName(); //---------------Test Result ----------------------- Assert.AreEqual(expectedRelatedPropName, relatedPropName); }
public void Test_GetRelatatedPropName_WhenNoRevNonDefaultNaming_ShouldReturnNamingProp() { //---------------Set up test pack------------------- SetFakeNameConvention(); var classType = typeof(FakeBoWithMultipleRel); const string expectedPropName = "MyMultipleRevRel"; PropertyInfo propertyInfo = classType.GetProperty(expectedPropName); OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propertyInfo); //---------------Assert Precondition---------------- Assert.AreEqual(0, propertyInfo.ToPropertyWrapper().GetSingleReverseRelPropInfos().Count); //---------------Execute Test ---------------------- var relatedPropName = autoMapper.GetRelatedPropName(); //---------------Test Result ----------------------- Assert.AreEqual(ClassAutoMapper.PropNamingConvention.GetIDPropertyName(classType.ToTypeWrapper()), relatedPropName); }