コード例 #1
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);
		}
コード例 #2
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);
		}
コード例 #3
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);
		}