-
Notifications
You must be signed in to change notification settings - Fork 2
[Add] CSV requirements input and VCD report output via Sep #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fabiantax
wants to merge
1
commit into
STARIONGROUP:development
Choose a base branch
from
fabiantax:feature/csv-support
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Identifier,Requirement Text,Section Nr,Main Section,WP,Priority,User Journey,Verif Method,Compliance (Y/N/P),Actual Compliance(Y/N/P),Close out status,Comments | ||
| REQ-01,The VCD Generator shall read the test results created by the NunitXml.TestLogger in the Nunit3 output format,1.1,VCD Generation,1,high,User Journey,Test,Y,Y,-,- | ||
| REQ-02 ,"Requirement text, with an embedded comma for RFC-4180 quoting",1.2,VCD Generation,2,high,User Journey,Test,Y,Y,-,- | ||
| ,Row with empty identifier should be skipped by the importer,1.3,VCD Generation,3,high,User Journey,Test,Y,Y,-,- | ||
| REQ-03,"Line one of requirement | ||
| Line two continues here",1.4,VCD Generation,4,high,User Journey,Test,Y,Y,-,- |
200 changes: 200 additions & 0 deletions
200
VCD-Generator.Tests/Services/CsvReportGeneratorTestFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| // ------------------------------------------------------------------------------------------------- | ||
| // <copyright file="CsvReportGeneratorTestFixture.cs" company="Starion Group S.A."> | ||
| // | ||
| // Copyright 2022-2024 Starion Group S.A. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace VCD.Generator.Tests.Services | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| using nietras.SeparatedValues; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using VCD.Generator.Services; | ||
|
|
||
| /// <summary> | ||
| /// Suite of tests for the <see cref="CsvReportGenerator"/> class | ||
| /// </summary> | ||
| [TestFixture] | ||
| public class CsvReportGeneratorTestFixture | ||
| { | ||
| private CsvReportGenerator csvReportGenerator; | ||
|
|
||
| private List<Requirement> requirements; | ||
|
|
||
| private string csvReportPath; | ||
|
|
||
| private ILoggerFactory loggerFactory; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| this.loggerFactory = LoggerFactory.Create(builder => | ||
| builder.AddConsole().SetMinimumLevel(LogLevel.Trace)); | ||
|
|
||
| this.csvReportPath = Path.Combine(Path.GetTempPath(), System.Guid.NewGuid().ToString("N") + ".csv"); | ||
|
|
||
| this.csvReportGenerator = new CsvReportGenerator(this.loggerFactory); | ||
|
|
||
| this.CreateTestData(); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| if (File.Exists(this.csvReportPath)) | ||
| { | ||
| File.Delete(this.csvReportPath); | ||
| } | ||
| } | ||
|
|
||
| private void CreateTestData() | ||
| { | ||
| this.requirements = new List<Requirement>(); | ||
|
|
||
| var requirement_1 = new Requirement | ||
| { | ||
| Identifier = "REQ-01", | ||
| Text = "The VCD Generator shall read the test results created by the NunitXml.TestLogger in the Nunit3 output format" | ||
| }; | ||
| this.requirements.Add(requirement_1); | ||
|
|
||
| var requirement_2 = new Requirement | ||
| { | ||
| Identifier = "REQ-02", | ||
| Text = "The VCD Generator shall read the requirements from an excel spreadsheet" | ||
| }; | ||
| this.requirements.Add(requirement_2); | ||
|
|
||
| var testCase_1_1 = new TestCase | ||
| { | ||
| Name = "Verify_that_Read_throws_exception", | ||
| FullName = "VCD.Generator.Tests.Services.TestResultReaderTestFixture.Verify_that_Read_throws_exception", | ||
| Description = "Verifies that the TestResultReader.Read methods trows an exception", | ||
| RequirementId = new List<string> { "REQ-01" }, | ||
| Result = "Passed" | ||
| }; | ||
| requirement_1.TestCases.Add(testCase_1_1); | ||
|
|
||
| var testCase_1_2 = new TestCase | ||
| { | ||
| Name = "Verify_that_Read_does_not_throw_exception", | ||
| FullName = "VCD.Generator.Tests.Services.TestResultReaderTestFixture.Verify_that_Read_does_not_throw_exception", | ||
| Description = "Verifies that the TestResultReader.Read methods does not throw an exception", | ||
| RequirementId = new List<string> { "REQ-01" }, | ||
| Result = "Passed" | ||
| }; | ||
| requirement_1.TestCases.Add(testCase_1_2); | ||
|
|
||
| var testCase_2 = new TestCase | ||
| { | ||
| Name = "Verify_that_Read_throws_exception", | ||
| FullName = "VCD.Generator.Tests.Services.RequirementsReaderTestFixture.Verify_that_Read_throws_exception", | ||
| Description = "Verifies that the TestResultReader.Read methods trows an exception", | ||
| RequirementId = new List<string> { "REQ-02" }, | ||
| Result = "Failed" | ||
| }; | ||
| requirement_2.TestCases.Add(testCase_2); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Generate_writes_header_row_and_rows() | ||
| { | ||
| this.csvReportGenerator.Generate(this.requirements, this.csvReportPath); | ||
|
|
||
| using var reader = Sep.Reader().FromFile(this.csvReportPath); | ||
|
|
||
| var header = reader.Header.ColNames.ToArray(); | ||
| Assert.That(header, Is.EqualTo(new[] { "REQUIREMENT-ID", "REQUIREMENT-TEXT", "TESTCASES" })); | ||
|
|
||
| var rows = new List<string[]>(); | ||
| foreach (var row in reader) | ||
| { | ||
| rows.Add(new[] { row[0].ToString(), row[1].ToString(), row[2].ToString() }); | ||
| } | ||
|
|
||
| Assert.That(rows.Count, Is.EqualTo(this.requirements.Count)); | ||
|
|
||
| for (var i = 0; i < this.requirements.Count; i++) | ||
| { | ||
| Assert.That(rows[i][0], Is.EqualTo(this.requirements[i].Identifier)); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_TESTCASES_cell_contains_embedded_newlines() | ||
| { | ||
| var requirement = this.requirements[0]; | ||
| var singleRequirement = new List<Requirement> { requirement }; | ||
|
|
||
| this.csvReportGenerator.Generate(singleRequirement, this.csvReportPath); | ||
|
|
||
| using var reader = Sep.Reader(o => o with { Unescape = true }).FromFile(this.csvReportPath); | ||
|
|
||
| var testCasesCells = new List<string>(); | ||
| foreach (var row in reader) | ||
| { | ||
| testCasesCells.Add(row["TESTCASES"].ToString()); | ||
| } | ||
|
|
||
| Assert.That(testCasesCells.Count, Is.EqualTo(1)); | ||
|
|
||
| var tc1 = requirement.TestCases[0]; | ||
| var tc2 = requirement.TestCases[1]; | ||
| var expected = $"{tc1.FullName} - {tc1.Result}\n{tc2.FullName} - {tc2.Result}"; | ||
|
|
||
| Assert.That(testCasesCells[0], Is.EqualTo(expected)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Generate_overwrites_existing_file() | ||
| { | ||
| this.csvReportGenerator.Generate(this.requirements, this.csvReportPath); | ||
|
|
||
| var secondBatch = new List<Requirement> | ||
| { | ||
| new Requirement | ||
| { | ||
| Identifier = "REQ-99", | ||
| Text = "Overwrite requirement" | ||
| } | ||
| }; | ||
|
|
||
| this.csvReportGenerator.Generate(secondBatch, this.csvReportPath); | ||
|
|
||
| using var reader = Sep.Reader().FromFile(this.csvReportPath); | ||
|
|
||
| var ids = new List<string>(); | ||
| var texts = new List<string>(); | ||
| foreach (var row in reader) | ||
| { | ||
| ids.Add(row["REQUIREMENT-ID"].ToString()); | ||
| texts.Add(row["REQUIREMENT-TEXT"].ToString()); | ||
| } | ||
|
|
||
| Assert.That(ids.Count, Is.EqualTo(1)); | ||
| Assert.That(ids[0], Is.EqualTo("REQ-99")); | ||
| Assert.That(texts[0], Is.EqualTo("Overwrite requirement")); | ||
| } | ||
| } | ||
| } | ||
137 changes: 137 additions & 0 deletions
137
VCD-Generator.Tests/Services/CsvRequirementsReaderTestFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // ------------------------------------------------------------------------------------------------- | ||
| // <copyright file="CsvRequirementsReaderTestFixture.cs" company="Starion Group S.A."> | ||
| // | ||
| // Copyright 2022-2024 Starion Group S.A. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace VCD.Generator.Tests.Services | ||
| { | ||
| using System.Linq; | ||
| using System.IO; | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using VCD.Generator.Services; | ||
|
|
||
| /// <summary> | ||
| /// Suite of tests for the <see cref="CsvRequirementsReader"/> class | ||
| /// </summary> | ||
| [TestFixture] | ||
| public class CsvRequirementsReaderTestFixture | ||
| { | ||
| private CsvRequirementsReader requirementsReader; | ||
|
|
||
| private FileInfo requirementsDocumentFileInfo; | ||
|
|
||
| private ILoggerFactory loggerFactory; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| this.loggerFactory = LoggerFactory.Create(builder => | ||
| builder.AddConsole().SetMinimumLevel(LogLevel.Trace)); | ||
|
|
||
| this.requirementsDocumentFileInfo = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, | ||
| "Data", "requirements.csv")); | ||
|
|
||
| this.requirementsReader = new CsvRequirementsReader(this.loggerFactory); | ||
| } | ||
|
|
||
| [Test(Description = "Verifies that the CsvRequirementsReader.Read method returns the expected requirements"), | ||
| Property("REQUIREMENT-ID", "REQ-02")] | ||
| public void Verify_that_Read_with_default_first_column_returns_expected_requirements() | ||
| { | ||
| var requirements = this.requirementsReader.Read(this.requirementsDocumentFileInfo).ToList(); | ||
|
|
||
| Assert.That(requirements, Is.Not.Empty); | ||
| Assert.That(requirements.Select(x => x.Identifier).ToList(), | ||
| Is.EqualTo(new[] { "REQ-01", "REQ-02", "REQ-03" })); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Read_with_named_identifier_column_returns_expected_requirements() | ||
| { | ||
| var requirements = this.requirementsReader | ||
| .Read(this.requirementsDocumentFileInfo, null, "Identifier").ToList(); | ||
|
|
||
| Assert.That(requirements.Select(x => x.Identifier).ToList(), | ||
| Is.EqualTo(new[] { "REQ-01", "REQ-02", "REQ-03" })); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Read_with_named_text_column_populates_Text() | ||
| { | ||
| var requirements = this.requirementsReader | ||
| .Read(this.requirementsDocumentFileInfo, null, "Identifier", "Requirement Text").ToList(); | ||
|
|
||
| Assert.That(requirements.Any(r => !string.IsNullOrEmpty(r.Text)), Is.True); | ||
|
|
||
| var multiline = requirements.Single(r => r.Identifier == "REQ-03"); | ||
| Assert.That(multiline.Text, Does.Contain("\n")); | ||
| Assert.That(multiline.Text, Does.Contain("Line one of requirement")); | ||
| Assert.That(multiline.Text, Does.Contain("Line two continues here")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Read_with_unknown_identifier_column_throws_InvalidRequirementsFormatException() | ||
| { | ||
| Assert.That( | ||
| () => this.requirementsReader | ||
| .Read(this.requirementsDocumentFileInfo, null, "NotAColumn").ToList(), | ||
| Throws.TypeOf<InvalidRequirementsFormatException>()); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_Read_with_unknown_text_column_throws_InvalidRequirementsFormatException() | ||
| { | ||
| Assert.That( | ||
| () => this.requirementsReader | ||
| .Read(this.requirementsDocumentFileInfo, null, "Identifier", "NotAColumn").ToList(), | ||
| Throws.TypeOf<InvalidRequirementsFormatException>()); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_empty_identifier_rows_are_skipped() | ||
| { | ||
| var requirements = this.requirementsReader.Read(this.requirementsDocumentFileInfo).ToList(); | ||
|
|
||
| Assert.That(requirements.Count, Is.EqualTo(3)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_identifier_is_trimmed() | ||
| { | ||
| var requirements = this.requirementsReader.Read(this.requirementsDocumentFileInfo).ToList(); | ||
|
|
||
| foreach (var requirement in requirements) | ||
| { | ||
| Assert.That(requirement.Identifier, Is.EqualTo(requirement.Identifier.Trim())); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void Verify_that_sheetName_is_ignored_for_csv_input() | ||
| { | ||
| var requirements = this.requirementsReader | ||
| .Read(this.requirementsDocumentFileInfo, "AnySheet", "Identifier", "Requirement Text").ToList(); | ||
|
|
||
| Assert.That(requirements.Count, Is.EqualTo(3)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2026 please