public void FindPropertyAccessorData_Property()
        {
            var result = _orderCache.FindPropertyAccessorData(typeof(Order), "OrderNumber");

            var expected = _orderCache.GetMandatoryPropertyAccessorData(typeof(Order), "OrderNumber");

            Assert.That(result, Is.EqualTo(expected));
        }
        public void FindPropertyAccessorData_FromDerivedType()
        {
            Assert.That(_distributorCache.GetPropertyAccessorData(typeof(Distributor), "ContactPerson"), Is.Null);

            var result = _distributorCache.FindPropertyAccessorData(typeof(Distributor), "ContactPerson");

            var expected = _distributorCache.GetMandatoryPropertyAccessorData(typeof(Partner), "ContactPerson");

            Assert.That(result, Is.EqualTo(expected));
        }
        public void FindPropertyAccessorData_WithShadowedProperty()
        {
            var shadowingResult   = _derivedClassWithMixedPropertiesCache.FindPropertyAccessorData(typeof(DerivedClassWithDifferentProperties), "String");
            var shadowingExpected =
                _derivedClassWithMixedPropertiesCache.GetMandatoryPropertyAccessorData(typeof(DerivedClassWithDifferentProperties), "String");

            Assert.That(shadowingResult, Is.EqualTo(shadowingExpected));

            var shadowedResult   = _derivedClassWithMixedPropertiesCache.FindPropertyAccessorData(typeof(ClassWithDifferentProperties), "String");
            var shadowedExpected = _derivedClassWithMixedPropertiesCache.GetMandatoryPropertyAccessorData(typeof(ClassWithDifferentProperties), "String");

            Assert.That(shadowedResult, Is.EqualTo(shadowedExpected));
        }
        public void FindPropertyAccessorData_FromGenericType()
        {
            Assert.That(
                _closedGenericClassCache.GetPropertyAccessorData(typeof(ClosedGenericClassWithManySideRelationProperties), "BaseUnidirectional"),
                Is.Null);

            var result = _closedGenericClassCache.FindPropertyAccessorData(typeof(ClosedGenericClassWithManySideRelationProperties), "BaseUnidirectional");

            var expected = _closedGenericClassCache.GetMandatoryPropertyAccessorData(
                typeof(GenericClassWithManySideRelationPropertiesNotInMapping <>),
                "BaseUnidirectional");

            Assert.That(result, Is.EqualTo(expected));
        }
Example #5
0
        /// <summary>
        /// Finds a property with the specified short name, starting its search at a given declaring type upwards the inheritance hierarchy.
        /// </summary>
        /// <param name="typeToStartSearch">The type to start searching from.</param>
        /// <param name="shortPropertyName">The short name of the property to find.</param>
        /// <returns>A <see cref="PropertyAccessor"/> encapsulating the first property with the given <paramref name="shortPropertyName"/>
        /// found when traversing upwards through the inheritance hierarchy, starting from <paramref name="typeToStartSearch"/>.</returns>
        /// <exception cref="ArgumentNullException">One or more of the arguments passed to this method are <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">No matching property could be found.</exception>
        public PropertyAccessor Find([NotNull] Type typeToStartSearch, [NotNull] string shortPropertyName)
        {
            ArgumentUtility.CheckNotNull("typeToStartSearch", typeToStartSearch);
            ArgumentUtility.CheckNotNullOrEmpty("shortPropertyName", shortPropertyName);

            var propertyAccessorData = PropertyAccessorDataCache.FindPropertyAccessorData(typeToStartSearch, shortPropertyName);

            if (propertyAccessorData == null)
            {
                var message = string.Format(
                    "The domain object type '{0}' does not have or inherit a mapping property with the short name '{1}'.",
                    typeToStartSearch.FullName,
                    shortPropertyName);
                throw new ArgumentException(message, "shortPropertyName");
            }

            return(GetPropertyAccessor(ClientTransaction, propertyAccessorData));
        }