コード例 #1
0
        public void Rules_Executables_Switch_DimitrySaturday()
        {
            //BookStorage.Instance = BookStorageFactory.Create();

            string xmlString = @"<rule>
	                                <switch>
		                                <expression>
			                                <getclosestday dayofweek=""суббота"" weekcount=""-1""><date>--11-08</date></getclosestday>
		                                </expression>
		                                <case>
			                                <values>
				                                 <date>--11-04</date>
			                                </values>
			                                <action>
				                                <modifyday servicesign=""12"" iscustomname=""true"">
					                                <getclosestday dayofweek=""суббота"" weekcount=""-2""><date>--11-08</date></getclosestday>
				                                </modifyday>
			                                </action>
		                                </case>
		                                <default>
			                                <modifyday servicesign=""12"" iscustomname=""true"">
					                                <getclosestday dayofweek=""суббота"" weekcount=""-1""><date>--11-08</date></getclosestday>
				                                </modifyday>
		                                </default>
	                                </switch>
                                </rule>";

            var element = TestRuleSerializer.Deserialize <ExecContainer>(xmlString);

            element.Interpret(BypassHandler.Instance);

            Assert.Pass("Success");
        }
コード例 #2
0
        public void KAfterRule_InKanonasRule()
        {
            string xmlString = @"<kanonasrule>
						            <k_after number=""3"">
							            <priest>
						                    <p>
							                    <item language=""cs-ru"">Благослове́н Бог наш всегда́, ны́не и при́сно, и во ве́ки веко́в</item>
						                    </p>
					                    </priest>
						            </k_after>
						            <k_after number=""6"">
							            <priest>
						                    <p>
							                    <item language=""cs-ru"">Благослове́н Бог наш всегда́, ны́не и при́сно, и во ве́ки веко́в</item>
						                    </p>
					                    </priest>
						            </k_after>
                                </kanonasrule>";

            var element = TestRuleSerializer.Deserialize <KanonasRule>(xmlString);

            element.Interpret(BypassHandler.Instance);

            Assert.AreEqual(2, element.AfterRules.Count());
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rule">Правило</param>
        /// <param name="text">Текст службы</param>
        /// <returns></returns>
        private RuleHandlerSettings CreateFakeSettings(string rule, string text)
        {
            var menologyRule = new MenologyRule
            {
                RuleDefinition = rule
            };

            var dayWorships = new List <DayWorship>()
            {
                new DayWorship()
                {
                    Definition = text
                }
            };

            var ruleContainer = TestRuleSerializer.Deserialize <RootContainer>(rule);// menologyRule.GetRule<ExecContainer>(TestRuleSerializer.Root);

            return(new RuleHandlerSettings
            {
                Date = DateTime.Today,
                //TypiconRule = menologyRule,
                Menologies = dayWorships,
                RuleContainer = ruleContainer
            });
        }
コード例 #4
0
        public void Rules_Executables_Case_DifferentTypes()
        {
            string xmlString = @"<case>
			                        <values>
				                        <date>--02-15</date>
				                        <int>-22</int>
			                        </values>
			                        <action>
				                        <modifyday servicesign=""6"" daymove=""0"" iscustomname=""true""/>
                                    </action>
                                </case> ";

            var element = TestRuleSerializer.Deserialize <Case>(xmlString);

            Assert.IsFalse(element.IsValid);

            //try
            //{
            //    Case element = new Case(xmlDoc.FirstChild);
            //}
            //catch (DefinitionsParsingException ex)
            //{
            //    Assert.Pass(ex.Message);
            //}
        }
コード例 #5
0
        public void CommonRuleElement_SimplePassing()
        {
            //находим первый попавшийся MenologyRule
            var dbContext = TypiconDbContextFactory.Create();

            var typiconEntity = dbContext.Set <TypiconVersion>().First(c => c.Id == 1);

            MenologyRule           rule    = typiconEntity.MenologyRules[0];
            ServiceSequenceHandler handler = new ServiceSequenceHandler
            {
                Settings = new RuleHandlerSettings()
                {
                    Date = DateTime.Today, TypiconVersionId = 1
                }
            };

            string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            var    reader     = new FileReader(folderPath);
            string xml        = reader.Read("CommonRuleElement_Simple.xml");

            var element = TestRuleSerializer.Deserialize <WorshipSequence>(xml);

            element.Interpret(handler);

            var model = handler.ActualWorshipChildElements;

            //WorshipSequenceViewModel model = new WorshipSequenceViewModel(element, handler);

            Assert.AreEqual(30, model.Count);
        }
コード例 #6
0
        public void ExapostilarionRuleTest_FromRealDB()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var typiconEntity = dbContext.Set <TypiconVersion>().First(c => c.Id == 1);

            ServiceSequenceHandler handler = new ServiceSequenceHandler();

            string xml = TestDataXmlReader.GetXmlString("ExapostilarionRuleTest.xml");

            DateTime date = new DateTime(2017, 11, 09);

            MenologyRule rule = typiconEntity.GetMenologyRule(date);

            rule.RuleDefinition = xml;

            handler.Settings.Menologies = rule.DayWorships.ToList();
            handler.Settings.Date       = date;

            OktoikhDay oktoikhDay = DataQueryProcessorFactory.Instance.Process(new OktoikhDayQuery(date));

            handler.Settings.OktoikhDay = oktoikhDay;

            var ruleContainer = TestRuleSerializer.Deserialize <ExapostilarionRule>(xml);

            ruleContainer.Interpret(handler);

            Assert.AreEqual(3, ruleContainer.Structure.Ymnis.Count);
            Assert.IsNotNull(ruleContainer.Structure.Theotokion);
        }
コード例 #7
0
        public void Variables_Test()
        {
            DateTime date = new DateTime(2017, 11, 09);
            string   xml  = TestDataXmlReader.GetXmlString("VariablesTest.xml");

            var handler = new CollectorRuleHandler <IHavingVariables>()
            {
                Settings = RuleHandlerSettingsTestFactory.Create(1, date, xml)
            };

            var ruleContainer = TestRuleSerializer.Deserialize <RootContainer>(xml);

            ruleContainer.Interpret(handler);

            var result = handler.GetResult();

            var variables = new List <string>();

            foreach (var r in result)
            {
                variables.AddRange(r.GetVariableNames().Select(c => c.Item1));
            }

            variables = variables.Distinct().ToList();

            Assert.AreEqual(2, variables.Count);
        }
コード例 #8
0
        public void CommonRuleElement_SimplePassing()
        {
            //находим первый попавшийся MenologyRule
            EFUnitOfWork _unitOfWork = new EFUnitOfWork();
            //BookStorage.Instance = BookStorageFactory.Create();
            GetTypiconEntityResponse resp          = new TypiconEntityService(_unitOfWork).GetTypiconEntity(1);
            TypiconEntity            typiconEntity = resp.TypiconEntity;
            MenologyRule             rule          = typiconEntity.MenologyRules[0];
            ServiceSequenceHandler   handler       = new ServiceSequenceHandler();

            handler.Settings = new RuleHandlerSettings()
            {
                Language = LanguageSettingsFactory.Create("cs-ru"), Rule = rule, Date = DateTime.Today
            };

            string     folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData");
            FileReader reader     = new FileReader(folderPath);
            string     xml        = reader.Read("CommonRuleElement_Simple.xml");

            var element = TestRuleSerializer.Deserialize <WorshipSequence>(xml);

            element.Interpret(handler);

            var model = handler.GetResult();

            //WorshipSequenceViewModel model = new WorshipSequenceViewModel(element, handler);

            Assert.AreEqual(30, model.FirstOrDefault()?.Count);
        }
コード例 #9
0
        public void Rules_Executables_Switch_Condition_check()
        {
            string xmlString = @"<rule>
	                                <switch>
		                                <expression>
			                                <getdayofweek><date>--01-07</date></getdayofweek>
		                                </expression>
		                                <case>
			                                <values>
					                                <getdayofweek name=""понедельник""></getdayofweek>
			                                </values>
			                                <action>
				                                <service time=""17.30"" name=""9-й час. Вечерня. малое повечерие."" isdaybefore=""true""/>
				                                <service time=""06.00"" name=""Полунощница. Утреня.""></service>
				                                <service time=""08.00"" name=""Великие Часы. Изобразительны. ""></service>
				                                <notice name=""Божественная литургия не совершается.""/>
			                                </action>
		                                </case>
		                                <default>
			                                <service time=""17.30"" name=""9-й час. Вечерня. Малое повечерие."" isdaybefore=""true""/>
			                                <service time=""06.00"" name=""Полуношница. Утреня. Часы.""></service>
			                                <service time=""08.00"" name=""Божественная литургия.""></service>
		                                </default>
	                                </switch>
                                </rule>";

            var element = TestRuleSerializer.Deserialize <ExecContainer>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #10
0
        public void Rules_Executables_Switch_NormalParsing()
        {
            string xmlString = @"<rule>
	                                <switch>
		                                <expression>
			                                <daysfromeaster><date>--04-06</date></daysfromeaster>
		                                </expression>
		                                <case>
			                                <values>
				                                <int>-19</int>
			                                </values>
			                                <action>
				                                <modifyday daymove=""-1"" />
			                                </action>
		                                </case>
		                                <case>
				                            <values>
					                            <int>-17</int>
				                            </values>
			                                <action>
				                                <modifyday daymove=""-1"" />
			                                </action>
		                                </case>
	                                </switch>
                                </rule>";

            var element = TestRuleSerializer.Deserialize <ExecContainer>(xmlString);

            element.Interpret(BypassHandler.Instance);

            Assert.Pass("Success");
        }
コード例 #11
0
        public void RootContainer_Deserialize()
        {
            var xml     = TestDataXmlReader.GetXmlString("RootContainerTest.xml");
            var element = TestRuleSerializer.Deserialize <RootContainer>(xml);

            // TODO: Add your test code here
            Assert.IsTrue(element is RootContainer);
        }
コード例 #12
0
        public void ModifyDay_NoDate()
        {
            string xmlString = @"<modifyday></modifyday>";

            var element = TestRuleSerializer.Deserialize <ModifyDay>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #13
0
        public void Rules_Expressions_More(bool expected, string xmlString)
        {
            var element = TestRuleSerializer.Deserialize <BooleanExpression>(xmlString);

            element.Interpret(BypassHandler.GetInstance(new DateTime(2017, 4, 15)));

            Assert.AreEqual(expected, element.ValueCalculated);
        }
コード例 #14
0
        public void Rules_Executables_Switch_Condition_check()
        {
            string xml = TestDataXmlReader.GetXmlString("SwitchTestCondition_check.xml");

            var element = TestRuleSerializer.Deserialize <ExecContainer>(xml);

            Assert.IsTrue(element.IsValid);
        }
コード例 #15
0
        public void KKatavasiaRule_Invalid_InvalidName()
        {
            string xmlString = @"<k_katavasia name=""invalid""/>";

            var element = TestRuleSerializer.Deserialize <KKatavasiaRule>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #16
0
        public void YmnosCutomRule_Deserialize(string filePath)
        {
            string xml = TestDataXmlReader.GetXmlString(filePath);

            var element = TestRuleSerializer.Deserialize <YmnosCustomRule>(xml);

            Assert.IsTrue(element.IsValid);
        }
コード例 #17
0
        public void GetClosestDay_RightDayOfWeekName()
        {
            string xmlString = @"<getclosestday dayofweek=""воскресенье"" weekcount=""-2""><date>--11-08</date></getclosestday>";

            var element = TestRuleSerializer.Deserialize <GetClosestDay>(xmlString);

            Assert.Pass("DayOfWeek " + element.DayOfWeek + ", WeekCount " + element.WeekCount);
        }
コード例 #18
0
        public void KKatavasiaRule_Source_Kanonas()
        {
            string xmlString = @"<k_katavasia source=""item1"" kanonas=""orthros1""/>";

            var element = TestRuleSerializer.Deserialize <KKatavasiaRule>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #19
0
        public void KKatavasiaRule_Invalid_Kanonas()
        {
            string xmlString = @"<k_katavasia kanonas=""orthros1""/>";

            var element = TestRuleSerializer.Deserialize <KKatavasiaRule>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #20
0
        public void Notice_WrongAttributes()
        {
            string xmlString = @"<notice time=""11.00""/> ";

            var element = TestRuleSerializer.Deserialize <Notice>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #21
0
        public void KKatavasiaRule_ValidName_FromDB()
        {
            string xmlString = @"<k_katavasia name=""отверзу_уста_моя""/>";

            var element = TestRuleSerializer.Deserialize <KKatavasiaRule>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #22
0
        public void ModifyDay_DateBydaysFromEaster()
        {
            string xmlString = @"<modifyday><datebydaysfromeaster><int>-43</int></datebydaysfromeaster></modifyday>";

            var element = TestRuleSerializer.Deserialize <ModifyDay>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #23
0
        public void Deserialize_Empty()
        {
            string xmlString = $@"<worship id=""moleben"" asaddition=""remove""/>";

            var element = TestRuleSerializer.Deserialize <WorshipRule>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #24
0
        public void TheotokionRule_Valid()
        {
            string xmlString = @"<theotokionrule source=""item1"" place=""kekragaria_theotokion"" count=""3"" startfrom=""2""/>";

            var element = TestRuleSerializer.Deserialize <TheotokionRule>(xmlString);

            Assert.IsTrue(element.IsValid);
        }
コード例 #25
0
        public void ModifyDay_UseFullNameTest()
        {
            string xmlString = @"<modifyday daymove = ""0"" priority=""3""/>";

            var element = TestRuleSerializer.Deserialize <ModifyDay>(xmlString);

            Assert.IsTrue(element.UseFullName);
        }
コード例 #26
0
        public void KAfterRule_InvalidNumber()
        {
            string xmlString = @"<k_after odinumber=""10""></k_after>";

            var element = TestRuleSerializer.Deserialize <KAfterRule>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #27
0
        public void TheotokionRule_SourceANDplaceMismatch()
        {
            string xmlString = @"<theotokionrule source=""irmologion"" place=""kekragaria"" count=""3"" startfrom=""2""/>";

            var element = TestRuleSerializer.Deserialize <TheotokionRule>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #28
0
        public void ModifyDay_Simple()
        {
            string xmlString = @"<modifyday daymove=""0""/>";

            var element = TestRuleSerializer.Deserialize <ModifyDay>(xmlString);

            Assert.AreEqual(0, element.DayMoveCount);
        }
コード例 #29
0
        public void TheotokionRule_ChildRequired()
        {
            string xmlString = @"<theotokionrule source=""irmologion"" place=""app1_aposticha"" count=""3"" startfrom=""2""/>";

            var element = TestRuleSerializer.Deserialize <TheotokionRule>(xmlString);

            Assert.IsFalse(element.IsValid);
        }
コード例 #30
0
        public void ModifyDay_WithinWrongDate()
        {
            string xmlString = @"<modifyday><date>--13-08</date></modifyday>";

            var element = TestRuleSerializer.Deserialize <ModifyDay>(xmlString);

            Assert.IsFalse(element.IsValid);
        }