Ejemplo n.º 1
0
        public void FindByPublished_Should_Return_Paged_Result()
        {
            using (BeginTransaction())
            {
                GenerateStories(true, false, true);

                _database.SubmitChanges();

                var pagedResult = _storyRepository.FindPublished(0, 5);

                Assert.Equal(5, pagedResult.Result.Count);
                Assert.Equal(10, pagedResult.Total);
            }
        }
        public void FindByPublished_Should_Return_Paged_Result()
        {
            var story1 = CreateStory();
            var story2 = CreateStory();
            var story3 = CreateStory();

            var rnd = new Random();

            Stories.AddRange(new[] { story1 as Story, story2 as Story, story3 as Story });

            Stories.ForEach(s => s.Publish(SystemTime.Now().AddDays(-rnd.Next(1, 5)), rnd.Next(1, 10)));

            var pagedResult = _storyRepository.FindPublished(0, 10);

            Assert.Equal(3, pagedResult.Result.Count);
            Assert.Equal(3, pagedResult.Total);
        }
Ejemplo n.º 3
0
        private HandlerCacheItem GetNewsSiteMap(HttpContextBase context)
        {
            const string DateFormat = "yyyy-MM-ddThh:mm:ssZ";
            const string CacheKey   = "newsSitemap";

            Log.Info("Generating {0}".FormatWith(CacheKey));

            HandlerCacheItem cacheItem;

            Cache.TryGet(CacheKey, out cacheItem);

            if (cacheItem == null)
            {
                XElement urlSet = new XElement(_ns + "urlset", new XAttribute("xmlns", _ns.ToString()), new XAttribute(XNamespace.Xmlns + "news", _googleNews.ToString()));

                PagedResult <IStory> pagedResult = StoryRepository.FindPublished(0, 1000); // Google only supports 1000 story

                int i = 0;

                foreach (IStory story in pagedResult.Result)
                {
                    SiteMapUpdatePriority priority = (i < 50) ? SiteMapUpdatePriority.Critical : SiteMapUpdatePriority.Normal;

                    AddStoryInNewsSiteMap(context, urlSet, story, priority, DateFormat);

                    i += 1;
                }

                XDocument doc = new XDocument();
                doc.Add(urlSet);

                cacheItem = new HandlerCacheItem {
                    Content = doc.ToXml()
                };

                if ((CacheDurationInMinutes > 0) && (!Cache.Contains(CacheKey)))
                {
                    Cache.Set(CacheKey, cacheItem, SystemTime.Now().AddMinutes(CacheDurationInMinutes));
                }
            }

            Log.Info("{0} generated".FormatWith(CacheKey));

            return(cacheItem);
        }
Ejemplo n.º 4
0
        private void AddStoriesInRegularSiteMap(HttpContextBase context, bool forMobile, XContainer target)
        {
            Action <IStory> addStory = story => target.Add(CreateEntry(context, Settings.RootUrl, "Detail", new { name = story.UniqueName }, story.LastActivityAt, SiteMapChangeFrequency.Weekly, SiteMapUpdatePriority.Critical, forMobile));

            ICollection <IStory> publishedStories = StoryRepository.FindPublished(0, PublishedStoryMaxCount).Result;

            foreach (IStory story in publishedStories)
            {
                addStory(story);
            }

            ICollection <IStory> upcomingStories = StoryRepository.FindUpcoming(0, UpcomingStoryMaxCount).Result;

            foreach (IStory story in upcomingStories)
            {
                addStory(story);
            }
        }