Example #1
0
 public MainPage()
 {
     InitializeComponent();
     PageProvider = new PageProvider();
     Detail       = PageProvider.Get(typeof(HomePage));
     Menu.ListView.ItemSelected += ListView_ItemSelected;
 }
Example #2
0
        public async Task UGetRecursive(int siteId)
        {
            LogMaxLevel  = 1;
            onlyUtestLog = true;
            SiteAuthorizationHandler.LogDisabled = true;
            PageAuthorizationHandler.LogDisabled = true;
            PostAuthorizationHandler.LogDisabled = true;

            SiteData siteDt = await DbUtil.GetSiteData(siteId);

            foreach (SiteClaim region in siteDt.regions)
            {
                // Create and init the context...
                WcmsAppContext ctx = await CreateAndInitAppContext(null, siteDt.site.Domain, "/", region.StringValue, null, false);

                if (ctx != null)
                {
                    _Log(1, ctx, $">>Checking page recursive get for region={region.StringValue}...");

                    PageProvider       provider = new PageProvider(ctx);
                    IEnumerable <Page> pages    = await provider?.Get(false, null, true);

                    Assert.NotEqual(null, pages);
                    //TODO: Add a check to validate a get with recusion enabled.
                }
            }
        }
Example #3
0
 public MainPage()
 {
     InitializeComponent();
     PageProvider = new PageProvider();
     PageProvider.SetLifeTime(typeof(StatisticPage), PageLifeTime.OneTime);
     Detail = PageProvider.Get(typeof(HomePage));
     Menu.ListView.ItemSelected += ListView_ItemSelected;
 }
Example #4
0
        public void CanGetPageById()
        {
            // Act
            Page r = PageProvider.Get(MyPage.Id);

            // Assert
            Assert.IsNotNull(r);
            Assert.AreEqual(MyPage.Id, r.Id);
            Assert.AreEqual(MyPage.Title, r.Title);
        }
Example #5
0
        public void Test_Add_Get_Updata_Remove()
        {
            var page = new Page(sampleSite, "Test_Add_Get_Updata_Remove")
            {
                HtmlTitle = "htmltitle"
            };

            //添加页面
            pageProvider.Add(page);

            //获取页面
            var actualPage1 = pageProvider.Get(page);

            //断言判断
            Assert.AreEqual(page.AbsoluteName, actualPage1.AbsoluteName);

            Assert.AreEqual(page.Site, actualPage1.Site);

            Assert.AreEqual(page.HtmlTitle, actualPage1.HtmlTitle);

            //修改页面
            actualPage1.HtmlTitle = "Content title1";

            pageProvider.Update(actualPage1, page);
            //重新获取页面
            var actualPage2 = pageProvider.Get(page);

            //修改断言
            Assert.AreEqual(actualPage1.HtmlTitle, actualPage2.HtmlTitle);

            //删除页面
            pageProvider.Remove(page);

            //删除断言
            var actualPage3 = pageProvider.Get(page);

            Assert.IsNull(actualPage3);
        }
Example #6
0
        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = e.SelectedItem as MasterViewMenuItem;

            if (item == null)
            {
                return;
            }

            var detailPage = PageProvider.Get(item.TargetType);

            Detail      = detailPage;
            IsPresented = false;
            Menu.ListView.SelectedItem = null;
        }
Example #7
0
        public void CanGetRecipePage()
        {
            // Arrange
            RecipePage p1 = RecipeBuilder.BuildRecipePage("milkshake");

            // Act
            Page p2 = PageProvider.Get(p1.Id);

            // Assert
            Assert.IsInstanceOf <RecipePage>(p2);
            RecipePage rp2 = (RecipePage)p2;

            Assert.AreEqual(p1.Id, rp2.Id);
            Assert.AreEqual(p1.Title, rp2.Title);
            Assert.AreEqual(p1.PageNo, rp2.PageNo);
            Assert.AreEqual(p1.RecipeId, rp2.RecipeId);
        }
Example #8
0
        public ActionResult showpage(string key, int page)
        {
            Book b      = BookProvider.GetByKey(key);
            Guid pageId = b.PageIds[page - 1];
            Page p      = PageProvider.Get(pageId);

            p.InitializeForView(ObjectResolver);

            PageViewModel result = new PageViewModel
            {
                Book             = b,
                Page             = p,
                PageTemplateName = "PageTemplates/" + p.TemplateName
            };

            return(View(result));
        }
Example #9
0
        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            try
            {
                if (!(e.SelectedItem is MasterViewMenuItem item))
                {
                    return;
                }

                var detailPage = PageProvider.Get(item.TargetType);

                IsPresented = false;
                Detail      = detailPage;
                Menu.ListView.SelectedItem = null;
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.Message);
            }
        }
Example #10
0
        public async Task UGet(int siteId)
        {
            LogMaxLevel  = 1;
            onlyUtestLog = true;
            SiteAuthorizationHandler.LogDisabled = true;
            PageAuthorizationHandler.LogDisabled = true;
            PostAuthorizationHandler.LogDisabled = true;
            int countTest      = 0;
            int countQueryTest = 0;

            SiteData siteDt = await DbUtil.GetSiteData(siteId, true);

            foreach (SiteClaim region in siteDt.regions)
            {
                foreach (ApplicationUser user in siteDt.users)
                {
                    string         role = user.HigherRole();
                    WcmsAppContext ctx  = await CreateAndInitAppContext(null, siteDt.site.Domain, "/", region.StringValue, user, false);

                    if (ctx != null)
                    {
                        string testDesc1 = $"region={region.StringValue}, user={user?.UserName} ({role})";
                        _Log(1, ctx, $">>{++countQueryTest}: Checking page get for {testDesc1}...");

                        PageProvider       provider = new PageProvider(ctx);
                        IEnumerable <Page> pages    = await provider?.Get(false, -1);

                        if (user != null && DbUtil.IsSiteUser(siteId, user) == false)
                        {
                            // User extern to the site: cannot view pages.
                            Assert_Equal <IEnumerable <Page> >(ctx, null, pages, $"Check extern to the site failed: {countQueryTest}: {testDesc1}");
                        }
                        else
                        {
                            Assert.NotEqual(null, pages);
                            Assert.NotEqual(0, pages.Count());
                            foreach (Page page in pages)
                            {
                                string testDesc2 = $"page {page?.Id ?? 0}({countQueryTest}-{++countTest})({page?.Title ?? "null"})";
                                string testDescT = $"{testDesc2}: {testDesc1}";
                                _Log(2, ctx, $"  >Checking {testDesc2}...");
                                if (countTest == 2611)
                                {
                                    int brk = 0;
                                }
                                Assert_NotEqual <Page>(ctx, null, page, $"Null page: {testDescT}");
                                page.RequestSite = ctx.Site;

                                _Log(4, ctx, "     Check site ID...");
                                Assert_Equal <int>(ctx, 1, page.SiteId, $"Check site failed: {testDescT}");
                                _Log(4, ctx, "     Check region...");
                                Assert_Equal <bool>(ctx, true, (page.Region1 == 0 || page.Region1 == ctx.Region.Id) ||
                                                    (page.Region2 == 0 || page.Region2 == ctx.Region.Id) ||
                                                    (page.Region3 == 0 || page.Region3 == ctx.Region.Id) ||
                                                    (page.Region4 == 0 || page.Region4 == ctx.Region.Id) ||
                                                    (page.Region5 == 0 || page.Region5 == ctx.Region.Id) ||
                                                    (page.Region6 == 0 || page.Region6 == ctx.Region.Id) ||
                                                    (page.Region7 == 0 || page.Region7 == ctx.Region.Id) ||
                                                    (page.Region8 == 0 || page.Region8 == ctx.Region.Id) ||
                                                    (page.Region9 == 0 || page.Region9 == ctx.Region.Id) ||
                                                    (page.Region10 == 0 || page.Region10 == ctx.Region.Id), $"Check region failed: {testDescT}");
                                _Log(4, ctx, "     Check for authorization...");
                                Assert_Equal <bool>(ctx, true, ((await ctx.AuthzProvider.AuthorizeAsync(ctx.UserPrincipal, page, new List <OperationAuthorizationRequirement>()
                                {
                                    new OperationAuthorizationRequirement {
                                        Name = AuthorizationRequirement.Read
                                    }
                                }))?.Succeeded ?? false),
                                                    $"Check authorization failed: {testDescT}");
                            }
                        }
                    }
                }
            }
        }