Пример #1
0
        /// <summary>Helper method to get a property from the type.</summary>
        /// <param name="structuredType">The structured type to get the property from.</param>
        /// <param name="name">The name of the property to get.</param>
        /// <returns>The property found or null otherwise.</returns>
        public static IEdmProperty ResolveProperty(this IEdmStructuredType structuredType, string name)
        {
            IEdmProperty property = structuredType.FindProperty(name);

            ExceptionUtilities.CheckObjectNotNull(property, "Can't find property '" + name + "' on type '" + structuredType.TestFullName() + "'.");
            return(property);
        }
Пример #2
0
        /// <summary>
        /// Compares two sets of structural properties (expected value in CSDL, actual as IEdmStructuredType).
        /// This can apply to both entity types and complex types.
        /// </summary>
        /// <param name="propertyElements">The CSDL element representing the properties.</param>
        /// <param name="modelType">The EDM model type to compare against.</param>
        private static void CompareStructuralProperties(IEnumerable <XElement> propertyElements, IEdmStructuredType modelType)
        {
            ExceptionUtilities.Assert(propertyElements.Count() == modelType.StructuralProperties().Count(), "Unexpected number of properties on type " + modelType.TestFullName());
            foreach (var propertyElement in propertyElements)
            {
                var propertyName    = propertyElement.GetAttributeValue("Name");
                var propertyOnModel = modelType.FindProperty(propertyName) as IEdmStructuralProperty;
                ExceptionUtilities.Assert(propertyOnModel != null, "Failed to find structural property " + propertyName + " on type " + modelType.TestFullName());
                CompareType(propertyElement, propertyOnModel.Type);
                // TODO: Enable this.
                // CompareTypeFacets(propertyElement, propertyOnModel.Type);

                string defaultValueString;
                if (propertyElement.TryGetAttributeValue("DefaultValue", out defaultValueString))
                {
                    ExceptionUtilities.Assert(string.Compare(defaultValueString, propertyOnModel.DefaultValueString) == 0, "Unexpected value for DefaultValue");
                }
                else
                {
                    ExceptionUtilities.Assert(string.IsNullOrEmpty(propertyOnModel.DefaultValueString), "Did not expect a value for DefaultValue property");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Compares two sets of navigation properties (expected value in CSDL, actual as IEdmStructuredType).
        /// </summary>
        /// <param name="navigationPropertyElements">The CSDL element representing the properties.</param>
        /// <param name="structuredType">The EDM model type to compare against.</param>
        private static void CompareNavigationProperties(IEnumerable <XElement> navigationPropertyElements, IEdmStructuredType structuredType)
        {
            string structuredTypeName   = structuredType.TestFullName();
            var    navigationProperties = structuredType.Properties().OfType <IEdmNavigationProperty>().ToArray();

            ExceptionUtilities.Assert(navigationPropertyElements.Count() == navigationProperties.Count(), "Unexpected number of navigation properties on type " + structuredTypeName);
            foreach (var navigationPropertyElement in navigationPropertyElements)
            {
                var propertyName       = navigationPropertyElement.GetAttributeValue("Name");
                var navigationProperty = navigationProperties.SingleOrDefault(np => np.Name == propertyName);
                ExceptionUtilities.Assert(navigationProperty != null, "Failed to find navigation property " + propertyName + " on type " + structuredTypeName);

                CompareType(navigationPropertyElement, navigationProperty.Type);

                // Compare NavigationProperty Partner, if present
                var partner = navigationPropertyElement.Attribute("Partner");
                if (partner == null)
                {
                    ExceptionUtilities.Assert(navigationProperty.Partner == null, "Did not expect a Partner value for navigation property " + propertyName + " on type " + structuredTypeName);
                }
                else
                {
                    ExceptionUtilities.Assert(navigationProperty.Partner != null, "Expected a Partner value for navigation property " + propertyName + " on type " + structuredTypeName);
                    ExceptionUtilities.Assert(partner.Value == navigationProperty.Partner.Name, "Unexpected value for navigation property partner");
                }

                // Compare any referential constraints
                var referentialConstraintElements = navigationPropertyElement.EdmElements("ReferentialConstraint").ToArray();
                if (referentialConstraintElements.Any())
                {
                    ExceptionUtilities.Assert(navigationProperty.ReferentialConstraint != null, "Expected a referential constraint to be present");
                    ExceptionUtilities.Assert(referentialConstraintElements.Count() == navigationProperty.ReferentialConstraint.PropertyPairs.Count(), "Unexpected number of referential constraint pairs");
                    foreach (var referentialConstraintElement in referentialConstraintElements)
                    {
                        var principalProperty  = referentialConstraintElement.GetAttributeValue("ReferencedProperty");
                        var referencedProperty = referentialConstraintElement.GetAttributeValue("Property");
                        var constraintPair     = navigationProperty.ReferentialConstraint.PropertyPairs
                                                 .SingleOrDefault(p => p.PrincipalProperty.Name == principalProperty && p.DependentProperty.Name == referencedProperty);

                        ExceptionUtilities.Assert(constraintPair != null, "Failed to find constraint pair (" + principalProperty + ", " + referencedProperty + ")");
                    }
                }
                else
                {
                    ExceptionUtilities.Assert(navigationProperty.ReferentialConstraint == null, "Did not expect any referential constraints");
                }

                // Compare OnDelete, if present
                var onDeleteElement = navigationPropertyElement.EdmElements("OnDelete").SingleOrDefault();
                if (onDeleteElement != null)
                {
                    EdmOnDeleteAction expectedAction;
                    EdmOnDeleteAction.TryParse(onDeleteElement.GetAttributeValue("Action"), out expectedAction);
                    ExceptionUtilities.Assert(expectedAction == navigationProperty.OnDelete, "Unexpected value for OnDelete");
                }
                else
                {
                    ExceptionUtilities.Assert(EdmOnDeleteAction.None == navigationProperty.OnDelete, "Unexpected value for OnDelete");
                }
            }
        }
Пример #4
0
        private static void CompareBaseType(XElement typeElement, IEdmStructuredType modelType)
        {
            var baseTypeAttribute = typeElement.Attribute("BaseType");

            if (baseTypeAttribute != null)
            {
                ExceptionUtilities.Assert(modelType.BaseType != null, "Expected base type for type " + modelType.TestFullName());
                CompareTypeValue(baseTypeAttribute.Value, modelType.BaseType.ToTypeReference());
            }
            else
            {
                ExceptionUtilities.Assert(modelType.BaseType == null, "Did not expect base type for type " + modelType.TestFullName());
            }
        }