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);
        }
Exemplo n.º 2
0
        public void CalculateOutputFormYearJob_Success()
        {
            var date = new DateTime(2019, 2, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();

            var yearHandler = CalculateModifiedYearJobHandlerTest.Build(dbContext, jobRepo);
            var yearJob     = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(yearJob);

            Task task = yearHandler.ExecuteAsync(yearJob);

            task.Wait();

            var weekHandler = Build(dbContext, jobRepo);
            var weekJob     = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(weekJob);

            task = weekHandler.ExecuteAsync(weekJob);
            task.Wait();

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(true, week.Success);
        }
Exemplo n.º 3
0
        public void CalculateOutputFormYearJob_Failed()
        {
            var date = new DateTime(2019, 9, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();
            var handler   = Build(dbContext, jobRepo);

            var job = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(job);

            var task = handler.ExecuteAsync(job);

            task.Wait();

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(false, week.Success);
        }
        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);
        }
        public void BooksXmlExportManagerTest_Export()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var manager = new BooksXmlExportManager(dbContext);

            var result = manager.Export();

            Assert.IsNotNull(result.Value);
        }
Exemplo n.º 6
0
        public void Validate_FromDB()
        {
            var dbContext = TypiconDbContextFactory.Create();

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

            var errs = version.GetBrokenConstraints(TestRuleSerializer.Create());

            Assert.AreEqual(errs.Count, 0);
        }
        public void TypiconExportProjectorTest_Export()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var typicon = dbContext.Set <TypiconVersion>().FirstOrDefault();

            var manager = new TypiconExportProjector();

            var projection = manager.Project(typicon);

            Assert.IsNotNull(projection.Value);
        }
        public void BooksXmlExportManagerTest_Serialize()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var booksProjector = new BooksProjector(dbContext);

            var projection = booksProjector.Project();

            var serializer = new TypiconSerializer();

            var xml = serializer.Serialize(projection);

            Assert.IsNotNull(xml);
        }
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 CalculateModifiedYearJob_Test()
        {
            var dbContext  = TypiconDbContextFactory.Create();
            var jobRepo    = new JobRepository();
            var jobHandler = Build(dbContext, jobRepo);

            var job = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(job);

            var task = jobHandler.ExecuteAsync(job);

            task.Wait();

            Assert.AreEqual(0, jobRepo.GetAll().Count());
        }
        public void ReloadRulesJob_Test(bool isTrue, TypiconVersionStatus status)
        {
            var context = TypiconDbContextFactory.Create();

            var jobRepo = new JobRepository();

            var handler = new ReloadRulesJobHandler(GetConfigRepo(), context, jobRepo);

            var job = new ReloadRulesJob(1, status);

            jobRepo.Create(job);

            var task = handler.ExecuteAsync(job);

            task.Wait();

            Assert.AreEqual(0, jobRepo.GetAll().Count());
        }
Exemplo n.º 12
0
        public void ValidateMenologyRule()
        {
            var dbContext    = TypiconDbContextFactory.Create();
            var menologyRule = dbContext.Set <MenologyRule>().FirstOrDefault();

            menologyRule.RuleDefinition = @"<rule><worship1></rule>";
            dbContext.Set <MenologyRule>().Update(menologyRule);
            dbContext.SaveChanges();

            var job = new ValidateMenologyRuleJob(menologyRule.Id);

            var jobRepo = new JobRepository(job);

            var processor = CommandProcessorFactory.CreateJobProcessor(dbContext, jobRepo);

            processor.ExecuteAsync(job);

            Assert.IsTrue(true);
        }
Exemplo n.º 13
0
        public async Task HostingService_OutputForm()
        {
            var date = new DateTime(2019, 2, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();

            var yearHandler = CalculateModifiedYearJobHandlerTest.Build(dbContext, jobRepo);
            var yearJob     = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(yearJob);

            Task task = yearHandler.ExecuteAsync(yearJob);

            task.Wait();

            var weekHandler = CalculateOutputFormWeekJobTest.Build(dbContext, jobRepo);
            var weekJob     = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(weekJob);

            task = weekHandler.ExecuteAsync(weekJob);
            task.Wait();

            var service = new JobAsyncHostedService(jobRepo, CommandProcessorFactory.Create(dbContext));

            await service.StartAsync(CancellationToken.None);

            while (jobRepo.GetAll().Count() > 0)
            {
                Thread.Sleep(50);
            }

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(true, week.Success);
        }
        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.º 15
0
        public void CloneTypiconVersion_CommonRules()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var version = dbContext.Set <TypiconVersion>()
                          .Include(c => c.CommonRules)
                          .AsNoTracking()
                          .FirstOrDefault();

            int countBefore = 1;// dbContext.Set<TypiconVersion>().Count();

            var clone = version.Clone(deep: true);

            clone.TypiconId = 1;

            dbContext.Set <TypiconVersion>().Add(clone);
            dbContext.SaveChanges();

            int countAfter = dbContext.Set <TypiconVersion>().Count();

            Assert.AreEqual(countAfter, countBefore + 1);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        private OutputDayFactory Build()
        {
            var dbContext = TypiconDbContextFactory.Create();

            var query = DataQueryProcessorFactory.Create(dbContext);

            var serializerRoot = TestRuleSerializer.Create(dbContext);

            var settingsFactory = new RuleHandlerSettingsFactory(serializerRoot);

            var dataCalculator = new ExplicitDataCalculator(query,
                                                            new AsAdditionDataCalculator(query,
                                                                                         new TransparentDataCalculator(query,
                                                                                                                       new MajorDataCalculator(query, settingsFactory)
                                                                                                                       , settingsFactory)
                                                                                         , settingsFactory)
                                                            , settingsFactory);

            return(new OutputDayFactory(dataCalculator
                                        , new ScheduleDayNameComposer(query)
                                        , serializerRoot.TypiconSerializer
                                        , new ServiceSequenceHandler()));
        }