Ejemplo n.º 1
0
 public void SizeIsFormattedCorrectly(long size, string expected)
 {
     Enclosure enc = new Enclosure();
     enc.Size = size;
     Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");
     Assert.AreEqual(expected, enc.FormattedSize, "Not the right formatting");
 }
Ejemplo n.º 2
0
        public void Create_WithInvalidEntry_ThrowsArgumentException()
        {
            // arrange
            var enclosure = new Enclosure{ EntryId = 0};

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            UnitTestHelper.AssertThrows<ArgumentException>(() => Enclosures.Create(enclosure));
        }
Ejemplo n.º 3
0
        public static bool Update(Enclosure enclosure)
        {
            if (enclosure == null)
                throw new ArgumentNullException("enclosure", "The enclosure can not be NULL.");

            if (!enclosure.IsValid)
                throw new ArgumentException(enclosure.ValidationMessage);

            return ObjectProvider.Instance().Update(enclosure);
        }
Ejemplo n.º 4
0
        public void Create_WithInvalidEntry_ThrowsArgumentException()
        {
            // arrange
            var repository = new DatabaseObjectProvider();
            var enclosure = new Enclosure { EntryId = 0 };

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            UnitTestHelper.AssertThrows<ArgumentException>(() => repository.Create(enclosure));
        }
Ejemplo n.º 5
0
        public void Update_WithInvalidEnclosure_ThrowsArgumentException()
        {
            // arrange
            var enclosure = new Enclosure {EntryId = 0};

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            var exception = UnitTestHelper.AssertThrows<ArgumentException>(() => Enclosures.Update(enclosure));
            Assert.AreEqual(enclosure.ValidationMessage, exception.Message);
        }
Ejemplo n.º 6
0
        public void IsValid_WithNullMimeType_ReturnsFalse()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 1, Url = "http://example.com", MimeType = null };

            // act
            bool valid = enclosure.IsValid;

            // assert
            Assert.IsFalse(valid);
            Assert.AreEqual(Resources.Enclosure_MimeTypeRequired, enclosure.ValidationMessage);
        }
Ejemplo n.º 7
0
        public void IsValid_WithNullUrl_ReturnsFalse()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 1, Url = null };

            // act
            bool valid = enclosure.IsValid;

            // assert
            Assert.IsFalse(valid);
            Assert.AreEqual(Resources.Enclosure_UrlRequired, enclosure.ValidationMessage);
        }
Ejemplo n.º 8
0
        public static int Create(Enclosure enclosure)
        {
            if (enclosure == null)
                throw new ArgumentNullException("enclosure", "The enclosure cannot be NULL");

            if(!enclosure.IsValid)
                throw new ArgumentException(enclosure.ValidationMessage);

            enclosure.Id = ObjectProvider.Instance().Create(enclosure);

            return enclosure.Id;
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 public abstract bool Update(Enclosure metaTag);
Ejemplo n.º 11
0
 public override int Create(Enclosure enclosure)
 {
     return DbProvider.Instance().InsertEnclosure(enclosure);
 }
Ejemplo n.º 12
0
        public void IsValid_WithValidEnclosure_ReturnsTrue()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 1, Url = "http://example.com", MimeType = "image/jpg", Size = 100};

            // act
            bool valid = enclosure.IsValid;

            // assert
            Assert.IsTrue(valid);
            Assert.IsNull(enclosure.ValidationMessage);
        }
Ejemplo n.º 13
0
        public void IsValid_WithZeroSize_ReturnsFalse()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 1, Url = "http://example.com", MimeType = "image/jpg", Size = 0};

            // act
            bool valid = enclosure.IsValid;

            // assert
            Assert.IsFalse(valid);
            Assert.AreEqual(Resources.Enclosure_SizeGreaterThanZero, enclosure.ValidationMessage);
        }
Ejemplo n.º 14
0
 public override void Create(Enclosure enclosure)
 {
     if (enclosure == null)
     {
         throw new ArgumentNullException("enclosure");
     }
     if (!enclosure.IsValid)
     {
         throw new ArgumentException(enclosure.ValidationMessage);
     }
     int enclosureId = _procedures.InsertEnclosure(enclosure.Title ?? string.Empty,
                                        enclosure.Url,
                                        enclosure.MimeType,
                                        enclosure.Size,
                                        enclosure.AddToFeed,
                                        enclosure.ShowWithPost,
                                        enclosure.EntryId);
     enclosure.Id = enclosureId;
 }
Ejemplo n.º 15
0
 public abstract int InsertEnclosure(Enclosure enclosure);
Ejemplo n.º 16
0
 public override bool Update(Enclosure enclosure)
 {
     return DbProvider.Instance().UpdateEnclosure(enclosure);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Adds the given enclosure to the data store
 /// </summary>
 /// <param name="enclosure"></param>
 /// <returns>Id of the enclosure created</returns>
 public abstract void Create(Enclosure enclosure);
Ejemplo n.º 18
0
 /// <summary>
 /// Adds the given enclosure to the data store
 /// </summary>
 /// <param name="enclosure"></param>
 /// <returns>Id of the enclosure created</returns>
 public abstract int Create(Enclosure enclosure);
Ejemplo n.º 19
0
 public override void Update(Enclosure enclosure)
 {
     if (enclosure == null)
     {
         throw new ArgumentNullException("enclosure");
     }
     if (!enclosure.IsValid)
     {
         throw new ArgumentException(enclosure.ValidationMessage);
     }
     _procedures.UpdateEnclosure(enclosure.Title,
                                        enclosure.Url,
                                        enclosure.MimeType,
                                        enclosure.Size,
                                        enclosure.AddToFeed,
                                        enclosure.ShowWithPost,
                                        enclosure.EntryId,
                                        enclosure.Id);
 }
Ejemplo n.º 20
0
 public abstract void Update(Enclosure metaTag);
Ejemplo n.º 21
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.");
        }
Ejemplo n.º 22
0
        public void RssWriterProducesValidFeed()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Title = "My Blog Is Better Than Yours";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.TimeZoneId = PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            List<Entry> entries = new List<Entry>(CreateSomeEntries());
            entries[0].Categories.AddRange(new string[] { "Category1", "Category2" });
            entries[0].Email = "*****@*****.**";
            entries[2].Categories.Add("Category 3");

            Enclosure enc = new Enclosure();

            enc.Url = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc.Title = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc.Size = 26707573;
            enc.MimeType = "audio/mp3";
            enc.AddToFeed = true;

            entries[2].Enclosure = enc;

            Enclosure enc1 = new Enclosure();

            enc1.Url = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc1.Title = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc1.Size = 26707573;
            enc1.MimeType = "audio/mp3";
            enc1.AddToFeed = false;

            entries[3].Enclosure = enc1;

            RssWriter writer = new RssWriter(entries, NullValue.NullDateTime, false);

            string expected = @"<rss version=""2.0"" "
                                    + @"xmlns:dc=""http://purl.org/dc/elements/1.1/"" "
                                    + @"xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" "
                                    + @"xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" "
                                    + @"xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" "
                                    + @"xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" "
                                    + @"xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                                + indent() + @"<channel>" + Environment.NewLine
                                        + indent(2) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                                        + indent(2) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                        + indent(2) + @"<description />" + Environment.NewLine
                                        + indent(2) + @"<language>en-US</language>" + Environment.NewLine
                                        + indent(2) + @"<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                                        + indent(2) + @"<managingEditor>[email protected]</managingEditor>" + Environment.NewLine
                                        + indent(2) + @"<generator>{0}</generator>" + Environment.NewLine
                                        + indent(2) + @"<image>" + Environment.NewLine
                                            + indent(3) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                                            + indent(3) + @"<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<width>77</width>" + Environment.NewLine
                                            + indent(3) + @"<height>60</height>" + Environment.NewLine
                                        + indent(2) + @"</image>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1001.</title>" + Environment.NewLine
                                            + indent(3) + @"<category>Category1</category>" + Environment.NewLine
                                            + indent(3) + @"<category>Category2</category>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1002.</title>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1003.</title>" + Environment.NewLine
                                            + indent(3) + @"<category>Category 3</category>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" + Environment.NewLine
                                            + indent(3) + @"<enclosure url=""http://perseus.franklins.net/hanselminutes_0107.mp3"" length=""26707573"" type=""audio/mp3"" />" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1004.</title>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                + indent() + @"</channel>" + Environment.NewLine
                              + @"</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            Console.WriteLine(expected);
            Console.WriteLine(writer.Xml);
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }
Ejemplo n.º 23
0
 public abstract bool UpdateEnclosure(Enclosure enclosure);
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
0
        public void IsValid_WithZeroEntryId_ReturnsFalse()
        {
            // arrange
            var enclosure = new Enclosure {EntryId = 0};

            // act
            bool valid = enclosure.IsValid;

            // assert
            Assert.IsFalse(valid);
            Assert.AreEqual(Resources.Enclosure_NeedsAnEntry, enclosure.ValidationMessage);
        }
Ejemplo n.º 26
0
        public static Enclosure LoadEnclosure(IDataReader reader)
        {
            Enclosure enclosure = new Enclosure();

            enclosure.Id = ReadInt32(reader, "EnclosureId");
            enclosure.Title = ReadString(reader, "EnclosureTitle");
            enclosure.Url = ReadString(reader, "EnclosureUrl");
            enclosure.MimeType = ReadString(reader, "EnclosureMimeType");
            enclosure.Size = ReadInt64(reader, "EnclosureSize");
            enclosure.EntryId = ReadInt32(reader, "ID");
            enclosure.AddToFeed = ReadBoolean(reader, "AddToFeed");
            enclosure.ShowWithPost = ReadBoolean(reader, "ShowWithPost");

            return enclosure;
        }
        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);
        }