public void Ctor_WithAllNonNullArgs_SetsProperties()
        {
            //arrange
            var            requestContext   = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData());
            var            urlHelper        = new UrlHelper(requestContext, new RouteCollection());
            ObjectProvider objectRepository = new Mock <ObjectProvider>().Object;
            var            blog             = new Blog();

            //act
            var subtextContext = new SubtextContext(blog, requestContext, urlHelper, objectRepository, null, null, null);

            //assert
            Assert.AreEqual(blog, subtextContext.Blog);
            Assert.AreEqual(urlHelper, subtextContext.UrlHelper);
            Assert.AreEqual(requestContext, subtextContext.RequestContext);
            Assert.AreEqual(objectRepository, subtextContext.Repository);
        }
Пример #2
0
        public static int Create(Entry entry)
        {
            var requestContext      = new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData());
            var serviceLocator      = new Mock <IDependencyResolver>().Object;
            var searchEngineService = new Mock <IIndexingService>().Object;

            DependencyResolver.SetResolver(serviceLocator);
            var routes        = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, serviceLocator);

            Routes.RegisterRoutes(subtextRoutes);
            var urlHelper      = new BlogUrlHelper(requestContext, routes);
            var subtextContext = new SubtextContext(Config.CurrentBlog, requestContext, urlHelper,
                                                    new DatabaseObjectProvider(), requestContext.HttpContext.User,
                                                    new SubtextCache(requestContext.HttpContext.Cache), serviceLocator);
            IEntryPublisher entryPublisher = CreateEntryPublisher(subtextContext, searchEngineService);
            int             id             = entryPublisher.Publish(entry);

            entry.Id = id;
            return(id);
        }
Пример #3
0
        protected override void Render(HtmlTextWriter writer)
        {
            //var ctx = Parent.Page
            SubtextContext ctx = base.SubtextContext as SubtextContext;

            if (ctx != null)
            {
                HtmlMeta summaryTitleMeta = new HtmlMeta();
                summaryTitleMeta.Name = "twitter:title";

                HtmlMeta descriptionMeta = new HtmlMeta();
                descriptionMeta.Name = "twitter:description";

                Entry entry = Cacher.GetEntryFromRequest(true, ctx);

                if (entry != null)
                {
                    string title       = entry.Title;
                    string description = entry.HasDescription ? entry.Description : entry.Body;

                    summaryTitleMeta.Content = title;

                    var cleanedDescription =
                        HttpUtility.HtmlDecode(Regex.Replace(description, "<[^>]*(>|$)", string.Empty));

                    var maxLen = (cleanedDescription.Length > 180) ? 180 : cleanedDescription.Length;

                    descriptionMeta.Content = cleanedDescription.Substring(0, maxLen) + "...";
                }
                else
                {
                    // get the default title/summary from the blog
                    summaryTitleMeta.Content = ctx.Blog.Title;
                    descriptionMeta.Content  = ctx.Blog.SubTitle;
                }
                summaryTitleMeta.RenderControl(writer);
                descriptionMeta.RenderControl(writer);
            }
        }
Пример #4
0
 public SkinsController(SubtextContext subtextContext)
 {
     SubtextContext = subtextContext;
 }