Ejemplo n.º 1
0
        private Task <SoftwareSpecification> BuildRequirementsFromDirectorySoftwareSpecification(string directory, ProductRequirement productRequirement)
        {
            var index         = Path.Combine(directory, "index.md");
            var directoryName = Path.GetFileName(directory.TrimEnd(Path.DirectorySeparatorChar));

            if (!File.Exists(index))
            {
                throw new DocGenException($"File 'index.md' doesn't exist for software specification {directoryName}");
            }

            SoftwareSpecification softwareSpecification;

            try
            {
                softwareSpecification = _requirementsParser.ParseSoftwareSpecification(File.ReadAllText(index));
            }
            catch (Exception ex)
            {
                throw new DocGenException($"Error parsing index.md for software specification {directoryName}: {ex.Message}");
            }

            softwareSpecification.ProductRequirement = productRequirement;
            softwareSpecification.Key = directoryName;

            foreach (var dir in Directory.GetDirectories(directory).OrderBy(x => x))
            {
                var childDirName = Path.GetFileName(dir.TrimEnd(Path.DirectorySeparatorChar));

                if (childDirName.Equals("tests", StringComparison.InvariantCultureIgnoreCase))
                {
                    // process tests
                    foreach (var file in Directory.GetFiles(dir, "*.md").OrderBy(x => x))
                    {
                        var testCase = _requirementsParser.ParseTestCase(File.ReadAllText(file));
                        testCase.SoftwareSpecification = softwareSpecification;
                        testCase.Key = Path.GetFileNameWithoutExtension(file);
                        softwareSpecification.TestCases.Add(testCase);
                    }
                }
                else
                {
                    throw new DocGenException($"Invalid directory {childDirName} in software specification {directoryName}");
                }
            }

            AssertUniqueNumbersForTestCases(softwareSpecification.TestCases);

            softwareSpecification.TestCases = softwareSpecification.TestCases.OrderBy(x => x.Number).ToList();

            return(Task.FromResult(softwareSpecification));
        }
Ejemplo n.º 2
0
        public void Can_parse_software_requirement()
        {
            var document = new StringBuilder();

            document.AppendLine("---");
            document.AppendLine("Number: 1.0");
            document.AppendLine("Title: Test title");
            document.AppendLine("---");
            document.AppendLine("# Requirement");
            document.AppendLine("Requirement content....");
            document.AppendLine("# Verification Method");
            document.AppendLine("Verification content...");

            var result = _requirementsParser.ParseSoftwareSpecification(document.ToString());

            Assert.Equal(result.Number, new Version(1, 0));
            Assert.Equal(result.Title, "Test title");
            Assert.Equal(result.Requirement, "Requirement content....");
            Assert.Equal(result.VerificationMethod, "Verification content...");
        }