private IBusinessObject GetPropertyValue( IBusinessObject currentObject, IBusinessObjectReferenceProperty currentProperty, BusinessObjectPropertyPath.ListValueBehavior listValueBehavior, int propertyIndex) { if (currentProperty.IsList) { if (listValueBehavior == BusinessObjectPropertyPath.ListValueBehavior.FailForListProperties) { throw new InvalidOperationException( string.Format("Property #{0} of property path '{1}' is not a single-value property.", propertyIndex, Identifier)); } var list = (IList)currentObject.GetProperty(currentProperty); if (list.Count > 0) { return((IBusinessObject)list[0]); } else { return(null); } } else { return((IBusinessObject)currentObject.GetProperty(currentProperty)); } }
public void GetProperty_NormallyReturnsNonNull() { ClassWithValueType <int> instance = ObjectFactory.Create <ClassWithValueType <int> > (ParamList.Empty); IBusinessObject instanceAsIBusinessObject = (IBusinessObject)instance; Assert.That(instanceAsIBusinessObject.GetProperty("Scalar"), Is.Not.Null); Assert.That(instanceAsIBusinessObject.GetProperty("Scalar"), Is.EqualTo(instance.Scalar)); }
public void GetProperty_ReturnsNonNull_WhenDefaultValueTrueOnList() { ClassWithValueType <int> instance = ObjectFactory.Create <ClassWithValueType <int> > (ParamList.Empty); IBusinessObject instanceAsIBusinessObject = (IBusinessObject)instance; Assert.That(instanceAsIBusinessObject.GetProperty("List"), Is.Not.Null); Assert.That(instanceAsIBusinessObject.GetProperty("List"), Is.EqualTo(instance.List)); }
public void Scalar_WithValue() { Expect.Call(_mockProperty.IsList).Return(false); Expect.Call(_mockBusinessObject.GetProperty(_mockProperty)).Return("ExpectedStringValue"); _mockRepository.ReplayAll(); string actual = _stringFormatterService.GetPropertyString(_mockBusinessObject, _mockProperty, null); _mockRepository.VerifyAll(); Assert.That(actual, Is.EqualTo("ExpectedStringValue")); }
public void Scalar_WithValue() { IEnumerationValueInfo enumValueInfo = new EnumerationValueInfo(TestEnum.Value5, "Value5", "ExpectedStringValue", true); Expect.Call(_mockProperty.IsList).Return(false); Expect.Call(_mockBusinessObject.GetProperty(_mockProperty)).Return(TestEnum.Value5); Expect.Call(_mockProperty.GetValueInfoByValue(TestEnum.Value5, _mockBusinessObject)).Return(enumValueInfo); _mockRepository.ReplayAll(); string actual = _stringFormatterService.GetPropertyString(_mockBusinessObject, _mockProperty, null); _mockRepository.VerifyAll(); Assert.That(actual, Is.EqualTo("ExpectedStringValue")); }
public void Scalar_WithValu_AndDateTimeProperty() { Expect.Call(_mockProperty.Type).Return(DateTimeType.DateTime); Expect.Call(_mockProperty.IsList).Return(false); Expect.Call(_mockBusinessObject.GetProperty(_mockProperty)).Return(new DateTime(2000, 4, 14, 3, 45, 10)); _mockRepository.ReplayAll(); using (new CultureScope(new CultureInfo("de-de"), new CultureInfo("de-de"))) { string actual = _stringFormatterService.GetPropertyString(_mockBusinessObject, _mockProperty, null); _mockRepository.VerifyAll(); Assert.That(actual, Is.EqualTo("14.04.2000 03:45")); } }
private string GetStringValues(IBusinessObject businessObject, IBusinessObjectProperty property, string format, int lines) { IList list = (IList)businessObject.GetProperty(property); if (list == null) { return(string.Empty); } int count = list.Count; StringBuilder sb = new StringBuilder(count * 40); for (int i = 0; i < count && (lines == -1 || i < lines); ++i) { if (i > 0) { sb.AppendLine(); } sb.Append(GetStringValue(businessObject, list[i], property, format)); } if (lines != -1 && count > lines) { sb.Append(" ... [" + count + "]"); } return(sb.ToString()); }
/// <summary> /// Gets the value accessed through the <see cref="IBusinessObjectProperty"/> identified by the passed <paramref name="propertyIdentifier"/>. /// </summary> /// <param name="businessObject">The <see cref="IBusinessObject"/> for which the property is declared. Must not be <see langword="null" />.</param> /// <param name="propertyIdentifier"> /// A <see cref="String"/> identifing the <see cref="IBusinessObjectProperty"/> used to access the value. /// Must not be <see langword="null" /> or empty. /// </param> /// <returns> The property value for the <paramref name="propertyIdentifier"/> parameter. </returns> /// <exception cref="BusinessObjectPropertyAccessException"> /// Thrown if the property's value could not be read. /// </exception> /// <exception cref="InvalidOperationException"> /// The <see cref="IBusinessObjectProperty"/> identified through the <paramref name="propertyIdentifier"/> is not part of this /// <paramref name="businessObject"/>'s <see cref="IBusinessObject.BusinessObjectClass"/>. /// </exception> public static object GetProperty(this IBusinessObject businessObject, string propertyIdentifier) { ArgumentUtility.CheckNotNull("businessObject", businessObject); ArgumentUtility.CheckNotNullOrEmpty("propertyIdentifier", propertyIdentifier); var propertyDefinition = GetPropertyDefinition(businessObject, propertyIdentifier); return(businessObject.GetProperty(propertyDefinition)); }
public void MixedProperty_DefaultValue() { var instance = BindableDomainObjectWithMixedPersistentProperties.NewObject(); IBusinessObject instanceAsBusinessObject = instance; var boClass = instanceAsBusinessObject.BusinessObjectClass; IBusinessObjectProperty mixedProperty = boClass.GetPropertyDefinition("MixedProperty"); Assert.That(instanceAsBusinessObject.GetProperty(mixedProperty), Is.Null); }
public void MixedProperty_NonDefaultValue_WithUnchangedValue() { var instance = BindableDomainObjectWithMixedPersistentProperties.NewObject(); IBusinessObject instanceAsBusinessObject = instance; var boClass = instanceAsBusinessObject.BusinessObjectClass; IBusinessObjectProperty mixedProperty = boClass.GetPropertyDefinition("MixedProperty"); var dateTime = ((IMixinAddingPersistentProperties)instance).MixedProperty; ((IMixinAddingPersistentProperties)instance).MixedProperty = dateTime; Assert.That(instanceAsBusinessObject.GetProperty(mixedProperty), Is.EqualTo(dateTime)); }
private void CheckDomainObjectSerializability <T> (Func <T> creator) where T : DomainObject { using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope()) { T instance = creator(); Tuple <T, ClientTransaction> deserializedTuple = Serializer.SerializeAndDeserialize(Tuple.Create(instance, ClientTransaction.Current)); T deserializedT = deserializedTuple.Item1; Assert.That(deserializedT, Is.Not.Null); IBusinessObject bindableOriginal = (IBusinessObject)instance; IBusinessObject bindableDeserialized = (IBusinessObject)deserializedT; foreach (IBusinessObjectProperty property in bindableOriginal.BusinessObjectClass.GetPropertyDefinitions()) { Assert.That(bindableDeserialized.BusinessObjectClass.GetPropertyDefinition(property.Identifier), Is.Not.Null); object value = null; bool propertyCanBeRetrieved; try { value = bindableOriginal.GetProperty(property); propertyCanBeRetrieved = true; } catch (Exception) { propertyCanBeRetrieved = false; } if (propertyCanBeRetrieved) { object newValue; using (deserializedTuple.Item2.EnterNonDiscardingScope()) { newValue = bindableDeserialized.GetProperty(property); } if (value != null && ReflectionUtility.IsDomainObject(property.PropertyType)) { Assert.That(((DomainObject)newValue).ID, Is.EqualTo(((DomainObject)value).ID)); } else { Assert.That(newValue, Is.EqualTo(value)); } } } } }
/// <summary> /// Gets the string representation of the value accessed through the specified <see cref="IBusinessObjectProperty"/> /// from the the passed <see cref="IBusinessObject"/>. /// </summary> /// <param name="businessObject"> The <see cref="IBusinessObject"/> whose property value will be returned. </param> /// <param name="property"> /// The <see cref="IBusinessObjectProperty"/> used to access the value. Must not be <see langword="null"/>. /// </param> /// <param name="format"> /// The format string passed to the value's <see cref="IFormattable.ToString(string,IFormatProvider)"/> method. /// </param> /// <returns> /// The string representation of the property value for the <paramref name="property"/> parameter. /// <list type="table"> /// <listheader> /// <term> Property and Property Value </term> /// <description> Return Value </description> /// </listheader> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectBooleanProperty"/> interface.</term> /// <description><see cref="IBusinessObjectBooleanProperty.GetDisplayName"/> is evaluated for the value and the resulting string is returned.</description> /// </item> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectDateTimeProperty"/> interface.</term> /// <description> /// The value is cast to <see cref="IFormattable"/> and the <see cref="IFormattable.ToString(string,IFormatProvider)"/> method is invoked, /// passing the <paramref name="format"/> string. /// </description> /// </item> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectEnumerationProperty"/> interface.</term> /// <description>The value's <see cref="IEnumerationValueInfo.DisplayName"/> is returned.</description> /// </item> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectNumericProperty"/> interface.</term> /// <description> /// The value is cast to <see cref="IFormattable"/> and the <see cref="IFormattable.ToString(string,IFormatProvider)"/> method is invoked, /// passing the <paramref name="format"/> string. /// </description> /// </item> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectReferenceProperty"/> interface.</term> /// <description> /// The value's <see cref="IBusinessObjectWithIdentity.DisplayName"/> is returned (including an acess check) /// if the object implements <see cref="IBusinessObjectWithIdentity"/>, otherwise, <see cref="object.ToString()"/> is used. /// </description> /// </item> /// <item> /// <term>The <paramref name="property"/> parameter implements the <see cref="IBusinessObjectStringProperty"/> interface.</term> /// <description>The value is cast to a string and returned.</description> /// </item> /// <item> /// <term>The value is <see langword="null"/>.</term> /// <description>An empty string is returned.</description> /// </item> /// <item> /// <term> The value is a list. </term> /// <description> /// The <paramref name="format"/> string is parsed to check whether it begins with <c>lines=<n></c>, where <c>n</c> is the number of /// items to render or <c>all</c> to render all items in the list. The value is then cast to <see cref="IList"/> and each item is processed /// according to the <paramref name="property"/>'s formatting logic. The resulting strings are concatenated and the total number of lines is /// appended, if not all items are shown. /// </description> /// </item> /// </list> /// </returns> /// <remarks> /// Uses the <paramref name="businessObject"/>'s <see cref="IBusinessObject.GetProperty"/> method for accessing the value. /// </remarks> /// <exception cref="Exception"> /// Thrown if the <paramref name="property"/> is not part of <paramref name="businessObject"/>'s class. /// </exception> public string GetPropertyString(IBusinessObject businessObject, IBusinessObjectProperty property, string format) { ArgumentUtility.CheckNotNull("businessObject", businessObject); ArgumentUtility.CheckNotNull("property", property); if (property.IsList) { Tuple <int, string> result = GetLineCountAndFormatString(format); return(GetStringValues(businessObject, property, result.Item2, result.Item1)); } else { return(GetStringValue(businessObject, businessObject.GetProperty(property), property, format)); } }
public object GetValue() { if (!_resultProperty.IsAccessible(_resultObject)) { return(null); } try { return(_resultObject.GetProperty(_resultProperty)); } catch (BusinessObjectPropertyAccessException) { return(null); } }
private void LoadAndSaveValue <T> (string propertyidentifier, T initialValue, T newValue, string newValueAsString = null) { _businessObject.SetProperty(propertyidentifier, initialValue); _bocTextValue.DataSource = _dataSource; _bocTextValue.Property = _businessObject.BusinessObjectClass.GetPropertyDefinition(propertyidentifier); _bocTextValue.LoadValue(false); Assert.That(_bocTextValue.Value, Is.EqualTo(initialValue)); Assert.That(_bocTextValue.IsDirty, Is.False); _bocTextValue.Text = newValueAsString ?? newValue.ToString(); Assert.That(_bocTextValue.IsDirty, Is.True); _bocTextValue.SaveValue(false); Assert.That(_bocTextValue.Value, Is.EqualTo(newValue)); Assert.That(_bocTextValue.IsDirty, Is.False); _bocTextValue.SaveValue(false); Assert.That(_businessObject.GetProperty(propertyidentifier), Is.EqualTo(newValue)); }
public void StandardProperty_DefaultValue() { IBusinessObjectProperty property = _classWithPropertiesMixinInstanceAsBusinessObjectClass.GetPropertyDefinition("RequiredStringProperty"); Assert.That(_classWithPropertiesMixinInstanceAsBusinessObject.GetProperty(property), Is.Null); }
public void MixedPublicProperty_DefaultValue() { IBusinessObjectProperty mixedProperty = _classWithMixedPropertiesInstanceAsBusinessObjectClass.GetPropertyDefinition("PublicMixedProperty"); Assert.That(_classWithMixedPropertiesInstanceAsBusinessObject.GetProperty(mixedProperty), Is.Null); }
public void List_WithoutLineCount() { Expect.Call(_mockProperty.IsList).Return(true); Expect.Call(_mockBusinessObject.GetProperty(_mockProperty)).Return(_mockValues); Expect.Call(_mockValues[0].ToString(null, null)).Return("First"); _mockRepository.ReplayAll(); string actual = _stringFormatterService.GetPropertyString(_mockBusinessObject, _mockProperty, null); _mockRepository.VerifyAll(); Assert.That(actual, Is.EqualTo("First ... [3]")); }
public void GetPropertyReturnsNonNullIfDefaultValue_OnExistingObject() { Assert.That(_loadedBusinessObject.GetProperty("Int32"), Is.Not.Null); Assert.That(_loadedBusinessObject.GetProperty("Int32"), Is.EqualTo(_loadedObject.Int32)); }
public void GetPropertyReturnsNullIfDefaultValue_OnNewObject() { Assert.That(_newBusinessOrder.GetProperty("Int32"), Is.Null); }
public void WithBusinessObjectProperty() { _bindableObject.String = "A String"; Assert.That(_businessObject.GetProperty(_businessObject.BusinessObjectClass.GetPropertyDefinition("String")), Is.EqualTo("A String")); }
public void WithoutGetter() { IBusinessObject businessObject = Mixin.Get <BindableObjectMixin> (ObjectFactory.Create <SimpleBusinessObjectClass>(ParamList.Empty)); businessObject.GetProperty("StringWithoutGetter"); }