public void VerifyThatAReqIFXMLDocumentCanBeDeserializedWitouthValidation()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "output.reqif"));

            Assert.AreEqual("en", reqIf.Lang);

            var reqIfContent   = reqIf.CoreContent.FirstOrDefault();
            var firstobject    = reqIfContent.SpecObjects.First();
            var xhtmlAttribute = firstobject.Values.OfType <AttributeValueXHTML>().SingleOrDefault();

            Assert.IsNotNull(xhtmlAttribute);
            Assert.IsNotEmpty(xhtmlAttribute.TheValue);
            Assert.IsNotNull(xhtmlAttribute.AttributeDefinition);

            Assert.AreEqual(AmountOfDataTypes, reqIfContent.DataTypes.Count);
            Assert.AreEqual(AmountOfSpecTypes, reqIfContent.SpecTypes.Count);
            Assert.AreEqual(AmountOfSpecObjects, reqIfContent.SpecObjects.Count);
            Assert.AreEqual(AmountOfSpecRelations, reqIfContent.SpecRelations.Count);
            Assert.AreEqual(AmountOfSpecifications, reqIfContent.Specifications.Count);
            Assert.AreEqual(AmountOfSpecificationChildren, reqIfContent.Specifications[0].Children.Count);
            Assert.AreEqual(AmountOfSpecificationSubChildren, reqIfContent.Specifications[0].Children[0].Children.Count);
            Assert.AreEqual(AmountOfSpecRelationGroups, reqIfContent.SpecRelationGroups.Count);

            var unknownSpecRel = reqIf.CoreContent.Single().SpecRelations.First(x => x.Identifier == "specobject_1-unknown");

            Assert.IsNotNull(unknownSpecRel.Target);
            Assert.AreEqual("unknown-specobject", unknownSpecRel.Target.Identifier);

            var unknownrelGroup = reqIf.CoreContent.Single().SpecRelationGroups.First(x => x.Identifier == "relationgroup-no-target");

            Assert.AreEqual("unknown", unknownrelGroup.TargetSpecification.Identifier);
        }
Exemplo n.º 2
0
        public async Task Verify_that_DefaultValueDemo_file_is_deserialized_and_async_serialized_with_equivalent_output()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "DefaultValueDemo.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIfs = await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token);

            var reqIf = reqIfs.First();

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

            var serializer = new ReqIFSerializer();
            await serializer.SerializeAsync(reqIf, resultFileUri, cancellationTokenSource.Token);

            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"));
        }
        /// <summary>
        /// Returns a list of InventoryItem of the passed *.reqif file. A row for the *.reqif file.
        /// </summary>
        /// <param name="lSpec"></param>
        /// <param name="file"></param>
        /// <param name="validate"></param>
        /// <returns></returns>
        private static bool InventoryReqIfFile(List <InventoryItem> lSpec, string file, bool validate = false)
        {
            ReqIFDeserializer deserializer = new ReqIFDeserializer();

            try
            {
                var reqIf = deserializer.Deserialize(file, validate: validate);
                var info  = (from core in reqIf.CoreContent
                             from s in core.Specifications
                             let count = (from spec in core.SpecObjects select spec.Identifier).Count()
                                         let countLinks = (from link in core.SpecRelations select link.Target).Count()
                                                          select new InventoryItem(Path.GetFileName(file), s.Identifier, s.LongName, s.Description, s.LastChange.ToString(CultureInfo.InvariantCulture),
                                                                                   count, countLinks))
                            .ToArray();
                lSpec.AddRange(info);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"Validation: {validate}

File: {file}

{ex}", "Error deserialize *.reqif file.", MessageBoxButton.OK);
                return(false);
            }
        }
        public async Task Verify_That_A_ReqIF_XML_Document_Can_Be_DeserializedAsync_Without_Validation()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var deserializer = new ReqIFDeserializer();
            var reqIf        = (await deserializer.DeserializeAsync(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "output.reqif"), cancellationTokenSource.Token)).First();

            Assert.AreEqual("en", reqIf.Lang);

            var firstobject    = reqIf.CoreContent.SpecObjects.First();
            var xhtmlAttribute = firstobject.Values.OfType <AttributeValueXHTML>().SingleOrDefault();

            Assert.IsNotNull(xhtmlAttribute);
            Assert.IsNotEmpty(xhtmlAttribute.TheValue);
            Assert.IsNotNull(xhtmlAttribute.AttributeDefinition);

            Assert.AreEqual(7, reqIf.CoreContent.DataTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecObjects.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelations.Count);
            Assert.AreEqual(3, reqIf.CoreContent.Specifications.Count);
            Assert.AreEqual(1, reqIf.CoreContent.Specifications[0].Children.Count);
            Assert.AreEqual(2, reqIf.CoreContent.Specifications[0].Children[0].Children.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelationGroups.Count);

            var unknownSpecRel = reqIf.CoreContent.SpecRelations.First(x => x.Identifier == "specobject_1-unknown");

            Assert.IsNotNull(unknownSpecRel.Target);
            Assert.AreEqual("unknown-specobject", unknownSpecRel.Target.Identifier);

            var unknownrelGroup = reqIf.CoreContent.SpecRelationGroups.First(x => x.Identifier == "relationgroup-no-target");

            Assert.AreEqual("unknown", unknownrelGroup.TargetSpecification.Identifier);
        }
        public void Verify_that_sampledebug_reqif_file_can_be_deserialized()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "sample_debug.reqif")).Single();
            var header       = reqIf.TheHeader;
            var content      = reqIf.CoreContent;

            Assert.That(header.Identifier, Is.EqualTo("_c1638633-9ec4-4f9f-aabd-4804f5e0110c"));

            var specObject = content.SpecObjects.Single(x => x.Identifier == "rmf-249cb10a-69cf-48ac-ac40-bcba7fc15d47");

            foreach (var attributeValueXhtml in specObject.Values.OfType <AttributeValueXHTML>())
            {
                Assert.That(attributeValueXhtml.TheValue, Is.Not.Null.Or.Empty);
                Console.WriteLine(attributeValueXhtml.TheValue);
            }

            var xhtmlAttributes = content.SpecObjects.SelectMany(x => x.Values.OfType <AttributeValueXHTML>()).ToList();

            foreach (var attributeValueXhtml in xhtmlAttributes)
            {
                Assert.That(attributeValueXhtml.TheValue, Is.Not.Null.Or.Empty);
                Console.WriteLine(attributeValueXhtml.TheValue);
            }
        }
        public async Task Verify_That_A_ReqIF_Archive_Can_Be_DeserializedAsync_Without_Validation()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var deserializer = new ReqIFDeserializer();
            var reqIf        = (await deserializer.DeserializeAsync(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "test-multiple-reqif.reqifz"), cancellationTokenSource.Token)).First();

            Assert.AreEqual("en", reqIf.Lang);

            var firstobject    = reqIf.CoreContent.SpecObjects.First();
            var xhtmlAttribute = firstobject.Values.OfType <AttributeValueXHTML>().SingleOrDefault();

            Assert.IsNotNull(xhtmlAttribute);
            Assert.IsNotEmpty(xhtmlAttribute.TheValue);
            Assert.IsNotNull(xhtmlAttribute.AttributeDefinition);

            Assert.AreEqual(7, reqIf.CoreContent.DataTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecTypes.Count);
            Assert.AreEqual(3, reqIf.CoreContent.SpecObjects.Count);
            Assert.AreEqual(1, reqIf.CoreContent.SpecRelations.Count);
            Assert.AreEqual(2, reqIf.CoreContent.Specifications.Count);
            Assert.AreEqual(1, reqIf.CoreContent.Specifications[0].Children.Count);
            Assert.AreEqual(2, reqIf.CoreContent.Specifications[0].Children[0].Children.Count);
            Assert.AreEqual(1, reqIf.CoreContent.SpecRelationGroups.Count);
        }
        public void VerifyThatAReqIFArchiveCanBeDeserializedWitouthValidation()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "test-multiple-reqif.reqifz"));

            Assert.IsTrue(reqIf.CoreContent.Count > 1);
        }
        public async Task Verify_that_ExternalObjects_are_created_and_that_local_data_can_be_queried_async()
        {
            var sw = Stopwatch.StartNew();

            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "requirements-and-objects.reqifz");
            var deserializer = new ReqIFDeserializer();

            var cancellationTokenSource = new CancellationTokenSource();

            var reqIf = (await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token)).First();

            foreach (var specObject in reqIf.CoreContent.SpecObjects)
            {
                foreach (var attributeValueXhtml in specObject.Values.OfType <AttributeValueXHTML>())
                {
                    foreach (var externalObject in attributeValueXhtml.ExternalObjects)
                    {
                        var targetStream = new MemoryStream();
                        externalObject.QueryLocalData(reqifPath, targetStream);
                        Assert.That(targetStream.Length, Is.GreaterThan(0));
                        await targetStream.DisposeAsync();
                    }
                }
            }

            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Exemplo n.º 9
0
        public void Deserialize(string filepath)
        {
            ReqIFDeserializer deserializer = new ReqIFDeserializer();

            reqif           = deserializer.Deserialize(filepath).First();
            header          = reqif.TheHeader;
            content         = reqif.CoreContent;
            embeddedObjects = reqif.EmbeddedObjects;

            PropertyGrid.DataContext = header;
            specObjectsViewModel     = new SpecObjectsViewModel(content);
            specObjectsViewModel.SpecObjects.CollectionChanged += SpecObjects_CollectionChanged;
            foreach (var specObject in specObjectsViewModel.SpecObjects)
            {
                foreach (var attribute in specObject.Values)
                {
                    attribute.PropertyChanged += Attribute_PropertyChanged;
                }
                foreach (var attribute in specObject.Values)
                {
                    if (attribute.AttributeValue != null)
                    {
                        attribute.AttributeValue.PropertyChanged += AttributeValue_PropertyChanged;
                    }
                }
            }
            initializeColumns();
            MainDataGrid.ItemsSource = specObjectsViewModel.SpecObjects;
        }
        public void Verify_that_ArgumentException_Are_thrown_on_read_from_file()
        {
            var deserializer = new ReqIFDeserializer();

            Assert.That(() => deserializer.Deserialize(""),
                        Throws.Exception.TypeOf <ArgumentException>()
                        .With.Message.Contains("The xml file path may not be null or empty"));
        }
        public void Verify_That_when_schema_is_not_available_A_ReqIF_file_Can_Be_Deserialized_With_Validation_and_that_schemavalidationexception_is_thrown()
        {
            var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");

            var deserializer = new ReqIFDeserializer();

            Assert.That(() => deserializer.Deserialize(reqifPath, true, this.ValidationEventHandler), Throws.Exception.TypeOf <XmlSchemaValidationException>());
        }
        public void Verify_that_ArgumentException_Are_thrown_on_read_from_file_async()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var deserializer = new ReqIFDeserializer();

            Assert.That(async() => await deserializer.DeserializeAsync("", cancellationTokenSource.Token),
                        Throws.Exception.TypeOf <ArgumentException>()
                        .With.Message.Contains("The xml file path may not be null or empty"));
        }
        public void Verify_that_when_ValidationEventHandler_is_not_null_exception_is_thrown()
        {
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "test-multiple-reqif.reqifz");

            var deserializer = new ReqIFDeserializer();

            Assert.That(
                () => deserializer.Deserialize(path, false, this.ValidationEventHandler),
                Throws.Exception.TypeOf <ArgumentException>()
                .With.Message.Contains("validationEventHandler must be null when validate is false"));
        }
        public void Verify_that_when_path_is_null_exception_is_thrown()
        {
            var deserializer = new ReqIFDeserializer();

            string xmlPath = null;

            Assert.That(
                () => deserializer.Deserialize(xmlPath),
                Throws.Exception.TypeOf <ArgumentException>()
                .With.Message.Contains("The xml file path may not be null or empty"));
        }
        public void Verify_That_A_ReqIF_Archive_Can_Be_Deserialized_With_Validation()
        {
            var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "test-multiple-reqif.reqifz");

            var deserializer = new ReqIFDeserializer();

            Assert.That(() => deserializer.Deserialize(reqifPath, true, this.ValidationEventHandler), Throws.Nothing);

            using (var sourceStream = new FileStream(reqifPath, FileMode.Open))
            {
                Assert.That(() => deserializer.Deserialize(sourceStream), Throws.Nothing);
            }
        }
        public async Task SetUp()
        {
            var cts = new CancellationTokenSource();

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

            await using var fileStream = new FileStream(reqifPath, FileMode.Open);
            var reqIfDeserializer  = new ReqIFDeserializer();
            var reqIfLoaderService = new ReqIFLoaderService(reqIfDeserializer);
            await reqIfLoaderService.Load(fileStream, cts.Token);

            this.reqIf = reqIfLoaderService.ReqIFData.Single();
        }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
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 Verify_that_XHTML_attributes_can_de_Deserialized()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "testreqif.reqif")).First();

            Assert.AreEqual("en", reqIf.Lang);

            var specObject = reqIf.CoreContent.SpecObjects.Single(r => r.Identifier == "R001");

            var xhtmlValue = specObject.Values.Single(x => x.AttributeDefinition.Identifier == "FUNC-REQ-NOTES") as AttributeValueXHTML;

            Assert.That(xhtmlValue.TheValue, Is.Not.Null.Or.Empty);
        }
        public void Verify_That_A_ReqIF_XML_Document_Can_Be_Deserialized_With_Validation()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "output.reqif"), true, this.ValidationEventHandler).First();

            Assert.AreEqual("en", reqIf.Lang);

            Assert.AreEqual(7, reqIf.CoreContent.DataTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecObjects.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelations.Count);
            Assert.AreEqual(3, reqIf.CoreContent.Specifications.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelationGroups.Count);
        }
        public void VerifyThatAReqIFXMLDocumentCanBeDeserializedWithValidation()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(Path.Combine(TestContext.CurrentContext.TestDirectory, "output.reqif"), true, this.ValidationEventHandler);

            Assert.AreEqual("en", reqIf.Lang);

            var reqIfContent = reqIf.CoreContent.FirstOrDefault();

            Assert.AreEqual(AmountOfDataTypes, reqIfContent.DataTypes.Count);
            Assert.AreEqual(AmountOfSpecTypes, reqIfContent.SpecTypes.Count);
            Assert.AreEqual(AmountOfSpecObjects, reqIfContent.SpecObjects.Count);
            Assert.AreEqual(AmountOfSpecRelations, reqIfContent.SpecRelations.Count);
            Assert.AreEqual(AmountOfSpecifications, reqIfContent.Specifications.Count);
            Assert.AreEqual(AmountOfSpecRelationGroups, reqIfContent.SpecRelationGroups.Count);
        }
        public async Task Verify_That_A_ReqIF_XML_Document_Can_Be_DeserializedAsync_With_Validation()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var deserializer = new ReqIFDeserializer();
            var reqIf        = (await deserializer.DeserializeAsync(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "output.reqif"), cancellationTokenSource.Token, true, this.ValidationEventHandler)).First();

            Assert.AreEqual("en", reqIf.Lang);

            Assert.AreEqual(7, reqIf.CoreContent.DataTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecTypes.Count);
            Assert.AreEqual(4, reqIf.CoreContent.SpecObjects.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelations.Count);
            Assert.AreEqual(3, reqIf.CoreContent.Specifications.Count);
            Assert.AreEqual(2, reqIf.CoreContent.SpecRelationGroups.Count);
        }
        public void VerifyThatAReqIFXMLDocumentCanBeDeserializedWithValidation()
        {
            var deserializer = new ReqIFDeserializer();
            var reqIf        = deserializer.Deserialize(this.xmlfilepath, true, this.ValidationEventHandler);

            Assert.AreEqual("en", reqIf.Lang);

            var reqIfContent = reqIf.CoreContent.FirstOrDefault();

            Assert.AreEqual(AmountOfDataTypes, reqIfContent.DataTypes.Count);
            Assert.AreEqual(AmountOfSpecTypes, reqIfContent.SpecTypes.Count);
            Assert.AreEqual(AmountOfSpecObjects, reqIfContent.SpecObjects.Count);
            Assert.AreEqual(AmountOfSpecRelations, reqIfContent.SpecRelations.Count);
            Assert.AreEqual(AmountOfSpecifications, reqIfContent.Specifications.Count);
            Assert.AreEqual(AmountOfSpecRelationGroups, reqIfContent.SpecRelationGroups.Count);
        }
        public async Task Verify_that_External_objects_are_Deserialized_Async()
        {
            var deserializer = new ReqIFDeserializer();

            var reqIf = await deserializer.DeserializeAsync(this.reqiffile, CancellationToken.None);

            var specObjects = reqIf.First().CoreContent.SpecObjects;

            Assert.That(specObjects.Count, Is.EqualTo(4));

            var specObjectWithExternalObjects = specObjects.Single(x => x.Identifier == "_5_b23d3568-8478-401c-8ee3-3246da83641d");

            var attributeValueXhtml = specObjectWithExternalObjects.Values.OfType <AttributeValueXHTML>().Single(x =>
                                                                                                                 x.Definition.Identifier == "_2792cc0c-3af9-4619-9968-c1d0f53d5bcb_OBJECTTEXT");

            Assert.That(attributeValueXhtml.ExternalObjects.Count, Is.EqualTo(2));
        }
Exemplo n.º 25
0
        public async Task Verify_That_Datatype_Demo_reqif_file_is_deserialized_and_async_serialized_with_equivalent_output()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Datatype-Demo.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIfs = await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token);

            var reqIf = reqIfs.First();

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

            var serializer = new ReqIFSerializer();

            Assert.DoesNotThrowAsync(async() => await serializer.SerializeAsync(reqIf, resultFileUri, cancellationTokenSource.Token));
        }
        public void Verify_that_ReqIF_can_be_Deserializaed_from_stream()
        {
            var deserializer = new ReqIFDeserializer();

            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "test-multiple-reqif.reqifz");

            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                var sw = Stopwatch.StartNew();

                var reqif = deserializer.Deserialize(fileStream, false, null).First();

                Console.WriteLine($"deserialization done in: {sw.ElapsedMilliseconds} [ms]");

                Assert.That(reqif, Is.Not.Null);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Deserialize ReqIF with or without XML validation. If error and no validation was selected ask if retrying with validation or cancel
        /// </summary>
        /// <param name="file"></param>
        /// <param name="validate"></param>
        /// <returns></returns>
        public static ReqIF DeSerializeReqIf(string file, bool validate = false)
        {
            // Deserialize
            ReqIFDeserializer deserializer = new ReqIFDeserializer();

            try
            {
                return(deserializer.Deserialize(file, validate: validate));
            }
            catch (Exception e)
            {
                if (validate)
                {
                    MessageBox.Show($@"File: {file}
Validate: true

{e}", @"Can't deserialize existing ReqIF file");
                    return(null);
                }
                else
                {
                    // was without validation, ask if retry with validation
                    var ret = MessageBox.Show($@"File: {file}
Validate: false

{e}", @"Can't deserialize existing ReqIF file, retry with XML validation?", MessageBoxButtons.RetryCancel);
                    if (ret == DialogResult.Cancel)
                    {
                        return(null);
                    }
                    try
                    {
                        return(deserializer.Deserialize(file, validate: true));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($@"File: {file}
Validate: true

{ex}", @"Can't deserialize existing ReqIF file, break!");
                        return(null);
                    }
                }
            }
        }
        public async Task Verify_that_the_Tool_Extensions_are_DeserializedAsync_from_ProR_Traceability_template()
        {
            var sw = Stopwatch.StartNew();

            var cancellationTokenSource = new CancellationTokenSource();

            var reqifPath    = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ProR_Traceability-Template-v1.0.reqif");
            var deserializer = new ReqIFDeserializer();

            var reqIf = (await deserializer.DeserializeAsync(reqifPath, cancellationTokenSource.Token)).First();

            Console.WriteLine(sw.ElapsedMilliseconds);

            Assert.That(reqIf.TheHeader.Identifier, Is.EqualTo("_o7scMadbEeafNduaIhMwQg"));
            Assert.That(reqIf.TheHeader.Comment, Is.EqualTo("Download this template and others at https://reqif.academy"));
            Assert.That(reqIf.TheHeader.ReqIFToolId, Is.EqualTo("fmStudio (http://formalmind.com/studio)"));
            Assert.That(reqIf.TheHeader.ReqIFVersion, Is.EqualTo("1.0"));
            Assert.That(reqIf.TheHeader.SourceToolId, Is.EqualTo("fmStudio (http://formalmind.com/studio)"));
            Assert.That(reqIf.TheHeader.Title, Is.EqualTo("Traceability Template"));

            Assert.That(reqIf.CoreContent.DocumentRoot, Is.EqualTo(reqIf));

            Assert.That(reqIf.CoreContent.DataTypes.Count, Is.EqualTo(8));
            Assert.That(reqIf.CoreContent.DataTypes.First().ReqIFContent, Is.EqualTo(reqIf.CoreContent));

            Assert.That(reqIf.CoreContent.SpecTypes.Count, Is.EqualTo(3));
            Assert.That(reqIf.CoreContent.SpecTypes.First().ReqIFContent, Is.EqualTo(reqIf.CoreContent));

            Assert.That(reqIf.CoreContent.SpecObjects.Count, Is.EqualTo(21));
            Assert.That(reqIf.CoreContent.SpecObjects.First().ReqIFContent, Is.EqualTo(reqIf.CoreContent));

            Assert.That(reqIf.CoreContent.SpecRelations.Count, Is.EqualTo(9));
            Assert.That(reqIf.CoreContent.SpecRelations.First().ReqIFContent, Is.EqualTo(reqIf.CoreContent));

            Assert.That(reqIf.CoreContent.Specifications.Count, Is.EqualTo(2));
            Assert.That(reqIf.CoreContent.Specifications.First().ReqIFContent, Is.EqualTo(reqIf.CoreContent));

            Assert.That(reqIf.ToolExtension.Count, Is.EqualTo(1));

            var toolExtension = reqIf.ToolExtension.First();

            Assert.That(toolExtension.InnerXml, Is.Not.Empty);
        }
        public async Task Verify_that_ReqIF_can_be_DeserializedAsync_from_stream()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var deserializer = new ReqIFDeserializer();

            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "test-multiple-reqif.reqifz");

            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                var sw = Stopwatch.StartNew();

                var reqif = (await deserializer.DeserializeAsync(fileStream, cancellationTokenSource.Token, false, null)).First();

                Console.WriteLine($"async deserialization done in: {sw.ElapsedMilliseconds} [ms]");

                Assert.That(reqif, Is.Not.Null);
            }
        }
        public void Verify_that_ArgumentException_Are_thrown_on_read_from_stream()
        {
            var deserializer = new ReqIFDeserializer();

            MemoryStream memoryStream = null;

            Assert.That(() => deserializer.Deserialize(memoryStream),
                        Throws.Exception.TypeOf <ArgumentNullException>());

            var validationEventHandler = new ValidationEventHandler(ValidationEventHandler);

            Assert.That(() => deserializer.Deserialize(memoryStream, false, validationEventHandler),
                        Throws.Exception.TypeOf <ArgumentException>()
                        .With.Message.Contains("validationEventHandler must be null when validate is false"));

            memoryStream = new MemoryStream();

            Assert.That(() => deserializer.Deserialize(memoryStream),
                        Throws.Exception.TypeOf <ArgumentException>());
        }