Inheritance: INotifyPropertyChanged
        public void PageStackDefault()
        {
            PageStack stack = new PageStack();

            stack.RegisterDefaultRoute("home", () => new Page());
            Assert.IsNull(stack.CurrentPage);
            stack.Navigate("");
            Assert.IsNotNull(stack.CurrentPage);
        }
Exemple #2
0
        internal void Compose()
        {
            var  pageStack = (Application as ConsolePageApp).PageStack;
            bool hadFocus  = this.Controls.Where(c => c.HasFocus).Count() > 0;

            this.Controls.Clear();

            string builtUpPath = "";

            foreach (var s in PageStack.GetSegments(pageStack.CurrentPath))
            {
                string myPath;

                if (builtUpPath == "")
                {
                    builtUpPath = s;
                    myPath      = s;
                }
                else
                {
                    var label = Add(new Label()
                    {
                        Mode = LabelRenderMode.SingleLineAutoSize, Text = "->".ToConsoleString(DefaultColors.H1Color)
                    });
                    builtUpPath += "/" + s;
                    myPath       = builtUpPath;
                }

                var crumb = Add(new BreadcrumbElement(() => { pageStack.TryNavigate(myPath); })
                {
                    Text = s.ToConsoleString()
                });
                crumb.Width = 10;
                if (hadFocus && builtUpPath.Contains("/") == false)
                {
                    var worked = crumb.TryFocus();
                }
            }

            this.Width = Layout.StackHorizontally(1, this.Controls);
        }
        public void PageStackBasic()
        {
            PageStack stack = new PageStack();

            bool observableWorked = false;

            PropertyChangedEventHandler firstChecker = (sender, e) =>
            {
                if(e.PropertyName != nameof(PageStack.CurrentPage))
                {
                    return;
                }

                Assert.IsNotNull(stack.CurrentPage);
                Assert.AreEqual(0, stack.CurrentPage.RouteVariables.Count);
                observableWorked = true;
            };

            stack.PropertyChanged += firstChecker;
            stack.RegisterRoute("Home", () => new Page());
            stack.Navigate("Home");
            Assert.IsTrue(observableWorked);
            stack.PropertyChanged -= firstChecker;

            try
            {
                stack.Navigate("BadRoute");
                Assert.Fail("An exception should have been thrown");
            }
            catch (KeyNotFoundException)
            {

            }

            stack.RegisterRoute("Applications/{ApplicationId}/Components/{ComponentId}", () => new Page());

            stack.Navigate("Applications/foo/Components/bar");
            Assert.IsTrue(stack.CurrentPage.RouteVariables.Count == 2);
            Assert.AreEqual("foo", stack.CurrentPage.RouteVariables["ApplicationId"]);
            Assert.AreEqual("bar", stack.CurrentPage.RouteVariables["ComponentId"]);
        }
 public ConsolePageApp(IEnumerable <string> markupFiles)
 {
     InitCommon();
     MarkupParser.Parse(this, markupFiles);
     PageStack.Navigate("");
 }
 private void ExpectGoodRoute(string goodRoute)
 {
     PageStack stack = new PageStack();
     stack.RegisterRoute(goodRoute, () => new Page());
 }
 private void ExpectBadRoute(string badRoute)
 {
     PageStack stack = new PageStack();
     try
     {
         stack.RegisterRoute(badRoute, () => new Page());
         Assert.Fail("An exception should have been thrown for bad route: "+ badRoute);
     }
     catch (FormatException) { }
 }