상속: CustomTypeSource
        public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClass_WhenInheritanceAndHasRelationship_ShouldCreateCorrectRelPropDefs()
        {
            //---------------Set up test pack-------------------
            var superClass           = typeof(FakeBOSuperClass);
            var subClass             = typeof(FakeBOSubClassWithRelationships);
            var source               = new FakeTypeSource(new[] { subClass, superClass });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef   = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);

            subClassDef.PropDefcol.ShouldHaveCount(1, "Should have FK for MultipleRel Created");
            superClassDef.PropDefcol.ShouldHaveCount(2, "Should have PK and Discriminator Created");

            subClassDef.RelationshipDefCol.ShouldHaveCount(2, "Should have Multiple and single Rel");
            var multipleRelDef     = subClassDef.RelationshipDefCol.First(relationshipDef => relationshipDef.IsOneToMany);
            var multipleRelPropDef = multipleRelDef.RelKeyDef.First();

            Assert.AreEqual("FakeBOSuperClassID", multipleRelPropDef.OwnerPropertyName);
            Assert.AreEqual("FakeBOSuperClassID", multipleRelPropDef.RelatedClassPropName);

            var singleRelDef     = subClassDef.RelationshipDefCol.First(relationshipDef => relationshipDef.IsManyToOne);
            var singleRelPropDef = singleRelDef.RelKeyDef.First();

            Assert.AreEqual("SingleRelID", singleRelPropDef.OwnerPropertyName);
            Assert.AreEqual("FakeBoNoPropsID", singleRelPropDef.RelatedClassPropName);
        }
        public void Test_Map_When2LayersOfInheritance_AndHasDiscriminatorProp_ShouldNotCreateDiscriminator()
        {
            //---------------Set up test pack-------------------
            var superSuperClass = typeof(FakeBOSuperClassWithDesc);
            var superClass      = typeof(FakeBOSubClassSuperHasDesc);
            var subClass        = typeof(FakeBOSubSubClassSuperHasDesc);
            var source          = new FakeTypeSource(new[] { superSuperClass, superClass, subClass });

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            var classDefCol          = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var subClassDef             = classDefCol.First(def => def.ClassName == "FakeBOSubSubClassSuperHasDesc");
            var inheritanceDef          = subClassDef.SuperClassDef;
            var superClassClassDef      = inheritanceDef.SuperClassClassDef;
            var superSuperClassClassDef = superClassClassDef.SuperClassDef.SuperClassClassDef;

            superClassClassDef.PropDefcol.ShouldHaveCount(0,
                                                          "No Properties Should be created for SuperClass since ID and Discriminator will be on SuperSuperClass");
            var superSuperClassProps = superSuperClassClassDef.PropDefcol;

            superSuperClassProps.ShouldHaveCount(2, "Discriminator and ID Prop should be created");

            superSuperClassProps.ShouldContain(def => def.PropertyName == "FakeBOSuperClassWithDescType");
        }
        public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClasses_When2LayersOfInheritance_ShouldMapInheritanceRelationships()
        {
            //---------------Set up test pack-------------------
            var superSuperClass      = typeof(FakeBOSuperClassWithDesc);
            var superClass           = typeof(FakeBOSubClassSuperHasDesc);
            var subClass             = typeof(FakeBOSubSubClassSuperHasDesc);
            var source               = new FakeTypeSource(new[] { subClass, superSuperClass, superClass });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(3);
            var subClassDef        = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef      = classDefCol.First(def => def.ClassType == superClass);
            var superSuperClassDef = classDefCol.First(def => def.ClassType == superSuperClass);

            Assert.AreEqual(superClassDef.ClassType, subClassDef.SuperClassDef.SuperClassClassDef.ClassType);
            Assert.AreSame(superClassDef, subClassDef.SuperClassDef.SuperClassClassDef);
            Assert.AreEqual(superSuperClassDef.ClassType, superClassDef.SuperClassDef.SuperClassClassDef.ClassType);
            Assert.AreSame(superSuperClassDef, superClassDef.SuperClassDef.SuperClassClassDef);
        }
        public void Test_Map_WhenNotHasRevRelDefined_AndIsOneToOne_ShouldCreateSingleRevRel()
        {
            //---------------Set up test pack-------------------
            Type           boWith12M          = typeof(FakeBOWithOneToOneRel);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWith12M, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWith12M = classDefCol[boWith12M];

            cDefWith12M.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWith12M.RelationshipDefCol.First();

            Assert.IsInstanceOf(typeof(SingleRelationshipDef), relationshipDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];

            Assert.AreEqual(relationshipDef.ReverseRelationshipName, reverseRelDef.RelationshipName);
            Assert.AreEqual(relationshipDef.RelationshipName, reverseRelDef.ReverseRelationshipName);
            Assert.IsInstanceOf(typeof(SingleRelationshipDef), reverseRelDef);
            Assert.AreEqual(RelationshipType.Association, reverseRelDef.RelationshipType);
            Assert.AreEqual(DeleteParentAction.DoNothing, reverseRelDef.DeleteParentAction);
            Assert.IsTrue(reverseRelDef.OwningBOHasForeignKey);
        }
예제 #5
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenIDPropDeclaredInClassDefXml_ShouldSetRelatedPropToNonStandardID_FixBug1355()
        {
            //---------------Set up test pack-------------------


            var superClassDef = SuperClassWithPKFromClassDef.LoadClassDef();//Loaded from XML
            var defCol        = new ClassDefCol {
                superClassDef
            };


            var subClassWithPKFromClassDef = typeof(SubClassWithPKFromClassDef);
            var relatedToSubClassWithPKFromClassDefType = typeof(RelatedToSubClassWithPKFromClassDef);

            var source = new FakeTypeSource(new[] { subClassWithPKFromClassDef, relatedToSubClassWithPKFromClassDefType });

            AllClassesAutoMapper.ClassDefCol = defCol;
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithPKFromClassDef = classDefCol.FindByClassName(relatedToSubClassWithPKFromClassDefType.Name);

            Assert.AreEqual(1, relatedToSubClassWithPKFromClassDef.RelationshipDefCol.Count);
            var subClassWithPKFromClassDefRelDef = relatedToSubClassWithPKFromClassDef.RelationshipDefCol["SubClassWithPKFromClassDefSingleRel"];

            Assert.AreEqual(1, subClassWithPKFromClassDefRelDef.RelKeyDef.Count, "Should have a non composite Key");
            var relPropDef = subClassWithPKFromClassDefRelDef.RelKeyDef.FirstOrDefault();

            Assert.AreEqual("SubClassWithPKFromClassDefSingleRelID", relPropDef.OwnerPropertyName);
            Assert.AreEqual("MYPKID", relPropDef.RelatedClassPropName);
        }
        public void Test_Map_WhenNotHasFKPropDefined_AndIsOneToMany_ShouldFKProp()
        {
            //---------------Set up test pack-------------------
            Type           boWith12M          = typeof(FakeBOWithMultipleRel);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWith12M, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWith12M = classDefCol[boWith12M];

            cDefWith12M.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWith12M.RelationshipDefCol.First();

            Assert.IsInstanceOf(typeof(MultipleRelationshipDef), relationshipDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef     = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];
            IRelPropDef      reverseRelPropDef = reverseRelDef.RelKeyDef.First();

            cDefNoDefinedRel.PropDefcol.ShouldContain(propDef => propDef.PropertyName == reverseRelPropDef.OwnerPropertyName);
        }
예제 #7
0
        public void Test_Map_WhenInheritanceWithNonStandardIDProp_ShouldMapWithCorrectNonStandardIDProp()
        {
            //---------------Set up test pack-------------------
            var subClassWithNonStdID   = typeof(SubClassWithNonStandardID);
            var superClassWithNonStdID = typeof(SuperClassWithNonStandardID);
            var source = new FakeTypeSource(new[] { subClassWithNonStdID, superClassWithNonStdID });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreSame(superClassWithNonStdID, subClassWithNonStdID.BaseType);
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            Assert.AreEqual(2, classDefCol.Count);
            classDefCol.ShouldContain(def => def.ClassName == subClassWithNonStdID.Name, "Should contain SubClass");
            classDefCol.ShouldContain(def => def.ClassName == superClassWithNonStdID.Name, "Should Contain SuperClass");

            var subClassDef = classDefCol.FindByClassName(subClassWithNonStdID.Name);

            Assert.IsNull(subClassDef.PrimaryKeyDef);
            var superClassDef = classDefCol.FindByClassName(superClassWithNonStdID.Name);

            Assert.IsNotNull(superClassDef.PrimaryKeyDef);
            Assert.AreEqual(1, superClassDef.PrimaryKeyDef.Count, "The PrimaryKey (ObjectID) Should not be composite");
            var propDef = superClassDef.PrimaryKeyDef[0];

            Assert.AreEqual("NonStandardID", propDef.PropertyName);
        }
        public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClass_WhenInheritance_ShouldCreateDiscriminatorPropInSuperClass()
        {
            //---------------Set up test pack-------------------
            var superClass           = typeof(FakeBOSuperClass);
            var subClass             = typeof(FakeBOSubClass);
            var source               = new FakeTypeSource(new[] { subClass, superClass });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef   = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);

            var discriminatorPropName = subClassDef.SuperClassDef.Discriminator;

            var superClassProps = superClassDef.PropDefcol;

            superClassProps.ShouldHaveCount(2);
            superClassProps.ShouldContain(propDef => propDef.PropertyName == discriminatorPropName);
        }
예제 #9
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenNonStandardIDProp_ShouldSetRelatedPropToNonStandardID_FixBug1355()
        {
            //---------------Set up test pack-------------------
            var subClassWithNonStdID               = typeof(SubClassWithNonStandardID);
            var superClassWithNonStdID             = typeof(SuperClassWithNonStandardID);
            var relatedToSubClassWithNonStandardID = typeof(RelatedToSubClassWithNonStandardID);

            var source = new FakeTypeSource(new[] { subClassWithNonStdID, superClassWithNonStdID, relatedToSubClassWithNonStandardID });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------

            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithNonStandardIDClassDef = classDefCol.FindByClassName(relatedToSubClassWithNonStandardID.Name);

            Assert.AreEqual(1, relatedToSubClassWithNonStandardIDClassDef.RelationshipDefCol.Count);
            var subClassWithNonStandardIDRelDef = relatedToSubClassWithNonStandardIDClassDef.RelationshipDefCol["SubClassWithNonStandardIDSingleRel"];

            Assert.AreEqual(1, subClassWithNonStandardIDRelDef.RelKeyDef.Count, "Should have a non composite Key");
            var relPropDef = subClassWithNonStandardIDRelDef.RelKeyDef.FirstOrDefault();

            Assert.AreEqual("SubClassWithNonStandardIDSingleRelID", relPropDef.OwnerPropertyName);
            Assert.AreEqual("NonStandardID", relPropDef.RelatedClassPropName);
        }
        public void Test_MapWhenHasAbstract_ShouldNotMap()
        {
            //---------------Set up test pack-------------------
            FakeTypeSource       source = new FakeTypeSource(typeof(FakeAbstractBoShouldNotBeLoaded));
            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, classDefCol.Count);
        }
        public void Test_MapWhenHasInterface_ShouldNotMap()
        {
            //---------------Set up test pack-------------------
            FakeTypeSource source = new FakeTypeSource();

            source.Add <IFakeBoInterfaceShouldNotBeLoaded>();
            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, classDefCol.Count);
        }
        public void Test_Map_WhenRelatedClassNotInClassDefCol_ShouldNotRaiseError()
        {
            //---------------Set up test pack-------------------
            Type           boWith12M = typeof(FakeBOWithMultipleRel);
            FakeTypeSource source    = new FakeTypeSource(
                new[] { boWith12M });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(1);
        }
예제 #13
0
        public void Test_Map_WhenHaveTwoClassesShouldMapBoth()
        {
            //---------------Set up test pack-------------------
            Type type1 = typeof(FakeBOWithNoRelationship);
            Type type2 = typeof(FakeBoNoProps);
            FakeTypeSource source = new FakeTypeSource(
                    new[] { type1, type2 });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            Assert.IsNotNull(classDefCol);
            Assert.AreEqual(2, classDefCol.Count);
            classDefCol.ShouldContain(def => def.ClassName == type1.Name);
            classDefCol.ShouldContain(def => def.ClassName == type2.Name);
        }
        public void Test_Map_GivenTypeSourceProvidesSubClassesBeforeSuperClass_WhenInheritanceWithMultipleDerivatives_ShouldSameSuperClass()
        {
            //---------------Set up test pack-------------------
            var parentSuperClass     = typeof(FakeBOSuperClass);
            var parentSubClassA      = typeof(FakeBOSubClass);
            var parentSubClassB      = typeof(FakeBOSubClassA);
            var source               = new FakeTypeSource(new[] { parentSubClassA, parentSubClassB, parentSuperClass });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(3);
            Assert.AreSame(classDefCol[parentSubClassA].SuperClassClassDef, classDefCol[parentSuperClass]);
            Assert.AreSame(classDefCol[parentSubClassB].SuperClassClassDef, classDefCol[parentSuperClass]);
            Assert.AreSame(classDefCol[parentSubClassA].SuperClassClassDef, classDefCol[parentSubClassB].SuperClassClassDef);
        }
예제 #15
0
        public void Test_Map_WhenHaveTwoClassesShouldMapBoth()
        {
            //---------------Set up test pack-------------------
            Type           type1  = typeof(FakeBOWithNoRelationship);
            Type           type2  = typeof(FakeBoNoProps);
            FakeTypeSource source = new FakeTypeSource(
                new[] { type1, type2 });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            Assert.IsNotNull(classDefCol);
            Assert.AreEqual(2, classDefCol.Count);
            classDefCol.ShouldContain(def => def.ClassName == type1.Name);
            classDefCol.ShouldContain(def => def.ClassName == type2.Name);
        }
        public void Test_Map_WhenTypeInSourceTwice_ShouldAddSingleClassDef()
        {
            //---------------Set up test pack-------------------
            Type           typeFirstTime  = typeof(FakeBOWithOneToOneRel);
            Type           typeSecondTime = typeof(FakeBOWithOneToOneRel);
            FakeTypeSource source         = new FakeTypeSource(
                new[] { typeFirstTime, typeSecondTime });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, classDefCol.Count);
            var classDef = classDefCol.First();

            Assert.AreSame(typeSecondTime, classDef.ClassType);
        }
        public void Test_Map_WhenSubClassHasSuperClassWithUniqueConstraint_ShouldNotCreateDuplicate()
        {
            //---------------Set up test pack-------------------
            var superClass = typeof(FakeBOSuperClassWithUC);
            var subClass   = typeof(FakeBOSubClassWithSuperHasUC);
            var source     = new FakeTypeSource(new[] { superClass, subClass });

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            var classDefCol          = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var subClassDef        = classDefCol.First(def => def.ClassName == "FakeBOSubClassWithSuperHasUC");
            var inheritanceDef     = subClassDef.SuperClassDef;
            var superClassClassDef = inheritanceDef.SuperClassClassDef;

            Assert.AreEqual(0, subClassDef.KeysCol.Count);
            Assert.AreEqual(1, superClassClassDef.KeysCol.Count);
            Assert.AreEqual("UC_Fake", superClassClassDef.KeysCol["UC_Fake"].KeyName);
        }
예제 #18
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenNonStandardIDProp_ShouldSetRelatedPropToNonStandardID_FixBug1355()
        {
            //---------------Set up test pack-------------------
            var subClassWithNonStdID = typeof(SubClassWithNonStandardID);
            var superClassWithNonStdID = typeof(SuperClassWithNonStandardID);
            var relatedToSubClassWithNonStandardID = typeof(RelatedToSubClassWithNonStandardID);

            var source = new FakeTypeSource(new[] { subClassWithNonStdID, superClassWithNonStdID, relatedToSubClassWithNonStandardID });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------

            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithNonStandardIDClassDef = classDefCol.FindByClassName(relatedToSubClassWithNonStandardID.Name);
            Assert.AreEqual(1, relatedToSubClassWithNonStandardIDClassDef.RelationshipDefCol.Count);
            var subClassWithNonStandardIDRelDef = relatedToSubClassWithNonStandardIDClassDef.RelationshipDefCol["SubClassWithNonStandardIDSingleRel"];
            Assert.AreEqual(1, subClassWithNonStandardIDRelDef.RelKeyDef.Count, "Should have a non composite Key");
            var relPropDef = subClassWithNonStandardIDRelDef.RelKeyDef.FirstOrDefault();
            Assert.AreEqual("SubClassWithNonStandardIDSingleRelID", relPropDef.OwnerPropertyName);
            Assert.AreEqual("NonStandardID", relPropDef.RelatedClassPropName);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateReverseRel()
        {
            //---------------Set up test pack-------------------
            Type           boWithM21          = typeof(FakeManyToOneBoRelNoFK);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];

            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();

            Assert.IsNotNull(relationshipDef);

            Assert.IsNotNullOrEmpty(relationshipDef.ReverseRelationshipName);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            cDefNoDefinedRel.RelationshipDefCol.ShouldHaveCount(1);

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];

            Assert.AreEqual(relationshipDef.ReverseRelationshipName, reverseRelDef.RelationshipName);
            Assert.AreEqual(relationshipDef.RelationshipName, reverseRelDef.ReverseRelationshipName);
            Assert.IsInstanceOf(typeof(MultipleRelationshipDef), reverseRelDef);
            Assert.AreEqual(RelationshipType.Association, reverseRelDef.RelationshipType);
            Assert.AreEqual(DeleteParentAction.Prevent, reverseRelDef.DeleteParentAction);
            Assert.IsFalse(reverseRelDef.OwningBOHasForeignKey);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateRelProp()
        {
            //---------------Set up test pack-------------------
            Type           boWithM21          = typeof(FakeManyToOneBoRelNoFK);
            Type           boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source             = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];

            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();

            Assert.IsNotNull(relationshipDef);
            relationshipDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef relPropDef = relationshipDef.RelKeyDef.FirstOrDefault();

            Assert.IsNotNull(relPropDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];

            reverseRelDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef revereRelPropDef = reverseRelDef.RelKeyDef.FirstOrDefault();

            Assert.IsNotNull(revereRelPropDef, "ReverseRelationship ShouldHave Been Created");
            Assert.AreEqual(relPropDef.OwnerPropertyName, revereRelPropDef.RelatedClassPropName);
            Assert.AreEqual(relPropDef.RelatedClassPropName, revereRelPropDef.OwnerPropertyName);
        }
예제 #21
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenIDPropDeclaredInClassDefXml_ShouldNotCreatePropDefOnSubClass()
        {
            //---------------Set up test pack-------------------

            var superClassDef = SuperClassWithPKFromClassDef.LoadClassDef();//Loaded from XML
            var defCol        = new ClassDefCol {
                superClassDef
            };

            var subClassWithPKFromClassDef = typeof(SubClassWithPKFromClassDef);
            var relatedToSubClassWithPKFromClassDefType = typeof(RelatedToSubClassWithPKFromClassDef);

            var source = new FakeTypeSource(new[] { subClassWithPKFromClassDef, relatedToSubClassWithPKFromClassDefType });

            AllClassesAutoMapper.ClassDefCol = defCol;
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithPKFromClassDef = classDefCol.FindByClassName(subClassWithPKFromClassDef.Name);

            relatedToSubClassWithPKFromClassDef.PropDefcol.ShouldNotContain(def => def.PropertyName == "MYPKID");
        }
예제 #22
0
        public void Test_Map_WhenInheritanceWithNonStandardIDProp_ShouldMapWithCorrectNonStandardIDProp()
        {
            //---------------Set up test pack-------------------
            var subClassWithNonStdID = typeof (SubClassWithNonStandardID);
            var superClassWithNonStdID = typeof(SuperClassWithNonStandardID);
            var source = new FakeTypeSource(new[] { subClassWithNonStdID, superClassWithNonStdID });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreSame(superClassWithNonStdID, subClassWithNonStdID.BaseType);
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, classDefCol.Count);
            classDefCol.ShouldContain(def => def.ClassName == subClassWithNonStdID.Name, "Should contain SubClass");
            classDefCol.ShouldContain(def => def.ClassName == superClassWithNonStdID.Name, "Should Contain SuperClass");

            var subClassDef = classDefCol.FindByClassName(subClassWithNonStdID.Name);
            Assert.IsNull(subClassDef.PrimaryKeyDef);
            var superClassDef = classDefCol.FindByClassName(superClassWithNonStdID.Name);
            Assert.IsNotNull(superClassDef.PrimaryKeyDef);
            Assert.AreEqual(1, superClassDef.PrimaryKeyDef.Count, "The PrimaryKey (ObjectID) Should not be composite");
            var propDef = superClassDef.PrimaryKeyDef[0];
            Assert.AreEqual("NonStandardID", propDef.PropertyName);
        }
        public void Test_Map_WhenInheritance_ShouldNotCreatePKInSubClass()
        {
            //---------------Set up test pack-------------------
            var superClass           = typeof(FakeBOSuperClass);
            var subClass             = typeof(FakeBOSubClass);
            var source               = new FakeTypeSource(new[] { superClass, subClass });
            var allClassesAutoMapper = new AllClassesAutoMapper(source);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();

            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef   = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);

            Assert.IsNotNull(superClassDef.PrimaryKeyDef);
            Assert.IsNull(subClassDef.PrimaryKeyDef, "Should Not Create a PK since it will use the super classes PK");

            subClassDef.PropDefcol.ShouldBeEmpty();
            superClassDef.PropDefcol.ShouldNotBeEmpty();
        }
 public void Test_Map_GivenTypeSourceProvidesSubClassesBeforeSuperClass_WhenInheritanceWithMultipleDerivatives_ShouldSameSuperClass()
 {
     //---------------Set up test pack-------------------
     var parentSuperClass = typeof(FakeBOSuperClass);
     var parentSubClassA = typeof(FakeBOSubClass);
     var parentSubClassB = typeof(FakeBOSubClassA);
     var source = new FakeTypeSource(new[] {parentSubClassA, parentSubClassB, parentSuperClass});
     var allClassesAutoMapper = new AllClassesAutoMapper(source);
     //---------------Assert Precondition----------------
     Assert.AreEqual(3, source.GetTypes().Count());
     //---------------Execute Test ----------------------
     var classDefCol = allClassesAutoMapper.Map();
     //---------------Test Result -----------------------
     classDefCol.ShouldHaveCount(3);
     Assert.AreSame(classDefCol[parentSubClassA].SuperClassClassDef, classDefCol[parentSuperClass]);
     Assert.AreSame(classDefCol[parentSubClassB].SuperClassClassDef, classDefCol[parentSuperClass]);
     Assert.AreSame(classDefCol[parentSubClassA].SuperClassClassDef, classDefCol[parentSubClassB].SuperClassClassDef);
 }
        public void Test_Map_WhenInheritance_ShouldNotCreatePKInSubClass()
        {
            //---------------Set up test pack-------------------
            var superClass = typeof(FakeBOSuperClass);
            var subClass = typeof(FakeBOSubClass);
            var source = new FakeTypeSource(new[] {superClass, subClass});
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);
            Assert.IsNotNull(superClassDef.PrimaryKeyDef);
            Assert.IsNull(subClassDef.PrimaryKeyDef, "Should Not Create a PK since it will use the super classes PK");

            subClassDef.PropDefcol.ShouldBeEmpty();
            superClassDef.PropDefcol.ShouldNotBeEmpty();
        }
        public void Test_Map_WhenRelatedClassNotInClassDefCol_ShouldNotRaiseError()
        {
            //---------------Set up test pack-------------------
            Type boWith12M = typeof(FakeBOWithMultipleRel);
            FakeTypeSource source = new FakeTypeSource(
                new[] { boWith12M});

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(1);
        }
 public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClasses_When2LayersOfInheritance_ShouldMapInheritanceRelationships()
 {
     //---------------Set up test pack-------------------
     var superSuperClass = typeof(FakeBOSuperClassWithDesc);
     var superClass = typeof(FakeBOSubClassSuperHasDesc);
     var subClass = typeof(FakeBOSubSubClassSuperHasDesc);
     var source = new FakeTypeSource(new[] {subClass, superSuperClass, superClass});
     var allClassesAutoMapper = new AllClassesAutoMapper(source);
     //---------------Assert Precondition----------------
     Assert.AreEqual(3, source.GetTypes().Count());
     //---------------Execute Test ----------------------
     var classDefCol = allClassesAutoMapper.Map();
     //---------------Test Result -----------------------
     classDefCol.ShouldHaveCount(3);
     var subClassDef = classDefCol.First(def => def.ClassType == subClass);
     var superClassDef = classDefCol.First(def => def.ClassType == superClass);
     var superSuperClassDef = classDefCol.First(def => def.ClassType == superSuperClass);
     Assert.AreEqual(superClassDef.ClassType, subClassDef.SuperClassDef.SuperClassClassDef.ClassType);
     Assert.AreSame(superClassDef, subClassDef.SuperClassDef.SuperClassClassDef);
     Assert.AreEqual(superSuperClassDef.ClassType, superClassDef.SuperClassDef.SuperClassClassDef.ClassType);
     Assert.AreSame(superSuperClassDef, superClassDef.SuperClassDef.SuperClassClassDef);
 }
        public void Test_Map_WhenNotHasRevRelDefined_AndIsOneToOne_ShouldCreateSingleRevRel()
        {
            //---------------Set up test pack-------------------
            Type boWith12M = typeof(FakeBOWithOneToOneRel);
            Type boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source = new FakeTypeSource(
                new[] { boWith12M, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWith12M = classDefCol[boWith12M];
            cDefWith12M.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWith12M.RelationshipDefCol.First();
            Assert.IsInstanceOf(typeof(SingleRelationshipDef), relationshipDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];
            Assert.AreEqual(relationshipDef.ReverseRelationshipName, reverseRelDef.RelationshipName);
            Assert.AreEqual(relationshipDef.RelationshipName, reverseRelDef.ReverseRelationshipName);
            Assert.IsInstanceOf(typeof(SingleRelationshipDef), reverseRelDef);
            Assert.AreEqual(RelationshipType.Association, reverseRelDef.RelationshipType);
            Assert.AreEqual(DeleteParentAction.DoNothing, reverseRelDef.DeleteParentAction);
            Assert.IsTrue(reverseRelDef.OwningBOHasForeignKey);
        }
        public void Test_Map_WhenTypeInSourceTwice_ShouldAddSingleClassDef()
        {
            //---------------Set up test pack-------------------
            Type typeFirstTime = typeof(FakeBOWithOneToOneRel);
            Type typeSecondTime = typeof(FakeBOWithOneToOneRel);
            FakeTypeSource source = new FakeTypeSource(
                new[] { typeFirstTime, typeSecondTime });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, classDefCol.Count);
            var classDef = classDefCol.First();
            Assert.AreSame(typeSecondTime, classDef.ClassType);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateRelProp()
        {

            //---------------Set up test pack-------------------
            Type boWithM21 = typeof(FakeManyToOneBoRelNoFK);
            Type boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];
            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();
            Assert.IsNotNull(relationshipDef);
            relationshipDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef relPropDef = relationshipDef.RelKeyDef.FirstOrDefault();
            Assert.IsNotNull(relPropDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];
            reverseRelDef.RelKeyDef.ShouldHaveCount(1);
            IRelPropDef revereRelPropDef = reverseRelDef.RelKeyDef.FirstOrDefault();
            Assert.IsNotNull(revereRelPropDef, "ReverseRelationship ShouldHave Been Created");
            Assert.AreEqual(relPropDef.OwnerPropertyName, revereRelPropDef.RelatedClassPropName);
            Assert.AreEqual(relPropDef.RelatedClassPropName, revereRelPropDef.OwnerPropertyName);
        }
        public void Test_Map_WhenNotHasFKPropDefined_AndIsOneToMany_ShouldFKProp()
        {
            //---------------Set up test pack-------------------
            Type boWith12M = typeof(FakeBOWithMultipleRel);
            Type boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source = new FakeTypeSource(
                new[] { boWith12M, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWith12M = classDefCol[boWith12M];
            cDefWith12M.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWith12M.RelationshipDefCol.First();
            Assert.IsInstanceOf(typeof(MultipleRelationshipDef), relationshipDef);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];
            IRelPropDef reverseRelPropDef = reverseRelDef.RelKeyDef.First();
            cDefNoDefinedRel.PropDefcol.ShouldContain(propDef => propDef.PropertyName == reverseRelPropDef.OwnerPropertyName);
        }
        public void Test_Map_WhenNotHasReverseRelDefined_ShouldCreateReverseRel()
        {
            //---------------Set up test pack-------------------
            Type boWithM21 = typeof(FakeManyToOneBoRelNoFK);
            Type boWithNoDefinedRel = typeof(FakeBOWithNoRelationship);
            FakeTypeSource source = new FakeTypeSource(
                new[] { boWithM21, boWithNoDefinedRel });

            AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            ClassDefCol classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            IClassDef cDefWithM21 = classDefCol[boWithM21];
            cDefWithM21.RelationshipDefCol.ShouldHaveCount(1);
            IRelationshipDef relationshipDef = cDefWithM21.RelationshipDefCol.FirstOrDefault();
            Assert.IsNotNull(relationshipDef);

            Assert.IsNotNullOrEmpty(relationshipDef.ReverseRelationshipName);

            IClassDef cDefNoDefinedRel = classDefCol[boWithNoDefinedRel];
            cDefNoDefinedRel.RelationshipDefCol.ShouldHaveCount(1);

            IRelationshipDef reverseRelDef = cDefNoDefinedRel.RelationshipDefCol[relationshipDef.ReverseRelationshipName];
            Assert.AreEqual(relationshipDef.ReverseRelationshipName, reverseRelDef.RelationshipName);
            Assert.AreEqual(relationshipDef.RelationshipName, reverseRelDef.ReverseRelationshipName);
            Assert.IsInstanceOf(typeof(MultipleRelationshipDef), reverseRelDef);
            Assert.AreEqual(RelationshipType.Association, reverseRelDef.RelationshipType);
            Assert.AreEqual(DeleteParentAction.Prevent, reverseRelDef.DeleteParentAction);
            Assert.IsFalse(reverseRelDef.OwningBOHasForeignKey);
        }
 public void Test_MapWhenHasAbstract_ShouldNotMap()
 {
     //---------------Set up test pack-------------------
     FakeTypeSource source = new FakeTypeSource(typeof(FakeAbstractBoShouldNotBeLoaded));
     AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, source.GetTypes().Count());
     //---------------Execute Test ----------------------
     ClassDefCol classDefCol = allClassesAutoMapper.Map();
     //---------------Test Result -----------------------
     Assert.AreEqual(0, classDefCol.Count);
 }
 public void Test_MapWhenHasInterface_ShouldNotMap()
 {
     //---------------Set up test pack-------------------
     FakeTypeSource source = new FakeTypeSource();
     source.Add<IFakeBoInterfaceShouldNotBeLoaded>();
     AllClassesAutoMapper allClassesAutoMapper = new AllClassesAutoMapper(source);
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, source.GetTypes().Count());
     //---------------Execute Test ----------------------
     ClassDefCol classDefCol = allClassesAutoMapper.Map();
     //---------------Test Result -----------------------
     Assert.AreEqual(0, classDefCol.Count);
 }
        public void Test_Map_When2LayersOfInheritance_AndHasDiscriminatorProp_ShouldNotCreateDiscriminator()
        {
            //---------------Set up test pack-------------------
            var superSuperClass = typeof(FakeBOSuperClassWithDesc);
            var superClass = typeof(FakeBOSubClassSuperHasDesc);
            var subClass = typeof(FakeBOSubSubClassSuperHasDesc);
            var source = new FakeTypeSource(new[] {superSuperClass, superClass, subClass});
            //---------------Assert Precondition----------------
            Assert.AreEqual(3, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var subClassDef = classDefCol.First(def => def.ClassName == "FakeBOSubSubClassSuperHasDesc");
            var inheritanceDef = subClassDef.SuperClassDef;
            var superClassClassDef = inheritanceDef.SuperClassClassDef;
            var superSuperClassClassDef = superClassClassDef.SuperClassDef.SuperClassClassDef;

            superClassClassDef.PropDefcol.ShouldHaveCount(0,
                "No Properties Should be created for SuperClass since ID and Discriminator will be on SuperSuperClass");
            var superSuperClassProps = superSuperClassClassDef.PropDefcol;
            superSuperClassProps.ShouldHaveCount(2, "Discriminator and ID Prop should be created");

            superSuperClassProps.ShouldContain(def => def.PropertyName == "FakeBOSuperClassWithDescType");
        }
        public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClass_WhenInheritance_ShouldCreateDiscriminatorPropInSuperClass()
        {
            //---------------Set up test pack-------------------
            var superClass = typeof(FakeBOSuperClass);
            var subClass = typeof(FakeBOSubClass);
            var source = new FakeTypeSource(new[] {subClass, superClass});
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);

            var discriminatorPropName = subClassDef.SuperClassDef.Discriminator;

            var superClassProps = superClassDef.PropDefcol;
            superClassProps.ShouldHaveCount(2);
            superClassProps.ShouldContain(propDef => propDef.PropertyName == discriminatorPropName);
        }
        public void Test_Map_GivenTypeSourceProvidesSubClassBeforeSuperClass_WhenInheritanceAndHasRelationship_ShouldCreateCorrectRelPropDefs()
        {
            //---------------Set up test pack-------------------
            var superClass = typeof(FakeBOSuperClass);
            var subClass = typeof(FakeBOSubClassWithRelationships);
            var source = new FakeTypeSource(new[] {subClass, superClass});
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            classDefCol.ShouldHaveCount(2);
            var subClassDef = classDefCol.First(def => def.ClassType == subClass);
            var superClassDef = classDefCol.First(def => def.ClassType == superClass);

            subClassDef.PropDefcol.ShouldHaveCount(1, "Should have FK for MultipleRel Created");
            superClassDef.PropDefcol.ShouldHaveCount(2, "Should have PK and Discriminator Created");

            subClassDef.RelationshipDefCol.ShouldHaveCount(2, "Should have Multiple and single Rel");
            var multipleRelDef = subClassDef.RelationshipDefCol.First(relationshipDef => relationshipDef.IsOneToMany);
            var multipleRelPropDef = multipleRelDef.RelKeyDef.First();
            Assert.AreEqual("FakeBOSuperClassID", multipleRelPropDef.OwnerPropertyName);
            Assert.AreEqual("FakeBOSuperClassID", multipleRelPropDef.RelatedClassPropName);

            var singleRelDef = subClassDef.RelationshipDefCol.First(relationshipDef => relationshipDef.IsManyToOne);
            var singleRelPropDef = singleRelDef.RelKeyDef.First();
            Assert.AreEqual("SingleRelID", singleRelPropDef.OwnerPropertyName);
            Assert.AreEqual("FakeBoNoPropsID", singleRelPropDef.RelatedClassPropName);
        }
예제 #38
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenIDPropDeclaredInClassDefXml_ShouldSetRelatedPropToNonStandardID_FixBug1355()
        {
            //---------------Set up test pack-------------------


            var superClassDef = SuperClassWithPKFromClassDef.LoadClassDef();//Loaded from XML
            var defCol = new ClassDefCol {superClassDef};


            var subClassWithPKFromClassDef = typeof(SubClassWithPKFromClassDef);
            var relatedToSubClassWithPKFromClassDefType = typeof(RelatedToSubClassWithPKFromClassDef);

            var source = new FakeTypeSource(new[] {subClassWithPKFromClassDef, relatedToSubClassWithPKFromClassDefType });
            AllClassesAutoMapper.ClassDefCol = defCol;
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithPKFromClassDef = classDefCol.FindByClassName(relatedToSubClassWithPKFromClassDefType.Name);
            Assert.AreEqual(1, relatedToSubClassWithPKFromClassDef.RelationshipDefCol.Count);
            var subClassWithPKFromClassDefRelDef = relatedToSubClassWithPKFromClassDef.RelationshipDefCol["SubClassWithPKFromClassDefSingleRel"];
            Assert.AreEqual(1, subClassWithPKFromClassDefRelDef.RelKeyDef.Count, "Should have a non composite Key");
            var relPropDef = subClassWithPKFromClassDefRelDef.RelKeyDef.FirstOrDefault();
            Assert.AreEqual("SubClassWithPKFromClassDefSingleRelID", relPropDef.OwnerPropertyName);
            Assert.AreEqual("MYPKID", relPropDef.RelatedClassPropName);
    }
        public void Test_Map_WhenSubClassHasSuperClassWithUniqueConstraint_ShouldNotCreateDuplicate()
        {
            //---------------Set up test pack-------------------
            var superClass = typeof(FakeBOSuperClassWithUC);
            var subClass = typeof(FakeBOSubClassWithSuperHasUC);
            var source = new FakeTypeSource(new[] {superClass, subClass});
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, source.GetTypes().Count());
            //---------------Execute Test ----------------------
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var subClassDef = classDefCol.First(def => def.ClassName == "FakeBOSubClassWithSuperHasUC");
            var inheritanceDef = subClassDef.SuperClassDef;
            var superClassClassDef = inheritanceDef.SuperClassClassDef;

            Assert.AreEqual(0, subClassDef.KeysCol.Count);
            Assert.AreEqual(1, superClassClassDef.KeysCol.Count);
            Assert.AreEqual("UC_Fake", superClassClassDef.KeysCol["UC_Fake"].KeyName);
        }
예제 #40
0
        public void Test_Map_WhenSingleRelationshipToSubClass_WhenIDPropDeclaredInClassDefXml_ShouldNotCreatePropDefOnSubClass()
        {
            //---------------Set up test pack-------------------

            var superClassDef = SuperClassWithPKFromClassDef.LoadClassDef();//Loaded from XML
            var defCol = new ClassDefCol {superClassDef};

            var subClassWithPKFromClassDef = typeof(SubClassWithPKFromClassDef);
            var relatedToSubClassWithPKFromClassDefType = typeof(RelatedToSubClassWithPKFromClassDef);

            var source = new FakeTypeSource(new[] {subClassWithPKFromClassDef, relatedToSubClassWithPKFromClassDefType });
            AllClassesAutoMapper.ClassDefCol = defCol;
            var allClassesAutoMapper = new AllClassesAutoMapper(source);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var classDefCol = allClassesAutoMapper.Map();
            //---------------Test Result -----------------------
            var relatedToSubClassWithPKFromClassDef = classDefCol.FindByClassName(subClassWithPKFromClassDef.Name);
            relatedToSubClassWithPKFromClassDef.PropDefcol.ShouldNotContain(def => def.PropertyName == "MYPKID");
        }