Example #1
0
        public void CreateBlogCannotHideAnotherBlog()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", _hostName, string.Empty);

            UnitTestHelper.AssertThrows <BlogHiddenException>(() => repository.CreateBlog("title", "username", "password", _hostName, "MyBlog"));
        }
Example #2
0
        public void CreateBlogCannotCreateOneWithDuplicateHostAndSubfolder()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", _hostName, "MyBlog");

            UnitTestHelper.AssertThrows <BlogDuplicationException>(() => repository.CreateBlog("title", "username2", "password2", _hostName, "MyBlog"));
        }
Example #3
0
        public void CreatingBlogWithDuplicateHostNameRequiresSubfolderName()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("", "username", "password", _hostName, "MyBlog1");


            UnitTestHelper.AssertThrows <BlogRequiresSubfolderException>(() => repository.CreateBlog("", "username", "password", _hostName, string.Empty));
        }
Example #4
0
        public void UpdateBlogCannotConflictWithDuplicateHost()
        {
            var    repository  = new DatabaseObjectProvider();
            string anotherHost = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("title", "username", "password", _hostName, string.Empty);
            repository.CreateBlog("title", "username2", "password2", anotherHost, string.Empty);
            Blog info = repository.GetBlog(anotherHost, string.Empty);

            info.Host = _hostName;

            UnitTestHelper.AssertThrows <BlogDuplicationException>(() => repository.UpdateConfigData(info));
        }
Example #5
0
        public void GetBlogInfoDoesNotFindBlogWithWrongSubfolderInMultiBlogSystem()
        {
            var    repository = new DatabaseObjectProvider();
            string subfolder1 = UnitTestHelper.GenerateUniqueString();
            string subfolder2 = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("title", "username", "password", hostName, subfolder1);
            repository.CreateBlog("title", "username", "password", hostName, subfolder2);

            Blog info = repository.GetBlog(hostName, string.Empty);

            Assert.IsNull(info, "Hmm... Looks like found a blog using too generic of search criteria.");
        }
Example #6
0
        public void CreateBlogCannotAddAliasThatIsDuplicateOfAnotherBlog()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", _hostName, string.Empty);
            repository.CreateBlog("title", "username2", "password2", "example.com", string.Empty);

            var alias = new BlogAlias {
                Host = "example.com", IsActive = true, BlogId = repository.GetBlog(_hostName, string.Empty).Id
            };

            UnitTestHelper.AssertThrows <BlogDuplicationException>(() => repository.AddBlogAlias(alias));
        }
Example #7
0
        public void UpdatingBlogWithDuplicateHostNameRequiresSubfolderName()
        {
            var    repository  = new DatabaseObjectProvider();
            string anotherHost = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("title", "username", "password", _hostName, "MyBlog1");
            repository.CreateBlog("title", "username", "password", anotherHost, string.Empty);

            Blog info = repository.GetBlog(anotherHost, string.Empty);

            info.Host      = _hostName;
            info.Subfolder = string.Empty;

            UnitTestHelper.AssertThrows <BlogRequiresSubfolderException>(() => repository.UpdateConfigData(info));
        }
Example #8
0
        public void GetPreviousAndNextEntriesReturnsNextWhenNoPreviousExists()
        {
            var    repository = new DatabaseObjectProvider();
            string hostname   = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);

            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.UtcNow.AddDays(-1));
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.UtcNow);

            int currentId = UnitTestHelper.Create(currentEntry);
            int nextId    = UnitTestHelper.Create(nextEntry);

            var entries = repository.GetPreviousAndNextEntries(currentId,
                                                               PostType.BlogPost);

            Assert.AreEqual(1, entries.Count, "Since there is no previous entry, should return only next");
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
        }
Example #9
0
        public void CanAddAndRemoveAllCategories()
        {
            string hostname   = UnitTestHelper.GenerateUniqueString();
            var    repository = new DatabaseObjectProvider();

            repository.CreateBlog("empty title", "username", "password", hostname, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty, "/");
            BlogRequest.Current.Blog = new DatabaseObjectProvider().GetBlog(hostname, "");
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Me", "Unit Test Entry", "Body");
            int   id    = UnitTestHelper.Create(entry);

            int categoryId = UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, "My Subtext UnitTest Category");

            repository.SetEntryCategoryList(id, new[] { categoryId });

            Entry loaded = UnitTestHelper.GetEntry(id, PostConfig.None, true);

            Assert.AreEqual("My Subtext UnitTest Category", loaded.Categories.First(),
                            "Expected a category for this entry");

            repository.SetEntryCategoryList(id, new int[] { });

            loaded = UnitTestHelper.GetEntry(id, PostConfig.None, true);
            Assert.AreEqual(0, loaded.Categories.Count, "Expected that our category would be removed.");
        }
Example #10
0
        /// <summary>
        /// Takes all the necessary steps to create a blog and set up the HTTP Context
        /// with the blog.
        /// </summary>
        /// <param name="subfolder">The 'virtualized' subfolder the blog lives in.</param>
        /// <param name="applicationPath">The name of the IIS virtual directory the blog lives in.</param>
        /// <param name="port">The port for this blog.</param>
        /// <param name="page">The page to request.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <returns>
        /// Returns a reference to a string builder.
        /// The stringbuilder will end up containing the Response of any simulated
        /// requests.
        /// </returns>
        internal static SimulatedRequestContext SetupBlog(string subfolder, string applicationPath, int port,
                                                          string page, string userName, string password)
        {
            var    repository = new DatabaseObjectProvider();
            string host       = GenerateUniqueString();

            HttpContext.Current = null;
            //I wish this returned the blog it created.
            repository.CreateBlog("Unit Test Blog", userName, password, host, subfolder);
            Blog blog = repository.GetBlog(host, subfolder);

            var                  sb      = new StringBuilder();
            TextWriter           output  = new StringWriter(sb);
            SimulatedHttpRequest request = SetHttpContextWithBlogRequest(host, port, subfolder, applicationPath, page,
                                                                         output, "GET");

            BlogRequest.Current.Blog = blog;

            if (Config.CurrentBlog != null)
            {
                Config.CurrentBlog.AutoFriendlyUrlEnabled = true;
            }
            HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(userName), new[] { "Administrators" });

            return(new SimulatedRequestContext(request, sb, output, host));
        }
Example #11
0
        public void CreateTrackbackSetsFeedbackTypeCorrectly()
        {
            string hostname   = UnitTestHelper.GenerateUniqueString();
            var    repository = new DatabaseObjectProvider();

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

            BlogRequest.Current.Blog = blog;

            Entry entry    = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "title", "body");
            int   parentId = UnitTestHelper.Create(entry);

            var trackback      = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body");
            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.Cache).Returns(new TestCache());
            subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable());
            var commentService = new CommentService(subtextContext.Object, null);
            int id             = commentService.Create(trackback, true /*runFilters*/);

            FeedbackItem loadedTrackback = repository.Get(id);

            Assert.IsNotNull(loadedTrackback, "Was not able to load trackback from storage.");
            Assert.AreEqual(FeedbackType.PingTrack, loadedTrackback.FeedbackType, "Feedback should be a PingTrack");
        }
        public void GetPagedEntriesHandlesPagingProperly(int total, int pageSize, int expectedPageCount,
                                                         int itemsCountOnLastPage)
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("", "username", "password", _hostName, "blog");
            BlogRequest.Current.Blog = repository.GetBlog(_hostName, "blog");
            AssertPagedCollection(new PagedEntryCollectionTester(), expectedPageCount, itemsCountOnLastPage, pageSize, total);
        }
Example #13
0
        public void Setup()
        {
            var    repository = new DatabaseObjectProvider();
            string hostname   = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);
        }
Example #14
0
        public void GetBlogInfoFindsBlogWithUniqueHostAndSubfolder()
        {
            var    repository = new DatabaseObjectProvider();
            string subfolder1 = UnitTestHelper.GenerateUniqueString();
            string subfolder2 = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("title", "username", "password", hostName, subfolder1);
            repository.CreateBlog("title", "username", "password", hostName, subfolder2);

            Blog info = repository.GetBlog(hostName, subfolder1);

            Assert.IsNotNull(info, "Could not find the blog with the unique hostName & subfolder combination.");
            Assert.AreEqual(info.Subfolder, subfolder1, "Oops! Looks like we found the wrong Blog!");

            info = repository.GetBlog(hostName, subfolder2);
            Assert.IsNotNull(info, "Could not find the blog with the unique hostName & subfolder combination.");
            Assert.AreEqual(info.Subfolder, subfolder2, "Oops! Looks like we found the wrong Blog!");
        }
Example #15
0
        public void UpdatingBlogIsFine()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", _hostName, string.Empty);
            Blog info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), string.Empty);

            info.Author = "Phil";
            repository.UpdateConfigData(info); //Make sure no exception is thrown.
        }
Example #16
0
        public void CannotRenameBlogToHaveSubfolderNameBin()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "blah", "blah", _hostName, "Anything");
            Blog info = repository.GetBlog(_hostName, "Anything");

            info.Subfolder = "bin";

            UnitTestHelper.AssertThrows <InvalidSubfolderNameException>(() => repository.UpdateConfigData(info));
        }
Example #17
0
        public void UpdatingBlogCannotHideAnotherBlog()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", "www.mydomain.com", string.Empty);

            Blog info = repository.GetBlog("www.mydomain.com", string.Empty);

            info.Host      = "mydomain.com";
            info.Subfolder = "MyBlog";
            repository.UpdateConfigData(info);
        }
Example #18
0
        public void AtomWriterProducesValidFeedFromDatabase()
        {
            string hostName   = UnitTestHelper.GenerateUniqueString();
            var    repository = new DatabaseObjectProvider();

            repository.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);
            Config.CurrentBlog.Email = "*****@*****.**";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            DateTime dateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            Entry    entry       = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null, dateCreated);

            UnitTestHelper.Create(entry); //persist to db.

            var    subtextContext = new Mock <ISubtextContext>();
            string rssOutput      = null;

            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            Mock <BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");
            var handler = new AtomHandler(subtextContext.Object);

            handler.ProcessRequest();
            HttpContext.Current.Response.Flush();

            var doc = new XmlDocument();

            doc.LoadXml(rssOutput);
            var nsmanager = new XmlNamespaceManager(doc.NameTable);

            nsmanager.AddNamespace("atom", "http://www.w3.org/2005/Atom");

            XmlNodeList itemNodes = doc.SelectNodes("/atom:feed/atom:entry", nsmanager);

            Assert.AreEqual(1, itemNodes.Count, "expected one entry node.");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("atom:title", nsmanager).InnerText,
                            "Not what we expected for the title.");
            string urlFormat = "http://{0}/archive/2008/01/23/{1}.aspx";

            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:id", nsmanager).InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:link/@href", nsmanager).InnerText,
                            "Not what we expected for the link.");
        }
Example #19
0
        public void SettingShowEmailAddressInRssFlagDoesntChangeOtherFlags()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", hostName, string.Empty);
            Blog info = repository.GetBlog(hostName, string.Empty);
            bool test = info.IsAggregated;

            info.ShowEmailAddressInRss = false;
            repository.UpdateConfigData(info);
            info = repository.GetBlog(hostName, string.Empty);

            Assert.AreEqual(test, info.IsAggregated);
        }
Example #20
0
        public void RssWriterProducesValidFeedFromDatabase()
        {
            var    repository = new DatabaseObjectProvider();
            string hostName   = UnitTestHelper.GenerateUniqueHostname();

            repository.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);

            Config.CurrentBlog.Email = "*****@*****.**";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author",
                                                                           "testtitle",
                                                                           "testbody",
                                                                           null,
                                                                           NullValue.NullDateTime);

            entry.DateCreatedUtc   = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.DatePublishedUtc = entry.DateCreatedUtc;
            UnitTestHelper.Create(entry); //persist to db.

            string rssOutput      = null;
            var    subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Repository).Returns(repository);
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            Mock <BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);

            Assert.AreEqual(1, itemNodes.Count, "expected one item nodes.");

            string urlFormat   = "http://{0}/archive/2008/01/23/{1}.aspx";
            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the title.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("link").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("guid").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl + "#feedback", itemNodes[0].SelectSingleNode("comments").InnerText,
                            "Not what we expected for the link.");
        }
Example #21
0
        public void ModifyingBlogShouldNotChangePassword()
        {
            var repository = new DatabaseObjectProvider();

            Config.Settings.UseHashedPasswords = true;
            repository.CreateBlog("", "username", "thePassword", _hostName, "MyBlog1");
            Blog   info     = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), "MyBlog1");
            string password = info.Password;

            info.LicenseUrl = "http://subtextproject.com/";
            repository.UpdateConfigData(info);

            info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), "MyBlog1");
            Assert.AreEqual(password, info.Password);
        }
Example #22
0
        public void CreatingBlogHashesPassword()
        {
            const string password       = "******";
            string       hashedPassword = SecurityHelper.HashPassword(password);
            var          repository     = new DatabaseObjectProvider();

            repository.CreateBlog("", "username", password, _hostName, "MyBlog1");
            Blog info = repository.GetBlog(_hostName, "MyBlog1");

            Assert.IsNotNull(info, "We tried to get blog at " + _hostName + "/MyBlog1 but it was null");

            Config.Settings.UseHashedPasswords = true;
            Assert.IsTrue(Config.Settings.UseHashedPasswords, "This test is voided because we're not hashing passwords");
            Assert.AreEqual(hashedPassword, info.Password, "The password wasn't hashed.");
        }
Example #23
0
        public static Blog CreateBlogAndSetupContext(string hostName = null, string subfolder = "")
        {
            hostName = hostName ?? GenerateUniqueString();
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("Just A Test Blog", "test", "test", hostName, subfolder /* subfolder */);
            Blog blog = repository.GetBlog(hostName, subfolder);

            SetHttpContextWithBlogRequest(hostName, subfolder);
            BlogRequest.Current.Blog = blog;
            Assert.IsNotNull(Config.CurrentBlog, "Current Blog is null.");

            // NOTE- is this OK?
            return(Config.CurrentBlog);
        }
Example #24
0
        public void CanUpdateMobileSkin()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", _hostName, string.Empty);
            Blog info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), string.Empty);

            info.MobileSkin = new SkinConfig {
                TemplateFolder = "Mobile", SkinStyleSheet = "Mobile.css"
            };
            repository.UpdateConfigData(info);
            Blog blog = repository.GetBlogById(info.Id);

            Assert.AreEqual("Mobile", blog.MobileSkin.TemplateFolder);
            Assert.AreEqual("Mobile.css", blog.MobileSkin.SkinStyleSheet);
        }
Example #25
0
        public void GetBlogInfoLoadsOpenIDSettings()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", hostName, string.Empty);

            Blog info = repository.GetBlog(hostName, string.Empty);

            info.OpenIdServer   = "http://server.example.com/";
            info.OpenIdDelegate = "http://delegate.example.com/";
            repository.UpdateConfigData(info);
            info = repository.GetBlog(hostName, string.Empty);

            Assert.AreEqual("http://server.example.com/", info.OpenIdServer);
            Assert.AreEqual("http://delegate.example.com/", info.OpenIdDelegate);
        }
Example #26
0
        public void CreatingMultipleBlogs_WithDistinctProperties_DoesNotThrowException()
        {
            var repository = new DatabaseObjectProvider();

            repository.CreateBlog("title", "username", "password", UnitTestHelper.GenerateUniqueString(), string.Empty);
            repository.CreateBlog("title", "username", "password", "www2." + UnitTestHelper.GenerateUniqueString(),
                                  string.Empty);
            repository.CreateBlog("title", "username", "password", UnitTestHelper.GenerateUniqueString(), string.Empty);
            repository.CreateBlog("title", "username", "password", _hostName, "Blog1");
            repository.CreateBlog("title", "username", "password", _hostName, "Blog2");
            repository.CreateBlog("title", "username", "password", _hostName, "Blog3");
        }
Example #27
0
        public void GetPreviousAndNextBasedOnSyndicationDateNotEntryId()
        {
            var    repository = new DatabaseObjectProvider();
            string hostname   = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);

            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");
            Entry currentEntry  = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");
            Entry nextEntry     = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");

            previousEntry.IsActive = false;
            currentEntry.IsActive  = false;
            nextEntry.IsActive     = false;

            //Create out of order.
            int currentId  = UnitTestHelper.Create(currentEntry);
            int nextId     = UnitTestHelper.Create(nextEntry);
            int previousId = UnitTestHelper.Create(previousEntry);

            //Now syndicate.
            previousEntry.IsActive = true;
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            UnitTestHelper.Update(previousEntry, subtextContext.Object);
            Thread.Sleep(100);
            currentEntry.IsActive = true;
            UnitTestHelper.Update(currentEntry, subtextContext.Object);
            Thread.Sleep(100);
            nextEntry.IsActive = true;
            UnitTestHelper.Update(nextEntry, subtextContext.Object);

            Assert.IsTrue(previousId > currentId, "Ids are out of order.");

            var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost);

            Assert.AreEqual(2, entries.Count, "Expected both previous and next.");
            //The first should be next because of descending sort.
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
            Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations.");
        }
Example #28
0
        public void GetPreviousAndNextEntriesReturnsCorrectEntries()
        {
            var    repository = new DatabaseObjectProvider();
            string hostname   = UnitTestHelper.GenerateUniqueString();

            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);

            Entry firstEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                UnitTestHelper.GenerateUniqueString(),
                                                                                DateTime.UtcNow.AddDays(-3));
            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                   UnitTestHelper.GenerateUniqueString(),
                                                                                   DateTime.UtcNow.AddDays(-2));
            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.UtcNow.AddDays(-1));
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.UtcNow);
            Entry lastEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.UtcNow.AddDays(1));

            Thread.Sleep(100);
            int previousId = UnitTestHelper.Create(previousEntry);

            Thread.Sleep(100);
            int currentId = UnitTestHelper.Create(currentEntry);

            Thread.Sleep(100);
            int nextId = UnitTestHelper.Create(nextEntry);

            Thread.Sleep(100);

            var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost);

            Assert.AreEqual(2, entries.Count, "Expected both previous and next.");

            //The more recent one is next because of desceding sort.
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
            Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations.");
        }
Example #29
0
        Entry SetupBlogForCommentsAndCreateEntry(DatabaseObjectProvider repository = null)
        {
            repository = repository ?? new DatabaseObjectProvider();
            repository.CreateBlog(string.Empty, "username", "password", _hostName, string.Empty);
            Blog info = repository.GetBlog(_hostName, string.Empty);

            BlogRequest.Current.Blog = info;
            info.Email             = "*****@*****.**";
            info.Title             = "You've been haacked";
            info.CommentsEnabled   = true;
            info.ModerationEnabled = false;

            repository.UpdateConfigData(info);

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("blah", "blah", "blah");

            UnitTestHelper.Create(entry);
            return(entry);
        }
Example #30
0
        public void RssHandlerHandlesDoesNotSyndicateFuturePosts()
        {
            // Arrange
            var    repository = new DatabaseObjectProvider();
            string hostName   = UnitTestHelper.GenerateUniqueHostname();

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            repository.CreateBlog("", "username", "password", hostName, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);

            //Create two entries, but only include one in main syndication.
            UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test",
                                                                                   "Body Rocking", null,
                                                                                   NullValue.NullDateTime));
            Entry futureEntry = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2",
                                                                                 "Body Rocking Pt 2", null,
                                                                                 NullValue.NullDateTime);

            futureEntry.DatePublishedUtc = DateTime.UtcNow.AddMinutes(20);
            UnitTestHelper.Create(futureEntry);

            string rssOutput      = null;
            var    subtextContext = new Mock <ISubtextContext>();

            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            Mock <BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/whatever");

            // Act
            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);

            // Assert
            Assert.AreEqual(1, itemNodes.Count, "expected one item node.");

            Assert.AreEqual("Title Test", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");
            Assert.AreEqual("Body Rocking",
                            itemNodes[0].SelectSingleNode("description").InnerText.Substring(0, "Body Rocking".Length),
                            "Not what we expected for the first body.");
        }