Exemplo n.º 1
0
        public void EntityGetMatchesWithRelationship( )
        {
            var query = new StructuredQuery
            {
                RootEntity = new ResourceEntity(Field.Field_Type)
            };

            // Root query type is 'EntityType'

            // Follow 'Fields' relationship
            var relatedResource = new RelatedResource
            {
                RelationshipDirection = RelationshipDirection.Forward,
                RelationshipTypeId    = new EntityRef(Field.FieldIsOnType_Field.Id),
                ResourceMustExist     = false
            };

            query.RootEntity.RelatedEntities.Add(relatedResource);

            query.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(relatedResource, EntityType.Name_Field),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue("Person")
            });

            IEnumerable <Field> personFields = Entity.GetMatches <Field>(query);

            Assert.IsTrue(personFields.Any( ));
        }
Exemplo n.º 2
0
        public void EntityGetMatchesWithRelationship2( )
        {
            var stringField      = Entity.Get <EntityType>(new EntityRef("core", "stringField"));
            var fieldIsOnTypeRel = Entity.Get <Relationship>(new EntityRef("core", "fieldIsOnType"));

            var query = new StructuredQuery
            {
                RootEntity = new ResourceEntity(stringField)
            };

            // Root query type is 'EntityType'

            // Follow 'Fields' relationship
            var relatedResource = new RelatedResource
            {
                RelationshipDirection = RelationshipDirection.Forward,
                RelationshipTypeId    = fieldIsOnTypeRel.Id,
                ResourceMustExist     = false
            };

            query.RootEntity.RelatedEntities.Add(relatedResource);

            //// check the condition
            query.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(relatedResource, EntityType.Name_Field),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue("Person")
            });

            IEnumerable <Field> descriptionStringFields = Entity.GetMatches <Field>(query);

            Assert.IsTrue(descriptionStringFields.Any( ), "There should be at least one person type");
        }
Exemplo n.º 3
0
        public void EntityGetMatches( )
        {
            // Test to load all instances of a particular entity type that have a field matching a particular value.

            // Test data
            // (Load all nav sections that have name='Home')
            var          type  = new EntityRef("console", "navSection");
            var          field = new EntityRef("core", "name");
            const string value = "Home";

            // Create query
            var query = new StructuredQuery
            {
                RootEntity = new ResourceEntity(type)
            };

            query.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(query.RootEntity, field),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue(value)
            });

            // Get results
            IEnumerable <NavSection> entities = Entity.GetMatches <NavSection>(query);

            NavSection[] eArr = entities.ToArray( );
            Assert.IsTrue(eArr.Count( ) == 1);
        }