Ejemplo n.º 1
0
        public void Verify_that_QueryDatatypeName_returns_expected_results()
        {
            var attributeDefinitionBoolean = new AttributeDefinitionBoolean();

            Assert.That(attributeDefinitionBoolean.QueryDatatypeName(), Is.EqualTo("Boolean"));

            var attributeDefinitionDate = new AttributeDefinitionDate();

            Assert.That(attributeDefinitionDate.QueryDatatypeName(), Is.EqualTo("Date"));

            var attributeDefinitionEnumeration = new AttributeDefinitionEnumeration();

            Assert.That(attributeDefinitionEnumeration.QueryDatatypeName(), Is.EqualTo("Enumeration"));

            var attributeDefinitionInteger = new AttributeDefinitionInteger();

            Assert.That(attributeDefinitionInteger.QueryDatatypeName(), Is.EqualTo("Integer"));

            var attributeDefinitionReal = new AttributeDefinitionReal();

            Assert.That(attributeDefinitionReal.QueryDatatypeName(), Is.EqualTo("Real"));

            var attributeDefinitionString = new AttributeDefinitionString();

            Assert.That(attributeDefinitionString.QueryDatatypeName(), Is.EqualTo("String"));

            var attributeDefinitionXhtml = new AttributeDefinitionXHTML();

            Assert.That(attributeDefinitionXhtml.QueryDatatypeName(), Is.EqualTo("XHTML"));
        }
Ejemplo n.º 2
0
        public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet()
        {
            var datatypeDefinitionDate    = new DatatypeDefinitionDate();
            var attributeDefinitionString = new AttributeDefinitionString();
            var attributeDefinition       = (AttributeDefinition)attributeDefinitionString;

            Assert.Throws <ArgumentException>(() => attributeDefinition.DatatypeDefinition = datatypeDefinitionDate);
        }
Ejemplo n.º 3
0
        public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set()
        {
            var attributeDefinitionString = new AttributeDefinitionString();
            var attributeValueDate        = new AttributeValueDate();
            var attributeValue            = (AttributeValue)attributeValueDate;

            Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString);
        }
Ejemplo n.º 4
0
        public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set()
        {
            var datatypeDefinitionDate    = new DatatypeDefinitionDate();
            var attributeDefinitionString = new AttributeDefinitionString();
            var attributeDefinition       = (AttributeDefinition)attributeDefinitionString;

            Assert.Throws <ArgumentException>(() => attributeDefinition.DatatypeDefinition = datatypeDefinitionDate);
        }
Ejemplo n.º 5
0
        public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet()
        {
            var attributeDefinitionString = new AttributeDefinitionString();
            var attributeValueBoolean     = new AttributeValueBoolean();
            var attributeValue            = (AttributeValue)attributeValueBoolean;

            Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString);
        }
        /// <summary>
        /// Create and add <see cref="AttributeDefinition"/>s to a <see cref="SpecType"/>
        /// </summary>
        /// <param name="specType">
        /// The <see cref="SpecType"/> to add the <see cref="AttributeDefinition"/>s to
        /// </param>
        /// <param name="reqIfContent">
        /// An instance of <see cref="ReqIFContent"/>
        /// </param>
        private void CreateAndAddAttributeDefinitionsToSpecType(SpecType specType, ReqIFContent reqIfContent)
        {
            var attributeDefinitionBoolean = new AttributeDefinitionBoolean();

            attributeDefinitionBoolean.LongName   = "boolean attribute";
            attributeDefinitionBoolean.Identifier = "specification-boolean-attribute";
            attributeDefinitionBoolean.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionBoolean.Type       = (DatatypeDefinitionBoolean)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionBoolean));
            specType.SpecAttributes.Add(attributeDefinitionBoolean);

            var attributeDefinitionDate = new AttributeDefinitionDate();

            attributeDefinitionDate.LongName   = "date attribute";
            attributeDefinitionDate.Identifier = "specification-date-attribute";
            attributeDefinitionDate.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionDate.Type       = (DatatypeDefinitionDate)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionDate));
            specType.SpecAttributes.Add(attributeDefinitionDate);

            var attributeDefinitionEnumeration = new AttributeDefinitionEnumeration();

            attributeDefinitionEnumeration.LongName   = "enumeration attribute";
            attributeDefinitionEnumeration.Identifier = "specification-enumeration-attribute";
            attributeDefinitionEnumeration.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionEnumeration.Type       = (DatatypeDefinitionEnumeration)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionEnumeration));
            specType.SpecAttributes.Add(attributeDefinitionEnumeration);

            var attributeDefinitionInteger = new AttributeDefinitionInteger();

            attributeDefinitionInteger.LongName   = "integer attribute";
            attributeDefinitionInteger.Identifier = "specification-integer-attribute";
            attributeDefinitionInteger.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionInteger.Type       = (DatatypeDefinitionInteger)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionInteger));
            specType.SpecAttributes.Add(attributeDefinitionInteger);

            var attributeDefinitionReal = new AttributeDefinitionReal();

            attributeDefinitionReal.LongName   = "real attribute";
            attributeDefinitionReal.Identifier = "specification-real-attribute";
            attributeDefinitionReal.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionReal.Type       = (DatatypeDefinitionReal)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionReal));
            specType.SpecAttributes.Add(attributeDefinitionReal);

            var attributeDefinitionString = new AttributeDefinitionString();

            attributeDefinitionString.LongName   = "string attribute";
            attributeDefinitionString.Identifier = "specification-string-attribute";
            attributeDefinitionString.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionString.Type       = (DatatypeDefinitionString)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionString));
            specType.SpecAttributes.Add(attributeDefinitionString);

            var attributeDefinitionXhtml = new AttributeDefinitionXHTML();

            attributeDefinitionXhtml.LongName   = "xhtml attribute";
            attributeDefinitionXhtml.Identifier = "specification-xhtml-attribute";
            attributeDefinitionXhtml.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionXhtml.Type       = (DatatypeDefinitionXHTML)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionXHTML));
            specType.SpecAttributes.Add(attributeDefinitionXhtml);
        }
Ejemplo n.º 7
0
        public void Verify_That_WriteXml_Throws_Exception_When_Type_Is_Null()
        {
            using var memoryStream = new MemoryStream();
            using var writer       = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true });

            var attributeDefinitionString = new AttributeDefinitionString();

            Assert.That(() => attributeDefinitionString.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>());
        }
Ejemplo n.º 8
0
        public void Verify_That_WriteXmlAsync_Throws_Exception_When_Type_Is_Null()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            using var memoryStream = new MemoryStream();
            using var writer       = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true, Async = true });

            var attributeDefinitionString = new AttributeDefinitionString();

            Assert.That(async() => await attributeDefinitionString.WriteXmlAsync(writer, cancellationTokenSource.Token), Throws.Exception.TypeOf <SerializationException>());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the <see cref="SpecObjectType"/> corresponding to a <see cref="Requirement"/>
        /// </summary>
        /// <param name="requirement">The <see cref="Requirement"/></param>
        /// <param name="appliedRules">The applied <see cref="ParameterizedCategoryRule"/></param>
        /// <param name="parameterTypeMap">The map of <see cref="ParameterType"/> to <see cref="DatatypeDefinition"/></param>
        /// <returns>the <see cref="SpecObjectType"/></returns>
        public SpecObjectType ToReqIfSpecObjectType(Requirement requirement, IReadOnlyCollection <ParameterizedCategoryRule> appliedRules, IReadOnlyDictionary <ParameterType, DatatypeDefinition> parameterTypeMap)
        {
            if (requirement == null)
            {
                throw new ArgumentNullException("requirement");
            }

            var specObjectType = new SpecObjectType()
            {
                Identifier  = Guid.NewGuid().ToString(),
                LongName    = appliedRules.Any() ? string.Join(", ", appliedRules.Select(r => r.ShortName)) : requirement.ClassKind.ToString(),
                LastChange  = DateTime.UtcNow,
                Description = appliedRules.Any() ? string.Join(", ", appliedRules.Select(r => r.Name)) : requirement.ClassKind.ToString()
            };

            this.AddCommonAttributeDefinition(specObjectType);

            var requirementAttDefinition = new AttributeDefinitionString
            {
                LongName    = RequirementTextAttributeDefName,
                LastChange  = DateTime.UtcNow,
                Description = "The Requirement Text Attribute Definition",
                Identifier  = Guid.NewGuid().ToString(),
                Type        = this.TextDatatypeDefinition
            };

            specObjectType.SpecAttributes.Add(requirementAttDefinition);

            var isDeprecatedAttributeDefinition = new AttributeDefinitionBoolean()
            {
                LongName    = IsDeprecatedAttributeDefName,
                LastChange  = DateTime.Now,
                Description = "The IsDeprecated Attribute Definition",
                Identifier  = Guid.NewGuid().ToString(),
                Type        = this.BooleanDatatypeDefinition
            };

            specObjectType.SpecAttributes.Add(isDeprecatedAttributeDefinition);

            // set the attribute-definition
            var parameterTypes            = appliedRules.SelectMany(r => r.ParameterType).ToList();
            var requirementParameterTypes = requirement.ParameterValue.Select(spv => spv.ParameterType);

            parameterTypes.AddRange(requirementParameterTypes);

            foreach (var parameterType in parameterTypes.Distinct())
            {
                var attibuteDef = this.ToReqIfAttributeDefinition(parameterType, parameterTypeMap);
                specObjectType.SpecAttributes.Add(attibuteDef);
            }

            return(specObjectType);
        }
Ejemplo n.º 10
0
 public void VerifyThatWriteXmlThrowsExceptionWhenTypeIsNull()
 {
     using (var fs = new FileStream("test.xml", FileMode.Create))
     {
         using (var writer = XmlWriter.Create(fs, new XmlWriterSettings {
             Indent = true
         }))
         {
             var attributeDefinitionString = new AttributeDefinitionString();
             Assert.Throws <SerializationException>(() => attributeDefinitionString.WriteXml(writer));
         }
     }
 }
Ejemplo n.º 11
0
        public void VerifyThatTheAttributeDefinitionCanBeSetOrGet()
        {
            var datatypeDefinitionString = new DatatypeDefinitionString();

            var attributeDefinitionString = new AttributeDefinitionString();

            attributeDefinitionString.Type = datatypeDefinitionString;

            var attributeDefinition = (AttributeDefinition)attributeDefinitionString;

            Assert.AreEqual(datatypeDefinitionString, attributeDefinition.DatatypeDefinition);

            attributeDefinition.DatatypeDefinition = datatypeDefinitionString;

            Assert.AreEqual(datatypeDefinitionString, attributeDefinition.DatatypeDefinition);
        }
Ejemplo n.º 12
0
        public void Verify_That_The_AttributeDefinition_Can_Be_Set_Or_Get()
        {
            var attributeDefinitionString = new AttributeDefinitionString();

            var attributeValueString = new AttributeValueString();

            attributeValueString.Definition = attributeDefinitionString;

            var attributeValue = (AttributeValue)attributeValueString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);

            attributeValue.AttributeDefinition = attributeDefinitionString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);
        }
Ejemplo n.º 13
0
        public void Verify_That_The_AttributeDefinition_Can_Be_Set_Or_Get()
        {
            var datatypeDefinitionString = new DatatypeDefinitionString();

            var attributeDefinitionString = new AttributeDefinitionString();

            attributeDefinitionString.Type = datatypeDefinitionString;

            var attributeDefinition = (AttributeDefinition)attributeDefinitionString;

            Assert.AreEqual(datatypeDefinitionString, attributeDefinition.DatatypeDefinition);

            attributeDefinition.DatatypeDefinition = datatypeDefinitionString;

            Assert.AreEqual(datatypeDefinitionString, attributeDefinition.DatatypeDefinition);
        }
Ejemplo n.º 14
0
        public void VerifyThatTheAttributeDefinitionCanBeSetOrGet()
        {
            var attributeDefinitionString = new AttributeDefinitionString();

            var attributeValueString = new AttributeValueString();

            attributeValueString.Definition = attributeDefinitionString;

            var attributeValue = (AttributeValue)attributeValueString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);

            attributeValue.AttributeDefinition = attributeDefinitionString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add the common <see cref="AttributeDefinition"/>s to the <see cref="SpecType"/>
        /// </summary>
        /// <param name="spectType">The <see cref="SpecType"/></param>
        private void AddCommonAttributeDefinition(SpecType spectType)
        {
            // set the attribute-definitions
            var shortNameAttributeDef = new AttributeDefinitionString
            {
                Identifier  = Guid.NewGuid().ToString(),
                Type        = this.TextDatatypeDefinition,
                Description = "The Short-Name Attribute",
                LastChange  = DateTime.UtcNow,
                LongName    = ShortNameAttributeDefName
            };

            spectType.SpecAttributes.Add(shortNameAttributeDef);

            var nameAttributeDef = new AttributeDefinitionString
            {
                Identifier  = Guid.NewGuid().ToString(),
                Type        = this.TextDatatypeDefinition,
                Description = "The Name Attribute",
                LastChange  = DateTime.UtcNow,
                LongName    = NameAttributeDefName
            };

            spectType.SpecAttributes.Add(nameAttributeDef);

            var catAttributeDef = new AttributeDefinitionString
            {
                Identifier  = Guid.NewGuid().ToString(),
                Type        = this.TextDatatypeDefinition,
                Description = "The Categories Attribute",
                LastChange  = DateTime.UtcNow,
                LongName    = CategoryAttributeDefName
            };

            spectType.SpecAttributes.Add(catAttributeDef);
        }
Ejemplo n.º 16
0
        public void Setup()
        {
            this.session = new Mock <ISession>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.assembler = new Assembler(this.uri);

            this.sitedir        = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.domain         = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup
            };

            this.sitedir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Domain.Add(this.domain);
            this.model.Iteration.Add(this.iteration);

            this.person      = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person = this.person
            };
            this.sitedir.Person.Add(this.person);
            this.modelsetup.Participant.Add(this.participant);

            this.pt = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl.ParameterType.Add(this.pt);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);
            this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.assembler.Cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));
            this.assembler.Cache.TryAdd(new CacheKey(this.sitedir.Iid, null), new Lazy <Thing>(() => this.sitedir));
            this.reqIf      = new ReqIF();
            this.reqIf.Lang = "en";
            var corecontent = new ReqIFContent();

            this.reqIf.CoreContent.Add(corecontent);
            this.stringDatadef = new DatatypeDefinitionString();
            this.spectype      = new RelationGroupType();
            this.attribute     = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.spectype.SpecAttributes.Add(this.attribute);

            corecontent.DataTypes.Add(this.stringDatadef);

            this.dialog = new RelationGroupTypeMappingDialogViewModel(new List <RelationGroupType> {
                this.spectype
            }, null, new Dictionary <DatatypeDefinition, DatatypeDefinitionMap> {
                { this.stringDatadef, new DatatypeDefinitionMap(this.stringDatadef, this.pt, null) }
            }, this.iteration, this.session.Object, this.thingDialogNavigationService.Object, "en");
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.session = new Mock <ISession>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ReqIf", "testreq.reqif");
            this.fileDialogService = new Mock <IOpenSaveFileDialogService>();
            this.fileDialogService.Setup(x => x.GetOpenFileDialog(true, true, false, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), 1)).Returns(new string[] { this.path });
            this.reqIf = new ReqIF {
                Lang = "en"
            };
            this.reqIf.TheHeader = new ReqIFHeader()
            {
                Identifier = Guid.NewGuid().ToString()
            };
            var corecontent = new ReqIFContent();

            this.reqIf.CoreContent = corecontent;
            this.stringDatadef     = new DatatypeDefinitionString();
            this.spectype          = new SpecificationType();
            this.attribute         = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.spectype.SpecAttributes.Add(this.attribute);

            corecontent.DataTypes.Add(this.stringDatadef);

            this.settings = new RequirementsModuleSettings()
            {
                SavedConfigurations =
                {
                    new ImportMappingConfiguration()
                    {
                        ReqIfId = this.reqIf.TheHeader.Identifier, Name = "Test"
                    }
                }
            };

            this.pluginSettingService = new Mock <IPluginSettingsService>();
            this.pluginSettingService.Setup(x => x.Read <RequirementsModuleSettings>(true, It.IsAny <JsonConverter[]>())).Returns(this.settings);
            this.pluginSettingService.Setup(x => x.Read <RequirementsModuleSettings>(false)).Returns(this.settings);

            this.reqIfSerialiser = new Mock <IReqIFDeSerializer>();
            this.reqIfSerialiser.Setup(x => x.Deserialize(It.IsAny <string>(), It.IsAny <bool>(), null)).Returns(new[] { this.reqIf });
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString());
            this.assembler = new Assembler(this.uri);

            this.sitedir        = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.domain         = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup
            };

            this.sitedir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Domain.Add(this.domain);
            this.model.Iteration.Add(this.iteration);

            this.person      = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person = this.person
            };
            this.sitedir.Person.Add(this.person);
            this.modelsetup.Participant.Add(this.participant);

            this.pt = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl.ParameterType.Add(this.pt);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);
            this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.assembler.Cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));

            this.dialog = new ReqIfImportDialogViewModel(new[] { this.session.Object }, new[] { this.iteration }, this.fileDialogService.Object, this.pluginSettingService.Object, this.reqIfSerialiser.Object);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);
        }
        private void SetupReqIf()
        {
            this.reqIf             = new ReqIF();
            this.reqIf.Lang        = "en";
            this.corecontent       = new ReqIFContent();
            this.reqIf.CoreContent = this.corecontent;
            this.stringDatadef     = new DatatypeDefinitionString();
            this.specificationtype = new SpecificationType();
            this.specobjecttype    = new SpecObjectType();
            this.specrelationtype  = new SpecRelationType();
            this.relationgrouptype = new RelationGroupType();

            this.specAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.reqAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };
            this.specRelationAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };
            this.relationgroupAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.specificationtype.SpecAttributes.Add(this.specAttribute);
            this.specobjecttype.SpecAttributes.Add(this.reqAttribute);
            this.specrelationtype.SpecAttributes.Add(this.specRelationAttribute);
            this.relationgrouptype.SpecAttributes.Add(this.relationgroupAttribute);

            this.specification1 = new Specification()
            {
                Type = this.specificationtype
            };
            this.specification2 = new Specification()
            {
                Type = this.specificationtype
            };

            this.specobject1 = new SpecObject()
            {
                Type = this.specobjecttype
            };
            this.specobject2 = new SpecObject()
            {
                Type = this.specobjecttype
            };

            this.specrelation = new SpecRelation()
            {
                Type = this.specrelationtype, Source = this.specobject1, Target = this.specobject2
            };
            this.relationgroup = new RelationGroup()
            {
                Type = this.relationgrouptype, SourceSpecification = this.specification1, TargetSpecification = this.specification2
            };

            this.specValue1 = new AttributeValueString()
            {
                AttributeDefinition = this.specAttribute, TheValue = "spec1"
            };
            this.specValue2 = new AttributeValueString()
            {
                AttributeDefinition = this.specAttribute, TheValue = "spec2"
            };
            this.objectValue1 = new AttributeValueString()
            {
                AttributeDefinition = this.reqAttribute, TheValue = "req1"
            };
            this.objectValue2 = new AttributeValueString()
            {
                AttributeDefinition = this.reqAttribute, TheValue = "req2"
            };
            this.relationgroupValue = new AttributeValueString()
            {
                AttributeDefinition = this.relationgroupAttribute, TheValue = "group"
            };
            this.specrelationValue = new AttributeValueString()
            {
                AttributeDefinition = this.specRelationAttribute, TheValue = "specrelation"
            };

            this.specification1.Values.Add(this.specValue1);
            this.specification2.Values.Add(this.specValue2);
            this.specobject1.Values.Add(this.objectValue1);
            this.specobject2.Values.Add(this.objectValue2);
            this.specrelation.Values.Add(this.specrelationValue);
            this.relationgroup.Values.Add(this.relationgroupValue);

            this.corecontent.DataTypes.Add(this.stringDatadef);
            this.corecontent.SpecTypes.AddRange(new SpecType[] { this.specobjecttype, this.specificationtype, this.specrelationtype, this.relationgrouptype });
            this.corecontent.SpecObjects.AddRange(new SpecObject[] { this.specobject1, this.specobject2 });
            this.corecontent.Specifications.AddRange(new Specification[] { this.specification1, this.specification2 });
            this.corecontent.SpecRelations.Add(this.specrelation);
            this.corecontent.SpecRelationGroups.Add(this.relationgroup);

            this.specification1.Children.Add(new SpecHierarchy()
            {
                Object = this.specobject1
            });
            this.specification2.Children.Add(new SpecHierarchy()
            {
                Object = this.specobject2
            });
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the <see cref="AttributeDefinition"/> representation of <see cref="SimpleParameterValue"/>
        /// </summary>
        /// <param name="parameterType">The <see cref="SimpleParameterValue"/></param>
        /// <param name="parameterTypeMap">The <see cref="ParameterType"/> map</param>
        /// <returns>The <see cref="AttributeDefinition"/></returns>
        private AttributeDefinition ToReqIfAttributeDefinition(ParameterType parameterType, IReadOnlyDictionary <ParameterType, DatatypeDefinition> parameterTypeMap)
        {
            if (parameterType == null)
            {
                throw new ArgumentNullException("parameterType");
            }

            AttributeDefinition attributeDefinition;

            var enumerationParameterType = parameterType as EnumerationParameterType;

            if (enumerationParameterType != null)
            {
                attributeDefinition = new AttributeDefinitionEnumeration
                {
                    IsMultiValued = enumerationParameterType.AllowMultiSelect,
                    Type          = (DatatypeDefinitionEnumeration)parameterTypeMap[parameterType],
                    Description   = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }
            else if (parameterType is DateParameterType ||
                     parameterType is DateTimeParameterType ||
                     parameterType is TimeOfDayParameterType)
            {
                attributeDefinition = new AttributeDefinitionDate
                {
                    Type        = (DatatypeDefinitionDate)parameterTypeMap[parameterType],
                    Description = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }
            else if (parameterType is TextParameterType)
            {
                attributeDefinition = new AttributeDefinitionString
                {
                    Type        = (DatatypeDefinitionString)parameterTypeMap[parameterType],
                    Description = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }
            else if (parameterType is BooleanParameterType)
            {
                attributeDefinition = new AttributeDefinitionBoolean
                {
                    Type        = (DatatypeDefinitionBoolean)parameterTypeMap[parameterType],
                    Description = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }
            else if (parameterType is QuantityKind)
            {
                attributeDefinition = new AttributeDefinitionString
                {
                    Type        = (DatatypeDefinitionString)parameterTypeMap[parameterType],
                    Description = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }
            else
            {
                // arrayParameterType
                attributeDefinition = new AttributeDefinitionString
                {
                    Type        = (DatatypeDefinitionString)parameterTypeMap[parameterType],
                    Description = parameterType.Definition.Any() ? parameterType.Definition.First().Content : emptyContent
                };
            }

            attributeDefinition.Identifier = Guid.NewGuid().ToString();
            return(attributeDefinition);
        }
        /// <summary>
        /// create a <see cref="RelationGroupType"/> with attribute definitions
        /// </summary>
        private void CreateRelationGroupType()
        {
            var reqIfContent = this.reqIF.CoreContent.SingleOrDefault();

            var relationGroupType = new RelationGroupType();

            relationGroupType.LongName   = "Relation Group Type";
            relationGroupType.Identifier = "relationgrouptype";
            relationGroupType.LastChange = DateTime.Parse("2015-12-01");

            var attributeDefinitionBoolean = new AttributeDefinitionBoolean();

            attributeDefinitionBoolean.LongName   = "boolean attribute";
            attributeDefinitionBoolean.Identifier = "relationgrouptype-boolean-attribute";
            attributeDefinitionBoolean.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionBoolean.Type       = (DatatypeDefinitionBoolean)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionBoolean));
            relationGroupType.SpecAttributes.Add(attributeDefinitionBoolean);

            var attributeDefinitionDate = new AttributeDefinitionDate();

            attributeDefinitionDate.LongName   = "date attribute";
            attributeDefinitionDate.Identifier = "relationgrouptype-date-attribute";
            attributeDefinitionDate.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionDate.Type       = (DatatypeDefinitionDate)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionDate));
            relationGroupType.SpecAttributes.Add(attributeDefinitionDate);

            var attributeDefinitionEnumeration = new AttributeDefinitionEnumeration();

            attributeDefinitionEnumeration.LongName   = "enumeration attribute";
            attributeDefinitionEnumeration.Identifier = "relationgrouptype-enumeration-attribute";
            attributeDefinitionEnumeration.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionEnumeration.Type       = (DatatypeDefinitionEnumeration)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionEnumeration));
            relationGroupType.SpecAttributes.Add(attributeDefinitionEnumeration);

            var attributeDefinitionInteger = new AttributeDefinitionInteger();

            attributeDefinitionInteger.LongName   = "integer attribute";
            attributeDefinitionInteger.Identifier = "relationgrouptype-integer-attribute";
            attributeDefinitionInteger.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionInteger.Type       = (DatatypeDefinitionInteger)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionInteger));
            relationGroupType.SpecAttributes.Add(attributeDefinitionInteger);

            var attributeDefinitionReal = new AttributeDefinitionReal();

            attributeDefinitionReal.LongName   = "real attribute";
            attributeDefinitionReal.Identifier = "relationgrouptype-real-attribute";
            attributeDefinitionReal.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionReal.Type       = (DatatypeDefinitionReal)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionReal));
            relationGroupType.SpecAttributes.Add(attributeDefinitionReal);

            var attributeDefinitionString = new AttributeDefinitionString();

            attributeDefinitionString.LongName   = "string attribute";
            attributeDefinitionString.Identifier = "relationgrouptype-string-attribute";
            attributeDefinitionString.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionString.Type       = (DatatypeDefinitionString)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionString));
            relationGroupType.SpecAttributes.Add(attributeDefinitionString);

            var attributeDefinitionXhtml = new AttributeDefinitionXHTML();

            attributeDefinitionXhtml.LongName   = "xhtml attribute";
            attributeDefinitionXhtml.Identifier = "relationgrouptype-xhtml-attribute";
            attributeDefinitionXhtml.LastChange = DateTime.Parse("2015-12-01");
            attributeDefinitionXhtml.Type       = (DatatypeDefinitionXHTML)reqIfContent.DataTypes.SingleOrDefault(x => x.GetType() == typeof(DatatypeDefinitionXHTML));
            relationGroupType.SpecAttributes.Add(attributeDefinitionXhtml);

            reqIfContent.SpecTypes.Add(relationGroupType);
        }