Revision: 3399
http://subtext.svn.sourceforge.net/subtext/?rev=3399&view=rev
Author: haacked
Date: 2009-03-09 06:58:11 +0000 (Mon, 09 Mar 2009)
Log Message:
-----------
Fixed up broken unit tests. Down to 4 failed tests.
Modified Paths:
--------------
trunk/SubtextSolution/Subtext.Framework/Configuration/UrlBasedBlogInfoProvider.cs
trunk/SubtextSolution/Subtext.Framework/ContentCache.cs
trunk/SubtextSolution/Subtext.Framework/Data/Cacher.cs
trunk/SubtextSolution/Subtext.Framework/Data/EntryRepository.cs
trunk/SubtextSolution/Subtext.Framework/Data/ICache.cs
trunk/SubtextSolution/Subtext.Framework/Data/SubtextCache.cs
trunk/SubtextSolution/Subtext.Framework/Entries.cs
trunk/SubtextSolution/Subtext.Framework/Links.cs
trunk/SubtextSolution/Subtext.Framework/Syndication/CommentHandler.cs
trunk/SubtextSolution/Subtext.Framework/Syndication/RssCategoryHandler.cs
trunk/SubtextSolution/Subtext.Framework/Syndication/RssCommentHandler.cs
trunk/SubtextSolution/Subtext.Framework/XmlRpc/MetaWeblog.cs
trunk/SubtextSolution/Subtext.Providers.BlogEntryEditor.FCKeditor/FileBrowserConnector.cs
trunk/SubtextSolution/Subtext.Web/Admin/EditCategories.aspx.cs
trunk/SubtextSolution/Subtext.Web/Admin/EditGalleries.aspx.cs
trunk/SubtextSolution/Subtext.Web/Admin/EditImage.aspx.cs
trunk/SubtextSolution/Subtext.Web/Admin/UserControls/EntriesList.ascx.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveDay.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveMonth.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/Calendar.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/CategoryDisplay.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/Comments.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/EntryList.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/LinkPage.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/PostComment.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/SingleColumn.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/StoryList.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/TagCloud.cs
trunk/SubtextSolution/Subtext.Web/UI/Controls/TagEntryList.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/Components/EntryTests/EntryFilterTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/CacherTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/ContentCacheTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/Email/EmailServiceTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/ImageTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/LinksTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/Tracking/TrackbackHandlerTests.cs
trunk/SubtextSolution/UnitTests.Subtext/Framework/XmlRpc/MetaBlogApiTests.cs
trunk/SubtextSolution/UnitTests.Subtext/MockExtensions.cs
trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/Providers/RichTextEditor/FtbProviderTests.cs
trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/SitemapHandlerTests.cs
Modified: trunk/SubtextSolution/Subtext.Framework/Configuration/UrlBasedBlogInfoProvider.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Configuration/UrlBasedBlogInfoProvider.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Configuration/UrlBasedBlogInfoProvider.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -109,7 +109,7 @@
}
}
- private static void MapImageDirectory(BlogRequest blogRequest)
+ public static void MapImageDirectory(BlogRequest blogRequest)
{
Blog info = blogRequest.Blog;
BlogConfigurationSettings settings = Config.Settings;
Modified: trunk/SubtextSolution/Subtext.Framework/ContentCache.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/ContentCache.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/ContentCache.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -4,6 +4,11 @@
using System.Threading;
using System.Web;
using System.Web.Caching;
+using System.Web.Routing;
+using Subtext.Framework.Configuration;
+using Subtext.Framework.Data;
+using Subtext.Framework.Providers;
+using Subtext.Framework.Routing;
namespace Subtext.Framework
{
@@ -14,25 +19,19 @@
/// </summary>
public class ContentCache : IEnumerable
{
- Cache cache;
+ ICache cache;
- /// <summary>
- /// Instantiates the specified content cache from the specific <see cref="HttpContext"/>.
- /// At some point, we might consider replacing HttpContext with a type we can extend.
- /// </summary>
- /// <returns></returns>
- public static ContentCache Instantiate()
- {
- //Check per-request cache.
- ContentCache cache = HttpContext.Current.Items["ContentCache"] as ContentCache;
- if(cache != null)
- return cache;
+ public static ContentCache Instantiate(ISubtextContext context) {
+ //Check per-request cache.
+ ContentCache cache = context.RequestContext.HttpContext.Items["ContentCache"] as ContentCache;
+ if (cache != null)
+ return cache;
- cache = new ContentCache(HttpContext.Current.Cache);
- //Per-Request Cache.
- HttpContext.Current.Items["ContentCache"] = cache;
- return cache;
- }
+ cache = new ContentCache(context.Cache);
+ //Per-Request Cache.
+ context.RequestContext.HttpContext.Items["ContentCache"] = cache;
+ return cache;
+ }
private ContentCache() {}
@@ -41,7 +40,7 @@
/// The specified <see cref="Cache"/> instance is wrapped by this instance.
/// </summary>
/// <param name="cache">The cache.</param>
- private ContentCache(Cache cache)
+ private ContentCache(ICache cache)
{
this.cache = cache;
}
@@ -129,7 +128,7 @@
/// <returns></returns>
public object Get(string key)
{
- return this.cache.Get(GetCacheKey(key));
+ return this.cache[GetCacheKey(key)];
}
/// <summary>
@@ -137,23 +136,16 @@
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
- public object Remove(string key)
+ public void Remove(string key)
{
- return this.cache.Remove(GetCacheKey(key));
+ this.cache.Remove(GetCacheKey(key));
}
- /// <summary>
- /// Returns an enumerator that can iterate through a collection.
- /// </summary>
- /// <returns>
- /// An <see cref="T:System.Collections.IEnumerator"/>
- /// that can be used to iterate through the collection.
- /// </returns>
- public IEnumerator GetEnumerator()
- {
- return this.cache.GetEnumerator();
- }
- }
+ public IEnumerator GetEnumerator()
+ {
+ return this.cache.GetEnumerator();
+ }
+ }
/// <summary>
/// Low granularity Cache Duration.
Modified: trunk/SubtextSolution/Subtext.Framework/Data/Cacher.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Data/Cacher.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Data/Cacher.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -40,16 +40,16 @@
/// </summary>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static ICollection<LinkCategory> GetActiveCategories(CacheDuration cacheDuration, Blog blog)
+ public static ICollection<LinkCategory> GetActiveCategories(CacheDuration cacheDuration, ISubtextContext context)
{
- string key = string.Format(ActiveLCCKey, blog.Id);
+ string key = string.Format(ActiveLCCKey, context.Blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ ContentCache cache = ContentCache.Instantiate(context);
ICollection<LinkCategory> categories = (ICollection<LinkCategory>)cache[key];
if(categories == null)
{
- categories = Links.GetActiveCategories();
+ categories = context.Repository.GetActiveCategories();
if(categories != null)
{
cache.Insert(key, categories, cacheDuration);
@@ -65,10 +65,10 @@
/// <param name="dt">The dt.</param>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static ICollection<Entry> GetMonth(DateTime dt, CacheDuration cacheDuration, Blog blog)
+ public static ICollection<Entry> GetMonth(DateTime dt, CacheDuration cacheDuration, ISubtextContext context)
{
- string key = string.Format(CultureInfo.InvariantCulture, EntryMonthKey, dt, blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ string key = string.Format(CultureInfo.InvariantCulture, EntryMonthKey, dt, context.Blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
ICollection<Entry> month = (ICollection<Entry>)cache[key];
if(month == null)
{
@@ -82,12 +82,12 @@
}
private static readonly string EntryDayKey = "EntryDay:Date{0:yyyyMMdd}Blog{1}";
- public static EntryDay GetDay(DateTime dt, CacheDuration cacheDuration, Blog blog)
+ public static EntryDay GetDay(DateTime dt, CacheDuration cacheDuration, ISubtextContext context)
{
- string key = string.Format(CultureInfo.InvariantCulture, EntryDayKey, dt, blog.Id);
+ string key = string.Format(CultureInfo.InvariantCulture, EntryDayKey, dt, context.Blog.Id);
+
+ ContentCache cache = ContentCache.Instantiate(context);
- ContentCache cache = ContentCache.Instantiate();
-
EntryDay day = (EntryDay)cache[key];
if(day == null)
{
@@ -102,10 +102,10 @@
}
private const string ECKey="EC:Count{0}Category{1}BlogId{2}";
- public static ICollection<Entry> GetEntriesByCategory(int count, CacheDuration cacheDuration, int categoryID, Blog blog)
+ public static ICollection<Entry> GetEntriesByCategory(int count, CacheDuration cacheDuration, int categoryID, ISubtextContext context)
{
- string key = string.Format(ECKey, count, categoryID, blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ string key = string.Format(ECKey, count, categoryID, context.Blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
ICollection<Entry> ec = (ICollection<Entry>)cache[key];
if(ec == null)
{
@@ -120,10 +120,10 @@
}
private static readonly string ETKey = "ET:Count{0}Tag{1}BlogId{2}";
- public static ICollection<Entry> GetEntriesByTag(int count, CacheDuration cacheDuration, string tag, Blog blog)
+ public static ICollection<Entry> GetEntriesByTag(int count, CacheDuration cacheDuration, string tag, ISubtextContext context)
{
- string key = string.Format(ETKey, count, tag, blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ string key = string.Format(ETKey, count, tag, context.Blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
ICollection<Entry> et = (ICollection<Entry>)cache[key];
if (et == null)
{
@@ -142,53 +142,53 @@
/// </summary>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static LinkCategory SingleCategory(CacheDuration cacheDuration, Blog blog)
+ public static LinkCategory SingleCategory(CacheDuration cacheDuration, ISubtextContext context)
{
- if (HttpContext.Current == null)
- throw new InvalidOperationException("This method requires the HttpContext. Argue all you want about whether that is good design. That's just the way it is for now.");
+ if (context == null)
+ throw new ArgumentNullException("context", "This method requires the HttpContext. Argue all you want about whether that is good design. That's just the way it is for now.");
- string path = WebPathStripper.RemoveRssSlash(HttpContext.Current.Request.Path);
+ string path = WebPathStripper.RemoveRssSlash(context.RequestContext.HttpContext.Request.Path);
string categoryName = Path.GetFileNameWithoutExtension(path);
if(categoryName.IsNumeric())
{
int categoryID = Int32.Parse(categoryName);
- return SingleCategory(cacheDuration, categoryID, true, blog);
+ return SingleCategory(cacheDuration, categoryID, true, context);
}
else
{
- return SingleCategory(cacheDuration, categoryName, true, blog);
+ return SingleCategory(cacheDuration, categoryName, true, context);
}
}
private static readonly string LCKey="LC{0}BlogId{1}";
- public static LinkCategory SingleCategory(CacheDuration cacheDuration, int categoryId, bool isActive, Blog blog)
+ public static LinkCategory SingleCategory(CacheDuration cacheDuration, int categoryId, bool isActive, ISubtextContext context)
{
- LinkCategoryRetrieval retrieval = delegate { return Links.GetLinkCategory(categoryId, isActive); };
- return SingleCategory(retrieval, cacheDuration, categoryId, blog);
+ LinkCategoryRetrieval retrieval = delegate { return context.Repository.GetLinkCategory(categoryId, isActive); };
+ return SingleCategory(retrieval, cacheDuration, categoryId, context);
}
- public static LinkCategory SingleCategory(CacheDuration cacheDuration, string categoryName, bool isActive, Blog blog)
+ public static LinkCategory SingleCategory(CacheDuration cacheDuration, string categoryName, bool isActive, ISubtextContext context)
{
- LinkCategoryRetrieval retrieval = delegate { return Links.GetLinkCategory(categoryName, isActive); };
- LinkCategory category = SingleCategory(retrieval, cacheDuration, categoryName, blog);
+ LinkCategoryRetrieval retrieval = delegate { return context.Repository.GetLinkCategory(categoryName, isActive); };
+ LinkCategory category = SingleCategory(retrieval, cacheDuration, categoryName, context);
if(category != null)
return category;
- if (blog.AutoFriendlyUrlEnabled)
+ if (context.Blog.AutoFriendlyUrlEnabled)
{
categoryName = categoryName.Replace(FriendlyUrlSettings.Settings.SeparatingCharacter, " ");
- retrieval = delegate { return Links.GetLinkCategory(categoryName, isActive); };
- return SingleCategory(retrieval, cacheDuration, categoryName, blog);
+ retrieval = delegate { return context.Repository.GetLinkCategory(categoryName, isActive); };
+ return SingleCategory(retrieval, cacheDuration, categoryName, context);
}
return null; //couldn't find category
}
- private static LinkCategory SingleCategory<T>(LinkCategoryRetrieval retrievalDelegate, CacheDuration cacheDuration, T categoryKey, Blog blog)
+ private static LinkCategory SingleCategory<T>(LinkCategoryRetrieval retrievalDelegate, CacheDuration cacheDuration, T categoryKey, ISubtextContext context)
{
- ContentCache cache = ContentCache.Instantiate();
- string key = string.Format(LCKey, categoryKey, blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
+ string key = string.Format(LCKey, categoryKey, context.Blog.Id);
LinkCategory lc = (LinkCategory)cache[key];
if(lc == null)
{
@@ -208,14 +208,14 @@
if (routeValues.ContainsKey("slug")) {
string slug = (string)routeValues["slug"];
- return GetEntry(slug, cacheDuration, context.Repository, context.Blog);
+ return GetEntry(slug, cacheDuration, context);
}
int id;
if (int.TryParse((string)routeValues["id"], out id))
{
- Entry entry = GetEntry(id, cacheDuration, context.Repository, context.Blog);
+ Entry entry = GetEntry(id, cacheDuration, context);
if (entry == null) {
return null;
}
@@ -247,11 +247,13 @@
/// <param name="EntryName">Name of the entry.</param>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static Entry GetEntry(string entryName, CacheDuration cacheDuration, ObjectProvider repository, Blog blog)
+ public static Entry GetEntry(string entryName, CacheDuration cacheDuration, ISubtextContext context)
{
+ Blog blog = context.Blog;
+ ObjectProvider repository = context.Repository;
int blogId = blog.Id;
-
- ContentCache cache = ContentCache.Instantiate();
+
+ ContentCache cache = ContentCache.Instantiate(context);
string key = string.Format(EntryKeyName, entryName, blogId);
Entry entry = (Entry)cache[key];
@@ -285,9 +287,13 @@
/// <param name="entryID">The entry ID.</param>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static Entry GetEntry(int entryId, CacheDuration cacheDuration, ObjectProvider repository, Blog blog)
+ public static Entry GetEntry(int entryId, CacheDuration cacheDuration, ISubtextContext context)
{
- ContentCache cache = ContentCache.Instantiate();
+ Blog blog = context.Blog;
+ ObjectProvider repository = context.Repository;
+ int blogId = blog.Id;
+
+ ContentCache cache = ContentCache.Instantiate(context);
string key = string.Format(EntryKeyID, entryId, blog.Id);
Entry entry = (Entry)cache[key];
@@ -311,10 +317,10 @@
/// <param name="ItemCount">The item count</param>
/// <param name="cacheDuration">The cache duration.</param>
/// <returns></returns>
- public static IEnumerable<Tag> GetTopTags(int ItemCount, CacheDuration cacheDuration, Blog blog)
+ public static IEnumerable<Tag> GetTopTags(int ItemCount, CacheDuration cacheDuration, ISubtextContext context)
{
- ContentCache cache = ContentCache.Instantiate();
- string key = string.Format(TagsKey, ItemCount, blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
+ string key = string.Format(TagsKey, ItemCount, context.Blog.Id);
IEnumerable<Tag> tags = (IEnumerable<Tag>)cache[key];
if (tags == null)
@@ -332,10 +338,10 @@
/// Clears the comment cache.
/// </summary>
/// <param name="entryID">The entry ID.</param>
- public static void ClearCommentCache(int entryId, Blog blog)
+ public static void ClearCommentCache(int entryId, ISubtextContext context)
{
- string key = string.Format(ParentCommentEntryKey, entryId, blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ string key = string.Format(ParentCommentEntryKey, entryId, context.Blog.Id);
+ ContentCache cache = ContentCache.Instantiate(context);
cache.Remove(key);
}
@@ -348,15 +354,15 @@
/// <param name="cacheDuration"></param>
/// <returns></returns>
/// <param name="fromCache"></param>
- public static ICollection<FeedbackItem> GetFeedback(Entry parentEntry, CacheDuration cacheDuration, bool fromCache, Blog blog)
+ public static ICollection<FeedbackItem> GetFeedback(Entry parentEntry, CacheDuration cacheDuration, bool fromCache, ISubtextContext context)
{
ICollection<FeedbackItem> comments = null;
ContentCache cache = null;
string key = null;
if (fromCache)
{
- key = string.Format(ParentCommentEntryKey, parentEntry.Id, blog.Id);
- cache = ContentCache.Instantiate();
+ key = string.Format(ParentCommentEntryKey, parentEntry.Id, context.Blog.Id);
+ cache = ContentCache.Instantiate(context);
comments = (ICollection<FeedbackItem>)cache[key];
}
if(comments == null)
Modified: trunk/SubtextSolution/Subtext.Framework/Data/EntryRepository.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Data/EntryRepository.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Data/EntryRepository.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -288,7 +288,7 @@
public override bool SetEntryCategoryList(int entryId, IEnumerable<int> categoryIds)
{
if (categoryIds == null)
- return false;
+ return _procedures.InsertLinkCategoryList(string.Empty, entryId, BlogId); ;
var idsAsStrings = categoryIds.Select(id => id.ToString(CultureInfo.InvariantCulture));
string catList = string.Join(",", idsAsStrings.ToArray());
Modified: trunk/SubtextSolution/Subtext.Framework/Data/ICache.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Data/ICache.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Data/ICache.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -1,13 +1,16 @@
-using System.Web.Caching;
-using System;
+using System;
+using System.Collections;
+using System.Web.Caching;
namespace Subtext.Framework.Data
{
- public interface ICache
+ public interface ICache : IEnumerable
{
object this[string key] { get; set; }
+ void Insert(string key, object value);
void Insert(string key, object value, CacheDependency dependency);
void Insert(string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration);
+ void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback);
void Remove(string key);
}
}
Modified: trunk/SubtextSolution/Subtext.Framework/Data/SubtextCache.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Data/SubtextCache.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Data/SubtextCache.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -1,4 +1,6 @@
-using System.Web.Caching;
+using System;
+using System.Collections;
+using System.Web.Caching;
namespace Subtext.Framework.Data
{
@@ -22,13 +24,15 @@
Cache[key] = value;
}
}
-
+
+ public void Insert(string key, object value) {
+ Cache.Insert(key, value);
+ }
+
public void Insert(string key, object value, CacheDependency dependency) {
Cache.Insert(key, value, dependency);
-
}
-
public void Insert(string key, object value, CacheDependency dependency, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration) {
Cache.Insert(key, value, dependency, absoluteExpiration, slidingExpiration);
}
@@ -36,5 +40,16 @@
public void Remove(string key) {
Cache.Remove(key);
}
+
+
+ public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
+ {
+ Cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return Cache.GetEnumerator();
+ }
}
}
Modified: trunk/SubtextSolution/Subtext.Framework/Entries.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Entries.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Entries.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -208,7 +208,7 @@
//We need to do something.
foreach(string category in entry.Categories)
{
- LinkCategory cat = Links.GetLinkCategory(category, true);
+ LinkCategory cat = ObjectProvider.Instance().GetLinkCategory(category, true);
if(cat != null)
{
catIds.Add(cat.Id);
Modified: trunk/SubtextSolution/Subtext.Framework/Links.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Links.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Links.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -56,11 +56,6 @@
return ObjectProvider.Instance().GetCategories(catType, status == ActiveFilter.ActiveOnly);
}
- public static ICollection<LinkCategory> GetActiveCategories()
- {
- return ObjectProvider.Instance().GetActiveCategories();
- }
-
public static ICollection<LinkCategory> GetLinkCategoriesByPostID(int postId)
{
List<Link> links = new List<Link>(GetLinkCollectionByPostID(postId));
@@ -85,24 +80,7 @@
#endregion
- #region LinkCategory
- public static LinkCategory GetLinkCategory(int categoryId, bool isActive)
- {
- //TODO: We need to check this for null and throw a custom
- // exception in the case that the category does not exist.
- return ObjectProvider.Instance().GetLinkCategory(categoryId, isActive);
- }
-
- public static LinkCategory GetLinkCategory(string categoryName, bool isActive)
- {
- //TODO: We need to check this for null and throw a custom
- // exception in the case that the category does not exist.
- return ObjectProvider.Instance().GetLinkCategory(categoryName, isActive);
- }
-
- #endregion
-
#region Edit Links/Categories
public static bool UpdateLink(Link link)
Modified: trunk/SubtextSolution/Subtext.Framework/Syndication/CommentHandler.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Syndication/CommentHandler.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Syndication/CommentHandler.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -14,6 +14,7 @@
#endregion
using System.Web;
+using System.Web.Routing;
using System.Xml;
using Subtext.Extensibility;
using Subtext.Framework.Components;
@@ -71,7 +72,10 @@
Blog blog = Config.CurrentBlog;
// [ 1644691 ] Closing comments didn't stop the CommentAPI
- if (!Cacher.GetEntry(comment.EntryId, CacheDuration.Medium, ObjectProvider.Instance(), blog).CommentingClosed) {
+ var requestContext = new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData());
+ var subtextContext = new SubtextContext(Config.CurrentBlog, requestContext, new UrlHelper(requestContext, RouteTable.Routes), ObjectProvider.Instance());
+
+ if (!Cacher.GetEntry(comment.EntryId, CacheDuration.Medium, subtextContext).CommentingClosed) {
var feedbackService = new AkismetSpamService(Config.CurrentBlog.FeedbackSpamServiceKey, blog, null, new UrlHelper(null, null));
FeedbackItem.Create(comment, new CommentFilter(new SubtextCache(HttpContext.Current.Cache), feedbackService, blog), blog);
}
Modified: trunk/SubtextSolution/Subtext.Framework/Syndication/RssCategoryHandler.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Syndication/RssCategoryHandler.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Syndication/RssCategoryHandler.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -38,12 +38,12 @@
{
if(Category == null)
{
- Category = Cacher.SingleCategory(CacheDuration.Short, Blog);
+ Category = Cacher.SingleCategory(CacheDuration.Short, SubtextContext);
}
if(Category != null && posts == null)
{
- posts = Cacher.GetEntriesByCategory(10, CacheDuration.Short, Category.Id, Blog);
+ posts = Cacher.GetEntriesByCategory(10, CacheDuration.Short, Category.Id, SubtextContext);
}
return posts;
Modified: trunk/SubtextSolution/Subtext.Framework/Syndication/RssCommentHandler.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/Syndication/RssCommentHandler.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/Syndication/RssCommentHandler.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -50,7 +50,7 @@
if(ParentEntry != null && Comments == null)
{
- Comments = Cacher.GetFeedback(ParentEntry, CacheDuration.Short, true, Blog);
+ Comments = Cacher.GetFeedback(ParentEntry, CacheDuration.Short, true, SubtextContext);
}
return Comments;
Modified: trunk/SubtextSolution/Subtext.Framework/XmlRpc/MetaWeblog.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Framework/XmlRpc/MetaWeblog.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Framework/XmlRpc/MetaWeblog.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -201,8 +201,9 @@
entry.IncludeInMainSyndication = true;
entry.Categories.Clear();
- if (post.categories != null)
+ if (post.categories != null) {
entry.Categories.AddRange(post.categories);
+ }
entry.PostType = PostType.BlogPost;
//User trying to change future dating.
Modified: trunk/SubtextSolution/Subtext.Providers.BlogEntryEditor.FCKeditor/FileBrowserConnector.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Providers.BlogEntryEditor.FCKeditor/FileBrowserConnector.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Providers.BlogEntryEditor.FCKeditor/FileBrowserConnector.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -53,6 +53,7 @@
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Format;
+using Subtext.Framework.Providers;
using Subtext.Framework.Routing;
namespace Subtext.Providers.BlogEntryEditor.FCKeditor
@@ -353,7 +354,7 @@
else
{
string categoryName=currentFolder.Substring(1,currentFolder.Length-2);
- LinkCategory cat = Links.GetLinkCategory(categoryName,false);
+ LinkCategory cat = ObjectProvider.Instance().GetLinkCategory(categoryName, false);
posts= Entries.GetPagedEntries(PostType.BlogPost, cat.Id, 0, 1000);
}
Modified: trunk/SubtextSolution/Subtext.Web/Admin/EditCategories.aspx.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/Admin/EditCategories.aspx.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/Admin/EditCategories.aspx.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -202,7 +202,7 @@
int id = Convert.ToInt32(dgrItems.DataKeys[e.Item.ItemIndex]);
- LinkCategory existingCategory = Links.GetLinkCategory(id,false);
+ LinkCategory existingCategory = SubtextContext.Repository.GetLinkCategory(id,false);
existingCategory.Description = txbDescription.Text;
existingCategory.Title = title.Text;
existingCategory.IsActive = isActive.Checked;
@@ -219,7 +219,7 @@
private void dgrCategories_DeleteCommand(object source, DataGridCommandEventArgs e)
{
int id = Convert.ToInt32(dgrItems.DataKeys[e.Item.ItemIndex]);
- LinkCategory lc = Links.GetLinkCategory(id,false);
+ LinkCategory lc = SubtextContext.Repository.GetLinkCategory(id,false);
ConfirmDelete(id, lc.Title);
}
Modified: trunk/SubtextSolution/Subtext.Web/Admin/EditGalleries.aspx.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/Admin/EditGalleries.aspx.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/Admin/EditGalleries.aspx.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -101,7 +101,7 @@
private void BindGallery(int galleryID)
{
CategoryID = galleryID;
- LinkCategory selectedGallery = Links.GetLinkCategory(galleryID,false);
+ LinkCategory selectedGallery = SubtextContext.Repository.GetLinkCategory(galleryID,false);
ICollection<Image> imageList = Images.GetImagesByCategoryID(galleryID, false);
plhImageHeader.Controls.Clear();
@@ -487,7 +487,7 @@
{
int id = Convert.ToInt32(dgrSelectionList.DataKeys[e.Item.ItemIndex]);
- LinkCategory existingCategory = Links.GetLinkCategory(id,false);
+ LinkCategory existingCategory = SubtextContext.Repository.GetLinkCategory(id,false);
existingCategory.Title = title.Text;
existingCategory.IsActive = isActive.Checked;
if(desc != null)
@@ -504,7 +504,7 @@
private void dgrSelectionList_DeleteCommand(object source, DataGridCommandEventArgs e)
{
int id = Convert.ToInt32(dgrSelectionList.DataKeys[e.Item.ItemIndex]);
- LinkCategory lc = Links.GetLinkCategory(id,false);
+ LinkCategory lc = SubtextContext.Repository.GetLinkCategory(id,false);
ConfirmDeleteGallery(id, lc.Title);
}
Modified: trunk/SubtextSolution/Subtext.Web/Admin/EditImage.aspx.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/Admin/EditImage.aspx.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/Admin/EditImage.aspx.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -127,7 +127,7 @@
protected void SetGalleryInfo(Image image)
{
- _galleryTitle = Links.GetLinkCategory(image.CategoryID,false).Title;
+ _galleryTitle = this.SubtextContext.Repository.GetLinkCategory(image.CategoryID,false).Title;
}
protected string EvalImageUrl(object imageObject)
Modified: trunk/SubtextSolution/Subtext.Web/Admin/UserControls/EntriesList.ascx.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/Admin/UserControls/EntriesList.ascx.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/Admin/UserControls/EntriesList.ascx.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -92,7 +92,7 @@
{
if (categoryId != NullValue.NullInt32)
{
- LinkCategory category = Links.GetLinkCategory(categoryId, false);
+ LinkCategory category = Repository.GetLinkCategory(categoryId, false);
if (category != null) {
HeaderText = "POSTS (" + category.Title + ")";
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveDay.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveDay.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveDay.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -37,7 +37,7 @@
try
{
DateTime dt = WebPathStripper.GetDateFromRequest(Request.Path,"archive");
- SingleDay.CurrentDay = Cacher.GetDay(dt, CacheDuration.Short, Blog);
+ SingleDay.CurrentDay = Cacher.GetDay(dt, CacheDuration.Short, SubtextContext);
Subtext.Web.UI.Globals.SetTitle(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1} Entries", Blog.Title, dt.ToString("D", CultureInfo.CurrentCulture)), Context);
}
catch(System.FormatException)
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveMonth.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveMonth.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/ArchiveMonth.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -38,7 +38,7 @@
try
{
DateTime dt = WebPathStripper.GetDateFromRequest(Request.Path,"archive");
- Days.EntryListItems = Cacher.GetMonth(dt, CacheDuration.Short, SubtextContext.Blog);
+ Days.EntryListItems = Cacher.GetMonth(dt, CacheDuration.Short, SubtextContext);
Days.EntryListTitle = string.Format(CultureInfo.InvariantCulture, "{0} Entries", dt.ToString("MMMM yyyy", CultureInfo.CurrentCulture));
Globals.SetTitle(string.Format(CultureInfo.InvariantCulture, "{0} - {1} Entries", Blog.Title, dt.ToString("MMMM yyyy", CultureInfo.CurrentCulture)),Context);
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/Calendar.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/Calendar.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/Calendar.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -148,7 +148,7 @@
/// </summary>
private void LoadMonthData()
{
- _monthEntries = Cacher.GetMonth(entryCal.SelectedDate, CacheDuration.Long, SubtextContext.Blog);
+ _monthEntries = Cacher.GetMonth(entryCal.SelectedDate, CacheDuration.Long, SubtextContext);
if (_monthEntries == null)
{
Trace.Warn("SubTextBlogCalendar Error: Cacher.GetMonth");
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/CategoryDisplay.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/CategoryDisplay.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/CategoryDisplay.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -31,11 +31,8 @@
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
-
- Categories.LinkCategories = Links.GetActiveCategories(); //Cacher.GetActiveCategories(CacheTime.Medium,Context);
+ Categories.LinkCategories = this.Repository.GetActiveCategories();
}
-
-
}
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/Comments.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/Comments.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/Comments.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -128,7 +128,7 @@
if (feedback != null)
{
FeedbackItem.Delete(feedback, null);
- Cacher.ClearCommentCache(feedback.EntryId, Blog);
+ Cacher.ClearCommentCache(feedback.EntryId, SubtextContext);
BindFeedback(false);
}
//Response.Redirect(string.Format(CultureInfo.InvariantCulture, "{0}?Pending=true", Request.Path));
@@ -337,7 +337,7 @@
{
try
{
- CommentList.DataSource = Cacher.GetFeedback(entry, CacheDuration.Short, fromCache, Blog);
+ CommentList.DataSource = Cacher.GetFeedback(entry, CacheDuration.Short, fromCache, SubtextContext);
CommentList.DataBind();
if (CommentList.Items.Count == 0)
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/EntryList.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/EntryList.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/EntryList.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -367,14 +367,14 @@
if (Category.IsNumeric())
{
int categoryID = Int32.Parse(Category);
- lc = Cacher.SingleCategory(CacheDuration.Short, categoryID, false, Blog);
+ lc = Cacher.SingleCategory(CacheDuration.Short, categoryID, false, SubtextContext);
}
else
{
- lc = Cacher.SingleCategory(CacheDuration.Short, Category, false, Blog);
+ lc = Cacher.SingleCategory(CacheDuration.Short, Category, false, SubtextContext);
}
EntryListTitle = lc.Title;
- EntryListItems = Cacher.GetEntriesByCategory(0, CacheDuration.Short, lc.Id, Blog);
+ EntryListItems = Cacher.GetEntriesByCategory(0, CacheDuration.Short, lc.Id, SubtextContext);
}
if(EntryListItems != null)
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/LinkPage.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/LinkPage.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/LinkPage.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -24,7 +24,7 @@
{
base.OnLoad (e);
List<LinkCategory> lcc = new List<LinkCategory>();
- lcc.AddRange(Links.GetActiveCategories());
+ lcc.AddRange(Repository.GetActiveCategories());
CatList.DataSource = lcc;
CatList.DataBind();
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/PostComment.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/PostComment.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/PostComment.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -261,7 +261,7 @@
Message.Text = "Thanks for your comment!";
Message.CssClass = "success";
this.Controls.Add(Message); //This needs to be here for ajax calls.
- Cacher.ClearCommentCache(feedbackItem.EntryId, Blog);
+ Cacher.ClearCommentCache(feedbackItem.EntryId, SubtextContext);
OnCommentApproved(feedbackItem);
return;
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/SingleColumn.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/SingleColumn.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/SingleColumn.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -75,7 +75,7 @@
if (imageCollection != null)
lcc.Add(imageCollection);
- lcc.AddRange(Links.GetActiveCategories());
+ lcc.AddRange(Repository.GetActiveCategories());
return lcc;
}
}
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/StoryList.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/StoryList.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/StoryList.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -44,7 +44,7 @@
{
Blog info = Blog;
- LinkCategory lc = Cacher.SingleCategory(CacheDuration.Short, Blog);
+ LinkCategory lc = Cacher.SingleCategory(CacheDuration.Short, SubtextContext);
int count = Request.QueryString["Show"] != null ? 0 : info.CategoryListPostCount;//as of 3sep2006, this is a configurable option.
//However, we retain the ability to overide the CategoryListPostCount setting via the query string, as usual.
@@ -55,7 +55,7 @@
return;
}
- ICollection<Entry> ec = Cacher.GetEntriesByCategory(count, CacheDuration.Short, lc.Id, info);
+ ICollection<Entry> ec = Cacher.GetEntriesByCategory(count, CacheDuration.Short, lc.Id, SubtextContext);
EntryStoryList.EntryListItems = ec;
EntryStoryList.EntryListTitle = lc.Title;
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/TagCloud.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/TagCloud.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/TagCloud.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -58,7 +58,7 @@
{
base.OnLoad(e);
- TagItems = Cacher.GetTopTags(ItemCount, CacheDuration.Short, Blog);
+ TagItems = Cacher.GetTopTags(ItemCount, CacheDuration.Short, SubtextContext);
int tagCount = TagItems.Count();
if (tagCount == 0) {
Modified: trunk/SubtextSolution/Subtext.Web/UI/Controls/TagEntryList.cs
===================================================================
--- trunk/SubtextSolution/Subtext.Web/UI/Controls/TagEntryList.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/Subtext.Web/UI/Controls/TagEntryList.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -47,7 +47,7 @@
Uri url = HttpContext.Current.Request.Url;
string tagName = HttpUtility.UrlDecode(url.Segments[url.Segments.Length - 2].Replace("/", ""));
- ICollection<Entry> et = Cacher.GetEntriesByTag(Count, CacheDuration.Short, tagName, Blog);
+ ICollection<Entry> et = Cacher.GetEntriesByTag(Count, CacheDuration.Short, tagName, SubtextContext);
EntryStoryList.EntryListItems = et;
EntryStoryList.EntryListTitle = tagName;
EntryStoryList.EntryListDescription = string.Format("There are {0} entries for the tag <em>{1}</em>", et.Count, tagName);
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/Components/EntryTests/EntryFilterTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/Components/EntryTests/EntryFilterTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/Components/EntryTests/EntryFilterTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -25,6 +25,7 @@
using Subtext.Framework.Exceptions;
using Subtext.Framework.Security;
using Subtext.Framework.Web.HttpModules;
+using System.Web.Caching;
namespace UnitTests.Subtext.Framework.Components.EntryTests
{
@@ -88,36 +89,6 @@
FeedbackItem.Create(feedbackItem, new CommentFilter(cache, null, blog), blog);
FeedbackItem.Create(feedbackItem, new CommentFilter(cache, null, blog), blog);
}
-
- private class TestCache : NameObjectCollectionBase, ICache
- {
- public object this[string key]
- {
- get
- {
- return BaseGet(key);
- }
- set
- {
- BaseSet(key, value);
- }
- }
-
- public void Insert(string key, object value, System.Web.Caching.CacheDependency dependency)
- {
- this[key] = value;
- }
-
- public void Insert(string key, object value, System.Web.Caching.CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
- {
- this[key] = value;
- }
-
- public void Remove(string key)
- {
- BaseRemove(key);
- }
- }
/// <summary>
/// Make sure that comments and Track/Pingbacks generated
@@ -177,4 +148,44 @@
Config.ConfigurationProvider = null;
}
}
+
+ internal class TestCache : NameObjectCollectionBase, ICache
+ {
+ public object this[string key]
+ {
+ get
+ {
+ return BaseGet(key);
+ }
+ set
+ {
+ BaseSet(key, value);
+ }
+ }
+
+ public void Insert(string key, object value, System.Web.Caching.CacheDependency dependency)
+ {
+ this[key] = value;
+ }
+
+ public void Insert(string key, object value, System.Web.Caching.CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
+ {
+ this[key] = value;
+ }
+
+ public void Remove(string key)
+ {
+ BaseRemove(key);
+ }
+
+ public void Insert(string key, object value)
+ {
+ this[key] = value;
+ }
+
+ public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback)
+ {
+ this[key] = value;
+ }
+ }
}
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/CacherTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/CacherTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/CacherTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -1,17 +1,19 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Web;
+using System.Web.Caching;
using System.Web.Routing;
using MbUnit.Framework;
using Moq;
+using Subtext.Extensibility;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Data;
using Subtext.Framework.Providers;
-using Subtext.Extensibility;
using Subtext.Framework.Routing;
using Subtext.Framework.Web.HttpModules;
@@ -27,21 +29,16 @@
/// This test is to make sure a bug I introduced never happens again.
/// </summary>
[Test]
- [RollBack]
public void GetEntryFromRequest_WithIdInRouteDataMatchingEntryInRepository_ReturnsEntry()
{
//arrange
- var repository = new Mock<ObjectProvider>();
- repository.Setup(r => r.GetEntry(123, true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, Title = "Testing 123" });
- UnitTestHelper.SetupBlog();
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/123.aspx");
var routeData = new RouteData();
routeData.Values.Add("id", "123");
- var requestContext = new RequestContext(httpContext.Object, routeData);
var subtextContext = new Mock<ISubtextContext>();
- subtextContext.Setup(c => c.RequestContext).Returns(requestContext);
- subtextContext.Setup(c => c.Repository).Returns(repository.Object);
+ subtextContext.SetupRequestContext(httpContext, routeData, new Blog { Id = 123 })
+ .Setup(c => c.Repository.GetEntry(123, true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, Title = "Testing 123" });
//act
Entry entry = Cacher.GetEntryFromRequest(CacheDuration.Short, true, subtextContext.Object);
@@ -75,12 +72,11 @@
httpContext.SetupSet(c => c.Response.RedirectLocation).Callback(s => redirectLocation = s);
var routeData = new RouteData();
routeData.Values.Add("id", "123");
- var requestContext = new RequestContext(httpContext.Object, routeData);
var subtextContext = new Mock<ISubtextContext>();
- subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
- subtextContext.Setup(c => c.RequestContext).Returns(requestContext);
- subtextContext.Setup(c => c.Repository).Returns(repository.Object);
- subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "localhost" });
+ subtextContext.SetupRequestContext(httpContext, routeData)
+ .SetupUrlHelper(urlHelper)
+ .SetupRepository(repository.Object)
+ .SetupBlog(new Blog { Host = "localhost" });
//act
Entry cachedEntry = Cacher.GetEntryFromRequest(CacheDuration.Short, true /* allowRedirect */, subtextContext.Object);
@@ -97,22 +93,17 @@
/// This test is to make sure a bug I introduced never happens again.
/// </summary>
[Test]
- [RollBack]
public void GetEntryFromRequest_WithSlugInRouteDataMatchingEntryInRepository_ReturnsEntry()
{
//arrange
- var repository = new Mock<ObjectProvider>();
- repository.Setup(r => r.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });
- UnitTestHelper.SetupBlog();
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/the-slug.aspx");
var routeData = new RouteData();
routeData.Values.Add("slug", "the-slug");
- var requestContext = new RequestContext(httpContext.Object, routeData);
var subtextContext = new Mock<ISubtextContext>();
- subtextContext.Setup(c => c.RequestContext).Returns(requestContext);
- subtextContext.Setup(c => c.Repository).Returns(repository.Object);
- subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 1, TimeZoneId = -2037797565 /* pacific */ });
+ subtextContext.SetupRequestContext(httpContext, routeData)
+ .SetupBlog(new Blog { Id = 1, TimeZoneId = -2037797565 /* pacific */ })
+ .Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });
//act
Entry entry = Cacher.GetEntryFromRequest(CacheDuration.Short, true, subtextContext.Object);
@@ -127,23 +118,17 @@
/// This test is to make sure a bug I introduced never happens again.
/// </summary>
[Test]
- [RollBack]
public void GetEntryFromRequest_WithNonExistentEntry_DoesNotThrowNullReferenceException()
{
//arrange
- var repository = new Mock<ObjectProvider>();
- repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns((Entry)null);
-
- UnitTestHelper.SetupBlog();
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/99999.aspx");
var routeData = new RouteData();
routeData.Values.Add("id", "999999");
- var requestContext = new RequestContext(httpContext.Object, routeData);
var subtextContext = new Mock<ISubtextContext>();
- subtextContext.Setup(c => c.RequestContext).Returns(requestContext);
- subtextContext.Setup(c => c.Repository).Returns(repository.Object);
-
+ subtextContext.SetupRequestContext(httpContext, routeData)
+ .Setup(c => c.Repository.GetEntry(It.IsAny<int>(), true, true)).Returns((Entry)null);
+
//act
Cacher.GetEntryFromRequest(CacheDuration.Short, true, subtextContext.Object);
@@ -152,69 +137,62 @@
}
[Test]
- [ExpectedException(typeof(InvalidOperationException))]
public void SingleCategoryThrowsExceptionIfContextNull()
{
- HttpContext.Current = null;
- Cacher.SingleCategory(CacheDuration.Short, Config.CurrentBlog);
+ UnitTestHelper.AssertThrows<ArgumentNullException>(
+ () => Cacher.SingleCategory(CacheDuration.Short, null)
+ );
}
[Test]
- [RollBack]
public void SingleCategoryReturnsNullForNonExistentCategory()
{
- string host = UnitTestHelper.GenerateUniqueString();
- Config.CreateBlog("test", UnitTestHelper.GenerateUniqueString(), UnitTestHelper.GenerateUniqueString(), host, "");
- UnitTestHelper.SetHttpContextWithBlogRequest(host, "", "", "/category/99.aspx");
- BlogRequest.Current.Blog = Config.GetBlog(host, string.Empty);
- Assert.IsNull(Cacher.SingleCategory(CacheDuration.Short, Config.CurrentBlog));
+ //arrange
+ var httpContext = new Mock<HttpContextBase>();
+ httpContext.FakeRequest("/category/99.aspx");
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext(httpContext)
+ .Setup(c => c.Repository.GetLinkCategory(It.IsAny<int>(), true)).Returns((LinkCategory)null);
+
+ //act
+ LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, subtextContext.Object);
+
+ //assert
+ Assert.IsNull(category);
}
[Test]
- [RollBack]
public void CanGetCategoryByIdRequest()
{
- string host = UnitTestHelper.GenerateUniqueString();
- Config.CreateBlog("test", UnitTestHelper.GenerateUniqueString(), UnitTestHelper.GenerateUniqueString(), host, "");
- UnitTestHelper.SetHttpContextWithBlogRequest(host, "", "", "/category/");
- Blog blog = Config.GetBlog(host, string.Empty);
- BlogRequest.Current.Blog = blog;
- int categoryId = UnitTestHelper.CreateCategory(blog.Id, "This Is a Test");
- UnitTestHelper.SetHttpContextWithBlogRequest(host, "", "", "/category/" + categoryId + ".aspx");
- blog = Config.GetBlog(host, string.Empty);
- BlogRequest.Current.Blog = blog;
- LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, blog);
- Assert.AreEqual("This Is a Test", category.Title);
+ //arrange
+ var httpContext = new Mock<HttpContextBase>();
+ httpContext.FakeRequest("/category/99.aspx");
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext(httpContext)
+ .Setup(c => c.Repository.GetLinkCategory(99, true)).Returns(new LinkCategory { Id = 99, Title = "this is a test"});
+
+ //act
+ LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, subtextContext.Object);
+
+ //assert
+ Assert.AreEqual("this is a test", category.Title);
}
[Test]
- [RollBack]
public void CanGetCategoryByNameRequest()
{
- string host = UnitTestHelper.GenerateUniqueString();
- Config.CreateBlog("test", UnitTestHelper.GenerateUniqueString(), UnitTestHelper.GenerateUniqueString(), host, "");
- UnitTestHelper.SetHttpContextWithBlogRequest(host, "", "", "/category/This Is a Test.aspx");
- Blog blog = Config.GetBlog(host, string.Empty);
- BlogRequest.Current.Blog = blog;
- UnitTestHelper.CreateCategory(blog.Id, "This Is a Test");
+ //arrange
+ var httpContext = new Mock<HttpContextBase>();
+ httpContext.FakeRequest("/category/this-is-a-test.aspx");
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext(httpContext)
+ .Setup(c => c.Repository.GetLinkCategory("this-is-a-test", true)).Returns(new LinkCategory { Id = 99, Title = "this is a test" });
- LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, blog);
- Assert.AreEqual("This Is a Test", category.Title);
- }
+ //act
+ LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, subtextContext.Object);
- [Test]
- [RollBack]
- public void CanGetCategoryByNameWithWordDelimitersRequest()
- {
- string host = UnitTestHelper.GenerateUniqueString();
- Config.CreateBlog("test", UnitTestHelper.GenerateUniqueString(), UnitTestHelper.GenerateUniqueString(), host, "");
- UnitTestHelper.SetHttpContextWithBlogRequest(host, "", "", "/category/This_Is_a_Test.aspx");
- Blog blog = Config.GetBlog(host, string.Empty);
- BlogRequest.Current.Blog = blog;
- UnitTestHelper.CreateCategory(blog.Id, "This Is a Test");
-
- LinkCategory category = Cacher.SingleCategory(CacheDuration.Short, blog);
- Assert.AreEqual("This Is a Test", category.Title);
+ //assert
+ Assert.AreEqual(99, category.Id);
}
/// <summary>
@@ -222,14 +200,13 @@
/// Locale correctly.
/// </summary>
[Test]
- [RollBack]
public void GetActiveCategoriesHandlesLocale()
{
- string hostName = UnitTestHelper.GenerateUniqueString();
- UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
- Config.CreateBlog("", "username", "thePassword", hostName, "");
- Blog blog = Config.GetBlog(hostName, string.Empty);
- BlogRequest.Current.Blog = blog;
+ //arrange
+ int blogId = 123;
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext();
+ subtextContext.SetupBlog(new Blog { Id = blogId });
//Start with en-US
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
@@ -241,11 +218,11 @@
//Note, this corresponds to a private var in Cacher.
string ActiveLCCKey = "ActiveLinkCategoryCollection:Blog{0}";
- ActiveLCCKey = String.Format(ActiveLCCKey, blog.Id);
- ContentCache cache = ContentCache.Instantiate();
+ ActiveLCCKey = String.Format(ActiveLCCKey, blogId);
+ ContentCache cache = ContentCache.Instantiate(subtextContext.Object);
cache[ActiveLCCKey] = cachedCategories;
- ICollection<LinkCategory> categories = Cacher.GetActiveCategories(CacheDuration.Short, blog);
+ ICollection<LinkCategory> categories = Cacher.GetActiveCategories(CacheDuration.Short, subtextContext.Object);
Assert.AreEqual(2, categories.Count, "Expected to get the cached categories.");
Assert.AreSame(cachedCategories, categories, "Categories should have been pulled from cache.");
@@ -255,7 +232,7 @@
spanishCachedCategories.Add(new LinkCategory(1, "prueba numero uno"));
cache[ActiveLCCKey] = spanishCachedCategories;
- ICollection<LinkCategory> spanishCategories = Cacher.GetActiveCategories(CacheDuration.Short, blog);
+ ICollection<LinkCategory> spanishCategories = Cacher.GetActiveCategories(CacheDuration.Short, subtextContext.Object);
Assert.AreEqual(1, spanishCategories.Count, "Only expected one category for spanish.");
}
}
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/ContentCacheTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/ContentCacheTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/Data/ContentCacheTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -5,6 +5,7 @@
using System.Web;
using MbUnit.Framework;
using Subtext.Framework;
+using Moq;
namespace UnitTests.Subtext.Framework.Data
{
@@ -22,17 +23,16 @@
[Test]
public void InstantiationOfContentCacheUsesRequestCaching()
{
- UnitTestHelper.SetHttpContextWithBlogRequest(UnitTestHelper.GenerateUniqueString(), "");
- Assert.IsNotNull(HttpContext.Current, "We did not set up the http context correctly.");
- Assert.AreEqual(1, HttpContext.Current.Items.Count, "Did not expect the request cache to have any items.");
-
- ContentCache cache = ContentCache.Instantiate();
+ //arrange
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext();
- Assert.AreEqual(2, HttpContext.Current.Items.Count, "Expected two item in the request cache.");
+ //act
+ ContentCache cache = ContentCache.Instantiate(subtextContext.Object);
- Assert.AreSame(cache, ContentCache.Instantiate(), "Expected second call to instantiate to return cached ContentCache.");
-
- HttpContext.Current = null;
+ //assert
+ Assert.AreEqual(1, subtextContext.Object.RequestContext.HttpContext.Items.Count);
+ Assert.AreSame(cache, ContentCache.Instantiate(subtextContext.Object), "Expected second call to instantiate to return cached ContentCache.");
}
/// <summary>
@@ -42,11 +42,12 @@
[Test]
public void ContentCacheCachesByLanguage()
{
- UnitTestHelper.SetHttpContextWithBlogRequest(UnitTestHelper.GenerateUniqueString(), "");
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext();
//Start with en-US
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
- ContentCache cache = ContentCache.Instantiate();
+ ContentCache cache = ContentCache.Instantiate(subtextContext.Object);
cache["test"] = "English";
Assert.AreEqual("English", cache["test"], "Did not store the value in the cache properly.");
@@ -60,40 +61,53 @@
Assert.AreEqual("English", cache["test"], "Should have changed the value based on language code.");
int stringCount = 0;
- foreach(DictionaryEntry item in cache)
+ foreach(string key in cache)
{
- if(item.Value.ToString() == "English" || item.Value.ToString() == "Espanol")
+ //Get rid of colon in key...
+ string rootKey = key.Split(':')[0];
+
+ string itemValue = cache.Get(rootKey) as string;
+
+ if(itemValue == "English" || itemValue == "Espanol")
{
stringCount++;
}
}
Assert.AreEqual(2, stringCount, "Expected two items in the cache.");
-
- HttpContext.Current = null;
}
/// <summary>
/// Make sure passing in a null value for caching throws an exception.
/// </summary>
[Test]
- [ExpectedException(typeof(ArgumentNullException))]
public void CannotInsertNullTest()
{
- UnitTestHelper.SetHttpContextWithBlogRequest(UnitTestHelper.GenerateUniqueString(), "");
- ContentCache cache = ContentCache.Instantiate();
- cache.Insert("test", null);
+ //arrange
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext();
+ ContentCache cache = ContentCache.Instantiate(subtextContext.Object);
+
+ //act, assert
+ UnitTestHelper.AssertThrows<ArgumentNullException>(
+ () => cache.Insert("test", null)
+ );
}
/// <summary>
/// Make sure passing in a null value for caching throws an exception.
/// </summary>
[Test]
- [ExpectedException(typeof(ArgumentNullException))]
public void CannotInsertNullWithCacheDurationTest()
{
- UnitTestHelper.SetHttpContextWithBlogRequest(UnitTestHelper.GenerateUniqueString(), "");
- ContentCache cache = ContentCache.Instantiate();
- cache.Insert("test", null, CacheDuration.Short);
+ //arrange
+ var subtextContext = new Mock<ISubtextContext>();
+ subtextContext.SetupRequestContext();
+ ContentCache cache = ContentCache.Instantiate(subtextContext.Object);
+
+ //act, assert
+ UnitTestHelper.AssertThrows<ArgumentNullException>(
+ () => cache.Insert("test", null, CacheDuration.Short)
+ );
}
}
}
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/Email/EmailServiceTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/Email/EmailServiceTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/Email/EmailServiceTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -27,7 +27,7 @@
context.Setup(c => c.User.Identity.Name).Returns("cody");
context.Setup(c => c.User.IsInRole("Admins")).Returns(true);
var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
- emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Never();
+ emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception());
//act
emailService.EmailCommentToBlogAuthor(comment);
@@ -44,7 +44,7 @@
context.Setup(c => c.UrlHelper).Returns(new Mock<UrlHelper>().Object);
context.Setup(c => c.Blog).Returns(blog);
var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
- emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Never();
+ emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception());
//act
emailService.EmailCommentToBlogAuthor(comment);
@@ -61,7 +61,8 @@
context.Setup(c => c.Blog).Returns(blog);
var emailProvider = new Mock<EmailProvider>();
var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
- emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Never();
+ emailProvider.Setup(e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception());
+
//act
emailService.EmailCommentToBlogAuthor(comment);
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/ImageTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/ImageTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/ImageTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -66,6 +66,7 @@
public void CanGetLocalGalleryFilePath()
{
UnitTestHelper.SetupBlog();
+
Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, @"image\42\"), Images.LocalGalleryFilePath(42));
}
@@ -74,8 +75,8 @@
public void CanGetGalleryVirtualUrl()
{
UnitTestHelper.SetupBlog();
- string expected = "http://" + BlogRequest.Current.Host + "/images/" + BlogRequest.Current.Host + "/1/";
-
+ UrlBasedBlogInfoProvider.MapImageDirectory(BlogRequest.Current);
+ string expected = string.Format("http://{0}/images/{0}/1/", BlogRequest.Current.Host);
Assert.AreEqual(expected, Images.GalleryVirtualUrl(1));
}
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/LinksTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/LinksTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/LinksTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -22,6 +22,7 @@
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
+using Subtext.Framework.Providers;
namespace UnitTests.Subtext.Framework
{
@@ -65,7 +66,7 @@
CreateLink("Link two", categoryIds[0], null);
CreateLink("Link one-two", categoryIds[1], null);
- ICollection<LinkCategory> linkCollections = Links.GetActiveCategories();
+ ICollection<LinkCategory> linkCollections = ObjectProvider.Instance().GetActiveCategories();
//Test ordering by title
Assert.AreEqual("Google Blogs", linkCollections.First().Title);
@@ -134,7 +135,7 @@
// Create some categories
int categoryId = Links.CreateLinkCategory(CreateCategory("My Favorite Feeds", "Some of my favorite RSS feeds", CategoryType.LinkCollection, true));
- LinkCategory category = Links.GetLinkCategory(categoryId, true);
+ LinkCategory category = ObjectProvider.Instance().GetLinkCategory(categoryId, true);
Assert.AreEqual(Config.CurrentBlog.Id, category.BlogId);
Assert.AreEqual("My Favorite Feeds", category.Title);
Assert.AreEqual("Some of my favorite RSS feeds", category.Description);
@@ -146,7 +147,7 @@
Assert.IsNotNull(category);
Links.DeleteLinkCategory(categoryId);
- Assert.IsNull(Links.GetLinkCategory(categoryId, true));
+ Assert.IsNull(ObjectProvider.Instance().GetLinkCategory(categoryId, true));
}
/// <summary>
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/Tracking/TrackbackHandlerTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/Tracking/TrackbackHandlerTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/Tracking/TrackbackHandlerTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
+using System.Collections.Specialized;
using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Web;
using MbUnit.Framework;
+using Moq;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
-using Subtext.Framework.Tracking;
-using Moq;
using Subtext.Framework.Providers;
using Subtext.Framework.Routing;
-using System.Collections.Specialized;
+using Subtext.Framework.Tracking;
namespace UnitTests.Subtext.Framework.Tracking
{
@@ -71,6 +69,7 @@
subtextContext.Object.RequestContext.RouteData.Values.Add("id", id.ToString());
var urlHelper = Mock.Get<UrlHelper>(subtextContext.Object.UrlHelper);
urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny<int>())).Returns("/whatever/trackback");
+ subtextContext.SetupBlog(blog);
//act
handler.ProcessRequest(subtextContext.Object);
@@ -98,6 +97,7 @@
subtextContext.Object.RequestContext.RouteData.Values.Add("id", int.MaxValue.ToString());
var urlHelper = Mock.Get<UrlHelper>(subtextContext.Object.UrlHelper);
urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny<int>())).Returns("/whatever/trackback");
+ subtextContext.SetupBlog(blog);
//act
handler.ProcessRequest(subtextContext.Object);
@@ -124,6 +124,7 @@
subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
var urlHelper = Mock.Get<UrlHelper>(subtextContext.Object.UrlHelper);
urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny<int>())).Returns("/whatever/trackback");
+ subtextContext.SetupBlog(blog);
//act
handler.ProcessRequest(subtextContext.Object);
@@ -157,6 +158,7 @@
var writer = subtextContext.FakeSubtextContextRequest(blog, "/trackbackhandler", "/", string.Empty);
subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
subtextContext.Object.RequestContext.RouteData.Values.Add("id", id.ToString());
+ subtextContext.SetupBlog(blog);
var urlHelper = Mock.Get<UrlHelper>(subtextContext.Object.UrlHelper);
urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever/entry");
urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny<int>())).Returns("/whatever/trackback");
Modified: trunk/SubtextSolution/UnitTests.Subtext/Framework/XmlRpc/MetaBlogApiTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/Framework/XmlRpc/MetaBlogApiTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/Framework/XmlRpc/MetaBlogApiTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -478,8 +478,9 @@
string hostname = UnitTestHelper.GenerateUniqueString();
Config.CreateBlog("", "username", "password", hostname, "");
UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
- BlogRequest.Current.Blog = Config.GetBlog(hostname, "");
- Config.CurrentBlog.AllowServiceAccess = true;
+ Blog blog = Config.GetBlog(hostname, "");
+ BlogRequest.Current.Blog = blog;
+ blog.AllowServiceAccess = true;
var urlHelper = new Mock<UrlHelper>();
urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/entry/whatever");
@@ -487,7 +488,7 @@
subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
//TODO: FIX!!!
subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
-
+ subtextContext.SetupBlog(blog);
subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
MetaWeblog api = new MetaWeblog(subtextContext.Object);
Modified: trunk/SubtextSolution/UnitTests.Subtext/MockExtensions.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/MockExtensions.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/MockExtensions.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -1,23 +1,26 @@
using System;
+using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Routing;
using Moq;
+using Subtext.Extensibility;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Providers;
using Subtext.Framework.Routing;
using Subtext.Framework.Web.HttpModules;
-using Subtext.Extensibility;
+using UnitTests.Subtext.Framework.Components.EntryTests;
namespace UnitTests.Subtext
{
public static class MockExtensions
{
- public static void FakeRequest(this Mock<HttpContextBase> httpContextMock, string virtualPath) {
+ public static Mock<HttpContextBase> FakeRequest(this Mock<HttpContextBase> httpContextMock, string virtualPath) {
httpContextMock.FakeRequest(virtualPath, null);
+ return httpContextMock;
}
public static StringWriter FakeSitemapHandlerRequest(this Mock<ISubtextContext> subtextContext, Mock<ObjectProvider> repository)
@@ -55,26 +58,83 @@
public static StringWriter FakeSubtextContextRequest(this Mock<ISubtextContext> subtextContextMock, Blog blog, string virtualPath, string applicationPath, string subfolder) {
var httpContext = new Mock<HttpContextBase>();
var writer = httpContext.FakeRequest(virtualPath, subfolder);
- httpContext.Setup(c => c.Request.ApplicationPath).Returns(applicationPath);
+ httpContext.SetupApplicationPath(applicationPath);
var urlHelper = new Mock<UrlHelper>();
var routeData = new RouteData();
routeData.Values.Add("subfolder", subfolder);
-
- var requestContext = new RequestContext(httpContext.Object, routeData);
-
- subtextContextMock.Setup(c => c.Blog).Returns(blog);
- subtextContextMock.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
- subtextContextMock.Setup(c => c.RequestContext).Returns(requestContext);
+
+ subtextContextMock.SetupBlog(blog)
+ .SetupUrlHelper(urlHelper)
+ .SetupRequestContext(httpContext, routeData);
return writer;
}
+
+ public static Mock<HttpContextBase> SetupApplicationPath(this Mock<HttpContextBase> httpContext, string applicationPath) {
+ httpContext.Setup(c => c.Request.ApplicationPath).Returns(applicationPath);
+ return httpContext;
+ }
+
+ public static Mock<ISubtextContext> SetupRequestContext(this Mock<ISubtextContext> context) {
+ return context.SetupRequestContext(null, null, null);
+ }
+
+ public static Mock<ISubtextContext> SetupRequestContext(this Mock<ISubtextContext> context, Mock<HttpContextBase> httpContext, RouteData routeData) {
+ return context.SetupRequestContext(httpContext, routeData, null);
+ }
+
+ public static Mock<ISubtextContext> SetupBlog(this Mock<ISubtextContext> context, Blog blog) {
+ context.Setup(c => c.Blog).Returns(blog);
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupUrlHelper(this Mock<ISubtextContext> context, Mock<UrlHelper> urlHelper) {
+ context.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupUrlHelper(this Mock<ISubtextContext> context, UrlHelper urlHelper) {
+ context.Setup(c => c.UrlHelper).Returns(urlHelper);
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupRepository(this Mock<ISubtextContext> context, Mock<ObjectProvider> repository) {
+ context.Setup(c => c.Repository).Returns(repository.Object);
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupRepository(this Mock<ISubtextContext> context, ObjectProvider repository) {
+ context.Setup(c => c.Repository).Returns(repository);
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupRequestContext(this Mock<ISubtextContext> context, Mock<HttpContextBase> httpContext, RouteData routeData, Blog blog) {
+ httpContext = httpContext ?? new Mock<HttpContextBase>();
+ routeData = routeData ?? new RouteData();
+ httpContext.Setup(c => c.Items).Returns(new Hashtable());
+ var requestContext = new RequestContext(httpContext.Object, routeData);
+ context.SetupRequestContext(requestContext);
+ context.Setup(c => c.Cache).Returns(new TestCache());
+ context.Setup(c => c.Blog).Returns(blog ?? new Blog());
+ return context;
+ }
+
+ public static Mock<ISubtextContext> SetupRequestContext(this Mock<ISubtextContext> context, Mock<HttpContextBase> httpContext) {
+ return context.SetupRequestContext(httpContext, null, null);
+ }
+
+ public static Mock<ISubtextContext> SetupRequestContext(this Mock<ISubtextContext> context, RequestContext requestContext) {
+ context.Setup(c => c.RequestContext).Returns(requestContext);
+ return context;
+ }
public static void FakeSyndicationContext(this Mock<ISubtextContext> subtextContextMock, Blog blog, string virtualPath, string applicationPath, string subfolder, Action<string> callback) {
var urlHelper = new Mock<UrlHelper>();
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeSyndicationRequest(virtualPath, applicationPath, callback);
+ httpContext.Setup(c => c.Items).Returns(new Hashtable());
string imagePath = "/images/RSS2Image.gif";
if (applicationPath != "/") {
@@ -89,9 +149,10 @@
var routeData = new RouteData();
routeData.Values.Add("subfolder", subfolder);
var requestContext = new RequestContext(httpContext.Object, routeData);
- subtextContextMock.Setup(c => c.Blog).Returns(blog);
- subtextContextMock.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
- subtextContextMock.Setup(c => c.RequestContext).Returns(requestContext);
+ subtextContextMock.SetupBlog(blog);
+ subtextContextMock.SetupUrlHelper(urlHelper.Object);
+ subtextContextMock.SetupRequestContext(requestContext);
+ subtextContextMock.Setup(c => c.Cache).Returns(new TestCache());
}
public static void FakeSyndicationContext(this Mock<ISubtextContext> subtextContextMock, Blog blog, string virtualPath, Action<string> callback) {
Modified: trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/Providers/RichTextEditor/FtbProviderTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/Providers/RichTextEditor/FtbProviderTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/Providers/RichTextEditor/FtbProviderTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -14,12 +14,13 @@
#endregion
using System;
-using MbUnit.Framework;
using System.Web.UI.WebControls;
using FreeTextBoxControls;
+using MbUnit.Framework;
+using Subtext.Framework;
using Subtext.Framework.Configuration;
+using Subtext.Framework.Web.HttpModules;
using Subtext.Web.Providers.BlogEntryEditor.FTB;
-using Subtext.Framework.Web.HttpModules;
namespace UnitTests.Subtext.SubtextWeb.Providers.RichTextEditor
{
@@ -55,7 +56,9 @@
public void SetText()
{
Config.CreateBlog("", "username", "password", _hostName, "MyBlog");
- BlogRequest.Current.Blog = Config.GetBlog(_hostName, string.Empty);
+ Blog blog = Config.GetBlog(_hostName, string.Empty);
+ blog.ImagePath = "/images/";
+ BlogRequest.Current.Blog = blog;
string test="Lorem Ipsum";
frtep.InitializeControl();
@@ -69,7 +72,9 @@
public void SetWidth()
{
Config.CreateBlog("", "username", "password", _hostName, "MyBlog");
- BlogRequest.Current.Blog = Config.GetBlog(_hostName, string.Empty);
+ Blog blog = Config.GetBlog(_hostName, string.Empty);
+ blog.ImagePath = "/images/";
+ BlogRequest.Current.Blog = blog;
Unit test=200;
frtep.InitializeControl();
@@ -82,7 +87,9 @@
public void SetHeight()
{
Config.CreateBlog("", "username", "password", _hostName, "MyBlog");
- BlogRequest.Current.Blog = Config.GetBlog(_hostName, string.Empty);
+ Blog blog = Config.GetBlog(_hostName, string.Empty);
+ blog.ImagePath = "/images/";
+ BlogRequest.Current.Blog = blog;
Unit test=100;
frtep.InitializeControl();
@@ -116,7 +123,9 @@
public void TestInitialization()
{
Config.CreateBlog("", "username", "password", _hostName, "MyBlog");
- BlogRequest.Current.Blog = Config.GetBlog(_hostName, string.Empty);
+ Blog blog = Config.GetBlog(_hostName, string.Empty);
+ blog.ImagePath = "/images/";
+ BlogRequest.Current.Blog = blog;
System.Collections.Specialized.NameValueCollection coll=GetNameValueCollection();
frtep.Initialize("FTBProvider", coll);
Modified: trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/SitemapHandlerTests.cs
===================================================================
--- trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/SitemapHandlerTests.cs 2009-03-02 07:08:07 UTC (rev 3398)
+++ trunk/SubtextSolution/UnitTests.Subtext/SubtextWeb/SitemapHandlerTests.cs 2009-03-09 06:58:11 UTC (rev 3399)
@@ -32,6 +32,7 @@
Mock<ISubtextContext> subtextContext = new Mock<ISubtextContext>();
StringWriter writer = subtextContext.FakeSitemapHandlerRequest(repository);
+ subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "localhost" });
var handler = new SiteMapHttpHandler();
handler.SubtextContext = subtextContext.Object;
@@ -59,9 +60,11 @@
repository.Setup(r => r.GetCategories(CategoryType.PostCollection, true)).Returns(new List<LinkCategory>());
Mock<ISubtextContext> subtextContext = new Mock<ISubtextContext>();
+
StringWriter writer = subtextContext.FakeSitemapHandlerRequest(repository);
var handler = new SiteMapHttpHandler();
handler.SubtextContext = subtextContext.Object;
+ subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "localhost" });
//act
handler.ProcessRequest(subtextContext.Object);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|