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 TestAddBusinessObjectAndUpdatesAnotherRow_UpdatesBO() { SetupTestData(); //IBusinessObject bo3 = _classDef.CreateNewBusinessObject(itsConnection); IBusinessObject bo3 = _classDef.CreateNewBusinessObject(); bo3.SetPropertyValue("TestProp", "bo3prop1"); bo3.SetPropertyValue("TestProp2", "s2"); const string updatedvalue = "UpdatedValue"; object origionalPropValue = itsBo1.GetPropertyValue("TestProp"); //---------------Assert Precondition---------------- Assert.AreEqual(2, itsTable.Rows.Count); Assert.AreNotEqual(updatedvalue, itsTable.Rows[0][1]); Assert.AreEqual(origionalPropValue, itsTable.Rows[0][1]); //---------------Execute Test ---------------------- _collection.Add(bo3); itsTable.Rows[0]["TestProp"] = updatedvalue; //---------------Test Result ----------------------- // Assert.AreEqual(3, itsTable.Rows.Count); Assert.AreEqual(updatedvalue, itsTable.Rows[0][1]); Assert.AreNotEqual(origionalPropValue, itsTable.Rows[0][1]); Assert.AreEqual(itsTable.Rows[0][0], itsBo1.ID.AsString_CurrentValue()); Assert.AreEqual(updatedvalue, itsBo1.GetPropertyValue("TestProp")); Assert.AreNotEqual(origionalPropValue, itsBo1.GetPropertyValue("TestProp")); }
private static IBusinessObjectCollection GetCol_BO_2Items(IClassDef classDef) { IBusinessObjectCollection col = new BusinessObjectCollection <BusinessObject>(classDef); IBusinessObject bo1 = classDef.CreateNewBusinessObject(); bo1.SetPropertyValue("TestProp", "Value1"); bo1.SetPropertyValue("TestProp2", "Value2"); IBusinessObject bo2 = classDef.CreateNewBusinessObject(); bo2.SetPropertyValue("TestProp", "2Value1"); bo2.SetPropertyValue("TestProp2", "2Value2"); col.Add(bo1); col.Add(bo2); return(col); }
private void UpdateExistingBo(IBusinessObject bo, IBusinessObject existingBo) { foreach (var prop in existingBo.Props) { existingBo.SetPropertyValue(prop.PropertyName, bo.GetPropertyValue(prop.PropertyName)); } }
public void Test_ClickCancel_WhenNotIsNew_ShouldCancelEditsAndNotMarkForDelete() { //---------------Set up test pack------------------- IBusinessObject bo = _classDefMyBo.CreateNewBusinessObject(); bo.Save(); IDefaultBOEditorForm boEditorForm = GetControlFactory() .CreateBOEditorForm((BusinessObject)bo, "default", () => null); ShowFormIfNecessary(boEditorForm); EditControlValueOnForm(boEditorForm, "TestProp", "TestValue"); EditControlValueOnForm(boEditorForm, "TestProp2", "TestValue2"); bo.SetPropertyValue("TestProp", "TestValue"); IButton cancelButton = boEditorForm.Buttons["Cancel"]; //--------------Assert PreConditions---------------- Assert.IsNotNull(cancelButton); Assert.IsTrue(bo.Status.IsDirty, "BO should be dirty prior to cancelling"); //---------------Execute Test ---------------------- cancelButton.PerformClick(); //---------------Test Result ----------------------- Assert.AreEqual(DialogResult.Cancel, boEditorForm.DialogResult); Assert.AreEqual(null, bo.GetPropertyValue("TestProp")); Assert.AreEqual(null, bo.GetPropertyValue("TestProp2")); Assert.IsFalse(bo.Status.IsDirty, "BO should not be dirty after cancelling"); Assert.IsFalse(bo.Status.IsDeleted, "Saved BO should not be deleted on cancelling edits"); Assert.IsNull(boEditorForm.PanelInfo.BusinessObject); }
public void TestSetPropertyValueWithString() { IBusinessObject bo = _itsClassDef.CreateNewBusinessObject(); bo.SetPropertyValue("TestProp", "test"); Assert.AreSame(typeof(SimpleValueObjectStub), bo.GetPropertyValue("TestProp").GetType()); Assert.AreEqual("test", bo.GetPropertyValue("TestProp").ToString()); }
private static IBusinessObjectCollection GetCol_BO_1CheckboxItem(IClassDef classDef) { IBusinessObjectCollection col = new BusinessObjectCollection <BusinessObject>(classDef); IBusinessObject bo1 = classDef.CreateNewBusinessObject(); bo1.SetPropertyValue("TestProp", true); col.Add(bo1); return(col); }
private static IBusinessObjectCollection GetCol_BO_1ComboBoxItem(IClassDef classDef) { IBusinessObjectCollection col = new BusinessObjectCollection <BusinessObject>(classDef); IBusinessObject bo1 = classDef.CreateNewBusinessObject(); bo1.SetPropertyValue("RelatedID", Guid.NewGuid()); col.Add(bo1); return(col); }
public void TestAddBOToCollectionAddsCorrectValues() { SetupTestData(); //IBusinessObject newBo = _classDef.CreateNewBusinessObject(itsConnection); IBusinessObject newBo = _classDef.CreateNewBusinessObject(); newBo.SetPropertyValue("TestProp", "TestVal"); _collection.Add(newBo); Assert.AreEqual("TestVal", itsTable.Rows[2][1]); }
///<summary> ///</summary> ///<param name="value">sets the objects autoincremented number from the database</param> public void SetAutoIncrementingFieldValue(long value) { foreach (PropDef def in _bo.ClassDef.PropDefcol) { if (def.AutoIncrementing) { _bo.SetPropertyValue(def.PropertyName, value); } } }
/// <summary> /// DereferenceThe Child <see cref="IBusinessObject"/> identified by <paramref name="bo"/> /// </summary> /// <param name="committer">The transaction commtter responsible for persisting this dereference.</param> /// <param name="bo">The Business Object being dereferenced.</param> protected void DereferenceChild(TransactionCommitter committer, IBusinessObject bo) { foreach (RelPropDef relPropDef in RelationshipDef.RelKeyDef) { bo.SetPropertyValue(relPropDef.RelatedClassPropName, null); } if (bo.Status.IsNew) { return; } committer.ExecuteTransactionToDataSource(committer.CreateTransactionalBusinessObject(bo)); }
public void Test_BOSetPropertyValue_ValidGuidString() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_guid.PropertyName]; object originalPropValue = Guid.NewGuid(); boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(Guid), _propDef_guid.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- businessObject.SetPropertyValue(boProp.PropertyName, _validGuid.ToString()); //---------------Test Result ----------------------- Assert.AreEqual(_validGuid, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_BOSetPropertyValue_ValidDisplayValueString() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_int.PropertyName]; object originalPropValue = _intKeyDoesNotExistInList; boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- businessObject.SetPropertyValue(boProp.PropertyName, _validLookupValue); //---------------Test Result ----------------------- Assert.AreEqual(_validID, boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void Test_BOSetPropertyValue_ValidDisplayValueString() { IBusinessObject businessObject = GetBusinessObjectStub(); BOProp boProp = (BOProp)businessObject.Props[_propDef_int.PropertyName]; const int originalPropValue = 99; boProp.Value = originalPropValue; //---------------Assert Precondition---------------- Assert.AreEqual(typeof(int), _propDef_int.PropertyType); Assert.IsNotNull(boProp.Value); //---------------Execute Test ---------------------- businessObject.SetPropertyValue(boProp.PropertyName, _validLookupValue); //---------------Test Result ----------------------- Assert.AreEqual(_validBusinessObject.ID.GetAsValue(), boProp.Value); Assert.IsInstanceOf(typeof(int), boProp.Value); Assert.AreEqual(_validLookupValue, boProp.PropertyValueToDisplay); }
public void TestPropertyValue() { //---------------Set up test pack------------------- IBusinessObject bo = _itsClassDef.CreateNewBusinessObject(); LongText longText = new LongText("test"); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bo.SetPropertyValue("TestProp", longText); object actualValue = bo.GetPropertyValue("TestProp"); //---------------Test Result ----------------------- Assert.IsNotNull(actualValue); Assert.IsInstanceOf(typeof(LongText), actualValue); Assert.AreSame(longText, actualValue); }
public void TestPropertyValue() { //---------------Set up test pack------------------- IBusinessObject bo = _itsClassDef.CreateNewBusinessObject(); var valueObject = new SimpleValueObjectStub("test"); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bo.SetPropertyValue("TestProp", valueObject); object actualValue = bo.GetPropertyValue("TestProp"); //---------------Test Result ----------------------- Assert.IsNotNull(actualValue); Assert.IsInstanceOf(typeof(SimpleValueObjectStub), actualValue); Assert.AreSame(valueObject, actualValue); }
public void TestPersistSqlParameterType() { TestUsingDatabase.SetupDBOracleConnection(); IBusinessObject bo = _itsClassDef.CreateNewBusinessObject(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('*', 2500); string value = stringBuilder.ToString(); bo.SetPropertyValue("TestProp", value); var sqlCol = new TransactionalBusinessObjectDB(bo, DatabaseConnection.CurrentConnection).GetPersistSql(); ISqlStatement sqlStatement = sqlCol.First(); IList parameters = sqlStatement.Parameters; IDbDataParameter longTextParam = (IDbDataParameter)parameters[1]; string oracleTypeEnumString = ReflectionUtilities.GetEnumPropertyValue(longTextParam, "OracleType"); Assert.IsTrue(oracleTypeEnumString == "Clob"); }
private void SourcePropUpdatedHandler(object sender, BOPropEventArgs e) { TInput sourcePropValue; try { sourcePropValue = GetSourcePropValue(); } catch (InvalidCastException ex) { string message = "An error occured in the Updating a property via the property Link " + ex.Message; throw new HabaneroDeveloperException(message, message, ex); } object destPropValue = _destinationProp.Value; object transformedValue = _transform(_previousSourceValue); if (destPropValue == null || destPropValue.Equals(transformedValue)) { _owningBO.SetPropertyValue(_destPropName, _transform(sourcePropValue)); } _previousSourceValue = sourcePropValue; }
/// <summary> /// Fixes a Business object that has been created. I.e. if the /// Business object has any <see cref="InterPropRule"/>s then /// these rules are used to ensure that the Property values do not /// conflict with the InterPropRules. /// </summary> /// <param name="bo"></param> public virtual void FixInvalidInterPropRules(IBusinessObject bo) { if (bo == null) { return; } if (!bo.Status.IsValid()) { IEnumerable <IBusinessObjectRule> businessObjectRules = GetBusinessObjectRules(bo); if (businessObjectRules != null) { IEnumerable <string> invalidInterPropRuleForProp = from businessObjectRule in businessObjectRules.OfType <InterPropRule>() where !businessObjectRule.IsValid(bo) select businessObjectRule.RightProp.PropertyName; foreach (string rightPropName in invalidInterPropRuleForProp) { bo.SetPropertyValue(rightPropName, this.GetValidPropValue(bo, rightPropName)); } } } }
public void TestPersistSqlParameterValue() { TestUsingDatabase.SetupDBOracleConnection(); IBusinessObject bo = _classDef.CreateNewBusinessObject(); bo.SetPropertyValue("TestProp", "test"); var sqlCol = new TransactionalBusinessObjectDB(bo, DatabaseConnection.CurrentConnection).GetPersistSql(); ISqlStatement sqlStatement = sqlCol.First(); IList parameters = sqlStatement.Parameters; IDbDataParameter byteStringParam = (IDbDataParameter)parameters[2]; Assert.IsTrue(byteStringParam.Value is byte[], "Should be a byte array"); byte[] paramValue = (byte[])byteStringParam.Value; Assert.AreEqual(paramValue.Length, itsByteArrSpelling_test.Length); Assert.AreEqual(paramValue[0], itsByteArrSpelling_test[0]); Assert.AreEqual(paramValue[1], itsByteArrSpelling_test[1]); Assert.AreEqual(paramValue[2], itsByteArrSpelling_test[2]); Assert.AreEqual(paramValue[3], itsByteArrSpelling_test[3]); Assert.AreEqual(paramValue[4], itsByteArrSpelling_test[4]); Assert.AreEqual(paramValue[5], itsByteArrSpelling_test[5]); Assert.AreEqual(paramValue[6], itsByteArrSpelling_test[6]); Assert.AreEqual(paramValue[7], itsByteArrSpelling_test[7]); }
protected void SetOrganisationID(IBusinessObject businessObject, object value) { if (businessObject == null) return; businessObject.SetPropertyValue("OrganisationID", value); }
/// <summary> /// Fixes a Business object that has been created. I.e. if the /// Business object has any <see cref="InterPropRule"/>s then /// these rules are used to ensure that the Property values do not /// conflict with the InterPropRules. /// </summary> /// <param name="bo"></param> public virtual void FixInvalidInterPropRules(IBusinessObject bo) { if (bo == null) return; if (!bo.Status.IsValid()) { IEnumerable<IBusinessObjectRule> businessObjectRules = GetBusinessObjectRules(bo); if (businessObjectRules != null) { IEnumerable<string> invalidInterPropRuleForProp = from businessObjectRule in businessObjectRules.OfType<InterPropRule>() where !businessObjectRule.IsValid(bo) select businessObjectRule.RightProp.PropertyName; foreach (string rightPropName in invalidInterPropRuleForProp) { bo.SetPropertyValue(rightPropName, this.GetValidPropValue(bo, rightPropName)); } } } }
/// <summary> /// DereferenceThe Child <see cref="IBusinessObject"/> identified by <paramref name="bo"/> /// </summary> /// <param name="committer">The transaction commtter responsible for persisting this dereference.</param> /// <param name="bo">The Business Object being dereferenced.</param> protected void DereferenceChild(TransactionCommitter committer, IBusinessObject bo) { foreach (RelPropDef relPropDef in RelationshipDef.RelKeyDef) { bo.SetPropertyValue(relPropDef.RelatedClassPropName, null); } if (bo.Status.IsNew) return; committer.ExecuteTransactionToDataSource(committer.CreateTransactionalBusinessObject(bo)); }