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 TestSuperClassKey() { IBOKey msuperKey = BOPrimaryKey.GetSuperClassKey((ClassDef)Circle.GetClassDef(), objCircle); Assert.IsTrue(msuperKey.Contains("ShapeID"), "Super class key should contain the ShapeID property"); Assert.AreEqual(1, msuperKey.Count, "Super class key should only have one prop"); Assert.AreEqual(msuperKey["ShapeID"].Value, objCircle.ID["CircleID"].Value, "ShapeID and CircleID should be the same"); }
/// <summary> /// Adds a key to the collection /// </summary> /// <param name="lBOKey">The BO key</param> public void Add(IBOKey lBOKey) { if (Contains(lBOKey.KeyName)) { throw new InvalidKeyException(String.Format( "A key with the name '{0}' is being added to a key " + "collection but already exists in the collection.", lBOKey.KeyName)); } _boKeys.Add(lBOKey.KeyName, lBOKey); }
public void TestSuperClassKey() { IBOKey msuperKey = BOPrimaryKey.GetSuperClassKey((ClassDef)FilledCircleInheritsCircleNoPK.GetClassDef(), _filledCircle); Assert.IsFalse(msuperKey.Contains("CircleID"), "Super class key should not contain the CircleID property"); Assert.IsTrue(msuperKey.Contains("ShapeID"), "Super class key should contain the ShapeID property"); Assert.AreEqual(1, msuperKey.Count, "Super class key should only have one prop"); Assert.AreEqual(_filledCircle.Props["ShapeID"].Value, //msuperKey["ShapeID"].Value, _filledCircle.ID["FilledCircleID"].Value, "ShapeID and FilledCircleID should be the same"); }
public void Test_AsString_PreviousValue_New() { //--------------- Set up test pack ------------------ IBOKey boKey = CreateBOKeyGuid(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- string keyAsString = boKey.AsString_PreviousValue(); //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase(boKey.AsString_CurrentValue(), keyAsString); }
public void Test_AsString_CurrentValue_New() { //--------------- Set up test pack ------------------ IBOKey boKey = CreateBOKeyGuid(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- string keyAsString = boKey.AsString_CurrentValue(); //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase("ContactPersonTestBO.PropName1=", keyAsString); }
public void TestIndexerPropertyNotFound() { try { IBOKey boKey = _keyDef1.CreateBOKey(_boPropCol1); IBOProp prop = boKey["invalidpropname"]; Assert.Fail("Expected to throw an InvalidPropertyNameException"); } //---------------Test Result ----------------------- catch (InvalidPropertyNameException ex) { StringAssert.Contains("invalidpropname", ex.Message); } }
public void TestAddDuplicateBOProp() { try { IBOKey boKey = _keyDef1.CreateBOKey(_boPropCol1); boKey.Add(boKey["PropName"]); Assert.Fail("Expected to throw an InvalidPropertyException"); } //---------------Test Result ----------------------- catch (InvalidPropertyException ex) { StringAssert.Contains("already exists in the key collection", ex.Message); } }
public void TestAddNullBOProp() { try { IBOKey boKey = _keyDef1.CreateBOKey(_boPropCol1); boKey.Add(null); Assert.Fail("Expected to throw an HabaneroArgumentException"); } //---------------Test Result ----------------------- catch (HabaneroArgumentException ex) { StringAssert.Contains("The argument 'boProp' is not valid. boProp cannot be null", ex.Message); } }
public void TestIndexerIntegerOutOfRange() { try { IBOKey boKey = _keyDef1.CreateBOKey(_boPropCol1); IBOProp prop = boKey[2]; Assert.Fail("Expected to throw an IndexOutOfRangeException"); } //---------------Test Result ----------------------- catch (IndexOutOfRangeException ex) { StringAssert.Contains("the collection does not contain that many items", ex.Message); } }
public void TestIndexer() { //---------------Set up test pack------------------- BOKeyCol col = new BOKeyCol(); col.Add(new BOKey(new KeyDef("anotherkey"))); BOKey boKey = new BOKey(new KeyDef("key")); col.Add(boKey); //---------------Execute Test ---------------------- IBOKey indexedKey = col["key"]; //---------------Test Result ----------------------- Assert.AreSame(boKey, indexedKey); }
public void Test_AsString_PreviousValue_FirstChange() { //--------------- Set up test pack ------------------ IBOKey boKey = CreateBOKeyGuid(); string expectedPreviousValue = boKey.AsString_CurrentValue(); Guid guid = Guid.NewGuid(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- boKey[0].Value = guid; string keyAsString = boKey.AsString_PreviousValue(); //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase(expectedPreviousValue, keyAsString); }
///<summary> ///</summary> ///<param name="boKey"></param> ///<param name="classDisplayName"></param> ///<returns></returns> private static string GetDuplicateObjectErrMsg(IBOKey boKey, string classDisplayName) { string propNames = ""; foreach (BOProp prop in boKey.GetBOPropCol()) { if (propNames.Length > 0) { propNames += ", "; } propNames += String.Format("{0} = {1}", prop.PropertyName, prop.Value); } var errMsg = String.Format("A '{0}' already exists with the same identifier: {1}.", classDisplayName, propNames); return(errMsg); }
public void Test_AsString_CurrentValue_TwoProps() { //--------------- Set up test pack ------------------ IBOKey boKey = CreateBOKeyGuidAndString(); Guid guid = Guid.NewGuid(); string str = TestUtil.GetRandomString(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- boKey[0].Value = guid; boKey[1].Value = str; string keyAsString = boKey.AsString_CurrentValue(); //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase("ContactPersonTestBO.PropName1=" + guid + ";ContactPersonTestBO.PropName2=" + str, keyAsString); }
public void TestIndexerWithNonExistingKey() { //---------------Set up test pack------------------- BOKeyCol col = new BOKeyCol(); //---------------Execute Test ---------------------- try { IBOKey key = col["invalidkey"]; Assert.Fail("Expected to throw an InvalidKeyException"); } //---------------Test Result ----------------------- catch (InvalidKeyException ex) { StringAssert.Contains("does not exist in the collection of keys", ex.Message); } }
public void Test_AsString_PreviousValue_TwoPropKey() { //--------------- Set up test pack ------------------ IBOKey boKey = CreateBOKeyGuidAndString(); string expectedPreviousValue = boKey.AsString_CurrentValue(); Guid guid = Guid.NewGuid(); string str = TestUtil.GetRandomString(); //--------------- Test Preconditions ---------------- //--------------- Execute Test ---------------------- boKey[0].Value = guid; boKey[1].Value = str; string keyAsString = boKey.AsString_PreviousValue(); //--------------- Test Result ----------------------- StringAssert.AreEqualIgnoringCase(expectedPreviousValue, keyAsString); }
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 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); }
/// <summary> /// Creates a "where" clause from the persisted properties held /// </summary> /// <param name="key"></param> /// <param name="sql">The sql statement used to generate and track /// parameters</param> /// <returns>Returns a string</returns> public static string PersistedDatabaseWhereClause(IBOKey key, ISqlStatement sql) { StringBuilder whereClause = new StringBuilder(key.Count * 30); foreach (BOProp prop in ((BOKey)key).SortedValues) { if (whereClause.Length > 0) { whereClause.Append(" AND "); } if (prop.PersistedPropertyValue == null) { whereClause.Append(DatabaseNameFieldNameValuePair(prop, (SqlStatement)sql)); } else { whereClause.Append(PersistedDatabaseNameFieldNameValuePair(prop, (SqlStatement)sql)); } } return(whereClause.ToString()); }
/// <summary> /// Constructor to initialise a new event argument /// with the affected BOKey /// </summary> /// <param name="boKey">The affected BOKey</param> public BOKeyEventArgs(IBOKey boKey) { _boKey = boKey; }
///<summary> ///</summary> ///<param name="boKey"></param> ///<param name="classDisplayName"></param> ///<returns></returns> private static string GetDuplicateObjectErrMsg(IBOKey boKey, string classDisplayName) { string propNames = ""; foreach (BOProp prop in boKey.GetBOPropCol()) { if (propNames.Length > 0) propNames += ", "; propNames += String.Format("{0} = {1}", prop.PropertyName, prop.Value); } var errMsg = String.Format("A '{0}' already exists with the same identifier: {1}.", classDisplayName, propNames); return errMsg; }