コード例 #1
0
 public void Should_Return_Collection()
 {
     var dataContext = new Mock<IAtomicCmsDataRepository>();
     var logger = new Mock<LoggingService>();
     ICollection<PageTag> pagesTagsCollection = new List<PageTag>();
     CmsPage page1 = new CmsPage(){Id = 1};
     CmsPage page2 = new CmsPage(){Id = 2};
     CmsPage page3 = new CmsPage(){Id = 3};
     CmsTag tag1 = new CmsTag() { Id = 1 };
     CmsTag tag2 = new CmsTag() { Id = 2 };
     CmsTag tag3 = new CmsTag() { Id = 3 };
     pagesTagsCollection.Add(new PageTag(){Page = page1, Tag = tag1});
     pagesTagsCollection.Add(new PageTag() { Page = page1, Tag = tag2 });
     pagesTagsCollection.Add(new PageTag() { Page = page2, Tag = tag1 });
     pagesTagsCollection.Add(new PageTag() { Page = page2, Tag = tag3 });
     pagesTagsCollection.Add(new PageTag() { Page = page3, Tag = tag1 });
     pagesTagsCollection.Add(new PageTag() { Page = page3, Tag = tag2 });
     dataContext.Setup(x => x.GetPagesTags()).Returns(pagesTagsCollection);
     WidgetService widgetService = new WidgetService(dataContext.Object, logger.Object);
     var c = new WidgetsController(widgetService);
     ActionResult ar = c.TagCloud();
     var view = ar as PartialViewResult;
     Assert.IsNotNull(view);
     Assert.IsNotEmpty((ICollection) view.ViewData.Model);
     ICollection<TagCount> tagCounts = view.ViewData.Model as ICollection<TagCount>;
     Assert.IsNotNull(tagCounts);
     Assert.AreEqual(3, tagCounts.Count);
     Assert.AreEqual(3, new List<TagCount>(tagCounts)[0].Count);
     Assert.AreEqual(2, new List<TagCount>(tagCounts)[1].Count);
     Assert.AreEqual(1, new List<TagCount>(tagCounts)[2].Count);
 }
コード例 #2
0
 private void UpdatePageStatus(CmsPage page, IValueProvider valueProvider)
 {
     int pageStatusId;
     if (Int32.TryParse(valueProvider.GetValue("Page.Status.Id").AttemptedValue, out pageStatusId))
     {
         Status pageStatus = pageService.LoadPageType(pageStatusId);
         page.Status = pageStatus;
     }
 }
コード例 #3
0
 private void AddHomePage(Sitemap sitemap, CmsPage page, string homePage)
 {
     var url = new SitemapUrl();
     url.Location = homePage;
     url.ChangeFrequency = CalculateFrequency(page.ModifiedAt);
     url.Priority = 0.9;
     url.LastModified = page.ModifiedAt.ToString();
     sitemap.Insert(0,
                    url);
 }
コード例 #4
0
 public void Should_Permanent_redirect_if_wrong_alias_provided_for_page_id()
 {
     int pageId = 3;
     var expectedPage = new CmsPage {Id = pageId, Alias = "expected-alias"};
     pageData.Setup(x => x.Load(pageId)).Returns(expectedPage);
     var result = c.Content(pageId, "this-is-wrong_alias") as LegacyUrl301Result;
     Assert.IsNotNull(result);
     string expectedUrl = expectedPage.GetUrl();
     Assert.AreEqual(expectedUrl, result.NewUrl);
 }
コード例 #5
0
        public static MvcHtmlString PageTitle(this HtmlHelper hh, CmsPage page)
        {
            if (hh.IsDefaultPage())
            {
                return MvcHtmlString.Create(page.PageTitle);
            }

            return hh.ActionLink(page.PageTitle,
                                 "Content",
                                 "Home",
                                 new {area = "", id = page.Id, name = page.Alias},
                                 new {title = page.PageTitle});
        }
コード例 #6
0
 public static MvcHtmlString ActionPageLink(this HtmlHelper hh, CmsPage p)
 {
     return hh.ActionLink(p.PageTitle, "Content", "Home",
                          new { id = p.Id, name = p.Alias, area = "" },
                          new {title = p.PageTitle});
 }
コード例 #7
0
 private ActionResult ShowPage(CmsPage entry)
 {
     return View("Index", entry);
 }
コード例 #8
0
 private ActionResult ShowPage(string page, CmsPage entry)
 {
     return View(page, entry);
 }
コード例 #9
0
 public void Save(CmsPage entry, string identity)
 {
     entry.ModifiedAt = DateTime.Now;
     FillTags(entry);
     EnsureFieldsAreFilled(entry);
     entry.Author = userData.Find(identity);
     pageData.Save(entry);
 }
コード例 #10
0
        private void FillTags(CmsPage page)
        {
            if (null == page)
            {
                return;
            }

            page.Tags.Clear();

            if (null != page.TagString && !string.IsNullOrEmpty(page.TagString.AttemptedValue))
            {
                string[] tags = page.TagString.AttemptedValue.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
                foreach (string tag in tags)
                {
                    string tagName = tag.Trim();
                    if (string.IsNullOrEmpty(tagName))
                        continue;
                    CmsTag cmsTag = pageData.LoadTag(tagName);
                    if (null != cmsTag && !page.Tags.Contains(cmsTag))
                    {
                        page.Tags.Add(cmsTag);
                    }
                    else
                    {
                        IEnumerable<CmsTag> alreadyCreated = page.Tags.Where(x => x.Name == tag.Trim());
                        if (alreadyCreated.Count() == 0)
                        {
                            page.Tags.Add(new CmsTag {Name = tag.Trim()});
                        }
                    }
                }
            }
        }
コード例 #11
0
        private void EnsureFieldsAreFilled(CmsPage entry)
        {
            if (string.IsNullOrEmpty(entry.SeoTitle))
            {
                entry.SeoTitle = entry.PageTitle;
            }

            if (string.IsNullOrEmpty(entry.MetaKeywords))
            {
                entry.MetaKeywords = entry.Tags.ToTagString();
            }

            if (string.IsNullOrEmpty(entry.MetaDescription))
            {
                entry.MetaDescription = entry.PageTitle;
            }
        }
コード例 #12
0
 public void CreateEntry(CmsPage entry, string userName)
 {
     entry.ModifiedAt = DateTime.Now;
     entry.CreatedAt = DateTime.Now;
     entry.Author = userData.Find(userName);
     EnsureFieldsAreFilled(entry);
     pageData.Save(entry);
 }
コード例 #13
0
 private bool IsDefaultPage(CmsPage page, int homePageId)
 {
     return page.Id == homePageId;
 }