Ejemplo n.º 1
0
        public void CreatePostWithImageTest()
        {
            TransitPost t_post = new TransitPost();

            t_post.Body    = Guid.NewGuid().ToString();
            t_post.Title   = Guid.NewGuid().ToString();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            TransitImage t_image = new TransitImage();

            t_image.Name = Guid.NewGuid().ToString();

            Bitmap   b = new Bitmap(480, 480);
            Graphics g = Graphics.FromImage(b);

            g.FillEllipse(Brushes.Red, 0, 0, 480, 480);
            ThumbnailBitmap tb = new ThumbnailBitmap(b);

            t_image.Data      = tb.Bitmap;
            t_image.Thumbnail = tb.Thumbnail;

            t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image);
            Assert.Greater(t_image.Id, 0);

            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 2
0
    public void GetData(object sender, EventArgs e)
    {
        TransitPost post = Post;

        // linkComment.NavigateUrl = string.Format("EditPostComment.aspx?sid={0}", post.Id);

        Title            = posttitle.Text = Renderer.Render(post.Title);
        postbody.Text    = RenderEx(post.Body, post.Id);
        posttopics.Text  = GetTopics(post.Topics);
        postcreated.Text = post.Created.ToString("d");

        if (SessionManager.CountersEnabled)
        {
            postcounter.Text = string.Format("{0} Click{1}", post.Counter.Count,
                                             post.Counter.Count != 1 ? "s" : string.Empty);
        }
        else
        {
            postcounter.Visible = false;
        }

        panelPicture.Visible = (post.ImageId != 0 && post.ImagesCount <= 1);
        postimage.ImageUrl   = string.Format("./ShowPicture.aspx?id={0}", post.ImageId);
        linkimage.HRef       = string.Format("./ShowImage.aspx?id={0}&pid={1}", post.ImageId, post.Id);

        twitterShare.Url  = string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri);
        twitterShare.Text = post.Title;

        disqusComments.DisqusId  = string.Format("Post_{0}", post.Id);
        disqusComments.DisqusUrl = string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri);

        GetImagesData(sender, e);
        GetCommentsData(sender, e);
    }
Ejemplo n.º 3
0
        public void CreatePostWithANewTopicTest()
        {
            // topic that doesn't exist
            TransitTopic t_topic1 = new TransitTopic();

            t_topic1.Name = Guid.NewGuid().ToString();
            // topic that exists
            TransitTopic t_topic2 = new TransitTopic();

            t_topic2.Name = Guid.NewGuid().ToString();
            t_topic2.Id   = Blog.CreateOrUpdateTopic(Ticket, t_topic2);

            // post
            TransitPost t_post = new TransitPost();

            t_post.Body  = Guid.NewGuid().ToString();
            t_post.Title = Guid.NewGuid().ToString();
            List <TransitTopic> topics = new List <TransitTopic>();

            topics.Add(t_topic1);
            topics.Add(t_topic2);
            t_post.Topics  = topics.ToArray();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            TransitPost t_post_retrieved = Blog.GetPostById(Ticket, t_post.Id);

            Assert.AreEqual(t_post_retrieved.Topics.Length, t_post.Topics.Length);

            Blog.DeletePost(Ticket, t_post.Id);
            t_topic1.Id = Blog.GetTopicByName(Ticket, t_topic1.Name).Id;
            Blog.DeleteTopic(Ticket, t_topic2.Id);
        }
Ejemplo n.º 4
0
    private void GetPost(object sender, EventArgs e)
    {
        Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\"";
        TransitPost post      = SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId);
        AtomEntry   atomEntry = GetPost(post);

        atomEntry.Save(Response.OutputStream);
        Response.End();
    }
Ejemplo n.º 5
0
    void GetCommentsData(object sender, EventArgs e)
    {
        TransitPost post = Post;

        comments.Visible          = (post.CommentsCount > 0);
        comments.CurrentPageIndex = 0;
        comments.VirtualItemCount = SessionManager.GetCachedCollectionCount <TransitPostComment>(
            "GetPostCommentsCount", SessionManager.PostTicket, new TransitPostCommentQueryOptions(Post.Id));
        comments_OnGetDataSource(sender, e);
        comments.DataBind();
    }
Ejemplo n.º 6
0
        public BlogPostTest()
        {
            mPost         = new TransitPost();
            mPost.Title   = Guid.NewGuid().ToString();
            mPost.Body    = Guid.NewGuid().ToString();
            mPost.Created = mPost.Modified = DateTime.UtcNow;

            mTopic1Test = new BlogTopicTest();
            AddDependent(mTopic1Test);
            mTopic2Test = new BlogTopicTest();
            AddDependent(mTopic2Test);
        }
Ejemplo n.º 7
0
        public void CreatePostWithNoTopicsTest()
        {
            // post
            TransitPost t_post = new TransitPost();

            t_post.Body    = Guid.NewGuid().ToString();
            t_post.Title   = Guid.NewGuid().ToString();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);
            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 8
0
    void GetImagesData(object sender, EventArgs e)
    {
        TransitPost post = Post;

        TransitPostImageQueryOptions imagesoptions = new TransitPostImageQueryOptions(Post.Id);

        imagesoptions.PreferredOnly = PreferredOnly;
        images.Visible          = (post.ImagesCount > 1);
        images.CurrentPageIndex = 0;
        images.VirtualItemCount = SessionManager.GetCachedCollectionCount <TransitPostImage>(
            "GetPostImagesCountEx", SessionManager.PostTicket, imagesoptions);
        images_OnGetDataSource(sender, e);
        images.DataBind();
    }
Ejemplo n.º 9
0
        public void CreatePostIncrementCounterTest()
        {
            TransitPost t_post = new TransitPost();

            t_post.Body    = Guid.NewGuid().ToString();
            t_post.Title   = Guid.NewGuid().ToString();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            Assert.AreEqual(1, Blog.IncrementPostCounter(Ticket, t_post.Id),
                            "New post counter must be one after a single increment.");

            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 10
0
    private AtomEntry GetPost(TransitPost post)
    {
        AtomEntry atomEntry = new AtomEntry();

        atomEntry.Title = new AtomTextConstruct(post.Title);
        foreach (TransitTopic topic in post.Topics)
        {
            atomEntry.Categories.Add(new AtomCategory(topic.Name));
        }
        atomEntry.Content     = new AtomContent(post.BodyXHTML, "html");
        atomEntry.PublishedOn = post.Created;
        atomEntry.UpdatedOn   = post.Modified;
        atomEntry.Id          = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id)));
        atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomBlog.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit"));
        AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate");

        atomEntryUri.ContentType = "text/html";
        atomEntry.Links.Add(atomEntryUri);
        return(atomEntry);
    }
Ejemplo n.º 11
0
    public void list_ItemCommand(object source, DataListCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
            case "Delete":
            {
                SessionManager.BlogService.DeletePost(SessionManager.Ticket, int.Parse(e.CommandArgument.ToString()));
                SessionManager.Invalidate <TransitPost>();
                ReportInfo("Item Deleted");
                GetData(source, e);
            }
            break;

            case "Display":
            {
                TransitPost t_post = SessionManager.BlogService.GetPostById(SessionManager.Ticket, int.Parse(e.CommandArgument.ToString()));
                t_post.Display = !t_post.Display;
                SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, t_post);
                ReportInfo(t_post.Display ? "Post Displayed" : "Post Hidden");
                GetData(source, e);
                break;
            }

            case "Sticky":
            {
                TransitPost t_post = SessionManager.BlogService.GetPostById(SessionManager.Ticket, int.Parse(e.CommandArgument.ToString()));
                t_post.Sticky = !t_post.Sticky;
                SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, t_post);
                ReportInfo(t_post.Sticky ? "Post Stuck" : "Post Unstuck");
                GetData(source, e);
                break;
            }
            }
        }
        catch (Exception ex)
        {
            ReportException(ex);
        }
    }
Ejemplo n.º 12
0
        public void CreateStickyPostTest()
        {
            TransitPost t_post1 = new TransitPost();

            t_post1.Body    = Guid.NewGuid().ToString();
            t_post1.Title   = Guid.NewGuid().ToString();
            t_post1.Publish = true;
            t_post1.Sticky  = true;
            t_post1.Created = t_post1.Modified = DateTime.UtcNow;
            t_post1.Id      = Blog.CreateOrUpdatePost(Ticket, t_post1);
            Assert.Greater(t_post1.Id, 0);

            Thread.Sleep(1000);

            TransitPost t_post2 = new TransitPost();

            t_post2.Body    = Guid.NewGuid().ToString();
            t_post2.Title   = Guid.NewGuid().ToString();
            t_post2.Publish = true;
            t_post2.Sticky  = false;
            t_post2.Created = t_post2.Modified = DateTime.UtcNow;
            t_post2.Id      = Blog.CreateOrUpdatePost(Ticket, t_post2);
            Assert.Greater(t_post1.Id, 0);

            TransitPostQueryOptions queryOptions = new TransitPostQueryOptions();

            queryOptions.PageNumber     = 0;
            queryOptions.PageSize       = 2;
            queryOptions.DateStart      = DateTime.MinValue;
            queryOptions.DateEnd        = DateTime.MaxValue;
            queryOptions.SortDirection  = WebServiceQuerySortDirection.Descending;
            queryOptions.SortExpression = "Created";
            TransitPost[] posts = Blog.GetPosts(Ticket, queryOptions);

            Blog.DeletePost(Ticket, t_post1.Id);
            Blog.DeletePost(Ticket, t_post2.Id);

            Assert.AreEqual(2, posts.Length);
            // make sure the sticky post is on top (the second post might not be in second position if there're other stick posts)
            Assert.AreEqual(t_post1.Id, posts[0].Id);
        }
Ejemplo n.º 13
0
        public void CreatePostWithImageAndCommentTest()
        {
            // post
            TransitPost t_post = new TransitPost();

            t_post.Body    = Guid.NewGuid().ToString();
            t_post.Title   = Guid.NewGuid().ToString();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            // image
            TransitImage t_image = new TransitImage();

            t_image.Name = Guid.NewGuid().ToString();

            Bitmap   b = new Bitmap(480, 480);
            Graphics g = Graphics.FromImage(b);

            g.FillEllipse(Brushes.Red, 0, 0, 480, 480);
            ThumbnailBitmap tb = new ThumbnailBitmap(b);

            t_image.Data      = tb.Bitmap;
            t_image.Thumbnail = tb.Thumbnail;

            t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image);
            Assert.Greater(t_image.Id, 0);

            // comment
            TransitComment t_comment = new TransitComment();

            t_comment.IpAddress = "127.0.0.1";
            t_comment.LoginId   = Blog.GetLogin(Ticket).Id;
            t_comment.Text      = Guid.NewGuid().ToString();

            t_comment.Id = Blog.CreateOrUpdateImageComment(Ticket, t_image.Id, t_comment);
            Assert.Greater(t_comment.Id, 0);

            Blog.DeleteImage(Ticket, t_image.Id);
            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 14
0
        public void CreatePostWithCommentTest()
        {
            TransitPost t_post = new TransitPost();

            t_post.Body    = Guid.NewGuid().ToString();
            t_post.Title   = Guid.NewGuid().ToString();
            t_post.Publish = true;
            t_post.Id      = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            TransitComment t_comment = new TransitComment();

            t_comment.IpAddress = "127.0.0.1";
            t_comment.LoginId   = Blog.GetLogin(Ticket).Id;
            t_comment.Text      = Guid.NewGuid().ToString();

            t_comment.Id = Blog.CreateOrUpdatePostComment(Ticket, t_post.Id, t_comment);
            Assert.Greater(t_comment.Id, 0);

            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 15
0
        public void CreateSecurePostTest()
        {
            TransitPost t_post = new TransitPost();

            t_post.Body  = Guid.NewGuid().ToString();
            t_post.Title = Guid.NewGuid().ToString();
            t_post.Id    = Blog.CreateOrUpdatePost(Ticket, t_post);
            Assert.Greater(t_post.Id, 0);

            TransitImage t_image = new TransitImage();

            t_image.Name = Guid.NewGuid().ToString();

            Bitmap   b = new Bitmap(480, 480);
            Graphics g = Graphics.FromImage(b);

            g.FillEllipse(Brushes.Red, 0, 0, 480, 480);
            ThumbnailBitmap tb = new ThumbnailBitmap(b);

            t_image.Data      = tb.Bitmap;
            t_image.Thumbnail = tb.Thumbnail;

            t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image);
            Assert.Greater(t_image.Id, 0);

            TransitLogin t_login = new TransitLogin();

            t_login.Username = Guid.NewGuid().ToString();
            t_login.Password = Guid.NewGuid().ToString();
            t_login.Role     = TransitLoginRole.Guest;
            t_login.Id       = Blog.CreateOrUpdateLogin(Ticket, t_login);
            Assert.Greater(t_login.Id, 0);

            TransitComment t_comment = new TransitComment();

            t_comment.IpAddress = "127.0.0.1";
            t_comment.Text      = Guid.NewGuid().ToString();
            t_comment.LoginId   = t_login.Id;
            t_comment.Id        = Blog.CreateOrUpdatePostComment(Ticket, t_post.Id, t_comment);
            Assert.Greater(t_comment.Id, 0);

            int t_postlogin_id = Blog.CreateOrUpdatePostLogin(Ticket, t_post.Id, t_login);

            Assert.Greater(t_postlogin_id, 0);

            string authticket = Blog.Login(t_login.Username, t_login.Password);

            // check access to posts

            TransitPost t_post_unauthorized = Blog.GetPostById(null, t_post.Id);

            Assert.IsTrue(string.IsNullOrEmpty(t_post_unauthorized.Body), "Unathorized post body wasn't stripped.");

            TransitPost t_post_authorized = Blog.GetPostById(authticket, t_post.Id);

            Assert.IsFalse(string.IsNullOrEmpty(t_post_authorized.Body), "Authorized post was stripped.");

            // check access to images

            TransitImage t_image_unauthorized = Blog.GetImageWithBitmapById(null, t_image.Id);

            Assert.IsTrue(t_image_unauthorized.Data == null, "Unathorized image returned data.");

            TransitImage t_image_authorized = Blog.GetImageWithBitmapById(authticket, t_image.Id);

            Assert.IsTrue(t_image_authorized.Data != null, "Authorized image didn't return data.");

            // check access to comments

            TransitComment t_comment_unauthorized = Blog.GetCommentById(null, t_comment.Id);

            Assert.IsTrue(string.IsNullOrEmpty(t_comment_unauthorized.Text), "Unathorized comment returned data.");

            TransitComment t_comment_authorized = Blog.GetCommentById(authticket, t_comment.Id);

            Assert.IsFalse(string.IsNullOrEmpty(t_comment_authorized.Text), "Authorized comment didn't return data.");

            Blog.DeletePost(Ticket, t_post.Id);
        }
Ejemplo n.º 16
0
    private void CreateOrUpdatePost(object sender, EventArgs e)
    {
        SessionManager.BasicAuth();

        if (!SessionManager.IsAdministrator)
        {
            throw new ManagedLogin.AccessDeniedException();
        }

        AtomEntry atomEntry = new AtomEntry();

        atomEntry.Load(Request.InputStream);

        TransitPost post = (RequestId > 0)
            ? SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId)
            : new TransitPost();

        post.Title = atomEntry.Title.Content;

        List <TransitTopic> topics = new List <TransitTopic>();

        foreach (AtomCategory category in atomEntry.Categories)
        {
            TransitTopic topic = SessionManager.BlogService.GetTopicByName(SessionManager.Ticket, category.Term);
            if (topic == null)
            {
                topic      = new TransitTopic();
                topic.Name = category.Term;
            }
            topics.Add(topic);
        }

        post.Topics  = topics.ToArray();
        post.Body    = atomEntry.Content.Content;
        post.Publish = true;
        post.Display = true;
        post.Sticky  = false;
        post.Export  = false;

        if (atomEntry.PublishedOn != DateTime.MinValue)
        {
            post.Created = atomEntry.PublishedOn;
        }
        if (atomEntry.UpdatedOn != DateTime.MinValue)
        {
            post.Modified = atomEntry.UpdatedOn;
        }

        post.Id = SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, post);

        Response.ContentType       = "application/atom+xml;type=entry;charset=\"utf-8\"";
        Response.StatusCode        = 201;
        Response.StatusDescription = "Created";
        string location = string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id);

        Response.Headers.Add("Location", location);
        Response.Headers.Add("Content-Location", location);
        Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString()));

        atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id)));
        atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id))));
        atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit"));
        AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate");

        atomEntryUri.ContentType = "text/html";
        atomEntry.Links.Add(atomEntryUri);
        atomEntry.Save(Response.OutputStream);

        Response.End();
    }