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); }
public void Test_Add_WithSameClassDef_IgnoresAdd() { //---------------Set up test pack------------------- ClassDef classDef = new ClassDef (typeof(MockBo), new PrimaryKeyDef(), new PropDefCol(), new KeyDefCol(), new RelationshipDefCol()); ClassDefCol classDefCol = new ClassDefCol(); classDefCol.Add(classDef); //---------------Assert PreConditions--------------- Assert.AreEqual(1, classDefCol.Count); //---------------Execute Test ---------------------- classDefCol.Add(classDef); //---------------Test Result ----------------------- Assert.AreEqual(1, classDefCol.Count); }
public void TestRemove() { ClassDef classDef = new ClassDef(typeof(String), null, null, null, null, null, null); ClassDefCol col = new ClassDefCol(); col.Add(classDef); Assert.AreEqual(1, col.Count); col.Remove(classDef); Assert.AreEqual(0, col.Count); col.Add(classDef); Assert.AreEqual(1, col.Count); col.Remove(typeof(String)); Assert.AreEqual(0, col.Count); }
/// <summary> /// Loads the class definition data from the reader /// </summary> protected override void LoadFromReader() { _classDefList = _defClassFactory.CreateClassDefCol(); //_classDefList = new ArrayList(); _reader.Read(); _reader.Read(); do { try { XmlClassLoader classLoader = new XmlClassLoader(DtdLoader, _defClassFactory); var classDefCol = classLoader.LoadClass(_reader.ReadOuterXml()); if (classDefCol != null) { _classDefList.Add(classDefCol); } } catch (Exception ex) { //This is a RecordingExceptionNotifiere so it will log this error and // allow the continued processing of this XMLFile. GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error "); } } while (_reader.Name == "class"); }
public void Test_GetPrimaryKeyDef_ClassWithPKFromSuperClass() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef parentDef = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestClassID""/> </primaryKey> </class>" ); IClassDef def = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders""> <superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" /> <property name=""TestProp"" type=""Guid"" /> </class> " ); ClassDefCol classDefCol = new ClassDefCol(); classDefCol.Add(parentDef); //---------------Assert Precondition---------------- Assert.IsNotNull(parentDef.PrimaryKeyDef); Assert.IsNotNull(def.SuperClassDef); Assert.IsNull(def.PrimaryKeyDef); //---------------Execute Test ---------------------- IPrimaryKeyDef primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(def, classDefCol); //---------------Test Result ----------------------- Assert.IsNotNull(primaryKeyDef); Assert.AreSame(parentDef.PrimaryKeyDef, primaryKeyDef); }
public void Test_Add_WithDuplicateClassDefs_ShouldNotAddAgain() { //---------------Set up test pack------------------- XmlClassDefsLoader loader = new XmlClassDefsLoader(GetTestClassDefinition(""), new DtdLoader(), new DefClassFactory()); ClassDefCol classDefCol = new ClassDefCol(); ClassDefCol classDefs = loader.LoadClassDefs(); classDefCol.Add(classDefs); //---------------Assert PreConditions--------------- Assert.AreEqual(2, classDefs.Count); Assert.AreEqual(2, classDefCol.Count); //---------------Execute Test ---------------------- classDefCol.Add(classDefs); //---------------Test Result ----------------------- Assert.AreEqual(2, classDefCol.Count); }
public void TestFindByClassName_NotFound() { //---------------Set up test pack------------------- ClassDefCol col = new ClassDefCol(); ClassDef classDef1 = new ClassDef("assembly", "class1", null, null, null, null, null); ClassDef classDef2 = new ClassDef("assembly", "class2", null, null, null, null, null); ClassDef classDef3 = new ClassDef("assembly", "class3", null, null, null, null, null); col.Add(classDef1); col.Add(classDef2); col.Add(classDef3); //---------------Execute Test ---------------------- IClassDef foundClass = col.FindByClassName("DoesNotExist"); //---------------Test Result ----------------------- Assert.IsNull(foundClass); }
public void TestAddDuplicateException() { //---------------Set up test pack------------------- ClassDef classDef1 = new ClassDef("ass", "class", null, null, null, null, null); ClassDef classDef2 = new ClassDef("ass", "class", null, null, null, null, null); ClassDefCol col = new ClassDefCol(); col.Add(classDef1); //---------------Execute Test ---------------------- try { col.Add(classDef2); Assert.Fail("Expected to throw an HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("A duplicate class element has been encountered", ex.Message); } }
public void Test_Add_WithNewClassDefs_ShouldAddThem() { //---------------Set up test pack------------------- XmlClassDefsLoader loader1 = new XmlClassDefsLoader(GetTestClassDefinition(""), new DtdLoader(), new DefClassFactory()); ClassDefCol classDefCol = new ClassDefCol(); ClassDefCol classDefs1 = loader1.LoadClassDefs(); classDefCol.Add(classDefs1); XmlClassDefsLoader loader2 = new XmlClassDefsLoader(GetTestClassDefinition("Other"), new DtdLoader(), new DefClassFactory()); ClassDefCol classDefs2 = loader2.LoadClassDefs(); //---------------Assert PreConditions--------------- Assert.AreEqual(2, classDefCol.Count); Assert.AreEqual(2, classDefs2.Count); //---------------Execute Test ---------------------- classDefCol.Add(classDefs2); //---------------Test Result ----------------------- Assert.AreEqual(4, classDefCol.Count); }
public void TestFindByClassName_Found() { //---------------Set up test pack------------------- ClassDefCol col = new ClassDefCol(); ClassDef classDef1 = new ClassDef("assembly", "class1", null, null, null, null, null); ClassDef classDef2 = new ClassDef("assembly", "class2", null, null, null, null, null); ClassDef classDef3 = new ClassDef("assembly", "class3", null, null, null, null, null); col.Add(classDef1); col.Add(classDef2); col.Add(classDef3); //---------------Execute Test ---------------------- IClassDef foundClass1 = col.FindByClassName("class1"); IClassDef foundClass2 = col.FindByClassName("class2"); IClassDef foundClass3 = col.FindByClassName("class3"); //---------------Test Result ----------------------- Assert.AreSame(classDef1, foundClass1); Assert.AreSame(classDef2, foundClass2); Assert.AreSame(classDef3, foundClass3); }
public void Test_Valid_Relationship_Loads_Where_RelatedClass_IsLoaded_After_InitialLoad_NoReverseRelationshipSetup() { //----------------------Test Setup ---------------------- XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), GetDefClassFactory()); ClassDefCol classDefCol = new ClassDefCol(); const string classDefsString = @" <classes> <class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestRelatedClassID"" type=""Guid"" /> <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestRelatedClassID""/> </primaryKey> </class> </classes> " ; classDefCol.Add(loader.LoadClassDefs(classDefsString)); //--------------------Execute Test------------------------- const string secondClassDefStringToLoad = @" <classes> <class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestClassID""/> </primaryKey> <relationship name=""TestRelatedClass"" type=""single"" relatedClass=""TestRelatedClass"" relatedAssembly=""Habanero.Test.BO.Loaders""> <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" /> </relationship> </class> </classes> " ; classDefCol.Add(loader.LoadClassDefs(secondClassDefStringToLoad)); //---------------Test Result ----------------------- Assert.AreEqual(2, classDefCol.Count); Assert.IsTrue(classDefCol.Contains("Habanero.Test.BO.Loaders", "TestClass"), "Class 'TestClass' should have been loaded."); Assert.IsTrue(classDefCol.Contains("Habanero.Test.BO.Loaders", "TestRelatedClass"), "Class 'TestRelatedClass' should have been loaded."); }
private static void MergeClassDefs(IClassDef classDef) { if (classDef.SuperClassDef != null) { //You always want the classDef that has been // Mapped via its subClass var superClassClassDef = classDef.SuperClassDef.SuperClassClassDef; MergeClassDefs(superClassClassDef); } if (!ClassDefCol.Contains(classDef.ClassType)) { ClassDefCol.Add(classDef); } }
public void TestIndexer_Get() { //---------------Set up test pack------------------- ClassDef classDef = new ClassDef (typeof(MockBo), new PrimaryKeyDef(), new PropDefCol(), new KeyDefCol(), new RelationshipDefCol()); ClassDefCol col = new ClassDefCol(); col.Add(classDef); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- IClassDef returnedClassDef = col[typeof(MockBo)]; //---------------Test Result ----------------------- Assert.AreEqual(classDef, returnedClassDef); }
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); }
public void Test_Remove_WithAssemblyAndClassName() { //---------------Set up test pack------------------- ClassDefCol col = new ClassDefCol(); string assemblyName = "Assembly1"; string className = "Class1"; ClassDef classDef = new ClassDef(assemblyName, className, null, null, null, null, null, null); col.Add(classDef); //---------------Assert PreConditions--------------- Assert.AreEqual(1, col.Count); //---------------Execute Test ---------------------- col.Remove(assemblyName, className); //---------------Test Result ----------------------- Assert.AreEqual(0, col.Count); //---------------Tear Down ------------------------- }
private static void AddDiscriminatorFields(ISelectQuery selectQuery, IClassDef classDef, ref Criteria criteria) { ClassDefCol classDefsToSearch = ((ClassDef)classDef).AllChildren; classDefsToSearch.Add((ClassDef)classDef); List <Criteria> discriminatorCriteriaList = new List <Criteria>(); string discriminator = null; foreach (ClassDef thisClassDef in classDefsToSearch) { if (!thisClassDef.IsUsingSingleTableInheritance()) { continue; } ISuperClassDef superClassDef = thisClassDef.SuperClassDef; discriminator = superClassDef.Discriminator; if (String.IsNullOrEmpty(discriminator)) { continue; } if (!selectQuery.Fields.ContainsKey(discriminator)) { selectQuery.Fields.Add(discriminator, new QueryField(discriminator, discriminator, new Source(((ClassDef)classDef).GetBaseClassOfSingleTableHierarchy().ClassNameExcludingTypeParameter, classDef.GetTableName()))); } discriminatorCriteriaList.Add(new Criteria(discriminator, Criteria.ComparisonOp.Equals, thisClassDef.ClassName)); } if (discriminatorCriteriaList.Count > 0) { if (!((ClassDef)classDef).IsUsingSingleTableInheritance()) { criteria = new Criteria(discriminator, Criteria.ComparisonOp.Is, "null"); } foreach (Criteria discCriteria in discriminatorCriteriaList) { if (criteria == null) { criteria = discCriteria; continue; } criteria = new Criteria(criteria, Criteria.LogicalOp.Or, discCriteria); } } }
public void Test_Valid_Relationship_Loads_Where_RelatedClass_IsLoaded_After_InitialLoad_NoReverseRelationshipSetup() { //----------------------Test Setup ---------------------- XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), GetDefClassFactory()); ClassDefCol classDefCol = new ClassDefCol(); const string classDefsString = @" <classes> <class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestRelatedClassID"" type=""Guid"" /> <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestRelatedClassID""/> </primaryKey> </class> </classes> "; classDefCol.Add(loader.LoadClassDefs(classDefsString)); //--------------------Execute Test------------------------- const string secondClassDefStringToLoad = @" <classes> <class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestClassID""/> </primaryKey> <relationship name=""TestRelatedClass"" type=""single"" relatedClass=""TestRelatedClass"" relatedAssembly=""Habanero.Test.BO.Loaders""> <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" /> </relationship> </class> </classes> "; classDefCol.Add(loader.LoadClassDefs(secondClassDefStringToLoad)); //---------------Test Result ----------------------- Assert.AreEqual(2, classDefCol.Count); Assert.IsTrue(classDefCol.Contains("Habanero.Test.BO.Loaders", "TestClass"), "Class 'TestClass' should have been loaded."); Assert.IsTrue(classDefCol.Contains("Habanero.Test.BO.Loaders", "TestRelatedClass"), "Class 'TestRelatedClass' should have been loaded."); }
/// <summary> /// Loads the class definition data from the reader /// </summary> protected override void LoadFromReader() { _classDefList = _defClassFactory.CreateClassDefCol(); //_classDefList = new ArrayList(); _reader.Read(); _reader.Read(); do { try { XmlClassLoader classLoader = new XmlClassLoader(DtdLoader, _defClassFactory); var classDefCol = classLoader.LoadClass(_reader.ReadOuterXml()); if(classDefCol != null) _classDefList.Add(classDefCol); } catch (Exception ex) { //This is a RecordingExceptionNotifiere so it will log this error and // allow the continued processing of this XMLFile. GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error "); } } while (_reader.Name == "class"); }
public void TestRemove() { ClassDef classDef = new ClassDef(typeof (String), null, null, null, null, null, null); ClassDefCol col = new ClassDefCol(); col.Add(classDef); Assert.AreEqual(1, col.Count); col.Remove(classDef); Assert.AreEqual(0, col.Count); col.Add(classDef); Assert.AreEqual(1, col.Count); col.Remove(typeof (String)); Assert.AreEqual(0, col.Count); }
public void Test_GetPrimaryKeyDef_ClassWithPKFromSuperClass() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef parentDef = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" > <property name=""TestClassID"" type=""Guid"" /> <primaryKey> <prop name=""TestClassID""/> </primaryKey> </class>"); IClassDef def = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass( @" <class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders""> <superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" /> <property name=""TestProp"" type=""Guid"" /> </class> "); ClassDefCol classDefCol = new ClassDefCol(); classDefCol.Add(parentDef); //---------------Assert Precondition---------------- Assert.IsNotNull(parentDef.PrimaryKeyDef); Assert.IsNotNull(def.SuperClassDef); Assert.IsNull(def.PrimaryKeyDef); //---------------Execute Test ---------------------- IPrimaryKeyDef primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(def, classDefCol); //---------------Test Result ----------------------- Assert.IsNotNull(primaryKeyDef); Assert.AreSame(parentDef.PrimaryKeyDef, primaryKeyDef); }
public void TestIndexer_Get() { //---------------Set up test pack------------------- ClassDef classDef = new ClassDef (typeof (MockBo), new PrimaryKeyDef(), new PropDefCol(), new KeyDefCol(), new RelationshipDefCol()); ClassDefCol col = new ClassDefCol(); col.Add(classDef); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- IClassDef returnedClassDef = col[typeof (MockBo)]; //---------------Test Result ----------------------- Assert.AreEqual(classDef, returnedClassDef); }