public void Test_CreateRelPropDef_WithDefaultIDConventionName_ShouldCreateWithCorrectOwningAndRelatedPropNames() { //---------------Set up test pack------------------- TypeWrapper ownerType; TypeWrapper relatedType; string relatedFKPropName; string owningFKPropName; var propertyWrapper = GetPropertyWrapper(out ownerType, out relatedType, out relatedFKPropName, out owningFKPropName); ownerType.SetHasProperty(owningFKPropName, true); relatedType.SetHasProperty(relatedFKPropName, true); var autoMapper = new OneToOneAutoMapper(propertyWrapper); //---------------Assert Precondition---------------- Assert.IsTrue(ownerType.HasProperty(owningFKPropName)); Assert.IsTrue(relatedType.HasProperty(relatedFKPropName)); Assert.IsNotNullOrEmpty(autoMapper.GetOwningPropName()); Assert.IsNotNullOrEmpty(autoMapper.GetRelatedPropName()); //---------------Execute Test ---------------------- var relPropDef = autoMapper.CreateRelPropDef(); //---------------Test Result ----------------------- Assert.IsNotNull(relPropDef); Assert.AreEqual(autoMapper.GetOwningPropName(), relPropDef.OwnerPropertyName); Assert.AreEqual(autoMapper.GetRelatedPropName(), relPropDef.RelatedClassPropName); }
public void Test_GetOwningPropName_WhenNeitherHaveProps_WhenOwnerGTRelated_ShouldReturnRevRelNameID() { //---------------Set up test pack------------------- var ownerType = MockRepository.GenerateMock<FakeTypeWrapper>(); var relatedType = MockRepository.GenerateMock<FakeTypeWrapper>(); var reverseRelName = GetRandomString(); var relationshipName = GetRandomString(); string owningFKPropName = relationshipName + "ID"; string relatedFKPropName = reverseRelName + "ID"; PropertyWrapper propertyWrapper = MockRepository.GenerateStub<FakePropertyWrapper>(); SetupMockPropWrapper(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName); ownerType.SetName("zzzzz"); relatedType.SetName("aaaa"); OneToOneAutoMapper autoMapper = new OneToOneAutoMapper(propertyWrapper); //---------------Assert Precondition---------------- Assert.IsFalse(ownerType.HasProperty(owningFKPropName)); Assert.IsFalse(relatedType.HasProperty(relatedFKPropName)); Assert.AreEqual(1, ownerType.Name.CompareTo(relatedType.Name)); AssertMockPropSetupCorrectly(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName); //---------------Execute Test ---------------------- var relatedPropName = autoMapper.GetOwningPropName(); //---------------Test Result ----------------------- Assert.AreEqual(owningFKPropName, relatedPropName); }
public void Test_GetOwningPropName_OwnerHasProp_RelatedNotHasProp_ShouldReturnRelatedTypePkName() { //---------------Set up test pack------------------- TypeWrapper ownerType; TypeWrapper relatedType; string relatedFKPropName; string owningFKPropName; var propertyWrapper = GetPropertyWrapper(out ownerType, out relatedType, out relatedFKPropName, out owningFKPropName); //SetupMockPropWrapper(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName); ownerType.SetHasProperty(owningFKPropName, true); OneToOneAutoMapper autoMapper = new OneToOneAutoMapper(propertyWrapper); //---------------Assert Precondition---------------- Assert.IsTrue(ownerType.HasProperty(owningFKPropName)); Assert.IsFalse(relatedType.HasProperty(relatedFKPropName)); //Assert.AreEqual(reverseRelName, propertyWrapper.GetSingleReverseRelationshipName<AutoMapOneToOne>()); Assert.AreSame(ownerType, propertyWrapper.DeclaringType); Assert.AreSame(relatedType, propertyWrapper.RelatedClassType); // Assert.AreEqual(relationshipName, propertyWrapper.Name); //---------------Execute Test ---------------------- var relatedPropName = autoMapper.GetOwningPropName(); //---------------Test Result ----------------------- Assert.AreEqual(owningFKPropName, relatedPropName); }
public void Test_GetOwningPropName_OwnerHasProp_RelatedHasProp_NonStandardNaming_ShouldReturnFoundRelName() { //---------------Set up test pack------------------- SetNonDefaultNamingConvention(); TypeWrapper ownerType; TypeWrapper relatedType; string relatedFKPropName; string owningFKPropName; var propertyWrapper = GetPropertyWrapper(out ownerType, out relatedType, out relatedFKPropName, out owningFKPropName); ownerType.SetHasProperty(owningFKPropName, true); relatedType.SetHasProperty(relatedFKPropName, true); OneToOneAutoMapper autoMapper = new OneToOneAutoMapper(propertyWrapper); //---------------Assert Precondition---------------- Assert.IsTrue(ownerType.HasProperty(owningFKPropName)); Assert.IsTrue(relatedType.HasProperty(relatedFKPropName)); // Assert.AreNotEqual(relationshipName, relatedType.Name); // AssertMockPropSetupCorrectly(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName); //---------------Execute Test ---------------------- var relatedPropName = autoMapper.GetOwningPropName(); //---------------Test Result ----------------------- Assert.AreEqual(owningFKPropName, relatedPropName); }
public void Test_Map_ShouldCreateRelProp_WithCorrectNames() { //---------------Set up test pack------------------- TypeWrapper ownerType; TypeWrapper relatedType; string relatedFKPropName; string owningFKPropName; var propertyWrapper = GetPropertyWrapper(out ownerType, out relatedType, out relatedFKPropName, out owningFKPropName); propertyWrapper.SetIsSingleRelationship(true); OneToOneAutoMapper autoMapper = new OneToOneAutoMapper(propertyWrapper); var expectedReverseRelName = propertyWrapper.GetSingleReverseRelationshipName<AutoMapOneToOneAttribute>(); //---------------Assert Precondition---------------- Assert.IsTrue(propertyWrapper.IsSingleRelationship); Assert.AreEqual(expectedReverseRelName, autoMapper.ReverseRelationshipName); //---------------Execute Test ---------------------- var relationshipDef = autoMapper.MapOneToOne(); //---------------Test Result ----------------------- Assert.IsNotNull(relationshipDef); Assert.IsInstanceOf(typeof (SingleRelationshipDef), relationshipDef); Assert.AreEqual(1, relationshipDef.RelKeyDef.Count); var relPropDef = relationshipDef.RelKeyDef[autoMapper.GetOwningPropName()]; Assert.AreEqual(autoMapper.GetRelatedPropName(), relPropDef.RelatedClassPropName); }