예제 #1
0
        public void Validate_Should_Return_Error_WhenSummarySection_Has_NoPages_Defined_InSection()
        {
            // Arrange
            var section = new Section
            {
                Title = "section title"
            };

            var element = new ElementBuilder()
                          .WithType(EElementType.Summary)
                          .withSummarySection(section)
                          .Build();

            var page1 = new PageBuilder()
                        .WithPageSlug("test-page")
                        .WithElement(element)
                        .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page1)
                         .Build();

            // Act
            var result = _validator.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.Single(result.Messages);
            Assert.Equal($"{IntegrityChecksConstants.FAILURE}FormSchemaIntegrityCheck::SummaryFormCheck, Summary section is defined but no pages have been specified to appear in the section.", result.Messages.First());
        }
예제 #2
0
        public JsonResult Edit()
        {
            IDictionary <string, object> data = Request.Form.ToDictionary();
            string key          = Request.Form[NamingCenter.PARAM_KEY_NAME];
            string pageId       = Request.QueryString[NamingCenter.PARAM_PAGE_ID];
            string ctrlId       = Request.QueryString[NamingCenter.PARAM_CTRL_ID];
            string formViewMode = Request.Form[NamingCenter.PARAM_FORM_VIEW_MODE];
            var    page         = PageBuilder.BuildPage(pageId);

            if (page == null)
            {
                throw new FoxOneException("Page_Not_Found");
            }
            var form = page.FindControl(ctrlId) as Form;

            if (form == null)
            {
                throw new FoxOneException("Ctrl_Not_Found");
            }
            var ds          = form.FormService as IFormService;
            int effectCount = 0;

            if (formViewMode.Equals(FormMode.Edit.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                effectCount = ds.Update(key, data);
            }
            else
            {
                effectCount = ds.Insert(data);
            }
            return(Json(effectCount > 0));
        }
        public async Task RenderAsync_ShouldCallGenerateDocumentUploadUrl_Base64StringCaseRef()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.DocumentUpload)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>();

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();

            //Act
            await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x.Equals("DocumentUpload")), It.IsAny <DocumentUpload>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.GenerateDocumentUploadUrl(It.IsAny <Element>(), It.IsAny <FormSchema>(), It.IsAny <FormAnswers>()), Times.Once);
        }
        public async Task Build_ShouldDeleteCacheEntry()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .Build();

            var guid = new Guid();

            // Act
            await _factory.Build(string.Empty, formSchema, guid.ToString(), new FormAnswers(), EBehaviourType.SubmitForm);

            // Assert
            _mockSessionHelper.Verify(_ => _.RemoveSessionGuid(), Times.Once);
            _mockDistributedCache.Verify(_ => _.Remove(It.Is <string>(x => x == guid.ToString())), Times.Once);
        }
예제 #5
0
        private static string AddDetails(string htmlpath, string imagePath, string name)
        {
            Directory.CreateDirectory(imagePath);

            eWolfBootstrap.Interfaces.IPageBuilder pageBuilder = new PageBuilder();

            pageBuilder.Append($"<hr/>");

            pageBuilder.Append($"<h2>{name}</h2>");

            string        path   = Constants.RawDataPath + $@"Catalog\{name}";
            List <string> images = ImageHelper.GetAllImages(path);

            pageBuilder.Append("<div class='container mt-4'><div class='row'>");
            int count = 2;

            foreach (string layoutImage in images)
            {
                if (images.Contains(layoutImage))
                {
                    HTMLHelper.AddImageToPage(htmlpath, imagePath, pageBuilder, layoutImage);
                    if (count-- == 0)
                    {
                        count = 2;
                        pageBuilder.Append("</div></div>");
                        pageBuilder.Append("<div class='container mt-4'><div class='row'>");
                    }
                }
            }
            pageBuilder.Append("</div></div>");
            return(pageBuilder.GetString());
        }
예제 #6
0
        public async Task <RuntimeResult> SeeMessageHistory(ulong messageId)
        {
            var db = Program.Services.GetRequiredService <MsgService>();

            using var DB = Program.Services.GetRequiredService <LogContext>();
            var dbMsg = DB.Messages.FirstOrDefault(x => x.MessageId == db.cast(messageId));

            if (dbMsg == null)
            {
                return(new BotResult("Message is not in database."));
            }
            var contents = db.GetContents(messageId).OrderBy(x => x.Timestamp);

            var url       = $"https://discord.com/channels/{dbMsg.Guild}/{dbMsg.Channel}/{dbMsg.Message}";
            var paginator = new StaticPaginatorBuilder()
                            .WithDefaultEmotes()
                            .WithFooter(PaginatorFooter.PageNumber);

            foreach (var content in contents)
            {
                var page = new PageBuilder()
                           .WithTitle($"Message at {content.Timestamp:dd/MM/yyyy HH:mm:ss}")
                           .WithText(url)
                           .WithDescription(content.Content);
                paginator.AddPage(page);
            }

            await PagedReplyAsync(paginator);

            return(new BotResult());
        }
예제 #7
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        contributors = CreateTestList();


        // instance reporting engine
        // assign parameters

        ReportEngine engine = new ReportEngine();

        string reportPath = Server.MapPath("ContributorList.srd");

        ReportModel reportModel = ReportEngine.LoadReportModel(reportPath);

        PageBuilder pageBuilder = engine.CreatePageBuilder(reportModel, contributors);

        pageBuilder.BuildExportList();
        string outputPath = Server.MapPath("ContributorList.pdf");

        // render report
        PdfRenderer pdfRenderer =
            PdfRenderer.CreateInstance(pageBuilder.Pages, outputPath, false);

        pdfRenderer.Start();
        pdfRenderer.RenderOutput();
        pdfRenderer.End();

        // send report to the client
        Response.ContentType = "Application/pdf";
        Response.WriteFile(outputPath);
        Response.End();
    }
예제 #8
0
        public void Parse_ShouldCallFormatter_WhenProvided()
        {
            var expectedString = "this value should be formatted: FAKE-FORMATTED-VALUE";

            var element = new ElementBuilder()
                          .WithType(EElementType.P)
                          .WithPropertyText("this value should be formatted: {{FORMDATA:firstname:testformatter}}")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formAnswers = new FormAnswers
            {
                AdditionalFormData = new Dictionary <string, object>
                {
                    { "firstname", "testfirstname" }
                }
            };

            var result = _tagParser.Parse(page, formAnswers);

            Assert.Equal(expectedString, result.Elements.FirstOrDefault().Properties.Text);
            _mockFormatter.Verify(_ => _.Parse(It.IsAny <string>()), Times.Once);
        }
        public void Parse_ShouldReturnUpdatedValue_WhenReplacingSingleValue()
        {
            var expectedString = "this value testfirstname should be replaced with name question";

            var element = new ElementBuilder()
                          .WithType(EElementType.P)
                          .WithPropertyText("this value {{QUESTION:firstname}} should be replaced with name question")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formAnswers = new FormAnswers
            {
                Pages = new List <PageAnswers>
                {
                    new PageAnswers
                    {
                        Answers = new List <Answers>
                        {
                            new Answers
                            {
                                QuestionId = "firstname",
                                Response   = "testfirstname"
                            }
                        }
                    }
                }
            };

            var result = _tagParser.Parse(page, formAnswers);

            Assert.Equal(expectedString, result.Elements.FirstOrDefault().Properties.Text);
        }
예제 #10
0
        public async Task RenderAsync_ShouldCall_ElementHelper_ToGetCurrentValue_ForAddressFields()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.AddressManual)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { AddressManualConstants.POSTCODE, "sk11aa" }
            };

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();
            //Act
            var result = await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x == "AddressManual"), It.IsAny <form_builder.Models.Elements.AddressManual>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.CurrentValue(It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormAnswers>(), It.IsAny <string>()), Times.Exactly(4));
        }
예제 #11
0
        public void CheckUploadedFilesSummaryQuestionsIsSet_ShouldThrowException_WhenElementDoNotContain_Required_Text()
        {
            // Arrange
            var pages = new List <Page>();

            var element = new ElementBuilder()
                          .WithType(EElementType.UploadedFilesSummary)
                          .WithPropertyText(string.Empty)
                          .WithFileUploadQuestionIds(new List <string> {
                ""
            })
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page)
                         .Build();

            // Act
            var check  = new UploadedFilesSummaryQuestionsIsSetCheck();
            var result = check.Validate(element);

            // Assert
            Assert.False(result.IsValid);
            Assert.Collection <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message));
        }
예제 #12
0
        public async Task ProcessStreet_Application_ShouldThrowApplicationException_WhenStreetProvider_ThrowsException()
        {
            _streetProvider.Setup(_ => _.SearchAsync(It.IsAny <string>())).Throws <Exception>();
            var fakeStreetProvider = EStreetProvider.Fake.ToString();

            var element = new ElementBuilder()
                          .WithType(EElementType.Street)
                          .WithQuestionId("street")
                          .WithStreetProvider(fakeStreetProvider)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .WithValidatedModel(true)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "Guid", Guid.NewGuid().ToString() },
                { "subPath", "" },
                { element.Properties.QuestionId, "streetname" },
            };

            var result = await Assert.ThrowsAsync <ApplicationException>(() => _service.ProcessStreet(viewModel, page, schema, "", "page-one"));

            _streetProvider.Verify(_ => _.SearchAsync(It.IsAny <string>()), Times.Once);
            _pageHelper.Verify(_ => _.GenerateHtml(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()), Times.Never);
            Assert.StartsWith($"StreetService::ProccessInitialStreet: An exception has occured while attempting to perform street lookup on Provider '{fakeStreetProvider}' with searchterm 'streetname' Exception:", result.Message);
        }
예제 #13
0
        private static void BuildDetails(PageBuilder pageBuilderMain, ILayoutPagesDetails detail)
        {
            if (!detail.Active)
            {
                return;
            }

            var detailBuilder = new PageBuilder();

            detailBuilder.Append($"<hr/>");
            detailBuilder.Append(detail.Title);
            detailBuilder.Append(detail.When.ToShortDateString());

            detailBuilder.Append(detail.Details.ToString());

            if (!string.IsNullOrWhiteSpace(detail.YouTubeLink))
            {
                string youTubeLink = $"https://www.youtube.com/embed/{detail.YouTubeLink}";
                detailBuilder.Append(AddYoutubePreview(youTubeLink));
            }

            if (!string.IsNullOrWhiteSpace(detail.ExportImagePath))
            {
                Directory.CreateDirectory(detail.ExportImagePath);
                detailBuilder.AddImages(Constants.FullMyLayouts, detail.ExportImagePath, detail.RawImagePath);
            }

            pageBuilderMain.Append(detailBuilder.GetString());
        }
        public void Build()
        {
            Directory.CreateDirectory(HtmlPath);

            _pageBuilder = new PageBuilder(HtmlFileName, LocalPath, CreateHeader(StationLocations), "../../");

            _pageBuilder.Append(NavBarHelper.NavBar("../../"));
            AddBreadCrumb(this);

            _pageBuilder.Append("<div class='container mt-4'>");
            Jumbotron(PageTitle, StationLocations);

            string path = Constants.RawDataPath + @"Stations\GCR-Rothley\Gallery";

            Add_Gallrey(HtmlPath, HtmlPath + "images\\", path);

            _pageBuilder.Append("</div>");
            _pageBuilder.Append("</div>");

            _pageBuilder.Append(HTMLRailHelper.Modal());

            _pageBuilder.Append("<script src='../../Scripts/script.js'></script>");

            _pageBuilder.Output();
        }
예제 #15
0
        public void GetNextPage_ShouldReturn_Behaviour_WhenIsNullOrEmpty_Condition_False()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToExternalPage)
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.GoToPage)
                             .WithCondition(new Condition {
                IsNullOrEmpty = false, QuestionId = "test", ConditionType = ECondition.IsNullOrEmpty
            })
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { "test", "value" }
            };

            // Act
            var result = page.GetNextPage(viewModel);

            // Assert
            Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType);
        }
예제 #16
0
        public void ConditionalElementsAreValidCheck_IsNotValid_NoConditionalElement(
            EElementType elementType,
            string conditionalElementId)
        {
            // Arrange
            var option1 = new Option {
                ConditionalElementId = conditionalElementId, Value = "Value1"
            };
            var element1 = new ElementBuilder()
                           .WithType(elementType)
                           .WithOptions(new List <Option> {
                option1
            })
                           .Build();

            var page = new PageBuilder()
                       .WithElement(element1)
                       .Build();

            var schema = new FormSchemaBuilder()
                         .WithPage(page)
                         .WithName("test-name")
                         .Build();

            // Act
            ConditionalElementCheck check = new();
            var result = check.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.All <string>(result.Messages, message => Assert.StartsWith(IntegrityChecksConstants.FAILURE, message));
        }
예제 #17
0
        public void CheckPageMeetsConditions_ShouldReturnFalse_If_RenderConditionsAreNotValid()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithPageSlug("page-continue")
                            .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithRenderConditions(new Condition
            {
                QuestionId      = "testRadio",
                ConditionType   = ECondition.EqualTo,
                ComparisonValue = "yes"
            })
                       .Build();

            var viewModel = new Dictionary <string, dynamic>();

            // Act
            var result = page.CheckPageMeetsConditions(viewModel);

            // Assert
            Assert.False(result);
        }
예제 #18
0
        public void Parse_ShouldReturnUpdatedValue_WhenReplacingSingleValue()
        {
            var expectedString = "this value testfirstname should be replaced with name question";

            var element = new ElementBuilder()
                          .WithType(EElementType.P)
                          .WithPropertyText("this value {{FORMDATA:firstname}} should be replaced with name question")
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var formAnswers = new FormAnswers
            {
                AdditionalFormData = new Dictionary <string, object>
                {
                    { "firstname", "testfirstname" }
                }
            };

            var result = _tagParser.Parse(page, formAnswers);

            Assert.Equal(expectedString, result.Elements.FirstOrDefault().Properties.Text);
        }
예제 #19
0
        public void GetNextPage_ShouldThrowException_WhenNoConditions_Match_WithCorrect_Confition_Log()
        {
            // Arrange
            var pageSlug  = "est-page";
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithCondition(new Condition {
                EqualTo = "apple", QuestionId = "otherquestion"
            })
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.SubmitAndPay)
                             .WithCondition(new Condition {
                EqualTo = "peach", QuestionId = "otherquestiontwo"
            })
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .WithPageSlug(pageSlug)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "otherquestion", "pear" }
            };

            // Act
            var result = Assert.Throws <ApplicationException>(() => page.GetNextPage(viewModel));

            // Assert
            Assert.Equal($"Page::GetNextPage, There was a problem whilst processing behaviors for page '{pageSlug}', Behaviour Answers and conditions: QuestionId: otherquestiontwo with answer 'null' QuestionId: otherquestion with answer pear", result.Message);
        }
예제 #20
0
        public async Task RenderAsync_ShouldCall_PageHelper_ToGetCurrentValue()
        {
            //Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.Map)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>();

            var schema = new FormSchemaBuilder()
                         .WithName("form-name")
                         .Build();

            var formAnswers = new FormAnswers();

            //Act
            await element.RenderAsync(
                _mockIViewRender.Object,
                _mockElementHelper.Object,
                string.Empty,
                viewModel,
                page,
                schema,
                _mockHostingEnv.Object,
                formAnswers);

            //Assert
            _mockIViewRender.Verify(_ => _.RenderAsync(It.Is <string>(x => x.Equals("Map")), It.IsAny <Map>(), It.IsAny <Dictionary <string, object> >()), Times.Once);
            _mockElementHelper.Verify(_ => _.CurrentValue <object>(It.IsAny <string>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormAnswers>(), It.IsAny <string>()), Times.Once);
        }
예제 #21
0
        public void GetNextPage_ShouldReturn_Behaviour_WhenCheckboxContains_Condition_True()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToExternalPage)
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.GoToPage)
                             .WithCondition(new Condition {
                CheckboxContains = "value", QuestionId = "test"
            })
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { "test", "value" }
            };

            // Act
            var result = page.GetNextPage(viewModel);

            // Assert
            Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType);
        }
예제 #22
0
        /// <summary>
        /// Let's just create a prototype of this layout, so we can use it more easily.
        /// Don't worry too much about the `HSelectivelyCacheableElement`. You'll learn more about that in the Caching tutorial.
        /// </summary>
        /// <param name="elements">the elements displayed on the page</param>
        /// <param name="filename">the filename to display</param>
        /// <returns>the page includig all layout elements</returns>
        internal static HSelectivelyCacheableElement GetPage(IEnumerable <HElement> elements, string filename)
        {
            // Create the page
            var page = new PageBuilder("LamestWebserver Reference")
            {
                StylesheetLinks = { "/style.css" } // <- Slash in front of the style.css tells the browser to always look for the files in the top directory
            };

            // Add the main-Container with all the elements and the footer
            page.AddElements(
                new HContainer()
            {
                Class    = "main",
                Elements = elements.ToList(),

                // We'll take a look at what this does in the Caching tutorial.
                CachingType = LamestWebserver.Caching.ECachingType.Cacheable
            },
                new HContainer()
            {
                Class    = "footer",
                Elements =
                {
                    new HImage("/lwsfooter.png"),     // <- Slash in front of the lwsfooter.png tells the browser to always look for the files in the top directory
                    new HText(filename + "\nLamestWebserver Reference v" + typeof(MainPage).Assembly.GetName().Version)
                },

                // We'll take a look at what this does in the Caching tutorial.
                CachingType = LamestWebserver.Caching.ECachingType.Cacheable
            });

            return(page);
        }
예제 #23
0
        public void GetNextPage_ShouldReturn_CorrectBehaviour_When_MixedConditions_Submit_And_EqualTo()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithCondition(new Condition {
                EqualTo = "apple", QuestionId = "test"
            })
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.SubmitForm)
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { "test", "apple" }
            };

            // Act
            var result = page.GetNextPage(viewModel);

            // Assert
            Assert.Equal(EBehaviourType.GoToPage, result.BehaviourType);
        }
        public async Task Build_ShouldReturn_Correct_StartPageUrl()
        {
            // Arrange
            var element = new ElementBuilder()
                          .WithType(EElementType.H2)
                          .Build();

            var page = new PageBuilder()
                       .WithElement(element)
                       .WithPageSlug("page-one")
                       .Build();

            var formSchema = new FormSchemaBuilder()
                             .WithStartPageUrl("page-one")
                             .WithBaseUrl("base-test")
                             .WithPage(page)
                             .Build();

            _mockPageContentFactory
            .Setup(_ => _.Build(It.IsAny <Page>(), It.IsAny <Dictionary <string, dynamic> >(), It.IsAny <FormSchema>(), It.IsAny <string>(), It.IsAny <FormAnswers>(), It.IsAny <List <object> >()))
            .ReturnsAsync(new FormBuilderViewModel());

            _mockPageHelper
            .Setup(_ => _.GetPageWithMatchingRenderConditions(It.IsAny <List <Page> >()))
            .Returns((Page)null);

            // Act
            var result = await _factory.Build(string.Empty, formSchema, string.Empty, new FormAnswers(), EBehaviourType.SubmitForm);

            // Assert
            Assert.Equal(formSchema.StartPageUrl, result.StartPageUrl);
        }
예제 #25
0
        public void GetNextPage_ShouldReturn_SubmitBehaviour_WhenMultipleSubmitForms()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.SubmitForm)
                            .WithPageSlug("submit-one")
                            .WithCondition(new Condition {
                EqualTo = "apple", QuestionId = "test"
            })
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.SubmitForm)
                             .WithPageSlug("submit-two")
                             .WithCondition(new Condition {
                CheckboxContains = "pear", QuestionId = "test"
            })
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .Build();

            var viewModel = new Dictionary <string, dynamic> {
                { "test", "pear" }
            };

            // Act
            var result = page.GetNextPage(viewModel);

            // Assert
            Assert.Equal(EBehaviourType.SubmitForm, result.BehaviourType);
            Assert.Equal("submit-two", result.PageSlug);
        }
예제 #26
0
        public void Validate_Should_Return_Error_WhenSummarySection_IsMissingTitle()
        {
            // Arrange
            var section = new Section
            {
                Pages = new List <string> {
                    "test-page"
                }
            };

            var element = new ElementBuilder()
                          .WithType(EElementType.Summary)
                          .withSummarySection(section)
                          .Build();

            var page1 = new PageBuilder()
                        .WithPageSlug("test-page")
                        .WithElement(element)
                        .Build();

            var schema = new FormSchemaBuilder()
                         .WithName("test-name")
                         .WithPage(page1)
                         .Build();

            // Act
            var result = _validator.Validate(schema);

            // Assert
            Assert.False(result.IsValid);
            Assert.Single(result.Messages);
            Assert.Equal($"{IntegrityChecksConstants.FAILURE}FormSchemaIntegrityCheck::SummaryFormCheck, Summary section is defined but section title is empty. Please add a title for the section.", result.Messages.First());
        }
예제 #27
0
        public void GetNextPage_ShouldReturn_BehaviourSubmit_WhenMix_OfMultipleEqualAndCheckbox_WithinSameBehaviour()
        {
            // Arrange
            var behaviour = new BehaviourBuilder()
                            .WithBehaviourType(EBehaviourType.GoToPage)
                            .WithCondition(new Condition {
                EqualTo = "apple", QuestionId = "test"
            })
                            .WithCondition(new Condition {
                CheckboxContains = "berry", QuestionId = "data"
            })
                            .Build();

            var behaviour2 = new BehaviourBuilder()
                             .WithBehaviourType(EBehaviourType.SubmitForm)
                             .Build();

            var page = new PageBuilder()
                       .WithBehaviour(behaviour)
                       .WithBehaviour(behaviour2)
                       .Build();

            var viewModel = new Dictionary <string, dynamic>
            {
                { "test", "pear" },
                { "data", "berry" }
            };

            // Act
            var result = page.GetNextPage(viewModel);

            // Assert
            Assert.Equal(EBehaviourType.SubmitForm, result.BehaviourType);
        }
예제 #28
0
        public async Task <Operation <IPage <TObject> > > GetAsync(string query         = null, SortOptions sort    = null,
                                                                   PageOptions page     = null, FieldOptions fields = null,
                                                                   FilterOptions filter = null, ProjectionOptions projection = null)
        {
            _db.SetTypeInfo(typeof(TObject));

            if (sort == null || sort == SortOptions.Empty)
            {
                sort = SortOptions.FromType <TObject>(x => x.Id);
            }

            if (page == null || page == PageOptions.Empty)
            {
                page = new PageOptions {
                    Page = 1, PerPage = _options.CurrentValue.PerPageDefault
                }
            }
            ;

            var sql  = _dialect.Build <TObject>(sort, fields, filter, projection);
            var data = (await _db.Current.QueryAsync <TObject>(PageBuilder.Page(_dialect, sql),
                                                               new { page.Page, page.PerPage })).AsList();
            var total = await _db.Current.ExecuteScalarAsync <long>(_dialect.Count(_descriptor, filter?.Fields));

            var slice = new Page <TObject>(data, data.Count, page.Page - 1, page.PerPage, total);

            return(new Operation <IPage <TObject> >(slice));
        }
        public void Build()
        {
            Directory.CreateDirectory(LocalPath);

            _pageBuilder = new PageBuilder("index.html", LocalPath, CreateHeader(), "../");

            _pageBuilder.Append(NavBarHelper.NavBar("../"));
            _pageBuilder.Append("<div class='container mt-4'>");
            _pageBuilder.Append(Jumbotron());
            _pageBuilder.Append("<div class='row mb-2'>");

            _pageBuilder.Append("<div class='container mt-4'>");
            _pageBuilder.Append("<p>Free to use clips for anything you like.</p>");
            _pageBuilder.Append("<p>More to follow.</p>");
            _pageBuilder.Append("</br>");
            _pageBuilder.Append("<div class='row mb-2'>");

            foreach (var detail in _details)
            {
                string youTubeLink = $"https://www.youtube.com/embed/{detail.YouTubeLink}";
                _pageBuilder.Append(AddYoutubePreview(youTubeLink));
            }

            _pageBuilder.Output();
        }
예제 #30
0
        public JsonResult Delete()
        {
            string key    = Request.Form[NamingCenter.PARAM_KEY_NAME];
            string pageId = Request.Form[NamingCenter.PARAM_PAGE_ID];
            string ctrlId = Request.Form[NamingCenter.PARAM_CTRL_ID];
            var    page   = PageBuilder.BuildPage(pageId);

            if (page == null)
            {
                throw new FoxOneException("Page_Not_Found");
            }
            var table = page.FindControl(ctrlId) as Table;

            if (table == null)
            {
                throw new FoxOneException("Ctrl_Not_Found");
            }
            var ds = table.DataSource as IFormService;

            if (key.IndexOf(",") > 0)
            {
                var keys = key.Split(',');
                int i    = 0;
                foreach (var k in keys)
                {
                    i += ds.Delete(k);
                }
                return(Json(i == keys.Length));
            }
            return(Json(ds.Delete(key) > 0));
        }
 //
 // GET: /Widget/
 public ActionResult Index(string id)
 {
     var pageBuilder = new PageBuilder(new WidgetCatalog());
     var model = pageBuilder.BuildPage(id);
     return View(model);
 }