Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void OrthrosTest_DeserializeFull()
        {
            string xml = TestDataXmlReader.GetXmlString("OrthrosTest_DeserializeFull.xml");

            TypiconSerializer ser     = new TypiconSerializer();
            Orthros           element = ser.Deserialize <Orthros>(xml);

            Assert.NotNull(element.SedalenKathisma1);
            Assert.NotNull(element.SedalenKathisma2);
            Assert.NotNull(element.SedalenKathisma3);
            Assert.NotNull(element.SedalenPolyeleos);

            Assert.AreEqual(element.Megalynarion.Count, 1);
            Assert.AreEqual(element.Eclogarion.Count, 17);
            Assert.AreEqual(element.Prokeimenon.Ihos, 3);

            Assert.NotNull(element.Evangelion);
            Assert.AreEqual(element.Evangelion.Count, 1);

            Assert.AreEqual(element.Sticheron50.Ymnis.Count, 1);
            Assert.AreEqual(element.Kanones.Count, 3);
            Assert.NotNull(element.SedalenKanonas);

            Assert.AreEqual(1, element.Kontakia.Count);
            Assert.AreEqual(1, element.Exapostilarion.Ymnis.Count);
            Assert.NotNull(element.Exapostilarion.Theotokion);

            Assert.NotNull(element.Ainoi);
            Assert.IsNull(element.Aposticha);
        }
        public void IAsAdditionElement_Rewrite()
        {
            var factory = new RuleHandlerSettingsTestFactory();

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

            var additionalSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml);

            xml = TestDataXmlReader.GetXmlString("AsAdditionRewrite2.xml");

            var mainSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml, additionalSettings);

            var handler = new IsAdditionTestHandler()
            {
                Settings = mainSettings
            };

            //mainSettings.RuleContainer.Interpret(handler);

            WorshipRule worshipRule = (mainSettings.RuleContainer as ExecContainer).ChildElements[0] as WorshipRule;

            var kanonasRule = worshipRule.Sequence.GetChildElements <KanonasRule>(mainSettings).FirstOrDefault();

            Assert.IsNotNull(kanonasRule);

            kanonasRule.AfterRules[0].Interpret(handler);

            var result = handler.GetResult();

            Assert.IsNotNull(result.FirstOrDefault(c => c is EktenisRule));
        }
        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);
        }
        public void YmnosCutomRule_Deserialize(string filePath)
        {
            string xml = TestDataXmlReader.GetXmlString(filePath);

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

            Assert.IsTrue(element.IsValid);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void RuleElement_Validate()
        {
            string xmlString = TestDataXmlReader.GetXmlString("BusinessConstraintTest.xml");

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

            Assert.IsFalse(element.IsValid);
            Assert.Pass(element.GetBrokenConstraints()[0].ConstraintFullDescription);
        }
Exemplo n.º 9
0
        public void VariableSynchronizer_Test()
        {
            string xml = TestDataXmlReader.GetXmlString("VariablesTest.xml");

            var dbContext = TypiconDbContextFactory.Create();

            var entity = dbContext.Set <Sign>().FirstOrDefault(c => c.TypiconVersionId == 1);

            entity.RuleDefinition = xml;

            entity.SyncRuleVariables(TestRuleSerializer.CreateCollectorSerializerRoot());

            Assert.IsTrue(entity.TypiconVersion.TypiconVariables.Count == 2);
        }
        public void YmnosStructureRule_FromRealDB()
        {
            DateTime date = new DateTime(2017, 11, 09);
            string   xml  = TestDataXmlReader.GetXmlString("YmnosStructureRuleTest.xml");

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = RuleHandlerSettingsTestFactory.Create(1, date, xml)
            };

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

            ruleContainer.Interpret(handler);

            Assert.AreEqual(3, ruleContainer.Structure.YmnosStructureCount);
            Assert.Pass(ruleContainer.Structure.YmnosStructureCount.ToString());
        }
Exemplo n.º 11
0
        public void KanonasRule_FromDB()
        {
            DateTime date = new DateTime(2017, 11, 11);
            string   xml  = TestDataXmlReader.GetXmlString("KanonasRuleTest.xml");

            ServiceSequenceHandler handler = new ServiceSequenceHandler()
            {
                Settings = RuleHandlerSettingsTestFactory.Create(1, date, xml)
            };

            handler.ClearResult();
            KanonasRule kanonasRule = TestRuleSerializer.Deserialize <KanonasRule>(xml);

            kanonasRule.Interpret(handler);

            Assert.AreEqual(4, kanonasRule.Odes[0].Kanones.Count());
        }
        public void WorshipVariables_Test()
        {
            string xml = TestDataXmlReader.GetXmlString("WorshipVariableTest_Rule.xml");

            //получаем контейнер с VariableWorshipRules
            var ruleContainer = VariablesSerializerRoot.Container <RootContainer>().Deserialize(xml);

            var handler = new ScheduleHandler();

            //Интерпретируем
            ruleContainer.Interpret(handler);

            //в итоге получаем определенные worships
            var worships = handler.GetResults();

            Assert.AreEqual(1, worships.DayBefore.Count);
            Assert.AreEqual(2, worships.ThisDay.Count);
        }
Exemplo n.º 13
0
        public void YmnosCutomRule_InStructureTheotokion()
        {
            string xml = TestDataXmlReader.GetXmlString("YmnosCutomRuleTest_InStructureTheotokion.xml");

            var settings = new RuleHandlerSettingsTestFactory().CreateSettings(1, new DateTime(2017, 11, 09), xml);

            var mockFactory = new Mock <IRuleHandler>();

            mockFactory.Setup(c => c.Execute((It.IsAny <ICustomInterpreted>())));
            mockFactory.Setup(c => c.IsTypeAuthorized(It.IsAny <ICustomInterpreted>())).Returns(true);
            mockFactory.SetupProperty(c => c.Settings, settings);

            KekragariaRule element = TestRuleSerializer.Deserialize <KekragariaRule>(xml);

            element.Interpret(mockFactory.Object);

            Assert.AreEqual(1, element.Structure.Theotokion[0].Ymnis.Count);
        }
        public void TypiconImportProjectorTest_Import()
        {
            var manager = new TypiconImportProjector(
                new CollectorSerializerRoot(
                    QueryProcessorFactory.Create()
                    , new TypiconSerializer()));

            var xml = TestDataXmlReader.GetXmlString("TypiconVersion.xml");

            var projection = new TypiconSerializer().Deserialize <TypiconVersionProjection>(xml);

            var entity = manager.Project(projection);

            var vars = entity.Value.Versions.First().TypiconVariables;

            Assert.AreEqual(3, vars.Count);
            Assert.Pass(string.Join('\n', vars.Select(c => c.Name)));
        }
Exemplo n.º 15
0
        public void TheotokionRule_FromRealDB()
        {
            var factory = new RuleHandlerSettingsTestFactory();

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

            var settings = factory.CreateSettings(1, new DateTime(2017, 01, 16), xml);

            //Дата --01-16 exists - false
            var handler = new ServiceSequenceHandler()
            {
                Settings = settings
            };

            KekragariaRule rule = (settings.RuleContainer as ExecContainer).ChildElements[0] as KekragariaRule;

            rule.Interpret(handler);

            Assert.AreEqual(3, rule.Structure.YmnosStructureCount);
            Assert.AreEqual(1, rule.Structure.Theotokion[0].Ymnis.Count);
        }
Exemplo n.º 16
0
        public void YmnosRule_AllPlaces()
        {
            string xmlRule = TestDataXmlReader.GetXmlString("YmnosRuleTest_AllPlaces.xml");
            string xmlText = TestDataXmlReader.GetXmlString("YmnosRuleTest_AllPlaces_Worship.xml");

            var handler = new IsAdditionTestHandler();

            foreach (PlaceYmnosSource place in Enum.GetValues(typeof(PlaceYmnosSource)))
            {
                var xmlModRule = xmlRule.Replace("[place]", place.ToString());
                handler.Settings = CreateFakeSettings(xmlModRule, xmlText);

                var rule = (handler.Settings.RuleContainer as ExecContainer).ChildElements[0] as KekragariaRule;

                rule.Interpret(handler);

                Assert.AreEqual(1, rule.Structure.YmnosStructureCount, $"Groups. place={place.ToString()}");
                Assert.AreEqual(1, rule.Structure.Doxastichon.Ymnis.Count, $"Doxastichon. place={place.ToString()}");
                Assert.AreEqual(1, rule.Structure.Theotokion[0].Ymnis.Count, $"Theotokion. place={place.ToString()}");
            }
        }
        public void TypiconImportProjectorTest_Import_To_Db()
        {
            var manager = new TypiconImportProjector(
                new CollectorSerializerRoot(
                    QueryProcessorFactory.Create()
                    , new TypiconSerializer()));

            var xml = TestDataXmlReader.GetXmlString("TypiconVersion.xml");

            var projection = new TypiconSerializer().Deserialize <TypiconVersionProjection>(xml);

            var entity = manager.Project(projection);

            var dbContext = TypiconDbContextFactory.Create();

            dbContext.Set <TypiconEntity>().Add(entity.Value);
            int i = dbContext.SaveChanges();

            Assert.Greater(i, 0);
            Assert.Pass(i.ToString());
        }
Exemplo n.º 18
0
        public void LessDate()
        {
            string xml = TestDataXmlReader.GetXmlString("LessDateTest.xml");

            var settings = new RuleHandlerSettings()
            {
                Date = new DateTime(2017, 02, 08)
            };

            var handler = new IsAdditionTestHandler()
            {
                Settings = settings
            };

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

            ruleContainer.Interpret(handler);

            var result = handler.GetResult();

            Assert.AreEqual(1, result.Count());
        }
Exemplo n.º 19
0
        public void Docx_FromFile()
        {
            var xml = TestDataXmlReader.GetXmlString("DocxViewerWeek.xml");

            var queryProcessor = new Mock <IQueryProcessor>();

            queryProcessor.Setup(c => c.Process(It.IsAny <PrintWeekTemplateQuery>()))
            .Returns(GetPrintWeekTemplate());

            queryProcessor.Setup(c => c.Process(It.IsAny <PrintDayTemplateQuery>()))
            .Returns <PrintDayTemplateQuery>(q => GetDayWeekTemplate(q.Number));

            var ser  = new TypiconSerializer();
            var week = ser.Deserialize <FilteredOutputWeek>(xml);

            var viewer = new DocxFromOutputTemplatesWeekViewer(queryProcessor.Object);

            var result = viewer.Execute(1, week);

            File.WriteAllBytes(GetPath($"PrintWeekTemplate.docx"), result.Value.Content);

            Assert.IsTrue(result.Success);
        }
        public void IAsAdditionElement_Append()
        {
            var factory = new RuleHandlerSettingsTestFactory();

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

            var additionalSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml);

            xml = TestDataXmlReader.GetXmlString("AsAdditionAppend1.xml");

            var mainSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml, additionalSettings);

            var handler = new IsAdditionTestHandler()
            {
                Settings = mainSettings
            };

            mainSettings.RuleContainer.Interpret(handler);

            var result = handler.GetResult();

            Assert.AreEqual(3, result.Count(c => c is KOdiRule));
        }
Exemplo n.º 21
0
        public void DBContextEvents_Test()
        {
            var dbContext = TypiconDbContextFactory.CreateWithEvents();

            var sign = dbContext.Set <Sign>().First();

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

            sign.ModRuleDefinition = xml;

            dbContext.SaveChanges();

            var template8 = dbContext.Set <PrintDayTemplate>()
                            .FirstOrDefault(c => c.TypiconVersionId == sign.TypiconVersionId &&
                                            c.Number == 8);

            var template10 = dbContext.Set <PrintDayTemplate>()
                             .FirstOrDefault(c => c.TypiconVersionId == sign.TypiconVersionId &&
                                             c.Number == 10);

            Assert.IsTrue(template8.SignPrintLinks.Where(c => c.EntityId == sign.Id).Count() == 1 &&
                          template10 != null);
        }
        public void ViewModelSerialization_Deserialize()
        {
            var factory = new RuleHandlerSettingsTestFactory();

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

            var settings = factory.CreateSettings(1, new DateTime(2017, 11, 13), xml);

            var handler = new ServiceSequenceHandler()
            {
                Settings = settings
            };

            settings.RuleContainer.Interpret(handler);

            var viewModel = handler.ActualWorshipChildElements;

            var serializer = new TypiconSerializer();

            var result = serializer.Serialize(viewModel);

            Assert.IsNotEmpty(result);
            Assert.Pass(result);
        }
        public void IAsAdditionElement_Remove()
        {
            var factory = new RuleHandlerSettingsTestFactory();

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

            var additionalSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml);

            xml = TestDataXmlReader.GetXmlString("AsAdditionRemove1.xml");

            var mainSettings = factory.CreateSettings(1, new DateTime(2017, 11, 09), xml, additionalSettings);

            var handler = new IsAdditionTestHandler()
            {
                Settings = mainSettings
            };

            mainSettings.RuleContainer.Interpret(handler);

            var result = handler.GetResult();

            Assert.AreEqual(4, result.Count(c => c is KOdiRule));
            Assert.IsNull(result.FirstOrDefault(c => c is KOdiRule && (c as KOdiRule).Number == 1));
        }