//[Theory]
        //[InlineData("2017")]
        //[InlineData("2016")]
        public void AllCST_AendringsDefinitioner(int year)
        {
            var file        = new FileInfo($"AendringsDefinitionParser/RealTestData/{year}-cst-aendringsdefinitioner.txt");
            var definitions = File.ReadAllLines(file.FullName);
            var sut         = new AendringDefintionParser();
            var errors      = definitions
                              .Select(line => line.Split(new[] { ';' }))
                              .Select((def, no) => new
            {
                LineNo    = no,
                SourceDok = def[0],
                Text      = def[1],
                Result    = sut.Parse(def[1])
            })
                              .Where(r => r.Result.ErrorResult.Errors.Any())
                              .ToArray();


            _logger.WriteLine($"COMPLETE: Parsed {definitions.Length} defintions from year {year} and found {errors.Length} errors:");

            foreach (var error in errors)
            {
                _logger.WriteLine("");
                _logger.WriteLine($"LineNo. {error.LineNo} - [{error.Text}]");
                foreach (var errorResultError in error.Result.ErrorResult.Errors)
                {
                    _logger.WriteLine($"   From source document {error.SourceDok}");
                    _logger.WriteLine($"   {errorResultError}");
                }
            }



            Assert.Equal(definitions.Length, definitions.Length - errors.Count());
        }
Esempio n. 2
0
        public void WhenInvalidString_ErrorsAreReported(string description, string inputString)
        {
            var parser = new AendringDefintionParser();
            var result = parser.Parse(inputString);

            Assert.NotEqual(Enumerable.Empty <string>(), result.ErrorResult.Errors);
        }
Esempio n. 3
0
        private Tuple <XElement, AendringDefinition>[] FindRelevantChanges(TargetDocument targetDocument, ChangeDocument change)
        {
            var aendringer = "//AendringCentreretParagraf/Exitus[1]";

            //Parse all paragrafindlendinger asynchronously
            var allParagrafIndledninger = Task.WhenAll(change.XDoc.XPathSelectElements(aendringer)
                                                       .Select(element => new { AendringCentreretParagrafNode = element.Parent, ParagrafText = element.Value })                             //Map to Paragraf Node and paragrafindledning text
                                                       .Select(s => Task.Run(() => new { s.AendringCentreretParagrafNode, ParseResult = _paragrafIndledningParser.Parse(s.ParagrafText) })) //parse paragrafindledning
                                                       .ToArray());

            allParagrafIndledninger.Wait();

            //find aendrings paragraffer that points to the target document
            var allParagrafNodesThatPointsToTargetDocument = allParagrafIndledninger.Result
                                                             .Where(map => !map.ParseResult.ErrorResult.HasErrors)
                                                             .Where(map => ParagrafIndledningerThatPointsToTargetDocument(targetDocument, map.ParseResult))
                                                             .Select(arg => arg.AendringCentreretParagrafNode)
                                                             .ToArray();

            //parse all aendringer in each paragrafindledninger
            return(allParagrafNodesThatPointsToTargetDocument.Descendants("Aendring")
                   .Where(element => element.Elements("AendringDefinition").Any())
                   .Select(element => new { Aendring = element, ParseResult = _aendringDefinitiontParser.Parse(element.Element("AendringDefinition")?.Value.Trim() ?? string.Empty) })
                   .Where(map => !map.ParseResult.ErrorResult.HasErrors)
                   .Select(map => new Tuple <XElement, AendringDefinition>(map.Aendring, map.ParseResult.Result))
                   .ToArray());
        }
Esempio n. 4
0
        public void WhenSpecialCaseWithMulitpleElements_ElementStructureIsCorrect(string inputString, string expectedTarget, string expectedReplacement)
        {
            //ændres »abc 987« til: »xyz 123«.
            var parser = new AendringDefintionParser();
            var result = parser.Parse(inputString);

            Assert.Equal((new string[] { }).ToList(), result.ErrorResult.Errors);

            Assert.Equal(expectedTarget, result.Result.Target.SubElementTarget.Target);
            Assert.Equal(expectedReplacement, result.Result.Target.SubElementTarget.Replacement);
        }
Esempio n. 5
0
        public void WhenContainsQuotedTextChanged_QuotedTextArePreserved(string inputString, string expectedTarget, string expectedReplacement)
        {
            //ændres »abc 987« til: »xyz 123«.
            var parser = new AendringDefintionParser();
            var result = parser.Parse(inputString);

            Assert.Equal(new string[] { }.ToList(), result.ErrorResult.Errors);

            Assert.Equal(expectedTarget, result.Result.Target.SubElementTarget.Target);
            Assert.Equal(expectedReplacement, result.Result.Target.SubElementTarget.Replacement);
        }
Esempio n. 6
0
        public void WhenContainsSingleQuotedTextAndAutomationIsPossible_QuotedTextAreSetInSubElementTarget(string inputString, string expectedTarget)
        {
            //ændres »abc 987« til: »xyz 123«.
            var parser = new AendringDefintionParser();
            var result = parser.Parse(inputString);

            Assert.Equal((new string[] { }).ToList(), result.ErrorResult.Errors);

            Assert.Equal(expectedTarget, result.Result.Target.SubElementTarget.Target);
            Assert.Null(result.Result.Target.SubElementTarget.Replacement);
        }
Esempio n. 7
0
        public void WhenValidString_ParserReturnsObject(string inputString
                                                        , Type expectedTargetType
                                                        , object expectednumber
                                                        , AktionType expectedAktionType)
        {
            var parser = new AendringDefintionParser();
            var result = parser.Parse(inputString);

            Assert.Equal((new string[] { }).ToList(), result.ErrorResult.Errors);


            Assert.Equal(expectedAktionType, result.Result.AktionType);

            Assert.Equal(expectednumber, result.Result.Target.Nummer);
            Assert.IsType(expectedTargetType, result.Result.Target);
        }
Esempio n. 8
0
        public void TestSubElementMultiTarget_QuotedTextChanged(string input, object[][] expectedSubElementTargets, object[] explicatusChain, Type[] typeChain)
        {
            var result = _sut.Parse(input);

            AssertErrors(result);
            Assert.Equal(1, result.Result.Targets.Length);
            AssertTargetElementChain(explicatusChain, AktionType.Erstat, typeChain, result.Result, result.Result.Target);
            AssertSubElementMultiReplaceChange(expectedSubElementTargets, result.Result.Target.SubElementTargets);
        }