public void ReceiveInteragtionRequest() { var request = new NotificationRequest(); var behavior = new BehaviorMock { NotificationRequest = request }; var page = new PageMock(); page.Behaviors.Add(behavior); request.Raise(); Assert.NotNull(behavior.Sender); Assert.Equal(request, behavior.Sender); Assert.NotNull(behavior.EventArgs); Assert.Equal(EventArgs.Empty, behavior.EventArgs); behavior.Sender = null; behavior.EventArgs = null; page.Behaviors.Clear(); request.Raise(); Assert.Null(behavior.Sender); Assert.Null(behavior.EventArgs); }
public async Task Render_MergedParametersHierarchy() { var conf = new Configuration(); conf.Add("$i1", new Dictionary <string, object>() { { "a1", "S1" }, { "a2", "S2" }, { "a3", "S3" } }); var md = new Metadata(); md.Add("$i1", new Dictionary <string, object>() { { "a1", "P1" }, { "a2", "P2" }, { "a3", "" } }); var p1 = new PageMock("", "", md); var s = new Site("", "", p1, conf); s.Includes.Add(new TemplateMock("i1", "abc", new Metadata() { { "a1", "T1" }, { "a2", "T2" }, { "a3", "" }, { "a4", "T4" } })); var res1 = await m_Handler.ResolveAll("{% i1 { a1: I1, a2:, a4: } %}", s, p1, "/page1/"); Assert.AreEqual("abc_page1.html_a1=I1,a2=P2,a3=S3,a4=T4", res1); }
public void ReceiveEventAfterEventChanged() { var behavior = new BehaviorMock { EventName = "TestEventA" }; var page = new PageMock(); page.Behaviors.Add(behavior); // ChangeEvent behavior.EventName = "TestEventB"; var eventArgs = new EventArgs(); page.RiseTestEventA(this, eventArgs); Assert.Null(behavior.Sender); Assert.Null(behavior.EventArgs); page.RiseTestEventB(this, eventArgs); Assert.NotNull(behavior.Sender); Assert.Equal(this, behavior.Sender); Assert.NotNull(behavior.EventArgs); Assert.Equal(eventArgs, behavior.EventArgs); }
public async Task Compile_ExcludePhantomPage() { var p1 = new PageMock("page1", "p1"); var p2 = new PhantomPageMock("page2"); var p3 = new PageMock("page3", "p3"); var p4 = new PhantomPageMock("page4"); var p5 = new PageMock("page5", "p5"); var p6 = new PageMock("page6", "p6"); p1.SubPages.Add(p2); p1.SubPages.Add(p5); p2.SubPages.Add(p3); p2.SubPages.Add(p4); p4.SubPages.Add(p6); var site = new Site("", "", p1, null); var files = await m_Compiler.Compile(site).ToListAsync(); Assert.AreEqual(4, files.Count); Assert.IsNotNull(files.FirstOrDefault(f => f.Location.ToId() == "index.html")); Assert.IsNotNull(files.FirstOrDefault(f => f.Location.ToId() == "page5::index.html")); Assert.IsNotNull(files.FirstOrDefault(f => f.Location.ToId() == "page2::page3::index.html")); Assert.IsNotNull(files.FirstOrDefault(f => f.Location.ToId() == "page2::page4::page6::index.html")); }
public void ReceiveInteragtionRequestAfterInteractionRequestChanged() { var requestA = new NotificationRequest(); var behavior = new BehaviorMock { NotificationRequest = requestA }; var page = new PageMock(); page.Behaviors.Add(behavior); var requestB = new NotificationRequest(); behavior.NotificationRequest = requestB; requestA.Raise(); Assert.Null(behavior.Sender); Assert.Null(behavior.EventArgs); requestB.Raise(); Assert.NotNull(behavior.Sender); Assert.Equal(requestB, behavior.Sender); Assert.NotNull(behavior.EventArgs); Assert.Equal(EventArgs.Empty, behavior.EventArgs); }
public async Task IncludePageTest() { var p1 = new PageMock("page1", "p1 {% i1 %}"); var p2 = new PageMock("page2", "{% i1 p1: B %} {% i2 p2: X %}"); p1.SubPages.Add(p2); var site = new Site("", "", p1, null); site.Includes.Add(new TemplateMock("i1", "Some Value @Model.Data[\"p1\"] @Model.Page.Url", new Metadata() { { "p1", "A" } })); site.Includes.Add(new TemplateMock("i2", "**@Model.Page.Url** @Model.Data.Count", new Metadata() { { "p1", "A" }, { "p2", "X" } })); var files = await m_Compiler.Compile(site).ToListAsync(); Assert.AreEqual("<p>p1 Some Value A /</p>", files.First(f => f.Location.ToId() == "index.html").AsTextContent()); Assert.AreEqual("<p>Some Value B /page2/ **/page2/** 2</p>", files.First(f => f.Location.ToId() == "page2::index.html").AsTextContent()); }
public AuthenticationServiceTests() { Mock <IElementHandle> elementMock = new Mock <IElementHandle>(); elementMock.Setup(x => x.FocusAsync()) .Returns(Task.Delay(0)); Mock <IKeyboard> keyboardMock = new Mock <IKeyboard>(); keyboardMock.Setup(x => x.PressAsync(It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.Delay(0)); PageMock.Setup(x => x.ClickAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <MouseButton>(), It.IsAny <int>(), It.IsAny <Modifier[]>(), It.IsAny <Point?>(), It.IsAny <int?>(), It.IsAny <bool>(), It.IsAny <bool?>())) .Returns(Task.Delay(0)); PageMock.Setup(x => x.GoToAsync(It.IsAny <string>(), It.IsAny <LifecycleEvent>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.FromResult(default(IResponse))); PageMock.Setup(x => x.QuerySelectorAsync(It.IsAny <string>())) .Returns(Task.FromResult(elementMock.Object)); PageMock.Setup(x => x.CloseAsync(It.IsAny <bool>())) .Callback(() => PageMock.SetupGet(x => x.IsClosed).Returns(true)) .Returns(Task.Delay(1)); PageMock.Setup(x => x.Keyboard) .Returns(keyboardMock.Object); Service = new AuthenticationService(BrowserMock.Object, LoggerMock.Object); }
public async Task NestedTemplatePageTest() { var t2 = new TemplateMock("t2", "*T2* @Model.Page.Url {{ content }}_T2"); var t1 = new TemplateMock("t1", "*T1* @Model.Page.Url {{ content }}_T1", null, t2); var t3 = new TemplateMock("t3", "T3{{ content }}T3"); var t4 = new TemplateMock("t4", "T4{{ content }}T4", null, t3); var p1 = new PageMock("page1", "**Page1** @Model.Page.Url", t1); var p2 = new PageMock("page2", "**Page2** @Model.Page.Url", t1); var p3 = new PageMock("page3", "Page3", t4); var p4 = new PageMock("page4", "Page4", t4); p1.SubPages.Add(p2); p1.SubPages.Add(p3); p1.SubPages.Add(p4); var site = new Site("", "", p1, null); var files = await m_Compiler.Compile(site).ToListAsync(); Assert.AreEqual("*T2* / *T1* / <p><strong>Page1</strong> @Model.Page.Url</p>_T1_T2", files.First(f => f.Location.ToId() == "index.html").AsTextContent()); Assert.AreEqual("*T2* /page2/ *T1* /page2/ <p><strong>Page2</strong> @Model.Page.Url</p>_T1_T2", files.First(f => f.Location.ToId() == "page2::index.html").AsTextContent()); Assert.AreEqual("T3T4<p>Page3</p>T4T3", files.First(f => f.Location.ToId() == "page3::index.html").AsTextContent()); Assert.AreEqual("T3T4<p>Page4</p>T4T3", files.First(f => f.Location.ToId() == "page4::index.html").AsTextContent()); }
public async Task Render_MissingIncludes() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); await AssertException.ThrowsInnerAsync <MissingIncludeException>(() => m_Handler.ResolveAll("{% i2 %}", s, p1, "/page1/")); }
public Site NewSite(string pageContent, string includePath, Metadata pageData = null, Configuration siteConfig = null) { var page = new PageMock("index", pageContent, pageData); var site = new Site("www.example.com", "", page, siteConfig); LoadInclude(includePath, site); return(site); }
public void GetAutowireViewModelShoudBeTrueWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); ViewModelLocator.SetAutowireViewModel(view, true); Assert.True(ViewModelLocator.GetAutowireViewModel(view)); }
protected virtual void SetUpPage() { _page = new PageMock(); _namingContainer = new NamingContainerMock(); _namingContainer.ID = "NamingContainer"; _page.Controls.Add(_namingContainer); _namingContainerInvoker = new ControlInvoker(_namingContainer); }
public void GetAutowireViewModelShoudBeTrueWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); ViewModelLocator.SetAutowireViewModel(view, true); Assert.True(ViewModelLocator.GetAutowireViewModel(view)); }
public void WhenNothingEventName() { var behavior = new BehaviorMock { EventName = "NothingEvent" }; var page = new PageMock(); var exception = Assert.Throws <NotImplementedException>(() => page.Behaviors.Add(behavior)); Assert.NotNull(exception); }
public async Task ReplaceAll_NewLineSingleLineInclude() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); var res = await m_Handler.ResolveAll("abc\r\n{% i1 a1: x %}\r\nxyz", s, p1, "/page1/"); Assert.AreEqual("abc\r\nabc_page1.html_a1=x\r\nxyz", res); }
public async Task IgnorePagesTest() { var site = ComponentsTest.Instance.NewSite("<channel>\r\n{% feed %}\r\n</channel>", INCLUDE_PATH); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1\r\nsitemap: false")); site.MainPage.SubPages.Add(p1); var res = UpdateBuildDate(await ComponentsTest.Instance.CompileMainPageNormalize(site)); Assert.AreEqual(Resources.feed4, res); }
public async Task AutoMenuHomeDefaultTest() { var site = ComponentsTest.Instance.NewSite("<div>\r\n{% toc %}\r\n</div>", INCLUDE_PATH); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1")); site.MainPage.SubPages.Add(p1); var res = await ComponentsTest.Instance.CompileMainPageNormalize(site); Assert.AreEqual(Resources.toc3, res); }
public async Task ReplaceAll_MultilineInlineInclude() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); var res = await m_Handler.ResolveAll("abc{% i1 a1: x\r\na2: y %}xyz", s, p1, "/page1/"); Assert.AreEqual("abcabc_page1.html_a1=x,a2=yxyz", res); }
public async Task Compile_NonDefaultPageTest() { var site = new Site("", "", new PageMock("", "P1"), null); var p2 = new PageMock("page2.html", "P2"); site.MainPage.SubPages.Add(p2); var files = await m_Compiler.Compile(site).ToListAsync(); Assert.AreEqual("CT_P1_CT", files.First(f => f.Location.ToId() == "index.html").AsTextContent()); Assert.AreEqual("CT_P2_CT", files.First(f => f.Location.ToId() == "page2.html").AsTextContent()); }
public async Task ReplaceAll_NestedIncludes() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); s.Includes.Add(new TemplateMock("i2", "xyz{% i1 a1: z %}")); var res1 = await m_Handler.ResolveAll("__{% i1 a1: x %}__{% i2 a2: y %}", s, p1, "/page1/"); Assert.AreEqual("__abc_page1.html_a1=x__xyzabc_page1.html_a1=z_page1.html_a2=y", res1); }
public void ShouldLocateViewModelWithDefaultSettings() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.IsType< PageMockViewModel>(view.BindingContext); }
public async Task CustomTitleTest() { var site = ComponentsTest.Instance.NewSite("<div>\r\n{% toc %}\r\n</div>", INCLUDE_PATH, null, ComponentsTest.Instance.GetData <Configuration>("$toc:\r\n home-menu: false\r\n title-attribute: abc")); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1\r\nabc: x1")); site.MainPage.SubPages.Add(p1); var res = await ComponentsTest.Instance.CompileMainPageNormalize(site); Assert.AreEqual(Resources.toc4, res); }
public void ShouldUseCustomDefaultViewTypeToViewModelTypeResolverWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => typeof(ViewModelLocatorFixture)); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.IsType<ViewModelLocatorFixture>(view.BindingContext); }
public async Task ReplaceAll_NestedMultiLevelIncludes() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); s.Includes.Add(new TemplateMock("i2", "xyz{% i1 a1: z %}")); s.Includes.Add(new TemplateMock("i3", "abc{% i2 %}")); var res1 = await m_Handler.ResolveAll("{% i3 %}__{% i1 %}", s, p1, "/page1/"); Assert.AreEqual("abcxyzabc_page1.html_a1=z_page1.html__page1.html___abc_page1.html_", res1); }
public void ShouldLocateViewModelWithDefaultSettings() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.IsType <PageMockViewModel>(view.BindingContext); }
public async Task IncludeMultilineTest() { var p1 = new PageMock("page1", "abc {% i1 \r\n %}"); var site = new Site("", "", p1, null); site.Includes.Add(new TemplateMock("i1", "Some Value")); var files = await m_Compiler.Compile(site).ToListAsync(); Assert.AreEqual("<p>abc Some Value</p>", files.First(f => f.Location.ToId() == "index.html").Content); }
public async Task FilterPageTest() { var site = ComponentsTest.Instance.NewSite("<div>\r\n{% nav { filter: [ '|*/SubPage1/' ] } %}\r\n</div>", INCLUDE_PATH); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1")); p1.SubPages.Add(new PageMock("SubPage1", "", ComponentsTest.Instance.GetData <Metadata>("title: sp1"))); p1.SubPages.Add(new PageMock("SubPage2", "", ComponentsTest.Instance.GetData <Metadata>("title: sp2"))); site.MainPage.SubPages.Add(p1); site.MainPage.SubPages.Add(new PageMock("Page2", "", ComponentsTest.Instance.GetData <Metadata>("title: p2"))); var res = await ComponentsTest.Instance.CompileMainPageNormalize(site); Assert.AreEqual(Resources.nav6, res); }
public void ShouldUseCustomDefaultViewModelFactoryWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); object mockObject = new object(); ViewModelLocationProvider.SetDefaultViewModelFactory(viewType => mockObject); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.Equal(mockObject, view.BindingContext); }
public async Task DefaultTest() { var site = ComponentsTest.Instance.NewSite("<channel>\r\n{% feed %}\r\n</channel>", INCLUDE_PATH); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1\r\ndescription: desc1")); p1.SubPages.Add(new PageMock("SubPage1", "", ComponentsTest.Instance.GetData <Metadata>("title: sp1"))); p1.SubPages.Add(new PageMock("SubPage2", "", ComponentsTest.Instance.GetData <Metadata>("title: sp2"))); site.MainPage.SubPages.Add(p1); site.MainPage.SubPages.Add(new PageMock("Page2", "", ComponentsTest.Instance.GetData <Metadata>("title: p2"))); var res = UpdateBuildDate(await ComponentsTest.Instance.CompileMainPageNormalize(site)); Assert.AreEqual(Resources.feed1, res); }
public async Task RootPageTest() { var site = ComponentsTest.Instance.NewSite("<div>\r\n{% toc { home-menu: false, root-page: /page1/ } %}\r\n</div>", INCLUDE_PATH); var p1 = new PageMock("Page1", "", ComponentsTest.Instance.GetData <Metadata>("title: p1")); p1.SubPages.Add(new PageMock("SubPage1", "", ComponentsTest.Instance.GetData <Metadata>("title: sp1"))); p1.SubPages.Add(new PageMock("SubPage2", "", ComponentsTest.Instance.GetData <Metadata>("title: sp2"))); site.MainPage.SubPages.Add(p1); site.MainPage.SubPages.Add(new PageMock("Page2", "", ComponentsTest.Instance.GetData <Metadata>("title: p2"))); var res = await ComponentsTest.Instance.CompileMainPageNormalize(site); Assert.AreEqual(Resources.toc5, res); }
public void ShouldUseCustomFactoryWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); string viewModel = "Test String"; ViewModelLocationProvider.Register(view.GetType().ToString(), () => viewModel); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.Equal(viewModel, view.BindingContext); }
public async Task Render_MergedIncludeParameters() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc", new Metadata() { { "a1", "A" }, { "a2", "B" } })); var res1 = await m_Handler.ResolveAll("{% i1 { a1: X, a3: Y} %}", s, p1, "/page1/"); Assert.AreEqual("abc_page1.html_a1=X,a2=B,a3=Y", res1); }
public async Task ReplaceAll_HtmlTagsInclude() { var p1 = new PageMock("", ""); var s = new Site("", "", p1, null); s.Includes.Add(new TemplateMock("i1", "abc")); var res1 = await m_Handler.ResolveAll("<div>{% i1 a1: x %}</div>", s, p1, "/page1/"); var res2 = await m_Handler.ResolveAll("<div>\r\n{% i1 a1: x %}\r\n</div>", s, p1, "/page1/"); Assert.AreEqual("<div>abc_page1.html_a1=x</div>", res1); Assert.AreEqual("<div>\r\nabc_page1.html_a1=x\r\n</div>", res2); }
public void ShouldUseCustomDefaultViewTypeToViewModelTypeResolverWhenSet() { ResetViewModelLocationProvider(); PageMock view = new PageMock(); Assert.Null(view.BindingContext); ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => typeof(ViewModelLocatorFixture)); ViewModelLocator.SetAutowireViewModel(view, true); Assert.NotNull(view.BindingContext); Assert.IsType <ViewModelLocatorFixture>(view.BindingContext); }
public void SetUp() { _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null); HttpContextHelper.SetCurrent(_currentHttpContext); _page = new PageMock(); _page.SetRequestValueCollection(new NameValueCollection()); _currentHttpContext.Handler = _page; _parent = new PlaceHolder(); _parent.ID = "Parent"; _parent.Init += new EventHandler(Control_Init); _parent.Load += new EventHandler(Control_Load); _parent.PreRender += new EventHandler(Control_PreRender); _page.Controls.Add(_parent); _child = new Literal(); _child.ID = "Child"; _child.Init += new EventHandler(Control_Init); _child.Load += new EventHandler(Control_Load); _child.PreRender += new EventHandler(Control_PreRender); _parent.Controls.Add(_child); _invoker = new ControlInvoker(_parent); _pageAfterPostBack = new PageMock(); _pageAfterPostBack.SetRequestValueCollection(new NameValueCollection()); _currentHttpContext.Handler = _pageAfterPostBack; _parentAfterPostBack = new PlaceHolder(); _parentAfterPostBack.ID = "Parent"; _parentAfterPostBack.Init += new EventHandler(Control_Init); _parentAfterPostBack.Load += new EventHandler(Control_Load); _parentAfterPostBack.PreRender += new EventHandler(Control_PreRender); _pageAfterPostBack.Controls.Add(_parentAfterPostBack); _childAfterPostBack = new Literal(); _childAfterPostBack.ID = "Child"; _childAfterPostBack.Init += new EventHandler(Control_Init); _childAfterPostBack.Load += new EventHandler(Control_Load); _childAfterPostBack.PreRender += new EventHandler(Control_PreRender); _parentAfterPostBack.Controls.Add(_childAfterPostBack); _invokerAfterPostBack = new ControlInvoker(_parentAfterPostBack); _events = string.Empty; }