public void ParseSimpleStylesheetWithTwoPagesAndSections_WillSucceed()
        {
            var  stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("emptyStylesheetWithTwoPagesAndSections.qls"), new SymbolTable());
            Node ast            = _parsingService.Process(stylesheetTask).Ast;

            _assertVisitor.EnqueueStylesheetNodeCallback(st =>
            {
                Assert.AreEqual("test", st.Label);
            });
            _assertVisitor.EnqueuePageNodeCallback(p =>
            {
                Assert.AreEqual("testPage", p.Label);
            });
            _assertVisitor.EnqueuePageNodeCallback(p =>
            {
                Assert.AreEqual("nextPage", p.Label);
            });
            _assertVisitor.EnqueueSectionNodeCallback(s =>
            {
                Assert.AreEqual("testSection", s.Label);
            });
            _assertVisitor.EnqueueSectionNodeCallback(s =>
            {
                Assert.AreEqual("nextSection", s.Label);
            });
            ast.Accept(_assertVisitor);
            _assertVisitor.VerifyAll();
        }
        public void StyleSheetWithDuplicateReference_OneErrorFound()
        {
            // Arrange
            var stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("onePageStylesheetDuplicateQuestion.qls"), new SymbolTable());

            // Act
            _parsingService.Process(stylesheetTask);

            // Assert
            Assert.AreEqual(1, stylesheetTask.Errors.Count);
            Assert.AreEqual("Reference error in line 5: \"questionOne\" was already defined.", stylesheetTask.Errors[0]);
        }
        public void ParseSimpleStylesheetWithOnePageOneSectionOneQuestionAndWidget_WillSucceed()
        {
            var  stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("onePageStylesheetWithQuestionAndWidget.qls"), new SymbolTable());
            Node ast            = _parsingService.Process(stylesheetTask).Ast;

            _assertVisitor.EnqueueWidgetNodeCallback(w =>
            {
                Assert.AreEqual("Radio", w.Widget.ToString());
            });
            ast.Accept(_assertVisitor);
            _assertVisitor.VerifyAll();
        }
Example #4
0
        public void RadioWidgetWithIntegerQuestion_OneTypeErrorFound()
        {
            // Arrange
            var QLquestions = new SymbolTable();

            QLquestions.Add(new Symbol("questionOne", QLType.Integer, null));
            var stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("onePageStylesheetWithQuestionAndWidget.qls"), QLquestions);

            // Act
            _parsingService.Process(stylesheetTask);

            // Assert
            Assert.AreEqual(1, stylesheetTask.Errors.Count);
            Assert.AreEqual("Type error in line 5: The type of \"questionOne\" (Integer) is not compatible with the type of the widget (Radio).", stylesheetTask.Errors[0]);
        }
Example #5
0
        public void StyleSheetWithMissingReference_OneErrorFound()
        {
            // Arrange
            var QLquestions = new SymbolTable();

            QLquestions.Add(new Symbol("a", QLType.Undefined, null));
            var stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("emptyStylesheetWithOnePage.qls"), QLquestions);

            // Act
            _parsingService.Process(stylesheetTask);

            // Assert
            Assert.AreEqual(1, stylesheetTask.Errors.Count);
            Assert.AreEqual("Reference error in line 0 of the QL file: No style was defined for \"a\" in QLS.", stylesheetTask.Errors[0]);
        }
Example #6
0
        private List <PageViewModel> CreatePaginatedFormFromStylesheet(IReadOnlyList <QuestionViewModel> questions)
        {
            var            stylesheetTask      = new StylesheetTask(_mainViewModel.StylesheetInput, _symbols);
            StylesheetTask processedStylesheet = _stylesheetPipeline.Process(stylesheetTask);

            if (processedStylesheet.Errors.Any())
            {
                _mainViewModel.QuestionnaireValidation = processedStylesheet.Errors.Aggregate(
                    $"Validation failed! There are {processedStylesheet.Errors.Count} error(s) in your questionnaire stylesheet.",
                    (err, acc) => err + Environment.NewLine + acc);
                return(new List <PageViewModel>());
            }

            var stylesheetVisitor = new StylesheetVisitor(questions);

            processedStylesheet.Ast.Accept(stylesheetVisitor);

            return(stylesheetVisitor.PageViewModels);
        }
        public void ParseSimpleStylesheetWithOnePageOneSectionOneQuestion_WillSucceed()
        {
            var  stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("onePageStylesheetWithQuestion.qls"), new SymbolTable());
            Node ast            = _parsingService.Process(stylesheetTask).Ast;

            _assertVisitor.EnqueueStylesheetNodeCallback(st =>
            {
                Assert.AreEqual("test", st.Label);
            });
            _assertVisitor.EnqueuePageNodeCallback(p =>
            {
                Assert.AreEqual("testPage", p.Label);
            });
            _assertVisitor.EnqueueQuestionNodeCallback(q =>
            {
                Assert.AreEqual("questionOne", q.Label);
            });
            ast.Accept(_assertVisitor);
            _assertVisitor.VerifyAll();
        }
        public void ParseOptionWidgetWithCustomText_WillSucceed()
        {
            var  stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("optionWidgetTest.qls"), new SymbolTable());
            Node ast            = _parsingService.Process(stylesheetTask).Ast;

            _assertVisitor.EnqueueWidgetNodeCallback(w =>
            {
                Assert.AreEqual("Radio", w.Widget.ToString());
            });
            _assertVisitor.EnqueueWidgetOptionNodeCallback(o =>
            {
                Assert.AreEqual("Good", o.Label);
            });
            _assertVisitor.EnqueueWidgetOptionNodeCallback(o =>
            {
                Assert.AreEqual("Evil", o.Label);
            });
            ast.Accept(_assertVisitor);
            _assertVisitor.VerifyAll();
        }
        public void ParseStylesheetWithALocalStyleAndAllProperties_WillSucceed()
        {
            var  stylesheetTask = new StylesheetTask(TestDataResolver.LoadTestFile("stylesheetWithOneQuestionAndLocalStyle.qls"), new SymbolTable());
            Node ast            = _parsingService.Process(stylesheetTask).Ast;

            _assertVisitor.EnqueueQuestionNodeCallback(q =>
            {
                Assert.AreEqual("questionOne", q.Label);
            });
            _assertVisitor.EnqueuePropertyNodeCallback(p =>
            {
                Assert.AreEqual("width", p.Name);
                Assert.AreEqual("400", p.Value);
            });
            _assertVisitor.EnqueuePropertyNodeCallback(p =>
            {
                Assert.AreEqual("font", p.Name);
                Assert.AreEqual("Arial", p.Value);
            });
            _assertVisitor.EnqueuePropertyNodeCallback(p =>
            {
                Assert.AreEqual("fontsize", p.Name);
                Assert.AreEqual("14", p.Value);
            });
            _assertVisitor.EnqueuePropertyNodeCallback(p =>
            {
                Assert.AreEqual("color", p.Name);
                Assert.AreEqual("#999999", p.Value);
            });
            _assertVisitor.EnqueueWidgetNodeCallback(p =>
            {
                Assert.AreEqual("Spinbox", p.Widget.ToString());
            });
            ast.Accept(_assertVisitor);
            _assertVisitor.VerifyAll();
        }