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_GetRelatedPropName_OwnerHasProp_RelatedHasProp_FakeNameConvention_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));
//            AssertMockPropSetupCorrectly(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName);
            //---------------Execute Test ----------------------
            var relatedPropName = autoMapper.GetRelatedPropName();
            //---------------Test Result -----------------------
            Assert.AreEqual(relatedFKPropName, relatedPropName);
        }
 public void Test_GetRelatedPropName_NeitherHaveProps_NonDefaultNaming_ShouldReturnRevRelNameID()
 {
     //---------------Set up test pack-------------------
     SetNonDefaultNamingConvention();
     var ownerType = MockRepository.GenerateMock<FakeTypeWrapper>();
     var relatedType = MockRepository.GenerateMock<FakeTypeWrapper>();
     var reverseRelName = GetRandomString();
     var relationshipName = GetRandomString();
     var owningFKPropName = GetFKPropName(relationshipName);
     var relatedFKPropName = GetFKPropName(reverseRelName);
     PropertyWrapper propertyWrapper = MockRepository.GenerateStub<FakePropertyWrapper>();
     SetupMockPropWrapper(propertyWrapper, ownerType, relatedType, relationshipName, reverseRelName);
     ownerType.SetName("1111");
     relatedType.SetName("2222");
     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.GetRelatedPropName();
     //---------------Test Result -----------------------
     Assert.AreEqual(relatedFKPropName, relatedPropName);
 }
 public void Test_GetRelatedPropName_WhenNeitherHaveProps_WhenOwnerGTRelated_ShouldReturnRevRelNameID()
 {
     //---------------Set up test pack-------------------
     var ownerType = MockRepository.GenerateMock<FakeTypeWrapper>();
     var relatedType = MockRepository.GenerateMock<FakeTypeWrapper>();
     relatedType.SetPKPropName(GetRandomString());
     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.GetRelatedPropName();
     //---------------Test Result -----------------------
     Assert.AreEqual(relatedType.GetPKPropName(), relatedPropName);
 }
        public void Test_GetRelatedPropName_OwnerNotHasProp_RelatedHasProp_ShouldReturnFoundRelName()
        {
            //---------------Set up test pack-------------------
            TypeWrapper ownerType; TypeWrapper relatedType;
            string relatedFKPropName; string owningFKPropName;
            var propertyWrapper
                    = GetPropertyWrapper(out ownerType, out relatedType, out relatedFKPropName, out owningFKPropName);

            relatedType.SetHasProperty(relatedFKPropName, true);
            OneToOneAutoMapper autoMapper = new OneToOneAutoMapper(propertyWrapper);
            //---------------Assert Precondition----------------
            Assert.IsFalse(ownerType.HasProperty(owningFKPropName));
            Assert.IsTrue(relatedType.HasProperty(relatedFKPropName));
            
            //---------------Execute Test ----------------------
            var relatedPropName = autoMapper.GetRelatedPropName();
            //---------------Test Result -----------------------
            Assert.AreEqual(relatedFKPropName, 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);
 }