public void FromProperty()
        {
            Expect.Call(_mockStringFormatterService.GetPropertyString(_businessObject, _property, "TheFormatString")).Return("TheStringValue");
            _mockRepository.ReplayAll();

            string actual = _businessObject.GetPropertyString(_property, "TheFormatString");

            _mockRepository.VerifyAll();
            Assert.That(actual, Is.EqualTo("TheStringValue"));
        }
예제 #2
0
        /// <summary>
        ///   Gets the string representation of 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.
        /// </param>
        /// <returns>
        ///   The string representation of the property value for the <see cref="IBusinessObjectProperty"/> identified by 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 string GetPropertyString(this IBusinessObject businessObject, string propertyIdentifier)
        {
            ArgumentUtility.CheckNotNull("businessObject", businessObject);
            ArgumentUtility.CheckNotNullOrEmpty("propertyIdentifier", propertyIdentifier);

            var propertyDefinition = GetPropertyDefinition(businessObject, propertyIdentifier);

            return(businessObject.GetPropertyString(propertyDefinition, null));
        }
        public string GetString(string format)
        {
            if (!_resultProperty.IsAccessible(_resultObject))
            {
                return(_resultObject.BusinessObjectClass.BusinessObjectProvider.GetNotAccessiblePropertyStringPlaceHolder());
            }

            try
            {
                return(_resultObject.GetPropertyString(_resultProperty, format));
            }
            catch (BusinessObjectPropertyAccessException)
            {
                return(_resultObject.BusinessObjectClass.BusinessObjectProvider.GetNotAccessiblePropertyStringPlaceHolder());
            }
        }