Ejemplo n.º 1
0
        public void Can_parse_product_requirement()
        {
            var document = new StringBuilder();

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

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

            Assert.Equal(result.Number, new Version(1, 0));
            Assert.Equal(result.Title, "Test title");
            Assert.Equal(result.Category, "Test category");
            Assert.Equal(result.Requirement, "Requirement content...." + Environment.NewLine + "Some more....");
            Assert.Equal(result.VerificationMethod, "Verification content..." + Environment.NewLine + "Some more....");
        }
Ejemplo n.º 2
0
        private async Task <ProductRequirement> BuildRequirementsFromDirectoryProductRequirement(string directory, UserNeed userNeed)
        {
            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 product requirement {directoryName}");
            }

            ProductRequirement productRequirement;

            try
            {
                productRequirement = _requirementsParser.ParseProductRequirement(File.ReadAllText(index));
            }
            catch (Exception ex)
            {
                throw new DocGenException($"Error parsing index.md for product requirement {directoryName}: {ex.Message}");
            }

            productRequirement.UserNeed = userNeed;
            productRequirement.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.ProductRequirement = productRequirement;
                        testCase.Key = Path.GetFileNameWithoutExtension(file);
                        productRequirement.TestCases.Add(testCase);
                    }
                }
                else
                {
                    // process software specification
                    productRequirement.SoftwareSpecifications.Add(await BuildRequirementsFromDirectorySoftwareSpecification(dir, productRequirement));
                }
            }

            var duplicateNumbers = productRequirement.SoftwareSpecifications.GroupBy(x => x.Number)
                                   .Where(x => x.Count() > 1)
                                   .Select(x => x.Key)
                                   .ToList();

            if (duplicateNumbers.Any())
            {
                var first = duplicateNumbers.First();
                var duplicateUserNeeds = productRequirement.SoftwareSpecifications.Where(x => x.Number == first).ToList();
                throw new DocGenException($"Duplicate number '{first}' for software specifications '{string.Join(",", duplicateUserNeeds.Select(x => x.Key).ToArray())}'");
            }

            AssertUniqueNumbersForTestCases(productRequirement.TestCases);

            productRequirement.SoftwareSpecifications = productRequirement.SoftwareSpecifications.OrderBy(x => x.Number).ToList();
            productRequirement.TestCases = productRequirement.TestCases.OrderBy(x => x.Number).ToList();

            return(productRequirement);
        }