/// <summary>
        /// Retrieve the Thuria Populated Relationship from a given Data Model
        /// </summary>
        /// <param name="dataModel">Data Model</param>
        /// <returns>A list of the Relationships Metadata</returns>
        public static IEnumerable <ThuriaDataModelRelationshipMetadata> GetThuriaPopulatedRelationshipMetadata(this object dataModel)
        {
            var dataModelType = dataModel.GetType();
            var allProperties = dataModelType.GetProperties();

            var allRelationships = new List <ThuriaDataModelRelationshipMetadata>();

            foreach (var currentProperty in allProperties)
            {
                if (currentProperty.GetCustomAttribute <ThuriaIgnoreAttribute>() != null)
                {
                    continue;
                }

                var currentRelationship = currentProperty.GetCustomAttribute <ThuriaRelationshipAttribute>();
                if (currentRelationship == null)
                {
                    continue;
                }

                var propertyValue = dataModel.GetPropertyValue(currentProperty.Name);
                if (propertyValue == null)
                {
                    continue;
                }

                var relationshipMetadata = new ThuriaDataModelRelationshipMetadata(currentProperty.Name, propertyValue, currentRelationship);
                allRelationships.Add(relationshipMetadata);
            }

            return(allRelationships);
        }
Ejemplo n.º 2
0
        public void Constructor()
        {
            //---------------Set up test pack-------------------
            var dataModel             = new ThuriaTestDataModel();
            var relationshipAttribute = new ThuriaRelationshipAttribute("ForeignTest", TharkRelationshipType.OneToOne, "Id", "ThuriaTestId");
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var relationshipMetadata = new ThuriaDataModelRelationshipMetadata("Id", dataModel, relationshipAttribute);

            //---------------Test Result -----------------------
            relationshipMetadata.Should().NotBeNull();
        }