示例#1
0
        public void GetPrefillReturnsEmptyStringIfVarNotFound()
        {
            var parser = new ReportTemplateParser(new StringReader("__var__X__var2:tst__"));

            Assert.AreEqual("", parser.GetPrefill("var"));
            Assert.AreEqual("tst", parser.GetPrefill("var2"));
        }
示例#2
0
        public void ReportTemplateParserCorrectlySubstitutesVariables()
        {
            var parser = new ReportTemplateParser(new StringReader("Hello __name__, you are __this__"));

            parser.SetValue("name", "john");
            parser.SetValue("this", "here");
            Assert.IsTrue("Hello john, you are here".Equals(parser.Parse()));
        }
示例#3
0
        public void ReportTemplateParserFindsAllPrefilledVars()
        {
            var parser    = new ReportTemplateParser(new StringReader("Hello __var__, __pre:filled____pre2:filled2__"));
            var prefilled = parser.GetAllPrefills();

            Assert.AreEqual(2, prefilled.Count);
            Assert.AreEqual("filled", prefilled["pre"]);
            Assert.AreEqual("filled2", prefilled["pre2"]);
        }
示例#4
0
        public void ReportTemplateParserCorrectlyExtractsPrefilledInputAndReplacesIt()
        {
            var parser  = new ReportTemplateParser(new StringReader("Hello__ThisIsALongVariable__ __name:This is prefill__"));
            var prefill = parser.GetPrefill("name");

            Assert.AreEqual("This is prefill", prefill);
            parser.SetValue("ThisIsALongVariable", "asdf");
            parser.SetValue("name", prefill + ".");
            Assert.AreEqual("Helloasdf This is prefill.", parser.Parse());
        }
示例#5
0
        private void ApplyStandartTemplatesToLine(Election election, StringBuilder text)
        {
            text.Replace(MACRO_ELECTION_NAME, election.Name);
            if (PlatformDetector.IsUnix)
            {
                text.Replace(MACRO_VOTING_DATE, ReportTemplateParser.DataConvert(
                                 _electionManager.SourceData.ElectionDate.ToString(ELECTION_DATE_FORMAT,
                                                                                   new System.Globalization.CultureInfo("ru-RU"))));
                text.Replace(MACRO_CURRENT_DATE, ReportTemplateParser.DataConvert(
                                 DateTime.Now.ToString(CURRENT_DATETIME_FORMAT, new System.Globalization.CultureInfo("ru-RU"))));
            }
            else
            {
                text.Replace(MACRO_VOTING_DATE,
                             _electionManager.SourceData.ElectionDate.ToString(ELECTION_DATE_FORMAT));
                text.Replace(MACRO_CURRENT_DATE, DateTime.Now.ToString(CURRENT_DATETIME_FORMAT));
            }
            text.Replace(MACRO_UIK, _electionManager.SourceData.Uik.ToString());
            var exp = new UikMemberNamesRegex();

            foreach (Match match in exp.Matches(text.ToString()))
            {
                var    altValue = match.Value.Split(':')[1].Trim('}');
                string name     = null;
                if (match.Value.Contains(CommitteeMemberType.ChairmanAssistant.ToString()))
                {
                    name = _electionManager.SourceData.GetCommitteeMemberInitialByType(CommitteeMemberType.ChairmanAssistant);
                }
                else if (match.Value.Contains(CommitteeMemberType.Chairman.ToString()))
                {
                    name =
                        _electionManager.SourceData.GetCommitteeMemberInitialByType(CommitteeMemberType.Chairman);
                }
                else if (match.Value.Contains(CommitteeMemberType.Secretary.ToString()))
                {
                    name = _electionManager.SourceData.GetCommitteeMemberInitialByType(CommitteeMemberType.Secretary);
                }
                text.Replace(match.Value, string.IsNullOrEmpty(name) ? altValue : name);
            }
        }
示例#6
0
 public abstract Table[] GetTables(ReportTemplateParser parser);
示例#7
0
 public abstract Lines ConstructContent(ReportTemplateParser parser);
示例#8
0
 public abstract Lines ConstructContent(ReportTemplateParser parser);
示例#9
0
 public abstract Table[] GetTables(ReportTemplateParser parser);