Esempio n. 1
0
        /// <summary>
        /// Build the <see cref="SpecHierarchy"/> for the <see cref="Specification"/> objects
        /// </summary>
        private void BuildSpecHierarchy()
        {
            foreach (var pair in this.requirementSpecificationsMap)
            {
                var requirementSpecification = pair.Key;
                var reqifSpecification       = pair.Value;

                foreach (var requirementsGroup in requirementSpecification.Group)
                {
                    var child = this.BuildGroupHierarchy(requirementSpecification, requirementsGroup);
                    reqifSpecification.Children.Add(child);
                }

                foreach (var requirement in requirementSpecification.Requirement.Where(x => x.Group == null))
                {
                    var child = new SpecHierarchy
                    {
                        Identifier = Guid.NewGuid().ToString(),
                        LastChange = DateTime.UtcNow,
                        Object     = this.requirementMap[requirement]
                    };

                    reqifSpecification.Children.Add(child);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Build the <see cref="SpecHierarchy"/> object for a <see cref="RequirementsGroup"/>
        /// </summary>
        /// <param name="reqSpec">The <see cref="RequirementsSpecification"/> containing the <see cref="Requirement"/>s</param>
        /// <param name="requirementGroup">The <see cref="RequirementsGroup"/> associated with the <see cref="SpecHierarchy"/> to build</param>
        /// <returns>The <see cref="SpecHierarchy"/></returns>
        private SpecHierarchy BuildGroupHierarchy(RequirementsSpecification reqSpec, RequirementsGroup requirementGroup)
        {
            var specHierarchy = new SpecHierarchy
            {
                Identifier = Guid.NewGuid().ToString(),
                LastChange = DateTime.UtcNow,
                Object     = this.requirementsGroupMap[requirementGroup]
            };

            foreach (var group in requirementGroup.Group)
            {
                var child = this.BuildGroupHierarchy(reqSpec, group);
                specHierarchy.Children.Add(child);
            }

            foreach (var requirement in reqSpec.Requirement.Where(x => x.Group == requirementGroup))
            {
                var child = new SpecHierarchy
                {
                    Identifier = Guid.NewGuid().ToString(),
                    LastChange = DateTime.UtcNow,
                    Object     = this.requirementMap[requirement]
                };

                specHierarchy.Children.Add(child);
            }

            return(specHierarchy);
        }
        /// <summary>
        /// create a <see cref="Specification"/>s
        /// </summary>
        private void CreateSpecifications()
        {
            var reqIfContent      = this.reqIF.CoreContent.SingleOrDefault();
            var specificationType = (SpecificationType)reqIfContent.SpecTypes.SingleOrDefault(x => x.GetType() == typeof(SpecificationType));

            var object1 = reqIfContent.SpecObjects.SingleOrDefault(x => x.Identifier == this.specobject_1_id);
            var object2 = reqIfContent.SpecObjects.SingleOrDefault(x => x.Identifier == this.specobject_2_id);
            var object3 = reqIfContent.SpecObjects.SingleOrDefault(x => x.Identifier == this.specobject_3_id);

            var specification1 = new Specification();

            specification1.Identifier = "specification-1";
            specification1.LastChange = DateTime.Parse("2015-12-01");
            specification1.LongName   = "specification 1";
            specification1.Type       = specificationType;
            this.CreateValuesForSpecElementWithAttributes(specification1, specificationType);

            var specHierarchy1 = new SpecHierarchy();

            specHierarchy1.Identifier = "spec-hierarchy-1";
            specHierarchy1.LastChange = DateTime.Parse("2015-12-01");
            specHierarchy1.LongName   = "specHierarchy 1";
            specHierarchy1.Object     = object1;

            var specHierarchy1_1 = new SpecHierarchy();

            specHierarchy1_1.Identifier = "spec-hierarchy-1-1";
            specHierarchy1_1.LastChange = DateTime.Parse("2015-12-01");
            specHierarchy1_1.LongName   = "specHierarchy 1_1";
            specHierarchy1_1.Object     = object2;

            var specHierarchy1_2 = new SpecHierarchy();

            specHierarchy1_2.Identifier = "spec-hierarchy-1-2";
            specHierarchy1_2.LastChange = DateTime.Parse("2015-12-01");
            specHierarchy1_2.LongName   = "specHierarchy 1_2";
            specHierarchy1_2.Object     = object3;

            specification1.Children.Add(specHierarchy1);

            specHierarchy1.Children.Add(specHierarchy1_1);
            specHierarchy1.Children.Add(specHierarchy1_2);

            reqIfContent.Specifications.Add(specification1);

            var specification2 = new Specification();

            specification2.Identifier = "specification-2";
            specification2.LastChange = DateTime.Parse("2015-12-01");
            specification2.LongName   = "specification 2";
            specification2.Type       = specificationType;
            this.CreateValuesForSpecElementWithAttributes(specification2, specificationType);
            reqIfContent.Specifications.Add(specification2);
        }
Esempio n. 4
0
        /// <summary>
        /// Create 10-25 <see cref="Thing"/>s from the <see cref="SpecHierarchy"/>
        /// </summary>
        /// <param name="specHierarchy">The <see cref="SpecHierarchy"/></param>
        /// <param name="reqContainer">The <see cref="RequirementsContainer"/> representing the current level of requirement</param>
        private void ComputeRequirementFromSpecHierarchy(SpecHierarchy specHierarchy, RequirementsContainer reqContainer)
        {
            // create a group if the specHierarchy has children
            if (specHierarchy.Children.Any())
            {
                var group = this.CreateRequirementGroup(specHierarchy.Object);
                reqContainer.Group.Add(group);
                foreach (var hierarchy in specHierarchy.Children)
                {
                    this.ComputeRequirementFromSpecHierarchy(hierarchy, group);
                }
            }

            SpecTypeMap specTypeMapping;

            if (!this.typeMap.TryGetValue(specHierarchy.Object.Type, out specTypeMapping))
            {
                // The instance of this type shall not be generated
                return;
            }

            var specObjectTypeMap = (SpecObjectTypeMap)specTypeMapping;

            if (!specObjectTypeMap.IsRequirement)
            {
                var group = this.CreateRequirementGroup(specHierarchy.Object);
                reqContainer.Group.Add(group);
                return;
            }

            var requirement = this.CreateRequirement(specHierarchy.Object);

            if (requirement != null)
            {
                var group = reqContainer as RequirementsGroup;
                if (group != null)
                {
                    requirement.Group = group;
                }

                RequirementsSpecification container = null;
                var specification = reqContainer as RequirementsSpecification;
                container = specification ?? reqContainer.GetContainerOfType <RequirementsSpecification>();

                if (container == null)
                {
                    throw new InvalidOperationException("The RequirementsSpecication container is null.");
                }

                container.Requirement.Add(requirement);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Queries all the contained (child) <see cref="SpecHierarchy"/> objects in a recursive manner from the <see cref="SpecHierarchy"/>
        /// </summary>
        /// <param name="specHierarchy">
        /// The subject <see cref="SpecHierarchy"/> from which all the child <see cref="SpecHierarchy"/> are queried.
        /// </param>
        /// <returns>
        /// An <see cref="IEnumerable{SpecHierarchy}"/>
        /// </returns>
        public static IEnumerable <SpecHierarchy> QueryAllContainedSpecHierarchies(this SpecHierarchy specHierarchy)
        {
            var result = new List <SpecHierarchy>();

            foreach (var child in specHierarchy.Children)
            {
                result.Add(child);

                var subChildren = child.QueryAllContainedSpecHierarchies();

                result.AddRange(subChildren);
            }

            return(result);
        }
Esempio n. 6
0
        public static IEnumerable <SpecHierarchy> Descendants(this SpecHierarchy root)
        {
            var nodes = new Stack <SpecHierarchy>(new[] { root });

            while (nodes.Any())
            {
                SpecHierarchy node = nodes.Pop();
                yield return(node);

                for (int i = node.Children.Count - 1; i >= 0; i--)
                {
                    nodes.Push(node.Children[i]);
                }
            }
        }
Esempio n. 7
0
        public void Verify_that_When_Object_is_null_WriteXml_throws_exception()
        {
            var stream = new MemoryStream();
            var writer = XmlWriter.Create(stream, this.settings);

            var specHierarchy = new SpecHierarchy
            {
                Identifier = "identifier",
                LongName   = "longname"
            };

            Assert.That(
                () => specHierarchy.WriteXml(writer),
                Throws.Exception.TypeOf <SerializationException>()
                .With.Message.Contains("The Object property of SpecHierarchy identifier:longname may not be null"));
        }
Esempio n. 8
0
        public void Verify_that_When_Object_is_null_WriteXmlAsync_throws_exception()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            this.settings.Async = true;

            var stream = new MemoryStream();
            var writer = XmlWriter.Create(stream, this.settings);

            var specHierarchy = new SpecHierarchy
            {
                Identifier = "identifier",
                LongName   = "longname"
            };

            Assert.That(
                async() => await specHierarchy.WriteXmlAsync(writer, cancellationTokenSource.Token),
                Throws.Exception.TypeOf <SerializationException>()
                .With.Message.Contains("The Object property of SpecHierarchy identifier:longname may not be null"));
        }
Esempio n. 9
0
        public void Edit_SpecObject(SpecobjectViewModel specObject, bool createSpecObject, string position = null)
        {
            SpecObjectViewerWindow SpecObjectViewer = new SpecObjectViewerWindow(specObject);

            SpecObjectViewer.Owner = Window.GetWindow(this);
            if (SpecObjectViewer.ShowDialog() == true)
            {
                if (createSpecObject)
                {
                    int currentIndex = 0;
                    SpecobjectViewModel currentModelObject = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedItem as SpecobjectViewModel;
                    SpecObject          currentObject      = (Application.Current.MainWindow as MainWindow).content.SpecObjects.Single(x => x.Identifier == currentModelObject.Identifier);
                    var specifications = (Application.Current.MainWindow as MainWindow).content.Specifications;

                    //Create new SpecObject and add Attributes
                    SpecObject newSpecObject = new SpecObject()
                    {
                        Description = specObject.Description,
                        Identifier  = specObject.Identifier,
                        LastChange  = specObject.LastChange,
                        Type        = currentObject.Type
                    };
                    foreach (var attribute in specObject.Values)
                    {
                        if (attribute.AttributeValue != null)
                        {
                            newSpecObject.Values.Add(attribute.AttributeValue);
                        }
                    }

                    //Add SpecObject to SpecHierarchy and to SpecObjects
                    SpecHierarchy specHierarchy = specifications.First().Children.First().Descendants()
                                                  .Where(node => node.Object == currentObject).First();
                    if (position == "after")
                    {
                        SpecHierarchy parentSpecHierarchy = specHierarchy.Container;
                        int           specHierarchyIndex  = parentSpecHierarchy.Children.IndexOf(specHierarchy);
                        parentSpecHierarchy.Children.Insert(specHierarchyIndex + 1, new SpecHierarchy()
                        {
                            Object     = newSpecObject,
                            Identifier = Guid.NewGuid().ToString(),
                            LastChange = DateTime.Now
                        });
                        var previousObject = specHierarchy.Descendants().Last().Object;
                        currentIndex = (Application.Current.MainWindow as MainWindow).content.SpecObjects.IndexOf(previousObject);
                    }
                    else if (position == "under")
                    {
                        specHierarchy.Children.Insert(0, new SpecHierarchy()
                        {
                            Object     = newSpecObject,
                            Identifier = Guid.NewGuid().ToString(),
                            LastChange = DateTime.Now
                        });
                        currentIndex = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedIndex;
                    }
                    this.specObjectsViewModel.SpecObjects.Insert(currentIndex + 1, specObject);
                    this.content.SpecObjects.Insert(currentIndex + 1, newSpecObject);
                }
                else
                {
                    var originalSpecObject = content.SpecObjects.Single(x => x.Identifier == specObject.Identifier);
                    //Update changed AttributeValues
                    foreach (var definition in specObject.Values.Where(x => x.changed == true))
                    {
                        originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).ObjectValue
                            = specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue.ObjectValue;
                    }
                    //Add new AttributeValues to original SpecObject
                    foreach (var definition in specObject.Values.Where(x => x.added == true))
                    {
                        originalSpecObject.Values.Add(specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue);
                    }
                    // Remove AttributeValues from original SpecObject
                    foreach (var definition in specObject.Values.Where(x => x.removed == true))
                    {
                        originalSpecObject.Values.Remove(originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition));
                    }
                }
            }
        }