Exemplo n.º 1
0
        void GenerateQueryOther(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "QueryOther");

            func.Statements.Add("var q = new " + NDOQuery(test.OtherClass.Name) + ';');
            func.Statements.Add("otherVar = q.ExecuteSingle();");
        }
Exemplo n.º 2
0
        void CreateTestChangeKeyHolderRightNoTouch(RelInfo ri)
        {
            if (IsForbiddenCase(ri))
            {
                return;                 // These would throw exceptions
            }
            // Check Keyholders only
            if (ri.ForeignIsList || !ri.IsBi)
            {
                return;
            }

            Function func = fixture.NewFunction("void", "TestChangeKeyHolderRightNoTouch");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";

            func.Statements.Add("CreateObjects();");
            // 1:1 or n:1 - we check only the left side
            func.Statements.Add("QueryOther();");
            func.Statements.Add(AssertNotNull("No Query Result", "otherVar"));
            func.Statements.Add(AssertNotNull("No related object", "otherVar.RelField"));
            // change our object
            func.Statements.Add("otherVar.Dummy = 4711;");
            func.Statements.Add("pm.Save();");
            func.Statements.Add("pm.UnloadCache();");
            func.Statements.Add("QueryOther();");
            func.Statements.Add(AssertNotNull("No Query Result", "otherVar"));
            func.Statements.Add(AssertNotNull("Wrong value", "otherVar.Dummy == 4711"));
            func.Statements.Add(AssertNotNull("No related object", "otherVar.RelField"));
        }
Exemplo n.º 3
0
        public RelInfo GetReverse()
        {
            RelInfo ri = new RelInfo(this.isBi, this.foreignIsList, this.IsList, false, this.otherPoly, this.ownPoly, this.useGuid);

            ri.hasTable   = this.hasTable;
            ri.isAbstract = this.isAbstract;
            return(ri);
        }
Exemplo n.º 4
0
        public RelInfo Clone()
        {
            RelInfo ri = new RelInfo(this.isBi, this.isList, this.foreignIsList, this.isComposite, this.ownPoly, this.otherPoly, this.useGuid);

            ri.hasTable   = this.hasTable;
            ri.isAbstract = this.isAbstract;
            return(ri);
        }
Exemplo n.º 5
0
        void AddRelationRemover(Class ownBaseClass, RelInfo ri)
        {
            if (!ri.IsList)
            {
                return;
            }
            Function func = ownBaseClass.NewFunction("void", "RemoveRelatedObject");

            func.AccessModifier = "public";
            func.Statements.Add("relField.RemoveAt(0);");
        }
Exemplo n.º 6
0
        void CreateTestUpdateOrder(RelInfo ri)
        {
            if (ri.HasTable || ri.UseGuid || IsForbiddenCase(ri))
            {
                return;
            }
            if (!ri.IsList && ri.IsBi && !ri.ForeignIsList)
            {
                return;
            }

            Function func = fixture.NewFunction("void", "TestUpdateOrder");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";

            func.Statements.Add("NDO.Mapping.NDOMapping mapping = pm.NDOMapping;");
            func.Statements.Add("MethodInfo mi = mapping.GetType().GetMethod(\"GetUpdateOrder\");");
            string br = null;

            if (!ri.IsList)
            {
                br = ">";
            }
            else
            {
                br = "<";
            }
            if ((!ri.OwnPoly && !ri.OtherPoly) || !ri.IsAbstract)
            {
                func.Statements.Add(Assert("Wrong order #1", @"((int)mi.Invoke(mapping, new object[]{typeof(" + test.OwnClass.Name + @")})) 
				"                 + br + " ((int)mi.Invoke(mapping, new object[]{typeof(" + test.OtherClass.Name + ")}))"));
            }
            if (ri.OwnPoly && !ri.OtherPoly)
            {
                func.Statements.Add(Assert("Wrong order #2", @"((int)mi.Invoke(mapping, new object[]{typeof(" + test.OwnDerivedClass.Name + @")})) 
				"                 + br + " ((int)mi.Invoke(mapping, new object[]{typeof(" + test.OtherClass.Name + ")}))"));
            }
            if (!ri.OwnPoly && ri.OtherPoly)
            {
                func.Statements.Add(Assert("Wrong order #2", @"((int)mi.Invoke(mapping, new object[]{typeof(" + test.OwnClass.Name + @")})) 
				"                 + br + " ((int)mi.Invoke(mapping, new object[]{typeof(" + test.OtherDerivedClass.Name + ")}))"));
            }
            if (ri.OwnPoly && ri.OtherPoly)
            {
                func.Statements.Add(Assert("Wrong order #2", @"((int)mi.Invoke(mapping, new object[]{typeof(" + test.OwnDerivedClass.Name + @")})) 
				"                 + br + " ((int)mi.Invoke(mapping, new object[]{typeof(" + test.OtherDerivedClass.Name + ")}))"));
            }
            func.Statements.Add("Debug.WriteLine(\"" + test.OwnClass.Name + "\");");
        }
Exemplo n.º 7
0
        void CreateTestSaveReloadRemove(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "TestSaveReloadRemove");

            func.AccessModifier = "public";
            func.Attributes.Add("Test");
            if (!ri.IsList)
            {
                return;
            }

            bool forbidden = IsForbiddenCase(ri);

            if (forbidden)
            {
                func.Statements.Add("bool thrown = false;");
                func.Statements.Add("try");
                func.Statements.Add("{");
            }
            func.Statements.Add("CreateObjects();");
            func.Statements.Add("QueryOwn();");
            func.Statements.Add(AssertNotNull("No Query Result", "ownVar"));

            if (ri.IsList)
            {
                func.Statements.Add(AssertEquals("Count wrong", 1, "ownVar.RelField.Count"));
            }
            else
            {
                func.Statements.Add(AssertNotNull("No related object", "ownVar.RelField"));
            }

            func.Statements.Add("ownVar.RemoveRelatedObject();");
            func.Statements.Add("pm.Save();");
            func.Statements.Add("pm.UnloadCache();");
            func.Statements.Add("QueryOwn();");

            func.Statements.Add(AssertNotNull("No Query Result", "ownVar"));

            func.Statements.Add(AssertEquals("Count wrong", 0, "ownVar.RelField.Count"));
            if (forbidden)
            {
                func.Statements.Add("}");
                func.Statements.Add("catch (NDOException)");
                func.Statements.Add("{");
                func.Statements.Add("thrown = true;");
                func.Statements.Add("}");
                func.Statements.Add(AssertEquals("NDOException should have been thrown", true, "thrown"));
            }
        }
Exemplo n.º 8
0
        void AddRelationAccessor(Class ownBaseClass, Class otherBaseClass, RelInfo ri)
        {
            Function func = ownBaseClass.NewFunction("void", "AssignRelation", new string[] { otherBaseClass.Name }, new string[] { "relObj" });

            func.AccessModifier = "public";
            if (ri.IsList)
            {
                func.Statements.Add("relField.Add(relObj);");
            }
            else
            {
                func.Statements.Add("relField = relObj;");
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            List <RelInfo> relInfos = new List <RelInfo>();

            for (int i = 0; i < 128; i++)
            {
                //   isBi      ||        !IsBi          &&  !ForeignIsList
                if ((i & isBi) != 0 || ((i & isBi) == 0 && (i & foreignIsList) == 0))
                {
                    RelInfo ri = new RelInfo((i & isBi) != 0, (i & isList) != 0, (i & foreignIsList) != 0, (i & isComposite) != 0, (i & ownPoly) != 0, (i & otherPoly) != 0, (i & useGuid) != 0);
                    relInfos.Add(ri);
                    if (!ri.MustHaveTable)
                    {
                        // We duplicate every scenario without a mapping table
                        // and try to map using a mapping table
                        ri          = new RelInfo((i & isBi) != 0, (i & isList) != 0, (i & foreignIsList) != 0, (i & isComposite) != 0, (i & ownPoly) != 0, (i & otherPoly) != 0, (i & useGuid) != 0);
                        ri.HasTable = true;
                        relInfos.Add(ri);
                    }
                }
            }

            // We duplicate all polymorphic scenarios
            // and use abstract base classes.
            List <RelInfo> newInfos = new List <RelInfo>();

            for (int i = 0; i < relInfos.Count; i++)
            {
                RelInfo ri = relInfos[i];
                if (ri.OtherPoly || ri.OwnPoly)
                {
                    ri            = ri.Clone();
                    ri.IsAbstract = true;
                    newInfos.Add(ri);
                }
            }

            relInfos.AddRange(newInfos);

            new ClassGenerator(relInfos).Generate();
            new TestGenerator(relInfos).Generate();
            new MappingTestGenerator(relInfos).Generate();
            Console.WriteLine(relInfos.Count);
//			for (int i = 0; i < relInfos.Count; i++)
//			{
//				Console.WriteLine(relInfos[i].ToString());
//			}
//			Console.WriteLine(relInfos.Count);
        }
Exemplo n.º 10
0
 void CreateTests(RelInfo ri)
 {
     CreateTestSaveReload(ri);
     CreateTestSaveReloadNull(ri);
     CreateTestSaveReloadRemove(ri);
     CreateTestChangeKeyHolderLeft(ri);
     CreateTestChangeKeyHolderRight(ri);
     CreateTestChangeKeyHolderLeftNoTouch(ri);
     CreateTestChangeKeyHolderRightNoTouch(ri);
     CreateTestUpdateOrder(ri);
     CreateTestRelationHash(ri);
     GenerateCreateObjects(ri);
     GenerateQueryOwn(ri);
     GenerateQueryOther(ri);
 }
Exemplo n.º 11
0
        public Relation NewRelation(RelInfo ri, string relatedTypeName)
        {
            Relation r;

            this.relations.Add((r = new Relation(this, ri, relatedTypeName)));
            if (ri.IsList)
            {
                this.Properties.Add(new Property("List<" + relatedTypeName + ">", Relation.StandardFieldName, true, true));
            }
            else
            {
                this.Properties.Add(new Property(relatedTypeName, Relation.StandardFieldName, true, true));
            }
            return(r);
        }
Exemplo n.º 12
0
 public void Generate()
 {
     this.mapping = new NDO.Mapping.NDOMapping(fileName);
     foreach (RelInfo ri in relInfos)
     {
         Test test = new Test(ri);
         CheckRelation(test, ri);
         if (ri.IsBi)
         {
             RelInfo reverseInfo = ri.GetReverse();
             Test    reverseTest = test.GetReverse();
             CheckRelation(reverseTest, reverseInfo);
         }
     }
     this.mapping.Save();
 }
Exemplo n.º 13
0
        void GenerateClassGroup(RelInfo ri)
        {
            Test test = new Test(ri, this.nameSpace);

            PersistentClass ownBaseClass   = test.OwnClass;
            PersistentClass otherBaseClass = test.OtherClass;

            ownBaseClass.AddVarAndProperty("int", "dummy");
            PersistentClass ownDerivedClass;

            ownBaseClass.NewRelation(ri, otherBaseClass.Name);
            AddRelationAccessor(ownBaseClass, otherBaseClass, ri);
            AddRelationRemover(ownBaseClass, ri);

            sw.WriteLine(ownBaseClass.ToString());
            if (ri.OwnPoly)
            {
                ownDerivedClass = test.OwnDerivedClass;
                sw.WriteLine(ownDerivedClass.ToString());
            }


            // Right class
            otherBaseClass.AddVarAndProperty("int", "dummy");
            if (ri.IsBi)
            {
                otherBaseClass.NewForeignRelation(ri, ownBaseClass.Name);
            }
            sw.WriteLine(otherBaseClass.ToString());
            if (ri.OtherPoly)
            {
                Class otherDerivedClass = test.OtherDerivedClass;
                sw.WriteLine(otherDerivedClass.ToString());
            }
            count += 2;
            if (ri.OwnPoly)
            {
                count++;
            }
            if (ri.OtherPoly)
            {
                count++;
            }
        }
Exemplo n.º 14
0
        void CreateTestHasMappingTable(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "HasMappingTable");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";
            if (ri.HasTable)
            {
                func.Statements.Add(AssertNotNull("Relation should have a MappingTable #1", "ownClass.Relations.First().MappingTable"));
                if (ri.OwnPoly)
                {
                    func.Statements.Add(AssertNotNull("Relation should have a MappingTable #2", "ownDerivedClass.Relations.First().MappingTable"));
                }
                if (ri.IsBi)
                {
                    func.Statements.Add(AssertNotNull("Relation should have a MappingTable #3", "otherClass.Relations.First().MappingTable"));
                    if (ri.OtherPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a MappingTable #4", "otherDerivedClass.Relations.First().MappingTable"));
                    }
                }
            }
            else
            {
                func.Statements.Add(AssertNull("Relation shouldn't have a MappingTable #5", "ownClass.Relations.First().MappingTable"));
                if (ri.OwnPoly)
                {
                    func.Statements.Add(AssertNull("Relation shouldn't have a MappingTable #6", "ownDerivedClass.Relations.First().MappingTable"));
                }
                if (ri.IsBi)
                {
                    func.Statements.Add(AssertNull("Relation shouldn't have a MappingTable #7", "otherClass.Relations.First().MappingTable"));
                    if (ri.OtherPoly)
                    {
                        func.Statements.Add(AssertNull("Relation shouldn't have a MappingTable #8", "otherDerivedClass.Relations.First().MappingTable"));
                    }
                }
            }
        }
Exemplo n.º 15
0
        void GenerateTestGroup(RelInfo ri)
        {
            fixture = new TestFixture(this.nameSpace, "Test" + ri.ToString());
            test    = new Test(ri, "RelationTestClasses");
            Class ownClass   = null;
            Class otherClass = null;

            if (ri.OwnPoly)
            {
                ownClass = test.OwnDerivedClass;
            }
            else
            {
                ownClass = test.OwnClass;
            }
            if (ri.OtherPoly)
            {
                otherClass = test.OtherDerivedClass;
            }
            else
            {
                otherClass = test.OtherClass;
            }


            fixture.Statements.Add(test.OwnClass.Name + " ownVar;");
            fixture.Statements.Add(test.OtherClass.Name + " otherVar;");                // always use the base class type
            fixture.Statements.Add("PersistenceManager pm;");

            fixture.SetUp.Statements.Add("pm = PmFactory.NewPersistenceManager();");
            fixture.SetUp.Statements.Add("ownVar = new " + ownClass.Name + "();");
            fixture.SetUp.Statements.Add("otherVar = new " + otherClass.Name + "();");

            GenerateTearDown(ri);

            CreateTests(ri);

            this.sw.WriteLine(fixture.ToString());
        }
Exemplo n.º 16
0
        void CreateTestHasTypeCode(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "HasTypeCode");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";
            if (!(ri.IsAbstract && ri.OwnPoly))             // abstract classes don't need a type code
            {
                func.Statements.Add(Assert("Class should have a Type Code #1", "this.ownClass.TypeCode != 0"));
            }
            if (!(ri.IsAbstract && ri.OtherPoly))
            {
                func.Statements.Add(Assert("Class should have a Type Code #2", "this.otherClass.TypeCode != 0"));
            }
            if (ri.OwnPoly)
            {
                func.Statements.Add(Assert("Class should have a Type Code #3", "this.ownDerivedClass.TypeCode != 0"));
            }
            if (ri.OtherPoly)
            {
                func.Statements.Add(Assert("Class should have a Type Code #4", "this.otherDerivedClass.TypeCode != 0"));
            }
        }
Exemplo n.º 17
0
        void GenerateTestGroup(RelInfo ri)
        {
            fixture = new TestFixture(this.nameSpace, "MappingTest" + ri.ToString());
            test    = new Test(ri, "RelationTestClasses");
            fixture.AddField("PersistenceManager", "pm");
            fixture.AddField("NDOMapping", "mapping");
            fixture.AddField("Class", "ownClass");
            fixture.AddField("Class", "otherClass");
            if (ri.OwnPoly)
            {
                fixture.AddField("Class", "ownDerivedClass");
            }
            if (ri.OtherPoly)
            {
                fixture.AddField("Class", "otherDerivedClass");
            }

            fixture.SetUp.Statements.Add("this.pm = PmFactory.NewPersistenceManager();");
            fixture.SetUp.Statements.Add("this.mapping = pm.NDOMapping;");
            fixture.SetUp.Statements.Add($"this.ownClass = this.mapping.FindClass( \"{test.OwnClass.FullName}\" );");
            fixture.SetUp.Statements.Add($"this.otherClass = this.mapping.FindClass( \"{test.OtherClass.FullName}\" );");
            if (ri.OwnPoly)
            {
                fixture.SetUp.Statements.Add($"this.ownDerivedClass = this.mapping.FindClass( \"{test.OwnDerivedClass.FullName}\" );");
            }
            if (ri.OtherPoly)
            {
                fixture.SetUp.Statements.Add($"this.otherDerivedClass = this.mapping.FindClass( \"{test.OtherDerivedClass.FullName}\" );");
            }

            //GenerateTearDown( ri );

            CreateTests(ri);

            this.sw.WriteLine(fixture.ToString());
        }
Exemplo n.º 18
0
        void GenerateTearDown(RelInfo ri)
        {
            Function func = fixture.TearDown;

            func.Statements.Add("try");
            func.Statements.Add("{");
            func.Statements.Add("pm.UnloadCache();");
            func.Statements.Add("var l = pm.Objects<" + test.OwnClass.Name + ">().ResultTable;");
            func.Statements.Add("pm.Delete(l);");
            func.Statements.Add("pm.Save();");
            func.Statements.Add("pm.UnloadCache();");
            if (!ri.IsComposite)
            {
                func.Statements.Add("var m = pm.Objects<" + test.OtherClass.Name + ">().ResultTable;");
                func.Statements.Add("pm.Delete(m);");
                func.Statements.Add("pm.Save();");
                func.Statements.Add("pm.UnloadCache();");
            }
            func.Statements.Add("decimal count;");
            func.Statements.Add("count = (decimal) new " + NDOQuery(test.OwnClass.Name) + ".ExecuteAggregate(\"dummy\", AggregateType.Count);");
            func.Statements.Add("Assert.AreEqual(0, count, \"Count wrong #1\");");
            func.Statements.Add("count = (decimal) new " + NDOQuery(test.OtherClass.Name) + ".ExecuteAggregate(\"dummy\", AggregateType.Count);");
            func.Statements.Add("Assert.AreEqual(0, count, \"Count wrong #2\");");
            func.Statements.Add("}");
            func.Statements.Add("catch (Exception)");
            func.Statements.Add("{");
            func.Statements.Add("var handler = pm.GetSqlPassThroughHandler( pm.NDOMapping.Connections.First() );");

            func.Statements.Add("handler.Execute($\"DELETE FROM {pm.NDOMapping.FindClass( ownVar.GetType() ).TableName}\");");
            func.Statements.Add("handler.Execute($\"DELETE FROM {pm.NDOMapping.FindClass( otherVar.GetType() ).TableName}\");");
            if (ri.HasTable)
            {
                func.Statements.Add("handler.Execute( $\"DELETE FROM {pm.NDOMapping.FindClass( ownVar.GetType() ).Relations.First().MappingTable.TableName}\" );");
            }
            func.Statements.Add("}");
        }
Exemplo n.º 19
0
        void GenerateCreateObjects(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "CreateObjects");

            func.Statements.Add("pm.MakePersistent(ownVar);");
            string secondMakePersistent = "pm.MakePersistent(otherVar);";
            string assignRelation       = "ownVar.AssignRelation(otherVar);";

            if (ri.IsComposite)
            {
                if (!ri.IsList && (ri.OtherPoly || ri.OwnPoly) && !ri.HasTable && !ri.UseGuid)
                {
                    func.Statements.Add("pm.Save();");
                }
                func.Statements.Add(assignRelation);
            }
            else
            {
                if (!ri.IsList && ri.OtherPoly && !ri.HasTable && !ri.UseGuid)
                {
                    func.Statements.Add("pm.Save();");
                }
                func.Statements.Add(secondMakePersistent);
                if (!ri.IsList && ri.OtherPoly && !ri.HasTable && !ri.UseGuid)
                {
                    func.Statements.Add("pm.Save();");
                }
                if (ri.IsBi && !ri.ForeignIsList && ri.OwnPoly && !ri.UseGuid)
                {
                    func.Statements.Add("pm.Save();");
                }
                func.Statements.Add(assignRelation);
            }
            func.Statements.Add("pm.Save();");
            func.Statements.Add("pm.UnloadCache();");
        }
Exemplo n.º 20
0
        void CreateTestRelationHash(RelInfo ri)
        {
            if (!ri.IsBi)
            {
                return;
            }
            Function func = fixture.NewFunction("void", "TestRelationHash");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";
            func.Statements.Add("Class clbaseLeft = pm.NDOMapping.FindClass(typeof(" + test.OwnClass.Name + "));");
            func.Statements.Add("Relation relbaseLeft = clbaseLeft.FindRelation(\"relField\");");
            func.Statements.Add("Class clbaseRight = pm.NDOMapping.FindClass(typeof(" + test.OtherClass.Name + "));");
            func.Statements.Add("Relation relbaseRight = clbaseRight.FindRelation(\"relField\");");
            func.Statements.Add(Assert("Relation should be equal #1", "relbaseRight.Equals(relbaseLeft)"));
            func.Statements.Add(Assert("Relation should be equal #2", "relbaseLeft.Equals(relbaseRight)"));
            if (ri.OwnPoly)
            {
                func.Statements.Add("Class clderLeft = pm.NDOMapping.FindClass(typeof(" + test.OwnDerivedClass.Name + "));");
                func.Statements.Add("Relation relderLeft = clderLeft.FindRelation(\"relField\");");
                func.Statements.Add(Assert("Relation should be equal #3", "relderLeft.Equals(relbaseRight)"));
                func.Statements.Add(Assert("Relation should be equal #4", "relbaseRight.Equals(relderLeft)"));
            }
            if (ri.OtherPoly)
            {
                func.Statements.Add("Class clderRight = pm.NDOMapping.FindClass(typeof(" + test.OtherDerivedClass.Name + "));");
                func.Statements.Add("Relation relderRight = clderRight.FindRelation(\"relField\");");
                func.Statements.Add(Assert("Relation should be equal #5", "relbaseLeft.Equals(relderRight)"));
                func.Statements.Add(Assert("Relation should be equal #6", "relderRight.Equals(relbaseLeft)"));
                if (ri.OwnPoly)
                {
                    func.Statements.Add(Assert("Relation should be equal #7", "relderLeft.Equals(relderRight)"));
                    func.Statements.Add(Assert("Relation should be equal #8", "relderRight.Equals(relderLeft)"));
                }
            }
        }
Exemplo n.º 21
0
        void CheckRelation(Test test, RelInfo ri)
        {
            if (!ri.HasTable)
            {
                return;
            }
            NDO.Mapping.Class clMapping = mapping.FindClass("RelationTestClasses." + test.OwnClass.Name);

            if (clMapping == null)
            {
                return;
            }
            NDO.Mapping.Relation rel = (NDO.Mapping.Relation)clMapping.Relations.FirstOrDefault();
            Debug.Assert(rel != null, "Relation mapping not found");
            if (rel == null)
            {
                throw new Exception("Cant find relation 0 of" + test.OwnClass.Name);
            }

            NDO.Mapping.Class    derivedMapping;
            NDO.Mapping.Relation derivedRel = null;

            if (ri.OwnPoly)
            {
                derivedMapping = mapping.FindClass("RelationTestClasses." + test.OwnDerivedClass.Name);
                if (derivedMapping == null)
                {
                    return;
                }
                derivedRel = (NDO.Mapping.Relation)derivedMapping.Relations.FirstOrDefault();
                if (rel == null)
                {
                    throw new Exception("Cant find relation 0 of" + test.OwnDerivedClass.Name);
                }
            }

            if (rel.MappingTable == null || ri.OwnPoly && derivedRel.MappingTable == null)
            {
                string tableName = null;
                if (test.OwnClass.Name.CompareTo(test.OtherClass.Name) < 0)
                {
                    tableName = "rel" + test.OwnClass.Name + test.OtherClass.Name;
                }
                else
                {
                    tableName = "rel" + test.OtherClass.Name + test.OwnClass.Name;
                }
                ForeignKeyColumn fkColumn = rel.NewForeignKeyColumn();
                fkColumn.Name = "ID" + test.OwnClass.Name;
                if (ri.OwnPoly)
                {
                    rel.ForeignKeyTypeColumnName = "TC" + test.OwnClass.Name;
                }
                else
                {
                    rel.ForeignKeyTypeColumnName = null;
                }
                rel.MappingTable           = new NDO.Mapping.MappingTable(rel);
                rel.MappingTable.TableName = tableName;
                fkColumn      = rel.MappingTable.NewForeignKeyColumn();
                fkColumn.Name = "ID" + test.OtherClass.Name;
                if (ri.OtherPoly)
                {
                    rel.MappingTable.ChildForeignKeyTypeColumnName = "TC" + test.OtherClass.Name;
                }
                else
                {
                    rel.MappingTable.ChildForeignKeyTypeColumnName = null;
                }
                rel.MappingTable.ConnectionId = clMapping.ConnectionId;

                if (ri.OwnPoly)
                {
                    ForeignKeyColumn dfkColumn = (ForeignKeyColumn)derivedRel.ForeignKeyColumns.FirstOrDefault();
                    dfkColumn.Name = ((ForeignKeyColumn)rel.ForeignKeyColumns.FirstOrDefault()).Name;
                    derivedRel.ForeignKeyTypeColumnName = rel.ForeignKeyTypeColumnName;
                    derivedRel.MappingTable             = rel.MappingTable;
                }
            }
        }
Exemplo n.º 22
0
        public Relation NewForeignRelation(RelInfo ri, string relatedTypeName)
        {
            RelInfo ri2 = ri.GetReverse();

            return(NewRelation(ri2, relatedTypeName));
        }
Exemplo n.º 23
0
 public Test(RelInfo ri, string nameSpace)
 {
     this.ri        = ri;
     this.nameSpace = nameSpace;
 }
Exemplo n.º 24
0
        void CreateTestHasTypeColumn(RelInfo ri)
        {
            Function func = fixture.NewFunction("void", "HasTypeColumn");

            func.Attributes.Add("Test");
            func.AccessModifier = "public";
            if (ri.HasTable)
            {
                if (ri.OwnPoly)
                {
                    func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #1", "ownClass.Relations.First().ForeignKeyTypeColumnName"));
                    func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #2", "ownDerivedClass.Relations.First().ForeignKeyTypeColumnName"));
                }
                if (ri.OtherPoly)
                {
                    func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #3", "ownClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                    if (ri.OwnPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #4", "ownDerivedClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                    }
                }
                if (ri.IsBi)
                {
                    if (ri.OtherPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #5", "otherClass.Relations.First().ForeignKeyTypeColumnName"));
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #6", "otherDerivedClass.Relations.First().ForeignKeyTypeColumnName"));
                    }
                    if (ri.OwnPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #7", "otherClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                        if (ri.OtherPoly)
                        {
                            func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #8", "otherDerivedClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                        }
                    }
                }
                if (!ri.OwnPoly)
                {
                    func.Statements.Add(AssertNull("Relation shouldn't have a TypeColumn #1", "ownClass.Relations.First().ForeignKeyTypeColumnName"));
                    if (ri.IsBi)
                    {
                        func.Statements.Add(AssertNull("Relation shouldn't have a TypeColumn #2", "otherClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                    }
                }
                if (!ri.OtherPoly)
                {
                    func.Statements.Add(AssertNull("Relation shouldn't have a TypeColumn #3", "ownClass.Relations.First().MappingTable.ChildForeignKeyTypeColumnName"));
                    if (ri.IsBi)
                    {
                        func.Statements.Add(AssertNull("Relation shouldn't have a TypeColumn #4", "otherClass.Relations.First().ForeignKeyTypeColumnName"));
                    }
                }
            }
            else              // No Mapping Table
            {
                if (!ri.OtherPoly)
                {
                    func.Statements.Add(AssertNull("Relation shouldn't have a TypeColumn #1", "ownClass.Relations.First().ForeignKeyTypeColumnName"));
                }

                // Polymorphic 1:n relations always have a mapping table,
                // so we check only the 1:1 relations.
                if (!ri.IsList)
                {
                    if (ri.OtherPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #9", "ownClass.Relations.First().ForeignKeyTypeColumnName"));
                    }
                    if (ri.IsBi && ri.OwnPoly)
                    {
                        func.Statements.Add(AssertNotNull("Relation should have a TypeColumn #10", "otherClass.Relations.First().ForeignKeyTypeColumnName"));
                    }
                }
            }
        }
Exemplo n.º 25
0
 bool IsForbiddenCase(RelInfo ri)
 {
     return(ri.IsComposite && !ri.UseGuid && !ri.HasTable && !ri.IsList && ri.OtherPoly);
 }
Exemplo n.º 26
0
 void CreateTests(RelInfo ri)
 {
     CreateTestHasMappingTable(ri);
     CreateTestHasTypeColumn(ri);
     CreateTestHasTypeCode(ri);
 }
Exemplo n.º 27
0
 public Relation(Class parent, RelInfo ri, string relatedTypeName)
 {
     this.parent          = parent;
     this.ri              = ri;
     this.relatedTypeName = relatedTypeName;
 }