public void Test_CreatePrimaryKey_TwoPropDefs() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("prop1", typeof(String), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("prop2", typeof(String), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef2); keyDef.Add(propDef1); BOPropCol boPropCol = new BOPropCol(); boPropCol.Add(propDef1.CreateBOProp(false)); boPropCol.Add(propDef2.CreateBOProp(false)); //---------------Assert Precondition---------------- Assert.AreEqual(2, keyDef.Count); //---------------Execute Test ---------------------- BOPrimaryKey boPrimaryKey = (BOPrimaryKey)keyDef.CreateBOKey(boPropCol); //---------------Test Result ----------------------- Assert.AreEqual(keyDef.Count, boPrimaryKey.Count); Assert.IsTrue(boPrimaryKey.IsCompositeKey); }
private static BOPrimaryKey CreatePrimaryBOKeyGuidAndString() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null) { ClassDef = ContactPersonTestBO.LoadDefaultClassDef() }; PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null) { ClassDef = propDef1.ClassDef }; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(true)); propCol.Add(propDef2.CreateBOProp(true)); // BOPropCol propCol = new BOPropCol(); // propCol.Add(propDef1.CreateBOProp(true)); // propCol.Add(propDef2.CreateBOProp(true)); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef1); keyDef.Add(propDef2); return((BOPrimaryKey)keyDef.CreateBOKey(propCol)); }
public void Setup() { ClassDef.ClassDefs.Clear(); _boPropCol1 = new BOPropCol(); _keyDef1 = new KeyDef(); _boPropCol2 = new BOPropCol(); _keyDef2 = new KeyDef(); //Props for KeyDef 1 PropDef lPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol1.Add(lPropDef.CreateBOProp(false)); _keyDef1.Add(lPropDef); lPropDef = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol1.Add(lPropDef.CreateBOProp(false)); _keyDef1.Add(lPropDef); //Props for KeyDef 2 lPropDef = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol2.Add(lPropDef.CreateBOProp(false)); _keyDef2.Add(lPropDef); lPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol2.Add(lPropDef.CreateBOProp(false)); _keyDef2.Add(lPropDef); }
public void TestHasAutoIncrementingProperty_TwoProps_True() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null); propDef2.AutoIncrementing = true; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef(); keyDef.Add(propDef1); keyDef.Add(propDef2); IBOKey boKey = keyDef.CreateBOKey(propCol); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- bool hasAutoIncrementingProperty = boKey.HasAutoIncrementingProperty; //---------------Test Result ----------------------- Assert.IsTrue(hasAutoIncrementingProperty); //---------------Tear Down ------------------------- }
public void Setup() { ClassDef.ClassDefs.Clear(); _boPropCol1 = new BOPropCol(); _keyDef1 = new KeyDef(); _boPropCol2 = new BOPropCol(); _keyDef2 = new KeyDef(); //Props for KeyDef 1 PropDef lPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol1.Add(lPropDef.CreateBOProp(false)); _keyDef1.Add(lPropDef); lPropDef = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol1.Add(lPropDef.CreateBOProp(false)); _keyDef1.Add(lPropDef); //Props for KeyDef 2 lPropDef = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol2.Add(lPropDef.CreateBOProp(false)); _keyDef2.Add(lPropDef); lPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); _boPropCol2.Add(lPropDef.CreateBOProp(false)); _keyDef2.Add(lPropDef); }
public void init() { mBOPropCol = new BOPropCol(); mPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); mBOPropCol.Add(mPropDef.CreateBOProp(false)); mPropDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, null); mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test Message", 1, 10, null)); mBOPropCol.Add(mPropDef.CreateBOProp(false)); BOPropCol anotherPropCol = new BOPropCol(); PropDef anotherPropDef = new PropDef("TestAddPropCol", typeof(string), PropReadWriteRule.ReadWrite, null); anotherPropCol.Add(anotherPropDef.CreateBOProp(false)); mBOPropCol.Add(anotherPropCol); }
public void init() { mBOPropCol = new BOPropCol(); mPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null); mBOPropCol.Add(mPropDef.CreateBOProp(false)); mPropDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, null); mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test Message", 1, 10, null)); mBOPropCol.Add(mPropDef.CreateBOProp(false)); BOPropCol anotherPropCol = new BOPropCol(); PropDef anotherPropDef = new PropDef("TestAddPropCol", typeof(string), PropReadWriteRule.ReadWrite, null); anotherPropCol.Add(anotherPropDef.CreateBOProp(false)); mBOPropCol.Add(anotherPropCol); }
public void TestIntegerIndexer() { PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadOnly, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef(); keyDef.Add(propDef1); keyDef.Add(propDef2); IBOKey boKey = keyDef.CreateBOKey(propCol); Assert.AreEqual(propCol["PropName1"], boKey[0]); Assert.AreEqual(propCol["PropName2"], boKey[1]); }
/// <summary> /// Creates a business object property collection that mirrors /// this one. The new collection will contain a BOProp object for /// each PropDef object in this collection, with that BOProp object /// storing an instance of the PropDef object. /// </summary> /// <param name="isNewObject">Whether the new BOProps in the /// collection will be new objects. See PropDef.CreateBOProp /// for more info.</param> /// <returns>Returns the new BOPropCol object</returns> public IBOPropCol CreateBOPropertyCol(bool isNewObject) { BOPropCol lBOPropertyCol = new BOPropCol(); foreach (IPropDef lPropDef in this) { lBOPropertyCol.Add(lPropDef.CreateBOProp(isNewObject)); } return(lBOPropertyCol); }
public void TestUpdatedEvent() { PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef { propDef1, propDef2 }; IBOKey boKey = keyDef.CreateBOKey(propCol); boKey.Updated += UpdatedEventHandler; propCol["PropName1"].Value = "new value"; Assert.IsTrue(_updatedEventHandled); }
private static IBOKey CreateBOKeyGuidAndString() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null) { ClassDef = ContactPersonTestBO.LoadDefaultClassDef() }; PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null) { ClassDef = propDef1.ClassDef }; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef { propDef1, propDef2 }; return(keyDef.CreateBOKey(propCol)); }
public void TestRemove() { PropDef propDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef.CreateBOProp(false)); Assert.AreEqual(1, propCol.Count); Assert.IsTrue(propCol.Contains("Prop3"), "BOPropCol should contain Prop3 after adding it."); propCol.Remove("Prop3"); Assert.AreEqual(0, propCol.Count, "Remove should remove a BOProp from a BOPropCol"); }
public void TestEquality() { BOKey boKey = (BOKey)_keyDef1.CreateBOKey(_boPropCol1); // Test when property count is different KeyDef keyDef = new KeyDef(); BOKey otherKey = new BOKey(keyDef); Assert.IsFalse(boKey == otherKey); // Same property count, but different prop names PropDef propDef1 = new PropDef("PropName5", typeof(string), PropReadWriteRule.ReadOnly, null); PropDef propDef2 = new PropDef("PropName6", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); keyDef.Add(propDef1); keyDef.Add(propDef2); otherKey = (BOKey)keyDef.CreateBOKey(propCol); Assert.IsFalse(boKey == otherKey); // Same props but different values (with one null) otherKey = (BOKey)_keyDef1.CreateBOKey(_boPropCol2); otherKey["PropName"].Value = "blah"; Assert.IsFalse(boKey == otherKey); // Same props but different values (neither are null) otherKey = (BOKey)_keyDef1.CreateBOKey(_boPropCol2); boKey["PropName"].Value = "diblah"; Assert.IsFalse(boKey == otherKey); Assert.IsFalse(boKey.Equals(otherKey)); // False when different type of object Assert.IsFalse(boKey.Equals(keyDef)); // Finally, when they are equal boKey["PropName"].Value = "blah"; Assert.IsTrue(boKey == otherKey); Assert.IsTrue(boKey.Equals(otherKey)); }
private static BOObjectID CreateBOObjectID() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); PrimaryKeyDef keyDef = new PrimaryKeyDef(); keyDef.IsGuidObjectID = true; keyDef.Add(propDef1); return((BOObjectID)keyDef.CreateBOKey(propCol)); }
public void TestDirtyXml() { mProp = mBOPropCol["Prop2"]; mProp.InitialiseProp("Prop2-Orig"); mProp.Value = "Prop2-New"; Assert.IsTrue(mProp.IsDirty); mProp = mBOPropCol["PropName"]; mProp.InitialiseProp("Propn-Orig"); mProp.Value = "PropName-new"; Assert.IsTrue(mProp.IsDirty); mPropDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null); mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test", 1, 40, null)); mBOPropCol.Add(mPropDef.CreateBOProp(false)); mProp = mBOPropCol["Prop3"]; mProp.InitialiseProp("Prop3-new"); Assert.IsFalse(mProp.IsDirty); const string dirtyXml = "<Properties><Prop2><PreviousValue>Prop2-Orig</PreviousValue><NewValue>Prop2-New</NewValue></Prop2><PropName><PreviousValue>Propn-Orig</PreviousValue><NewValue>PropName-new</NewValue></PropName></Properties>"; Assert.AreEqual(dirtyXml, mBOPropCol.DirtyXml); }
///<summary> /// Generate SqlStatementCollection for the Relationsp ///</summary> ///<param name="relationship"></param> ///<param name="relatedBusinessObject"></param> ///<returns></returns> public IEnumerable <ISqlStatement> GenerateForRelationship(IRelationship relationship, IBusinessObject relatedBusinessObject) { _statements = new List <ISqlStatement>(); var propsToInclude = new BOPropCol(); IBOProp oneProp = null; foreach (var propDef in relationship.RelationshipDef.RelKeyDef) { oneProp = relatedBusinessObject.Props[propDef.RelatedClassPropName]; propsToInclude.Add(oneProp); } if (oneProp == null) { return(_statements); } IClassDef classDef = relatedBusinessObject.ClassDef; string tableName = classDef.GetTableName(oneProp.PropDef); GenerateSingleUpdateStatement(tableName, propsToInclude, false, (ClassDef)classDef); return(_statements); }
private static BOPrimaryKey CreatePrimaryBOKeyGuidAndString() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null) { ClassDef = ContactPersonTestBO.LoadDefaultClassDef()}; PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null) { ClassDef = propDef1.ClassDef}; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(true)); propCol.Add(propDef2.CreateBOProp(true)); // BOPropCol propCol = new BOPropCol(); // propCol.Add(propDef1.CreateBOProp(true)); // propCol.Add(propDef2.CreateBOProp(true)); PrimaryKeyDef keyDef = new PrimaryKeyDef {IsGuidObjectID = false}; keyDef.Add(propDef1); keyDef.Add(propDef2); return (BOPrimaryKey)keyDef.CreateBOKey(propCol); }
public void TestIntegerIndexer() { PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadOnly, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef(); keyDef.Add(propDef1); keyDef.Add(propDef2); IBOKey boKey = keyDef.CreateBOKey(propCol); Assert.AreEqual(propCol["PropName1"], boKey[0]); Assert.AreEqual(propCol["PropName2"], boKey[1]); }
public void TestRemove() { PropDef propDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef.CreateBOProp(false)); Assert.AreEqual(1, propCol.Count); Assert.IsTrue(propCol.Contains("Prop3"), "BOPropCol should contain Prop3 after adding it."); propCol.Remove("Prop3"); Assert.AreEqual(0, propCol.Count, "Remove should remove a BOProp from a BOPropCol"); }
public void Test_CreatePrimaryKey_OnePropDefs() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("prop1", typeof(String), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef1); BOPropCol boPropCol = new BOPropCol(); boPropCol.Add(propDef1.CreateBOProp(false)); //---------------Assert Precondition---------------- Assert.AreEqual(1, keyDef.Count); //---------------Execute Test ---------------------- BOPrimaryKey boPrimaryKey = (BOPrimaryKey)keyDef.CreateBOKey(boPropCol); //---------------Test Result ----------------------- Assert.AreEqual(keyDef.Count, boPrimaryKey.Count); Assert.IsFalse(boPrimaryKey.IsCompositeKey); }
private static BOObjectID CreateBOObjectID() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); PrimaryKeyDef keyDef = new PrimaryKeyDef(); keyDef.IsGuidObjectID = true; keyDef.Add(propDef1); return (BOObjectID)keyDef.CreateBOKey(propCol); }
///<summary> /// Generate SqlStatementCollection for the Relationsp ///</summary> ///<param name="relationship"></param> ///<param name="relatedBusinessObject"></param> ///<returns></returns> public IEnumerable<ISqlStatement> GenerateForRelationship(IRelationship relationship, IBusinessObject relatedBusinessObject) { _statements = new List<ISqlStatement>(); var propsToInclude = new BOPropCol(); IBOProp oneProp = null; foreach (var propDef in relationship.RelationshipDef.RelKeyDef) { oneProp = relatedBusinessObject.Props[propDef.RelatedClassPropName]; propsToInclude.Add(oneProp); } if (oneProp == null) return _statements; IClassDef classDef = relatedBusinessObject.ClassDef; string tableName = classDef.GetTableName(oneProp.PropDef); GenerateSingleUpdateStatement(tableName, propsToInclude, false, (ClassDef) classDef); return _statements; }
public void TestFromIRelationship_MultipleProps() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); RelKeyDef relKeyDef = new RelKeyDef(); const string propValue1 = "bob1"; PropDef boPropDef1 = new PropDef("Prop1", typeof(String), PropReadWriteRule.ReadWrite, propValue1); relKeyDef.Add(new RelPropDef(boPropDef1, "RelatedProp1")); const string propValue2 = "bob2"; PropDef boPropDef2 = new PropDef("Prop2", typeof(String), PropReadWriteRule.ReadWrite, propValue2); relKeyDef.Add(new RelPropDef(boPropDef2, "RelatedProp2")); RelationshipDef reldef = new MultipleRelationshipDef("bob", "Habanero.Test", "MyBO", relKeyDef, false, "", DeleteParentAction.DoNothing); ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); BOPropCol col = new BOPropCol(); col.Add(boPropDef1.CreateBOProp(true)); col.Add(boPropDef2.CreateBOProp(true)); IRelationship relationship = reldef.CreateRelationship(cp, col); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- Criteria criteria = Criteria.FromRelationship(relationship); //---------------Test Result ----------------------- string expectedString = string.Format("(RelatedProp1 = '{0}') AND (RelatedProp2 = '{1}')", propValue1, propValue2); StringAssert.AreEqualIgnoringCase(expectedString, criteria.ToString()); //---------------Tear Down ------------------------- }
public void TestEquality() { BOKey boKey = (BOKey) _keyDef1.CreateBOKey(_boPropCol1); // Test when property count is different KeyDef keyDef = new KeyDef(); BOKey otherKey = new BOKey(keyDef); Assert.IsFalse(boKey == otherKey); // Same property count, but different prop names PropDef propDef1 = new PropDef("PropName5", typeof(string), PropReadWriteRule.ReadOnly, null); PropDef propDef2 = new PropDef("PropName6", typeof(string), PropReadWriteRule.ReadOnly, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); keyDef.Add(propDef1); keyDef.Add(propDef2); otherKey = (BOKey) keyDef.CreateBOKey(propCol); Assert.IsFalse(boKey == otherKey); // Same props but different values (with one null) otherKey = (BOKey) _keyDef1.CreateBOKey(_boPropCol2); otherKey["PropName"].Value = "blah"; Assert.IsFalse(boKey == otherKey); // Same props but different values (neither are null) otherKey = (BOKey) _keyDef1.CreateBOKey(_boPropCol2); boKey["PropName"].Value = "diblah"; Assert.IsFalse(boKey == otherKey); Assert.IsFalse(boKey.Equals(otherKey)); // False when different type of object Assert.IsFalse(boKey.Equals(keyDef)); // Finally, when they are equal boKey["PropName"].Value = "blah"; Assert.IsTrue(boKey == otherKey); Assert.IsTrue(boKey.Equals(otherKey)); }
private static IBOKey CreateBOKeyGuidAndString() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null) {ClassDef = ContactPersonTestBO.LoadDefaultClassDef()}; PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null) {ClassDef = propDef1.ClassDef}; BOPropCol propCol = new BOPropCol(); propCol.Add( propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef {propDef1, propDef2}; return keyDef.CreateBOKey(propCol); }
public void TestHasAutoIncrementingProperty_TwoProps_True() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null); propDef2.AutoIncrementing = true; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef(); keyDef.Add(propDef1); keyDef.Add(propDef2); IBOKey boKey = keyDef.CreateBOKey(propCol); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- bool hasAutoIncrementingProperty = boKey.HasAutoIncrementingProperty; //---------------Test Result ----------------------- Assert.IsTrue(hasAutoIncrementingProperty); //---------------Tear Down ------------------------- }
public void TestUpdatedEvent() { PropDef propDef1 = new PropDef("PropName1", typeof(string), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); propCol.Add(propDef2.CreateBOProp(false)); KeyDef keyDef = new KeyDef {propDef1, propDef2}; IBOKey boKey = keyDef.CreateBOKey(propCol); boKey.Updated += UpdatedEventHandler; propCol["PropName1"].Value = "new value"; Assert.IsTrue(_updatedEventHandled); }