Exemplo n.º 1
0
        public void getCategories_ReturnsCategoriesInRepository()
        {
            //arrange
            var blog = new Blog {
                AllowServiceAccess = true, Host = "localhost", UserName = "******", Password = "******"
            };
            var category = new LinkCategory
            {
                BlogId       = blog.Id,
                IsActive     = true,
                Description  = "Test category",
                Title        = "CategoryA",
                CategoryType = CategoryType.PostCollection,
                Id           = 42
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.CategoryUrl(It.IsAny <LinkCategory>())).Returns("/Category/42.aspx");
            subtextContext.Setup(c => c.UrlHelper.CategoryRssUrl(It.IsAny <LinkCategory>())).Returns("/rss.aspx?catId=42");
            subtextContext.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false)).Returns(new[] { category });
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object);
            var api = new MetaWeblog(subtextContext.Object);

            //act
            CategoryInfo[] categories = api.getCategories(blog.Id.ToString(), "username", "password");

            //assert
            Assert.AreEqual(1, categories.Length);
            Assert.AreEqual("http://localhost/Category/42.aspx", categories[0].htmlUrl);
            Assert.AreEqual("http://localhost/rss.aspx?catId=42", categories[0].rssUrl);
        }
Exemplo n.º 2
0
        public void editPost_WithPostHavingDifferentCategoryThanEntry_UpdatesCategory()
        {
            // arrange
            var entry = new Entry(PostType.BlogPost)
            {
                Id = 12345, Title = "Title 1", Body = "Blah", IsActive = true
            };

            entry.Categories.Add("Category1");
            entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            var subtextContext = new Mock <ISubtextContext>();
            var blog           = new Blog {
                Id = 999, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******"
            };

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny <Int32>(), false, true)).Returns(entry);
            var   entryPublisher = new Mock <IEntryPublisher>();
            Entry publishedEntry = null;

            entryPublisher.Setup(p => p.Publish(It.IsAny <Entry>())).Callback <Entry>(e => publishedEntry = e);
            var post = new Post {
                title = "Title 2", description = "Blah", categories = new[] { "Category2" }, dateCreated = DateTime.UtcNow
            };
            var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object);

            // act
            bool result = api.editPost("12345", "username", "password", post, true);

            // assert
            Assert.AreEqual(1, publishedEntry.Categories.Count);
            Assert.AreEqual("Category2", publishedEntry.Categories.First());
            Assert.IsTrue(result);
        }
Exemplo n.º 3
0
        public void editPost_WithNoCategories_RemovesCategoriesFromEntry()
        {
            //arrange
            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Title 1", Body = "Blah", IsActive = true
            };

            entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add("TestCategory");
            var blog = new Blog {
                Id = 123, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******"
            };
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny <Int32>(), false, true)).Returns(entry);
            var   entryPublisher = new Mock <IEntryPublisher>();
            Entry publishedEntry = null;

            entryPublisher.Setup(p => p.Publish(It.IsAny <Entry>())).Callback <Entry>(e => publishedEntry = e);
            var post = new Post {
                title = "Title 2", description = "Blah", categories = null, dateCreated = DateTime.UtcNow
            };
            var metaWeblog = new MetaWeblog(subtextContext.Object, entryPublisher.Object);

            // act
            metaWeblog.editPost("123", "username", "password", post, true);

            // assert
            Assert.AreEqual(0, publishedEntry.Categories.Count, "We expected no category.");
        }
Exemplo n.º 4
0
        public void newPost_WithCategory_CreatesEntryWithCategory()
        {
            //arrange
            var repository = new DatabaseObjectProvider();
            var blog       = new Blog {
                Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost"
            };

            var   entryPublisher = new Mock <IEntryPublisher>();
            Entry publishedEntry = null;

            entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Callback <Entry>(e => publishedEntry = e);
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object);

            var api  = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
            var post = new Post
            {
                categories  = new[] { "CategoryA" },
                description = "A unit test",
                title       = "A unit testing title",
                dateCreated = DateTime.UtcNow
            };

            //act
            api.newPost("42", "username", "password", post, true);

            //assert
            Assert.IsNotNull(publishedEntry);
            Assert.AreEqual(1, publishedEntry.Categories.Count);
            Assert.AreEqual("CategoryA", publishedEntry.Categories.First());
        }
Exemplo n.º 5
0
        /// <summary>
        /// The handle post to blog.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="subject">
        /// The subject.
        /// </param>
        /// <returns>
        /// The handle post to blog.
        /// </returns>
        protected string HandlePostToBlog(string message, string subject)
        {
            string blogPostID = string.Empty;

            // Does user wish to post this to their blog?
            if (this.PageContext.BoardSettings.AllowPostToBlog && this.PostToBlog.Checked)
            {
                try
                {
                    // Post to blog
                    var blog = new MetaWeblog(this.PageContext.Profile.BlogServiceUrl);
                    blogPostID = blog.newPost(
                        this.PageContext.Profile.BlogServicePassword,
                        this.PageContext.Profile.BlogServiceUsername,
                        this.BlogPassword.Text,
                        subject,
                        message);
                }
                catch
                {
                    this.PageContext.AddLoadMessage(this.GetText("POSTTOBLOG_FAILED"));
                }
            }

            return(blogPostID);
        }
Exemplo n.º 6
0
        public void NewPostAcceptsNullEnclosure()
        {
            //arrange
            var blog = new Blog {
                Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost"
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            Entry publishedEntry = null;
            var   entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Returns(42).Callback <Entry>(
                entry => publishedEntry = entry);
            DateTime now    = DateTime.UtcNow;
            DateTime utcNow = now.ToUniversalTime();

            var api  = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
            var post = new Post();

            post.categories  = null;
            post.description = "A unit test";
            post.title       = "A unit testing title";
            post.dateCreated = utcNow.AddDays(1);
            post.enclosure   = null;

            // act
            string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post,
                                        true);

            // assert
            Assert.IsNull(publishedEntry.Enclosure);
        }
Exemplo n.º 7
0
        public void NewPost_WithNullCategories_DoesNotTHrowException()
        {
            //arrange
            var blog = new Blog {
                Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost"
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            Entry publishedEntry = null;
            var   entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Returns(42).Callback <Entry>(
                entry => publishedEntry = entry);

            var api  = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
            var post = new Post
            {
                categories  = null,
                description = "A unit test",
                title       = "A unit testing title",
                dateCreated = DateTime.UtcNow
            };

            // act
            string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post,
                                        true);

            // assert
            int entryId = int.Parse(result);

            Assert.AreEqual(42, entryId);
            Assert.AreEqual(0, publishedEntry.Categories.Count, "Should not have added categories.");
        }
        public void Fetch()
        {
            Posts = new ObservableCollection <Entry>();

            var proxy = new MetaWeblog(this.SelectedBlog.WebAPI);

            proxy
            .GetRecentPostsAsync(SelectedBlog.BlogInfo.blogid, SelectedBlog.Username, SelectedBlog.Password, 100)
            .ContinueWith(UpdateBlogPosts, TaskScheduler.FromCurrentSynchronizationContext())
            .ContinueWith(HandleFetchError);
        }
        public void FetchBlogs()
        {
            SelectedAPIBlog = null;

            var proxy = new MetaWeblog(CurrentBlog.WebAPI);

            APIBlogs = new ObservableCollection <FetchedBlogInfo>();

            proxy
            .GetUsersBlogsAsync("MarkPad", CurrentBlog.Username, CurrentBlog.Password)
            .ContinueWith(UpdateBlogList, TaskScheduler.FromCurrentSynchronizationContext())
            .ContinueWith(HandleFetchError);
        }
Exemplo n.º 10
0
        public void editPost_WithEntryHavingEnclosure_UpdatesEntryEnclosureWithNewEnclosure()
        {
            //arrange
            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Title 1", Body = "Blah", IsActive = true
            };

            entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add("TestCategory");
            var blog = new Blog {
                Id = 123, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******"
            };
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny <Int32>(), false, true)).Returns(entry);
            var   entryPublisher = new Mock <IEntryPublisher>();
            Entry publishedEntry = null;

            entryPublisher.Setup(p => p.Publish(It.IsAny <Entry>())).Callback <Entry>(e => publishedEntry = e);
            FrameworkEnclosure enclosure = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                                                         "http://perseus.franklins.net/hanselminutes_0107.mp3", "audio/mp3", 123, 26707573, true, true);

            entry.Enclosure = enclosure;
            var post = new Post {
                title = "Title 2", description = "Blah", dateCreated = DateTime.UtcNow
            };

            var postEnclosure = new Enclosure
            {
                url    = "http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3",
                type   = "audio/mp3",
                length = 123456789
            };

            post.enclosure = postEnclosure;
            var metaWeblog = new MetaWeblog(subtextContext.Object, entryPublisher.Object);

            // act
            bool result = metaWeblog.editPost("123", "username", "password", post, true);

            // assert
            Assert.IsTrue(result);
            Assert.IsNotNull(publishedEntry.Enclosure);
            Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcastUpdated.mp3", entry.Enclosure.Url);
        }
Exemplo n.º 11
0
        public void NewPostWithEnclosureCreatesEntryWithEnclosure()
        {
            //arrange
            var blog = new Blog {
                Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost"
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            FrameworkEnclosure publishedEnclosure = null;

            subtextContext.Setup(c => c.Repository.Create(It.IsAny <FrameworkEnclosure>())).Callback <FrameworkEnclosure>(
                enclosure => publishedEnclosure = enclosure);
            var entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Returns(42);
            DateTime now    = DateTime.UtcNow;
            DateTime utcNow = now.ToUniversalTime();

            var api  = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
            var post = new Post();

            post.categories  = null;
            post.description = "A unit test";
            post.title       = "A unit testing title";
            post.dateCreated = utcNow.AddDays(1);

            var postEnclosure = new Enclosure();

            postEnclosure.url    = "http://codeclimber.net.nz/podcast/mypodcast.mp3";
            postEnclosure.type   = "audio/mp3";
            postEnclosure.length = 123456789;
            post.enclosure       = postEnclosure;

            // act
            string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post,
                                        true);

            // assert
            Assert.IsNotNull(publishedEnclosure);
            Assert.AreEqual("http://codeclimber.net.nz/podcast/mypodcast.mp3", publishedEnclosure.Url);
            Assert.AreEqual("audio/mp3", publishedEnclosure.MimeType);
            Assert.AreEqual(123456789, publishedEnclosure.Size);
        }
Exemplo n.º 12
0
        public void EditPost_WithoutEnclosure_RemovesEnclosureFromEntry()
        {
            // arrange
            FrameworkEnclosure enclosure = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                                                         "http://example.com/foo.mp3", "audio/mp3", 123, 2650, true, true);

            enclosure.Id = 321;
            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Title 1", Body = "Blah", IsActive = true, Enclosure = enclosure
            };

            entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            var subtextContext = new Mock <ISubtextContext>();
            var blog           = new Blog {
                Id = 999, Host = "localhost", AllowServiceAccess = true, UserName = "******", Password = "******"
            };

            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.Repository.GetEntry(It.IsAny <Int32>(), false, true)).Returns(entry);
            bool enclosureDeleted = false;

            subtextContext.Setup(c => c.Repository.DeleteEnclosure(321)).Callback(() => enclosureDeleted = true);
            var entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(p => p.Publish(It.IsAny <Entry>()));
            var post = new Post {
                title = "Title 2", description = "Blah", dateCreated = DateTime.UtcNow
            };
            var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object);

            // act
            bool result = api.editPost("999", "username", "password", post, true);

            // assert
            Assert.IsTrue(enclosureDeleted);
            Assert.IsTrue(result);
        }
Exemplo n.º 13
0
        public void NewPost_WithFutureDate_SyndicatesInTheFuture()
        {
            //arrange
            var blog = new Blog {
                Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost"
            };

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(blog);
            Entry publishedEntry = null;
            var   entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Returns(42).Callback <Entry>(
                entry => publishedEntry = entry);
            var utcNow = DateTime.UtcNow;
            var now    = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute, utcNow.Second, DateTimeKind.Unspecified);

            var api  = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
            var post = new Post
            {
                categories  = null,
                description = "A unit test",
                title       = "A unit testing title",
                dateCreated = now.AddDays(1)
            };

            // act
            api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);

            // assert
            Assert.IsNotNull(publishedEntry);
            Assert.Greater(publishedEntry.DateSyndicated, now.AddDays(.75));
            Assert.LowerEqualThan(publishedEntry.DateSyndicated, now.AddDays(1));
            Assert.AreEqual(publishedEntry.DatePublishedUtc.Kind, DateTimeKind.Utc);
        }
Exemplo n.º 14
0
        public void Publish(string postid, string postTitle, string[] categories, BlogSetting blog)
        {
            if (categories == null)
            {
                categories = new string[0];
            }

            var proxy = new MetaWeblog(blog.WebAPI);

            var newpost = new Post();

            try
            {
                var renderBody = DocumentParser.GetBodyContents(Document.Text);

                if (string.IsNullOrWhiteSpace(postid))
                {
                    var permalink = DisplayName.Split('.')[0] == "New Document"
                                ? postTitle
                                : DisplayName.Split('.')[0];

                    newpost = new Post
                    {
                        permalink   = permalink,
                        title       = postTitle,
                        dateCreated = DateTime.Now,
                        description = blog.Language == "HTML" ? renderBody : Document.Text,
                        categories  = categories
                    };
                    newpost.postid = proxy.NewPost(blog.BlogInfo.blogid, blog.Username, blog.Password, newpost, true);

                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
                else
                {
                    newpost             = proxy.GetPost(postid, blog.Username, blog.Password);
                    newpost.title       = postTitle;
                    newpost.description = blog.Language == "HTML" ? renderBody : Document.Text;
                    newpost.categories  = categories;
                    newpost.format      = blog.Language;

                    proxy.EditPost(postid, blog.Username, blog.Password, newpost, true);

                    //Not sure what this is doing??
                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
            }
            catch (WebException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcFaultException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }

            Post     = newpost;
            Original = Document.Text;
            title    = postTitle;
            NotifyOfPropertyChange(() => DisplayName);
        }
Exemplo n.º 15
0
        public void GetPage_ReturnsPostWithhCorrectEntrUrl()
        {
            //arrange
            var    repository = new DatabaseObjectProvider();
            string hostname   = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("", "username", "password", hostname, "");
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            BlogRequest.Current.Blog = repository.GetBlog(hostname, "");
            Config.CurrentBlog.AllowServiceAccess = true;

            var urlHelper = new Mock <BlogUrlHelper>();

            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/entry/whatever");
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            //TODO: FIX!!!
            subtextContext.Setup(c => c.Repository).Returns(repository);
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object);
            subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object);

            var    api           = new MetaWeblog(subtextContext.Object);
            string category1Name = UnitTestHelper.GenerateUniqueString();
            string category2Name = UnitTestHelper.GenerateUniqueString();

            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name);
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name);

            var entry = new Entry(PostType.Story);

            entry.Title    = "Title 1";
            entry.Body     = "Blah";
            entry.IsActive = true;
            entry.IncludeInMainSyndication = true;
            entry.DateCreatedUtc           =
                entry.DatePublishedUtc     =
                    entry.DateModifiedUtc  = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.Categories.Add(category1Name);
            int    entryId           = UnitTestHelper.Create(entry);
            string enclosureUrl      = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            string enclosureMimeType = "audio/mp3";
            long   enclosureSize     = 26707573;


            FrameworkEnclosure enc =
                UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true);

            repository.Create(enc);

            //act
            Post post = api.getPage(Config.CurrentBlog.Id.ToString(), entryId.ToString(), "username", "password");

            //assert
            Assert.AreEqual(1, post.categories.Length);
            Assert.AreEqual("http://" + hostname + "/entry/whatever", post.link);
            Assert.AreEqual("http://" + hostname + "/entry/whatever", post.permalink);
            Assert.AreEqual(category1Name, post.categories[0]);
            Assert.AreEqual(enclosureUrl, post.enclosure.Value.url);
            Assert.AreEqual(enclosureMimeType, post.enclosure.Value.type);
            Assert.AreEqual(enclosureSize, post.enclosure.Value.length);
        }
Exemplo n.º 16
0
        // Metaweblog
        bool IMetaWeblog.metaweblog_editPost(string postid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            int postNum;

            if (int.TryParse(postid, out postNum) &&
                 postNum > 0 && postNum <= mwPosts.Count )
            {
                post.postid = postid;
                mwPosts[postNum-1] = post;
            }
            return true;
        }
Exemplo n.º 17
0
        public void GetRecentPosts_ReturnsRecentPosts()
        {
            string hostname   = UnitTestHelper.GenerateUniqueString();
            var    repository = new DatabaseObjectProvider();

            repository.CreateBlog("", "username", "password", hostname, "");
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            Blog blog = repository.GetBlog(hostname, "");

            BlogRequest.Current.Blog = blog;
            blog.AllowServiceAccess  = true;

            var urlHelper = new Mock <BlogUrlHelper>();

            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/entry/whatever");
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            //TODO: FIX!!!
            subtextContext.Setup(c => c.Repository).Returns(repository);
            subtextContext.SetupBlog(blog);
            subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object);

            var api = new MetaWeblog(subtextContext.Object);

            Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10);
            Assert.AreEqual(0, posts.Length);

            string category1Name = UnitTestHelper.GenerateUniqueString();
            string category2Name = UnitTestHelper.GenerateUniqueString();

            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name);
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name);

            var entry = new Entry(PostType.BlogPost);

            entry.Title    = "Title 1";
            entry.Body     = "Blah";
            entry.IsActive = true;
            entry.IncludeInMainSyndication = true;
            entry.DateCreatedUtc           =
                entry.DatePublishedUtc     =
                    entry.DateModifiedUtc  = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.Categories.Add(category1Name);
            UnitTestHelper.Create(entry);

            entry = new Entry(PostType.BlogPost);
            entry.IncludeInMainSyndication = true;
            entry.Title                   = "Title 2";
            entry.Body                    = "Blah1";
            entry.IsActive                = true;
            entry.DateCreatedUtc          =
                entry.DatePublishedUtc    =
                    entry.DateModifiedUtc = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.Categories.Add(category1Name);
            entry.Categories.Add(category2Name);
            UnitTestHelper.Create(entry);

            entry       = new Entry(PostType.BlogPost);
            entry.Title = "Title 3";
            entry.IncludeInMainSyndication = true;
            entry.Body                    = "Blah2";
            entry.IsActive                = true;
            entry.DateCreatedUtc          =
                entry.DatePublishedUtc    =
                    entry.DateModifiedUtc = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            UnitTestHelper.Create(entry);

            entry       = new Entry(PostType.BlogPost);
            entry.Title = "Title 4";
            entry.IncludeInMainSyndication = true;
            entry.Body                    = "Blah3";
            entry.IsActive                = true;
            entry.DateCreatedUtc          =
                entry.DatePublishedUtc    =
                    entry.DateModifiedUtc = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.Categories.Add(category2Name);
            int entryId = UnitTestHelper.Create(entry);

            string enclosureUrl      = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            string enclosureMimeType = "audio/mp3";
            long   enclosureSize     = 26707573;

            FrameworkEnclosure enc =
                UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true);

            repository.Create(enc);

            posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10);
            Assert.AreEqual(4, posts.Length, "Expected 4 posts");
            Assert.AreEqual(1, posts[3].categories.Length, "Expected our categories to be there.");
            Assert.AreEqual(2, posts[2].categories.Length, "Expected our categories to be there.");
            Assert.IsNotNull(posts[1].categories, "Expected our categories to be there.");
            Assert.AreEqual(1, posts[0].categories.Length, "Expected our categories to be there.");
            Assert.AreEqual(category1Name, posts[3].categories[0], "The category returned by the MetaBlogApi is wrong.");
            Assert.AreEqual(category2Name, posts[0].categories[0], "The category returned by the MetaBlogApi is wrong.");

            Assert.AreEqual(enclosureUrl, posts[0].enclosure.Value.url, "Not what we expected for the enclosure url.");
            Assert.AreEqual(enclosureMimeType, posts[0].enclosure.Value.type,
                            "Not what we expected for the enclosure mimetype.");
            Assert.AreEqual(enclosureSize, posts[0].enclosure.Value.length,
                            "Not what we expected for the enclosure size.");
        }
Exemplo n.º 18
0
 string IMetaWeblog.metaweblog_newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish)
 {
     int newId = mwPosts.Count + 1;
     post.postid = newId.ToString();
     post.dateCreated = DateTime.Now;
     mwPosts.Add(post);
     return post.postid;
 }
Exemplo n.º 19
0
 public MetaWeblogService(string url)
 {
     proxy = new MetaWeblog(url);
 }
Exemplo n.º 20
0
		protected string HandlePostToBlog(string message, string subject)
		{
			string blogPostID = string.Empty;

			// Does user wish to post this to their blog?
			if (PageContext.BoardSettings.AllowPostToBlog && PostToBlog.Checked)
			{
				try
				{
					// Post to blog
					MetaWeblog blog = new MetaWeblog(PageContext.Profile.BlogServiceUrl);
					blogPostID = blog.newPost(PageContext.Profile.BlogServicePassword, PageContext.Profile.BlogServiceUsername, BlogPassword.Text, subject, message);
				}
				catch
				{
					PageContext.AddLoadMessage(GetText("POSTTOBLOG_FAILED"));
				}
			}

			return blogPostID;
		}
        public void GetPages_WithNumberOfPosts_ReturnsPostsInPages()
        {
            //arrange
            string hostname = UnitTestHelper.GenerateUniqueString();

            Config.CreateBlog("", "username", "password", hostname, "");
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostname, "");
            Config.CurrentBlog.AllowServiceAccess = true;

            var urlHelper = new Mock <UrlHelper>();

            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/entry/whatever");
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            //TODO: FIX!!!
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IServiceLocator>().Object);
            subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object);

            var api = new MetaWeblog(subtextContext.Object);

            Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10);
            Assert.AreEqual(0, posts.Length);

            string category1Name = UnitTestHelper.GenerateUniqueString();
            string category2Name = UnitTestHelper.GenerateUniqueString();

            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name);
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name);

            var entry = new Entry(PostType.Story);

            entry.Title    = "Title 1";
            entry.Body     = "Blah";
            entry.IsActive = true;
            entry.IncludeInMainSyndication = true;
            entry.DateCreated          =
                entry.DateSyndicated   =
                    entry.DateModified = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            UnitTestHelper.Create(entry);

            entry = new Entry(PostType.Story);
            entry.IncludeInMainSyndication = true;
            entry.Title                = "Title 2";
            entry.Body                 = "Blah1";
            entry.IsActive             = true;
            entry.DateCreated          =
                entry.DateSyndicated   =
                    entry.DateModified = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            UnitTestHelper.Create(entry);

            entry = new Entry(PostType.Story);
            entry.Categories.Add(category1Name);
            entry.Categories.Add(category2Name);
            entry.Title = "Title 3";
            entry.IncludeInMainSyndication = true;
            entry.Body                 = "Blah2";
            entry.IsActive             = true;
            entry.DateCreated          =
                entry.DateSyndicated   =
                    entry.DateModified = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            UnitTestHelper.Create(entry);

            entry       = new Entry(PostType.Story);
            entry.Title = "Title 4";
            entry.IncludeInMainSyndication = true;
            entry.Body                 = "Blah3";
            entry.IsActive             = true;
            entry.DateCreated          =
                entry.DateSyndicated   =
                    entry.DateModified = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add(category2Name);
            int entryId = UnitTestHelper.Create(entry);

            string enclosureUrl      = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            string enclosureMimeType = "audio/mp3";
            long   enclosureSize     = 26707573;

            FrameworkEnclosure enc =
                UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true);

            Enclosures.Create(enc);

            //act
            posts = api.getPages(Config.CurrentBlog.Id.ToString(), "username", "password", 2);

            //assert
            Assert.AreEqual(2, posts.Length);
            Assert.AreEqual(1, posts[0].categories.Length);
            Assert.AreEqual(2, posts[1].categories.Length);
            Assert.IsNotNull(posts[1].categories, "Expected our categories to be there.");

            Assert.AreEqual(enclosureUrl, posts[0].enclosure.Value.url);
            Assert.AreEqual(enclosureMimeType, posts[0].enclosure.Value.type);
            Assert.AreEqual(enclosureSize, posts[0].enclosure.Value.length);
        }