Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the RelationMember class based on the data from RelationInfo object.
        /// </summary>
        /// <param name="info">The RelationMemberInfo object that contains data about member.</param>
        /// <param name="entities">The entities that can be referenced by RelationMember.</param>
        /// <param name="throwOnMissing">bool value indicating whether references to the missing entity should cause exception.</param>
        /// <returns>The RelationMember object created from RelationMemberInfo or null if referenced node is missing.</returns>
        public static RelationMember FromRelationMemberInfo(RelationMemberInfo info, IEntityCollection <IOsmGeometry> entities, bool throwOnMissing)
        {
            if (info.MemberType == EntityType.Unknown)
            {
                throw new ArgumentException("info.MemberType cannot be EntityType.Unknown");
            }

            if (entities.Contains(info.Reference, info.MemberType) == false)
            {
                if (throwOnMissing)
                {
                    throw new ArgumentException(string.Format("Referenced Entity (ID = {0}, type = {1}) not found in entities collection.", info.Reference, info.MemberType), "info.Reference");
                }
                else
                {
                    return(null);
                }
            }

            RelationMember result = new RelationMember(entities[info.Reference, info.MemberType], info.Role)
            {
                MemberType = info.MemberType
            };

            if (result.Member.EntityType != info.MemberType)
            {
                throw new ArgumentException("Type of the referenced entity doesn't match type of the entity in the collection.");
            }

            return(result);
        }
Exemplo n.º 2
0
        public void FromRelationMemberInfo_ThrowExceptionIfReferencedEntityIsNotAvailable()
        {
            RelationMemberInfo info = new RelationMemberInfo()
            {
                Reference = 10000, MemberType = EntityType.Node, Role = "role"
            };

            Assert.Throws <ArgumentException>(() => RelationMember.FromRelationMemberInfo(info, _nodesEntityCollection, true));
        }
Exemplo n.º 3
0
        public void FromRelationMemberInfo_ThrowExceptionIfTypeIsUnknown()
        {
            RelationMemberInfo info = new RelationMemberInfo()
            {
                Reference = 1, MemberType = EntityType.Unknown, Role = "role"
            };

            Assert.Throws <ArgumentException>(() => RelationMember.FromRelationMemberInfo(info, _nodesEntityCollection, true));
        }
Exemplo n.º 4
0
        public void FromRelationMemberInfo_ThrowExceptionIfReferencedEntityTypeDoesntMatchMemberType()
        {
            RelationMemberInfo info = new RelationMemberInfo()
            {
                Reference = 1, MemberType = EntityType.Way, Role = "role"
            };

            Assert.Throws <ArgumentException>(() => RelationMember.FromRelationMemberInfo(info, _nodesEntityCollection, true));
        }
Exemplo n.º 5
0
        public void FromRelationMemberInfo_ReturnsNullIfReferencedEntityIsNotAvailableAndThrowOnMissingIsFalse()
        {
            RelationMemberInfo info = new RelationMemberInfo()
            {
                Reference = 10000, MemberType = EntityType.Node, Role = "role"
            };

            Assert.Null(RelationMember.FromRelationMemberInfo(info, _nodesEntityCollection, false));
        }
Exemplo n.º 6
0
        public void Constructor_RelationMember_SetsProperties()
        {
            RelationMember member = new RelationMember(new Node(1), "test-role");

            RelationMemberInfo target = new RelationMemberInfo(member);

            Assert.Equal(member.Member.ID, target.Reference);
            Assert.Equal(member.MemberType, target.MemberType);
            Assert.Equal(member.Role, target.Role);
        }
Exemplo n.º 7
0
        public void FromRelationMemberInfo_CreatesRelationMember()
        {
            RelationMemberInfo info = new RelationMemberInfo()
            {
                Reference = 1, MemberType = EntityType.Node, Role = "role"
            };
            RelationMember target = RelationMember.FromRelationMemberInfo(info, _nodesEntityCollection, true);

            Assert.Equal(info.Reference, target.Member.ID);
            Assert.Equal(info.Role, target.Role);
            Assert.Equal(info.MemberType, target.MemberType);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new instance of the RelationMember class based on the data from RelationInfo object.
        /// </summary>
        /// <param name="info">The RelationMemberInfo object that contains data about member.</param>
        /// <param name="entities">The entities that can be referenced by RelationMember.</param>
        /// <param name="throwOnMissing">bool value indicating whether references to the missing entity should cause exception.</param>
        /// <returns>The RelationMember object created from RelationMemberInfo or null if referenced node is missing.</returns>
        public static RelationMember FromRelationMemberInfo(RelationMemberInfo info, IEntityCollection<IOsmGeometry> entities, bool throwOnMissing)
        {
            if (info.MemberType == EntityType.Unknown) {
                throw new ArgumentException("info.MemberType cannot be EntityType.Unknown");
            }

            if (entities.Contains(info.Reference, info.MemberType) == false) {
                if (throwOnMissing) {
                    throw new ArgumentException(string.Format("Referenced Entity (ID = {0}, type = {1}) not found in entities collection.", info.Reference, info.MemberType), "info.Reference");
                }
                else {
                    return null;
                }
            }

            RelationMember result = new RelationMember(entities[info.Reference, info.MemberType], info.Role) { MemberType = info.MemberType };
            if (result.Member.EntityType != info.MemberType) {
                throw new ArgumentException("Type of the referenced entity doesn't match type of the entity in the collection.");
            }

            return result;
        }