public static relationship NewRelationship(PropertyAndValue pavcIn)
        {
            relationship r = null;

            if (pavcIn.pValues[(int)CecilConst.PropertyName.Name] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.Name.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.FullName] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.FQName.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.ArchiMateElementType] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.ArchiMateElementType.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.APIType] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.APIType.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.SourceIdentifier] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.SourceIdentifier.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.TargetIdentifier] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.TargetIdentifier.ToString());
            }

            string label             = pavcIn.pValues[(int)CecilConst.PropertyName.Name];
            string fullname          = pavcIn.pValues[(int)CecilConst.PropertyName.FullName];
            string type              = pavcIn.pValues[(int)CecilConst.PropertyName.ArchiMateElementType];
            string eSourceIdentifier = pavcIn.pValues[(int)CecilConst.PropertyName.SourceIdentifier];
            string eTargetIdentifier = pavcIn.pValues[(int)CecilConst.PropertyName.TargetIdentifier];

            properties ps = ModelFactory.NewProperties();

            foreach (CecilConst.PropertyName pn in Enum.GetValues(typeof(CecilConst.PropertyName)))
            {
                if (pn == CecilConst.PropertyName.NumberOfItems)
                {
                    break;
                }

                int ipn = (int)pn;
                if (pavcIn.pValues[ipn] != null)
                {
                    property p = ModelFactory.NewProperty(ModelFactory.NewValue(pavcIn.pValues[ipn]), pdc[ipn]);
                    ps.property.Add(p);
                }
            }

            ModelConst.RelationshipType eType = (ModelConst.RelationshipType)Enum.Parse(typeof(ModelConst.RelationshipType), type);
            r = ModelFactory.NewRelationship(fullname, eType, eSourceIdentifier, eTargetIdentifier, ps);

            r.label.ElementAt(0).label_text = label; // short name for display; fullname to compute unique identifier

            return(r);
        }
Exemple #2
0
        public void ShouldCreatePropertyAndValue_Preamble()
        {
            // Arrange
            var encoding     = Encoding.UTF8;
            var propertyInfo = typeof(Encoding).GetProperties().Single(p => p.Name == nameof(Encoding.Preamble));

            // Act
            var propertyAndValue = new PropertyAndValue(encoding, propertyInfo);

            // Assert
            propertyAndValue.DefaultValue.Should().Be("{BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)}");
            propertyAndValue.Value.Should().Be("{NotSupportedException: Specified method is not supported.}");
        }
        public static element NewElement(PropertyAndValue pavcIn)
        {
            element e = null;

            if (pavcIn.pValues[(int)CecilConst.PropertyName.Name] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.Name.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.FullName] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.FQName.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.ArchiMateElementType] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.ArchiMateElementType.ToString());
            }
            if (pavcIn.pValues[(int)CecilConst.PropertyName.APIType] == null)
            {
                throw new ArgumentNullException(CecilConst.PropertyName.APIType.ToString());
            }

            string label    = pavcIn.pValues[(int)CecilConst.PropertyName.Name];
            string fullname = pavcIn.pValues[(int)CecilConst.PropertyName.FullName];
            string type     = pavcIn.pValues[(int)CecilConst.PropertyName.ArchiMateElementType];

            //if (fullname.Contains("_annotations")) System.Diagnostics.Debugger.Break();

            properties ps = ModelFactory.NewProperties();

            foreach (CecilConst.PropertyName pn in Enum.GetValues(typeof(CecilConst.PropertyName)))
            {
                if (pn == CecilConst.PropertyName.NumberOfItems)
                {
                    break;
                }

                int ipn = (int)pn;
                if (pavcIn.pValues[ipn] != null)
                {
                    property p = ModelFactory.NewProperty(ModelFactory.NewValue(pavcIn.pValues[ipn]), pdc[ipn]);
                    ps.property.Add(p);
                }
            }

            ModelConst.ElementType eType = (ModelConst.ElementType)Enum.Parse(typeof(ModelConst.ElementType), type);
            e = ModelFactory.NewElement(fullname, eType, ps);

            e.label.ElementAt(0).label_text = label; // short name for display; fullname to compute unique identifier

            return(e);
        }
Exemple #4
0
        public void ShouldCreatePropertyAndValue()
        {
            // Arrange
            var person = new Person {
                Age = 30
            };
            var propertyInfo = typeof(Person).GetProperties().Single(p => p.Name == nameof(Person.Age));

            // Act
            var propertyAndValue = new PropertyAndValue(person, propertyInfo);

            // Assert
            propertyAndValue.DefaultValue.Should().Be(0);
            propertyAndValue.Value.Should().Be(30);
        }