Пример #1
0
        public void Can_parse_test_case()
        {
            var document = new StringBuilder();

            document.AppendLine("---");
            document.AppendLine("Number: 1.0");
            document.AppendLine("ResponseType: Done");
            document.AppendLine("ValidationType: Validation");
            document.AppendLine("Type: Hardware");
            document.AppendLine("---");
            document.AppendLine("# Action");
            document.AppendLine("Action....");
            document.AppendLine("# Expected");
            document.AppendLine("Expected...");

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

            Assert.Equal(result.Number, new Version(1, 0));
            Assert.Equal(result.ResponseType, TestCaseResponseTypeEnum.Done);
            Assert.Equal(result.ValidationType, TestCaseValidationTypeEnum.Validation);
            Assert.Equal(result.Type, TestCaseTypeEnum.Hardware);
            Assert.Equal(result.Action, "Action....");
            Assert.Equal(result.Expected, "Expected...");
        }
Пример #2
0
        private async Task <UserNeed> BuildRequirementsFromDirectoryUserNeed(string directory)
        {
            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 user need {directoryName}");
            }

            UserNeed userNeed;

            try
            {
                userNeed = _requirementsParser.ParseUserNeed(File.ReadAllText(index));
            }
            catch (Exception ex)
            {
                throw new DocGenException($"Error parsing index.md for user need {directoryName}: {ex.Message}");
            }

            userNeed.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.UserNeed = userNeed;
                        testCase.Key      = Path.GetFileNameWithoutExtension(file);
                        userNeed.TestCases.Add(testCase);
                    }
                }
                else
                {
                    // process product requirements
                    userNeed.ProductRequirements.Add(await BuildRequirementsFromDirectoryProductRequirement(dir, userNeed));
                }
            }

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

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

            AssertUniqueNumbersForTestCases(userNeed.TestCases);

            userNeed.ProductRequirements = userNeed.ProductRequirements.OrderBy(x => x.Number).ToList();
            userNeed.TestCases           = userNeed.TestCases.OrderBy(x => x.Number).ToList();

            return(userNeed);
        }