Manages a super-class in the case where inheritance is being used.
Inheritance: ISuperClassDef
 protected override void SetupInheritanceSpecifics()
 {
     SuperClassDef superClassDef = new SuperClassDef(Shape.GetClassDef(), ORMapping.ClassTableInheritance);
     Circle.GetClassDef().SuperClassDef =
         superClassDef;
     superClassDef.ID = "CircleID";
 }
Exemplo n.º 2
0
        public void TestSetIDForSingleTableException()
        {
            //---------------Execute Test ----------------------
            try
            {
                SuperClassDef superClassDef =
                    new SuperClassDef("ass", "class", ORMapping.SingleTableInheritance, "id", null);

                Assert.Fail("Expected to throw an ArgumentException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentException ex)
            {
                StringAssert.Contains("An 'ID' property has been specified for a super-class definition where the OR-mapping type is other than ClassTableInheritance", ex.Message);
            }
        }
Exemplo n.º 3
0
        public void TestSetDiscriminatorForConcreteTableException()
        {
            //---------------Execute Test ----------------------
            try
            {
                SuperClassDef superClassDef =
                    new SuperClassDef("ass", "class", ORMapping.ConcreteTableInheritance, null, "disc");

                Assert.Fail("Expected to throw an ArgumentException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentException ex)
            {
                StringAssert.Contains("A 'Discriminator' property has been specified for a super-class definition where the OR-mapping type is ConcreteTableInheritance", ex.Message);
            }
        }
Exemplo n.º 4
0
 public void Test_GetSuperClassClassDef()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ClassDefCol classDefCol = new ClassDefCol();
     ClassDef classDef = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);
     classDefCol.Add(classDef);
     SuperClassDef superClassDef = new SuperClassDef(classDef.AssemblyName, classDef.ClassName, ORMapping.ClassTableInheritance, null, null);
     //---------------Assert Precondition----------------
     Assert.AreEqual(0, ClassDef.ClassDefs.Count);
     Assert.AreEqual(1, classDefCol.Count);
     //---------------Execute Test ----------------------
     IClassDef def = ClassDefHelper.GetSuperClassClassDef(superClassDef, classDefCol);
     //---------------Test Result -----------------------
     Assert.IsNotNull(def);
     Assert.AreSame(classDef, def);
 }
Exemplo n.º 5
0
 public void Test_GetSuperClassClassDef_WithTypeParameter()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ClassDefCol classDefCol = new ClassDefCol();
     ClassDef classDef1 = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);
     classDef1.TypeParameter = "TypeParam1";
     classDefCol.Add(classDef1);
     ClassDef classDef2 = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);
     classDef2.TypeParameter = "TypeParam2";
     classDefCol.Add(classDef2);
     SuperClassDef superClassDef = new SuperClassDef(classDef2.AssemblyName, classDef2.ClassNameExcludingTypeParameter, ORMapping.ClassTableInheritance, null, null);
     superClassDef.TypeParameter = classDef2.TypeParameter;
     //---------------Assert Precondition----------------
     Assert.AreEqual(0, ClassDef.ClassDefs.Count);
     Assert.AreEqual(2, classDefCol.Count);
     //---------------Execute Test ----------------------
     IClassDef def = ClassDefHelper.GetSuperClassClassDef(superClassDef, classDefCol);
     //---------------Test Result -----------------------
     Assert.IsNotNull(def);
     Assert.AreSame(classDef2, def);
 }
Exemplo n.º 6
0
 public static IClassDef GetClassDefWithSingleTableInheritance()
 {
     IClassDef shapeClassDef = Shape.GetClassDef();
     IClassDef circleClassDef = GetClassDef();
     SuperClassDef superClassDef = new SuperClassDef(shapeClassDef, ORMapping.SingleTableInheritance);
     circleClassDef.SuperClassDef = superClassDef;
     superClassDef.Discriminator = "ShapeType";
     return circleClassDef;
 }
Exemplo n.º 7
0
 public static IClassDef GetClassDefWithClassTableInheritance()
 {
     IClassDef shapeClassDef = Shape.GetClassDef();
     IClassDef circleClassDef = GetClassDef();
     SuperClassDef superClassDef = new SuperClassDef(shapeClassDef, ORMapping.ClassTableInheritance);
     circleClassDef.SuperClassDef = superClassDef;
     superClassDef.ID = "ShapeID";
     return circleClassDef;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ISuperClassDef Map()
        {
            if (MustBeMapped())
            {
                var baseType = this.TypeWrapper.BaseType;

                var superClassInheritanceRel = baseType.MapInheritance();
                var superClassDef = baseType.MapClass();
                ISuperClassDef inheritanceDef;
                if (superClassDef != null)
                {
                    if (superClassInheritanceRel != null)
                    {
                        superClassDef.SuperClassDef = superClassInheritanceRel;
                    }
                    inheritanceDef = new SuperClassDef(superClassDef, ORMapping.SingleTableInheritance);

                    //If this is the Most Base Type i.e. it 
                    // does not have another Business object as its super class
                    // then you should create the discriminator Property
                    if (superClassInheritanceRel == null)
                    {
                        inheritanceDef.Discriminator = superClassDef.ClassName + "Type";
                        CreateDiscriminatorProp(inheritanceDef);
                    }else
                    {
                        inheritanceDef.Discriminator = superClassInheritanceRel.Discriminator;
                    }
                    return inheritanceDef;
                }

            }
            return null;
        }
Exemplo n.º 9
0
 public void TestCantFindSuperClassClassDefException() {
 
     //---------------Set up test pack-------------------
     SuperClassDef superClassDef =
         new SuperClassDef("ass", "class", ORMapping.ClassTableInheritance, null, null);
     //---------------Execute Test ----------------------
     try
     {
         IClassDef classDef = superClassDef.SuperClassClassDef;
         Assert.Fail("Expected to throw an HabaneroDeveloperException");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         StringAssert.Contains("The class definition for the super class with the type 'ass.class' was not found", ex.Message);
     }
 }
Exemplo n.º 10
0
        public void Test_SuperClassClassDef_NotFound()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            SuperClassDef superClassDef = new SuperClassDef("Habanero.Test.BO", "UnknownClass", ORMapping.ClassTableInheritance, null, null);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                IClassDef def = superClassDef.SuperClassClassDef;
                //---------------Test Result -----------------------
                Assert.Fail("Expected to throw an InvalidXmlDefinitionException");
            }
            catch (InvalidXmlDefinitionException ex)
            {
                StringAssert.Contains("The class definition for the super class with the type " +
                    "'Habanero.Test.BO.UnknownClass' was not found. Check that the class definition " +
                    "exists or that spelling and capitalisation are correct. " +
                    "There are 0 class definitions currently loaded.", ex.Message);
            }
        }
Exemplo n.º 11
0
        public void Test_Construct_WithClassDef_ShouldSetClassName()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDef classDef = new ClassDef(typeof(FakeBO), new PrimaryKeyDef(), new PropDefCol(), null, null);
            ClassDef.ClassDefs.Add(classDef);
            SuperClassDef superClassDef = new SuperClassDef(classDef, ORMapping.ClassTableInheritance);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IClassDef def = superClassDef.SuperClassClassDef;
            //---------------Test Result -----------------------
            Assert.IsNotNull(def);
            Assert.AreSame(classDef, def);
            Assert.AreSame(classDef.ClassName, superClassDef.ClassName);
        }
Exemplo n.º 12
0
        public void Test_SuperClassClassDef()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDef classDef = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);
            ClassDef.ClassDefs.Add(classDef);
            SuperClassDef superClassDef = new SuperClassDef(classDef.AssemblyName, classDef.ClassName, ORMapping.ClassTableInheritance, null, null);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IClassDef def = superClassDef.SuperClassClassDef;
            //---------------Test Result -----------------------
            Assert.IsNotNull(def);
            Assert.AreSame(classDef, def);
        }