Exemple #1
0
        public static void SaveFile_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var    serializer = new ReqIFSerializer(false);
            string extension  = Path.GetExtension((sender as MainWindow).filePath);

            if (extension == ".reqif")
            {
                serializer.Serialize((sender as MainWindow).reqif, (sender as MainWindow).filePath, null);
            }
            else if (extension == ".reqifz")
            {
                string reqif = serializer.Serialize((sender as MainWindow).reqif);
                using (var archive = ZipFile.Open((sender as MainWindow).filePath, ZipArchiveMode.Update))
                {
                    var entry    = archive.Entries.Where(x => x.Name.EndsWith(".reqif", StringComparison.CurrentCultureIgnoreCase)).First();
                    var fullName = entry.FullName;
                    entry.Delete();
                    entry = archive.CreateEntry(fullName);

                    using (StreamWriter writer = new StreamWriter(entry.Open()))
                    {
                        writer.Write(reqif);
                    }
                }
            }
            (sender as MainWindow).isContenChanged = false;
        }
        /// <summary>
        /// Serialize ReqIF
        /// </summary>
        /// <param name="file"></param>
        /// <param name="compress"></param>
        /// <param name="prefixReqIf">Prefix to add to the reqIF file (e.g. "_")</param>
        /// <returns></returns>
        protected bool SerializeReqIf(string file, bool compress = true, string prefixReqIf = "")
        {
            var serializer = new ReqIFSerializer(false);

            Debug.Assert(file != null, nameof(file) + " != null");
            string pathSerialize = file;

            try
            {
                string prefix = Path.GetFileNameWithoutExtension(file).StartsWith(prefixReqIf) ? "" : prefixReqIf;
                pathSerialize = Path.Combine(Path.GetDirectoryName(file) ?? throw new InvalidOperationException(),
                                             $"{prefix}{Path.GetFileNameWithoutExtension(file)}.reqif");

                serializer.Serialize(ReqIfDeserialized, pathSerialize, null);
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Path:
'{pathSerialize}'

{e}", @"Error serialize ReqIF, break!");
                return(false);
            }
            if (compress)
            {
                return(Compress(ImportModuleFile, Path.GetDirectoryName(pathSerialize)));
            }
            return(true);
        }
Exemple #3
0
        public void Verify_that_DefaultValueDemo_file_is_deserialized_and_serialized_with_equivalent_output()
        {
            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "DefaultValueDemo.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIf = deserializer.Deserialize(reqifPath).First();

            var resultFileUri = Path.Combine(TestContext.CurrentContext.TestDirectory, "DefaultValueDemo-reserialize.reqif");

            var serializer = new ReqIFSerializer();

            serializer.Serialize(reqIf, resultFileUri);

            var reqIf2 = deserializer.Deserialize(resultFileUri).First();

            var OBJECT_TYPE = reqIf2.CoreContent.SpecTypes.First(x => x.Identifier == "_94301492-ef46-443d-9778-596b14a0a20e");
            var attributeDefinitionEnumeration = OBJECT_TYPE.SpecAttributes.OfType <AttributeDefinitionEnumeration>().First(x => x.Identifier == "_e5e971b3-62e3-4607-8696-f359c1ae85f3");

            Assert.That(attributeDefinitionEnumeration.DefaultValue, Is.Not.Null);
            var defaultEnumerationValue = attributeDefinitionEnumeration.DefaultValue.Values.Single();

            Assert.That(defaultEnumerationValue.Identifier, Is.EqualTo("_6feb570f-8ad8-40d9-9517-5abd6fe6f63a"));
            Assert.That(attributeDefinitionEnumeration.DefaultValue.Definition.Identifier, Is.EqualTo("_e5e971b3-62e3-4607-8696-f359c1ae85f3"));

            var DOCTYPE_GROUP_TYPE        = reqIf2.CoreContent.SpecTypes.First(x => x.Identifier == "_80811ce1-0a28-4554-b49a-11bf2b7e9422");
            var attributeDefinitionString = DOCTYPE_GROUP_TYPE.SpecAttributes.OfType <AttributeDefinitionString>().First(x => x.Identifier == "_d0368b53-d0c6-43a1-a746-45243624b027");

            Assert.That(attributeDefinitionString.DefaultValue.TheValue, Is.EqualTo("LAH ---.---.---.-"));
            Assert.That(attributeDefinitionString.DefaultValue.Definition.Identifier, Is.EqualTo("_d0368b53-d0c6-43a1-a746-45243624b027"));
        }
Exemple #4
0
        public void Verify_That_Datatype_Demo_reqif_file_is_deserialized_and_serialized_with_equivalent_output()
        {
            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Datatype-Demo.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIf = deserializer.Deserialize(reqifPath).First();

            var resultFileUri = Path.Combine(TestContext.CurrentContext.TestDirectory, "Datatype-Demo-reserialize.reqif");

            var serializer = new ReqIFSerializer();

            Assert.DoesNotThrow(() => serializer.Serialize(reqIf, resultFileUri));
        }
Exemple #5
0
        public void Verify_That_ProR_Traceability_Template_reqif_file_can_deserialized_and_serialized_with_equivalent_output()
        {
            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIf = deserializer.Deserialize(reqifPath).First();

            var resultFileUri = Path.Combine(TestContext.CurrentContext.TestDirectory, "ProR_Traceability-Template-v1.0-reserialize.reqif");

            var serializer = new ReqIFSerializer();

            Assert.DoesNotThrow(() => serializer.Serialize(reqIf, resultFileUri));
        }
        public void VerifyThatArgumentExceptionIsRaisedOnSerialize()
        {
#if NETFULL
            var serializer = new ReqIFSerializer(false);

            Assert.That(
                () => serializer.Serialize(null, null, null),
                Throws.Exception.TypeOf <ArgumentNullException>()
                .With.Message.ContainsSubstring("The reqIf object cannot be null."));

            Assert.That(
                () => serializer.Serialize(this.reqIF, null, null),
                Throws.Exception.TypeOf <ArgumentNullException>()
                .With.Message.ContainsSubstring("The path of the file cannot be null."));

            Assert.That(
                () => serializer.Serialize(this.reqIF, string.Empty, null),
                Throws.Exception.TypeOf <ArgumentOutOfRangeException>()
                .With.Message.ContainsSubstring("The path of the file cannot be empty."));
#else
            var serializer = new ReqIFSerializer();

            Assert.That(
                () => serializer.Serialize(null, null),
                Throws.Exception.TypeOf <ArgumentNullException>()
                .With.Message.ContainsSubstring("The reqIf object cannot be null."));

            Assert.That(
                () => serializer.Serialize(this.reqIF, null),
                Throws.Exception.TypeOf <ArgumentNullException>()
                .With.Message.ContainsSubstring("The path of the file cannot be null."));

            Assert.That(
                () => serializer.Serialize(this.reqIF, string.Empty),
                Throws.Exception.TypeOf <ArgumentOutOfRangeException>()
                .With.Message.ContainsSubstring("The path of the file cannot be empty."));
#endif
        }
        public void VerifyThatTheReqIfSerializerSerializesaReqIfDocumentWithoutValidation()
        {
#if NETFULL
            var serializer = new ReqIFSerializer(false);
            serializer.Serialize(this.reqIF, this.resultFileUri, null);

            Assert.IsTrue(File.Exists(this.resultFileUri));
#else
            var serializer = new ReqIFSerializer();
            serializer.Serialize(this.reqIF, this.resultFileUri);

            Assert.IsTrue(File.Exists(this.resultFileUri));
#endif
        }
Exemple #8
0
        public void VerifyThatRequirementSpecificationCanBeExportedIntoReqIF()
        {
            var builder = new ReqIFBuilder();

            var reqif = builder.BuildReqIF(this.session.Object, this.iteration);

            Assert.IsNotNull(reqif);
            // 2 + 1 extra datatype for requriement text
            Assert.AreEqual(3, reqif.CoreContent.Single().DataTypes.Count);          // booleanPt and boolean and Text datatype
            Assert.AreEqual(7, reqif.CoreContent.Single().SpecObjects.Count);        // 4 requirements + 2 groups
            Assert.AreEqual(3, reqif.CoreContent.Single().Specifications.Count);     // 2 specification
            Assert.AreEqual(9, reqif.CoreContent.Single().SpecTypes.Count);          // 1 group type, 1 Req type, 1 Spec type, 1 Relation type, 1 relationGroup type
            Assert.AreEqual(3, reqif.CoreContent.Single().SpecRelations.Count);      // 3 specRelation from 3 relationship
            Assert.AreEqual(1, reqif.CoreContent.Single().SpecRelationGroups.Count); // 1 RelationGroup from 1 binaryRelationship

            Assert.IsNotEmpty(reqif.CoreContent.Single().SpecRelationGroups.Single().SpecRelations);

            var serializer = new ReqIFSerializer(false);

            serializer.Serialize(reqif, @"output.xml", (o, e) => { throw new Exception(); });
        }
        public void Verify_that_DatatypeDefinitionDate_can_be_serialized_and_deserialized()
        {
            var document = new ReqIF
            {
                Lang        = "en",
                TheHeader   = new ReqIFHeader(),
                CoreContent = new ReqIFContent()
            };

            var lastChange = new DateTime(1831, 07, 21);

            var dateDefinition = new DatatypeDefinitionDate
            {
                Identifier = "dateDefinition",
                LongName   = "Date",
                LastChange = lastChange
            };

            document.CoreContent.DataTypes.Add(dateDefinition);

            this.resultFileUri = Path.Combine(TestContext.CurrentContext.TestDirectory, "result.xml");

            var serializer = new ReqIFSerializer();

            Assert.That(() => serializer.Serialize(document, this.resultFileUri), Throws.Nothing);

            var deserializer = new ReqIFDeserializer();

            var reqIf = deserializer.Deserialize(this.resultFileUri).First();

            var datatypeDefinition = reqIf.CoreContent.DataTypes.Single(x => x.Identifier == "dateDefinition");

            Assert.That(datatypeDefinition, Is.TypeOf <DatatypeDefinitionDate>());
            Assert.That(datatypeDefinition.LongName, Is.EqualTo("Date"));
            Assert.That(datatypeDefinition.LastChange, Is.EqualTo(lastChange));
        }