コード例 #1
0
		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);
		}
コード例 #2
0
		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);
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		public void Test_MustBeMapped_WhenPropIsInherited_ShouldRetFalse()
		{
			//---------------Set up test pack-------------------

			var propertyWrapper = MockRepository.GenerateStub<FakePropertyWrapper>();
			propertyWrapper.Stub(wrapper => wrapper.IsPublic).Return(true);
			propertyWrapper.Stub(wrapper => wrapper.IsInherited).Return(true);
			propertyWrapper.Stub(wrapper => wrapper.IsMultipleRelationship).Return(true);
//            propertyWrapper.Stub(wrapper => wrapper.PropertyInfo).Return(GetFakePropertyInfo());
			propertyWrapper.Stub(wrapper => wrapper.DeclaringType).Return(GetFakeTypeWrapper());
			var mapper = new OneToManyAutoMapper(propertyWrapper);
			//---------------Assert Precondition----------------

			Assert.IsFalse(propertyWrapper.IsStatic);
			Assert.IsTrue(propertyWrapper.IsPublic);
			Assert.IsTrue(propertyWrapper.IsMultipleRelationship);
			Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);
//            Assert.IsTrue(propertyWrapper.HasOneToOneAttribute);
//            Assert.IsNotNull(propertyWrapper.PropertyInfo);
			Assert.IsNotNull(propertyWrapper.DeclaringType);

			Assert.IsTrue(propertyWrapper.IsInherited);
			//---------------Execute Test ----------------------
			var mustBeMapped = mapper.MustBeMapped();
			//---------------Test Result -----------------------
			Assert.IsFalse(mustBeMapped);
		}
コード例 #5
0
		public void Test_CreateRelPropDef_WhenHasReverse_ShouldCreateRelProp_WithNonStdNaming_WithNonStdReverseRelName()
		{
			//---------------Set up test pack-------------------
			var nameConvention = SetFakeNameConvention();
			var classType = typeof(FakeBOAttributePKAndPKNaming);
			const string expectedPropName = "MyMultipleRevRel2";
			var propertyInfo = classType.GetPropertyWrapper(expectedPropName);
			OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propertyInfo);
			//---------------Assert Precondition----------------
			classType.AssertPropertyExists(expectedPropName);
			propertyInfo.AssertIsMultipleRelationship();
			Assert.IsTrue(propertyInfo.HasSingleReverseRelationship, "There is no reverse single rel");

			PropertyWrapper reverseRelPropInfo = propertyInfo.GetSingleReverseRelPropInfos()[0];
			string expectedOwnerPropName = classType.ToTypeWrapper().GetPKPropName();
			//---------------Execute Test ----------------------
			var relPropDef = autoMapper.CreateRelPropDef();
			//---------------Test Result -----------------------
			Assert.AreEqual(expectedOwnerPropName, relPropDef.OwnerPropertyName);

			//Need to do reverse rel before can do this the RelatedProp should 
			string expectedRelatedPropName = nameConvention.GetSingleRelOwningPropName(reverseRelPropInfo.Name);
			Assert.AreEqual(expectedRelatedPropName, relPropDef.RelatedClassPropName);
		}
コード例 #6
0
		public void Test_CreateRelPropDef_WhenAutoMapPrimaryKey_WhenNoReverse_ShouldCreateRelProp_WithPrimaryKeyName()
		{
			//---------------Set up test pack-------------------
			SetFakeNameConvention();

			var classType = typeof(FakeBOAttributePKAndPKNaming);
			const string expectedPropName = "MyMultipleRevRel";
			var propertyInfo = classType.GetPropertyWrapper(expectedPropName);

			string expectedOwnerPropName = classType.ToTypeWrapper().GetPKPropName();
			string expectedRelatedPropName = expectedOwnerPropName;
			OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propertyInfo);
			//---------------Assert Precondition----------------
			classType.AssertPropertyExists(expectedPropName);
			propertyInfo.AssertIsMultipleRelationship();
			Assert.IsFalse(propertyInfo.HasSingleReverseRelationship, "There is no reverse single rel");
			//---------------Execute Test ----------------------
			var relPropDef = autoMapper.CreateRelPropDef();
			//---------------Test Result -----------------------
			Assert.AreEqual(expectedOwnerPropName, relPropDef.OwnerPropertyName);

			Assert.AreEqual(expectedRelatedPropName, relPropDef.RelatedClassPropName);
		}
コード例 #7
0
		public void Test_CreateRelPropDef__WhenNonDefaultNameConventionSet_WhenNoReverseRel_ShouldCreateRelPropWithConventionName()
		{
			//---------------Set up test pack-------------------
			INamingConventions nameConvention = SetFakeNameConvention();

			var classType = typeof(FakeBoWithMultipleRel);
			const string expectedPropName = "MyMultipleRevRel";
			var propWrapper = classType.GetPropertyWrapper(expectedPropName);
			OneToManyAutoMapper autoMapper = new OneToManyAutoMapper(propWrapper);
			//---------------Assert Precondition----------------
			classType.AssertPropertyExists(expectedPropName);
			propWrapper.AssertIsMultipleRelationship();
			Assert.IsFalse(propWrapper.HasSingleReverseRelationship, "There is no reverse single rel");
			//---------------Execute Test ----------------------
			var relPropDef = autoMapper.CreateRelPropDef();
			//---------------Test Result -----------------------
			string expectedOwnerPropName = nameConvention.GetIDPropertyName(classType.ToTypeWrapper());
			Assert.AreEqual(expectedOwnerPropName, relPropDef.OwnerPropertyName);

			//Need to do reverse rel before can do this the RelatedProp should 
			string expectedRelatedPropName = expectedOwnerPropName;
			Assert.AreEqual(expectedRelatedPropName, relPropDef.RelatedClassPropName);
		}