public void HandleDynamicContentShould_ReturnUnchangedPageIfItErrors() { //Arrange var myPage = new PageVM() { PageId = "TestPage", PageName = "", DynamicContent = new DynamicContentVM() { DefaultAction = "This will return an error" }, Questions = new List <QuestionVM>() { new QuestionVM() { QuestionId = "Test Question" } } }; //Act var sut = DynamicContentHelpers.HandleDynamicContent(myPage, formContext); //Assert sut.Should().BeEquivalentTo(myPage); }
public void EvaluateConditionShould_ErrorIfNoAnswerSupplied() { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Answer = null } }; //Act + Assert var ex = Assert.Throws <NullReferenceException>(() => DynamicContentHelpers.EvaluateCondition(condition, formContext)); ex.Message.Should().Contain("Object reference not set to an instance of an object"); }
public void EvaluateConditionShould_ErrorIfVariableNotFound() { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Source = "formData", Variable = "not-a-formData-id", Answer = "" } }; //Act + Assert var ex = Assert.Throws <Exception>(() => DynamicContentHelpers.EvaluateCondition(condition, formContext)); ex.Message.Should().Contain("Unable to resolve dynamic content variable"); }
public void EvaluateConditionShould_ErrorIfVariableSourceUnrecognised() { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Source = "not-a-source", Answer = "" } }; //Act + Assert var ex = Assert.Throws <ArgumentException>(() => DynamicContentHelpers.EvaluateCondition(condition, formContext)); ex.Message.Should().Contain("Unrecognised variable source type"); }
public void EvaluateConditionShould_ErrorIf_OperatorIsGreaterOrLessThan_AndVariableOrAnswerCannotBeParsedToFloat(string variable, string Operator, string answer) { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Source = "answer", Variable = variable, Operator = Operator, Answer = answer } }; //Act + Assert var ex = Assert.Throws <ArgumentException>(() => DynamicContentHelpers.EvaluateCondition(condition, formContext)); ex.Message.Should().Contain("cannot be parsed to float"); }
public void EvaluateConditionShould_ErrorIfOperatorUnrecognised() { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Source = "answer", Variable = "page1-question1", Operator = "not-an-operator", Answer = "" } }; //Act + Assert var ex = Assert.Throws <ArgumentException>(() => DynamicContentHelpers.EvaluateCondition(condition, formContext)); ex.Message.Should().Contain("Unrecognised logic operator"); }
public void EvaluateConditionShould_ReturnFalse(string source, string variable, string Operator, string answer) { //Arrange var condition = new ConditionVM() { Logic = new LogicVM() { Source = source, Variable = variable, Operator = Operator, Answer = answer } }; //Act var sut = DynamicContentHelpers.EvaluateCondition(condition, formContext); //Assert sut.Should().BeFalse(); }
public void HandleDynamicContentShould_ReturnSamePageIf_NoDynamicContent() { //Arrange var myPage = new PageVM() { PageId = "TestPage", PageName = "Test page", Questions = new List <QuestionVM>() { new QuestionVM() { QuestionId = "Test Question" } } }; //Act var sut = DynamicContentHelpers.HandleDynamicContent(myPage, formContext); //Assert sut.Should().BeEquivalentTo(myPage); }
public ContentPagesAdminModule(IDocumentSession session) : base("ContentPages") { Get["/"] = p => { var list = session.Advanced.LoadStartingWith <ContentPage>(DocumentPrefix + ContentPage.FullContentPageId(string.Empty), null, 0, 25); return(View["List", list.ToArray()]); }; Get["/create/"] = p => View["Edit", new ContentPage { ContentType = DynamicContentType.Markdown }]; Post["/create/"] = p => { var cp = this.Bind <ContentPage>(); var pageId = ContentPage.FullContentPageId(DynamicContentHelpers.TitleToSlug(cp.Title)); var page = session.Load <ContentPage>(pageId); if (page != null) { //ModelState.AddModelError("Id", "Page already exists for the slug you're trying to create it under"); return(View["Edit", cp]); } session.Store(cp, pageId); session.SaveChanges(); return(Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug))); }; Get["/edit/{slug}"] = p => { var cp = session.Load <ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string)p.slug)); if (cp == null) { return(404); } return(View["Edit", cp]); }; Post["/edit/{slug}"] = p => { var input = this.Bind <ContentPage>(); if (input.Id != (string)p.slug) { return("<h1>Error</h1><p>Slugs mismatch</p>"); } var cp = session.Load <ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string)p.slug)); if (cp == null) { return(404); } cp.Content = input.Content; cp.ContentType = input.ContentType; cp.Title = input.Title; cp.LastChanged = DateTimeOffset.Now; return(Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug))); }; // Post["/delete/{slug}"] = p => // { // // }; }