public void Test_InitialiseProp_InvalidBusinessObject_IDNotGuid() { //---------------Set up test pack------------------- TestAutoInc.LoadClassDefWithAutoIncrementingID(); BOProp boProp = new BOProp(_propDef); //Use auto incrementing because it is the only bo prop that has TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testautoincid", 1); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(bo); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + bo.ToString(), ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("Guid", ex.Message); Assert.AreEqual(null, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_WriteOnce_PersistedValueSet_IsEditable_False() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("Name", typeof(string), PropReadWriteRule.WriteOnce, "DD", "", false, false); BOProp prop1 = new BOProp(propDef) { Value = "new Value", IsObjectNew = false }; prop1.BackupPropValue(); //---------------Assert Precondition---------------- Assert.AreEqual(PropReadWriteRule.WriteOnce, prop1.PropDef.ReadWriteRule); Assert.IsNotNull(prop1.PersistedPropertyValue); //---------------Execute Test ---------------------- string message; bool isEditable = prop1.IsEditable(out message); //---------------Test Result ----------------------- Assert.IsFalse(isEditable); StringAssert.Contains("The property ", message); StringAssert.Contains ("Name' is not editable since it is set up as WriteOnce and the value has already been set", message); }
public void Test_GetValidPropValue_WhenStringAndMaxLength_ShouldRetValidValue() { //---------------Set up test pack------------------- IPropDef def = new PropDefFake { PropertyType = typeof(string) }; def.AddPropRule(CreatePropRuleString(3, 7)); IBOProp prop = new BOProp(def); var factory = new BOTestFactory(typeof(FakeBO)); //---------------Assert Precondition---------------- Assert.AreSame(typeof(string), prop.PropertyType); Assert.IsNotEmpty(def.PropRules.OfType <PropRuleString>().ToList()); var propRule = def.PropRules.OfType <PropRuleString>().First(); Assert.AreEqual(3, propRule.MinLength); Assert.AreEqual(7, propRule.MaxLength); //---------------Execute Test ---------------------- var validPropValue = factory.GetValidPropValue(prop); //---------------Test Result ----------------------- Assert.IsNotNull(validPropValue); Assert.GreaterOrEqual(validPropValue.ToString().Length, 3); Assert.LessOrEqual(validPropValue.ToString().Length, 7); }
public void Test_GetValue_AllowRead_True() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanRead_True(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); myBoStub.Save(); //---------------Assert Precondition---------------- Assert.IsTrue(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanRead)); string message; Assert.IsTrue(prop1.IsReadable(out message)); //---------------Execute Test ---------------------- const string newPropValue = "1112"; prop1.Value = newPropValue; //---------------Test Result ----------------------- Assert.IsTrue(prop1.IsDirty); Assert.AreEqual(newPropValue, prop1.Value); }
public void Test_SetValue_InvalidString_RaiseError() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string invalid = "Invalid"; object originalPropValue = Guid.NewGuid(); boProp.Value = originalPropValue; //---------------Assert Precondition --------------- Assert.AreEqual(typeof(Guid), _propDef.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.Value = invalid; //expectedGuid.ToString("B"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + invalid, ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("Guid", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_SetValue_Fail_ReadOnly_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef_ReadOnlyProp1(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; //---------------Assert Precondition---------------- string message; Assert.IsFalse(prop1.IsEditable(out message)); //---------------Execute Test ---------------------- const string newPropValue = "1112"; try { prop1.Value = newPropValue; Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BOPropWriteException ex) { StringAssert.Contains ("The property 'MyBoAuthenticationStub.Prop 1' is not editable since it is set up as ReadOnly", ex.Message); } }
public void Test_BOSetPropertyValue_InvalidString() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_guid.PropertyName]; const string invalid = "Invalid"; object originalPropValue = _validGuid; businessObject.SetPropertyValue(_propDef_guid.PropertyName, originalPropValue); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(Guid), _propDef_guid.PropertyType); Assert.IsNotNull(boProp.Value); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsInstanceOf(typeof(BOPropLookupList), boProp); Assert.IsTrue(boProp.IsValid); //---------------Execute Test ---------------------- try { businessObject.SetPropertyValue(boProp.PropertyName, invalid); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to '" + invalid + "'", ex.Message); StringAssert.Contains("this value cannot be converted to a System.Guid", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_BOSetPropertyValue_InvalidString() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_int.PropertyName]; const string invalid = "Invalid"; object originalPropValue = _intKeyDoesNotExistInList; businessObject.SetPropertyValue(_propDef_int.PropertyName, originalPropValue); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); Assert.IsNotNull(boProp.Value); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsInstanceOf(typeof(BOPropLookupList), boProp); Assert.IsTrue(boProp.PropDef.LookupList.LimitToList); Assert.IsFalse(boProp.IsValid); //---------------Execute Test ---------------------- try { businessObject.SetPropertyValue(boProp.PropertyName, invalid); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroApplicationException ex) { //You are trying to set the value for a lookup property PropName to 'Invalid' this value does not exist in the lookup list StringAssert.Contains(boProp.PropertyName + " cannot be set to '" + invalid + "'", ex.Message); StringAssert.Contains("this value cannot be converted to a System.Int32", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsFalse(boProp.IsValid); } }
public void Test_SetValue_InvalidDateTimeString() { BOProp boProp = new BOProp(_propDef); const string invalid = "Invalid"; object originalPropValue = DateTime.MinValue.AddDays(1); boProp.Value = originalPropValue; PropDef propDef = (PropDef)boProp.PropDef; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(DateTime), propDef.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.Value = invalid; //expectedGuid.ToString("B"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + invalid, ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("DateTime", ex.Message); Assert.AreEqual(originalPropValue, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void TestPropertyValueToDisplay_BusinessObjectLookupList_NotInList() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_int.PropertyName]; BOWithIntID bo1 = new BOWithIntID { TestField = "PropValue" }; string expectedPropValueToDisplay = bo1.ToString(); bo1.IntID = 55; object expctedID = bo1.IntID; bo1.Save(); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); Assert.IsNull(boProp.Value); Assert.IsFalse(bo1.Status.IsNew); Assert.IsNotNull(bo1.IntID); //---------------Execute Test ---------------------- boProp.Value = expctedID; //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(expctedID, boProp.Value); Assert.AreEqual(expectedPropValueToDisplay, boProp.PropertyValueToDisplay); }
public void Test_InitialiseProp_WithDecimal_Max() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const decimal value = decimal.MaxValue; decimal expectedInteger = Math.Round(value); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(value); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + value, ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("Int32", ex.Message); Assert.AreEqual(null, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_Initialise_InvalidDateTimeString() { BOProp boProp = new BOProp(_propDef); const string invalid = "Invalid"; PropDef propDef = (PropDef)boProp.PropDef; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(DateTime), propDef.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(invalid); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + invalid, ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("DateTime", ex.Message); Assert.AreEqual(null, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_BO_GetPropertyValue_Fail_AllowRead_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanRead_False(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); //---------------Assert Precondition---------------- Assert.IsFalse(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanRead)); string message; Assert.IsFalse(prop1.IsReadable(out message)); //---------------Execute Test ---------------------- try { myBoStub.GetPropertyValue("Prop1"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BOPropReadException ex) { StringAssert.Contains("The logged on user is not authorised to read the Prop1 ", ex.Message); } }
public void Test_SetValue_Fail_AllowUpdate_False() { //---------------Set up test pack------------------- MyBoAuthenticationStub.LoadDefaultClassDef(); IBOPropAuthorisation propAuthorisationStub = GetPropAuthorisationStub_CanUpdate_False(); MyBoAuthenticationStub myBoStub = new MyBoAuthenticationStub(); BOProp prop1 = (BOProp)myBoStub.Props["Prop1"]; prop1.SetAuthorisationRules(propAuthorisationStub); myBoStub.Save(); //---------------Assert Precondition---------------- Assert.IsFalse(propAuthorisationStub.IsAuthorised(prop1, BOPropActions.CanUpdate)); Assert.IsFalse(myBoStub.Status.IsNew); string message; Assert.IsFalse(prop1.IsEditable(out message)); //---------------Execute Test ---------------------- const string newPropValue = "1112"; try { prop1.Value = newPropValue; Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (BOPropWriteException ex) { StringAssert.Contains("The logged on user is not authorised to update the Prop1 ", ex.Message); } }
public void Test_SetValue_DBNull() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Execute Test ---------------------- boProp.Value = DBNull.Value; //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); Assert.IsTrue(boProp.IsValid); }
public void Test_SetValue_Null() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string nullValue = null; //---------------Execute Test ---------------------- boProp.Value = nullValue; //---------------Test Result ----------------------- Assert.AreEqual(nullValue, boProp.Value); Assert.IsTrue(boProp.IsValid); }
public void Test_SetValue_ValidDateTime() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); DateTime expectedDateTime = DateTime.MinValue.AddDays(1); //---------------Execute Test ---------------------- boProp.Value = expectedDateTime; //---------------Test Result ----------------------- Assert.IsTrue(boProp.IsValid); Assert.AreEqual(expectedDateTime, boProp.Value); }
public void Test_SetValue_Valid() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string expectedString = "Valid"; //---------------Execute Test ---------------------- boProp.Value = expectedString; //---------------Test Result ----------------------- Assert.IsTrue(boProp.IsValid); Assert.AreEqual(expectedString, boProp.Value); }
public void Test_SetValue_ValidInteger() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Int32 expectedInteger = TestUtil.GetRandomInt(); //---------------Execute Test ---------------------- boProp.Value = expectedInteger; //---------------Test Result ----------------------- Assert.IsTrue(boProp.IsValid); Assert.AreEqual(expectedInteger, boProp.Value); }
public void Test_InialiseProp_DBNUll() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(DBNull.Value); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
public void Test_SetValue_EmptyString() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string expectedString = ""; //---------------Execute Test ---------------------- boProp.Value = expectedString; //---------------Test Result ----------------------- Assert.IsTrue(boProp.IsValid); Assert.IsNull(boProp.Value); }
public void Test_InitialiseProp_EmptyGuidString_B() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Guid guid = Guid.Empty; //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(guid.ToString("B")); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
public void Test_SetValue_Null() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Execute Test ---------------------- boProp.Value = null; //---------------Test Result ----------------------- Assert.IsTrue(boProp.IsValid); Assert.IsNull(boProp.Value); Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); }
public void Test_InitialiseProp_ValidDateTimeTodayString() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp("yesterday"); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(DateTime.Today.AddDays(-1), boProp.Value); }
public void Test_InitialiseProp_NullValue() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.AreEqual(typeof(DateTime), boProp.PropertyType); Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(null); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); }
/// <summary> /// Adds the specified property value as a parameter /// </summary> /// <param name="prop">The business object property</param> private void AddPropToInsertStatement(BOProp prop) { if (!_firstField) { _dbFieldList.Append(", "); _dbValueList.Append(", "); } _dbFieldList.Append(_connection.SqlFormatter.DelimitField(prop.DatabaseFieldName)); string paramName = _gen.GetNextParameterName(); _dbValueList.Append(paramName); _insertSql.AddParameter(paramName, prop.Value, prop.PropertyType); _firstField = false; }
public void Test_InitialiseProp_ValidDateTime() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); DateTime value = DateTime.MinValue.AddDays(1); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InitialiseProp_ValidInteger() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); Int32 value = TestUtil.GetRandomInt(); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InitialiseProp_Valid() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); const string value = "Valid"; //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(value); //---------------Test Result ----------------------- Assert.IsNotNull(boProp.Value); Assert.AreEqual(value, boProp.Value); }
public void Test_InialiseProp_EmptyGuid() { //---------------Set up test pack------------------- BOProp boProp = new BOProp(_propDef); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- boProp.InitialiseProp(Guid.Empty); //---------------Test Result ----------------------- Assert.IsNull(boProp.Value); Assert.AreEqual("", boProp.InvalidReason); Assert.IsTrue(boProp.IsValid); }