本文整理汇总了C#中Subtext.Framework.Components.FeedbackItem类的典型用法代码示例。如果您正苦于以下问题:C# FeedbackItem类的具体用法?C# FeedbackItem怎么用?C# FeedbackItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FeedbackItem类属于Subtext.Framework.Components命名空间,在下文中一共展示了FeedbackItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create_WithFeedbackItem_SetsDateCreatedAndModifiedToUtcNow
public void Create_WithFeedbackItem_SetsDateCreatedAndModifiedToUtcNow()
{
// Arrange
var now = DateTime.UtcNow;
var sps = new Mock<StoredProcedures>("test");
sps.Setup(s => s.InsertFeedback(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<int?>(),
It.IsAny<string>(),
It.IsAny<bool>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<bool>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<DateTime?>(),
It.IsAny<DateTime>()));
var repository = new DatabaseObjectProvider(blogId: 1, procedures: sps.Object);
var feedback = new FeedbackItem(FeedbackType.Comment) { Body = "blah" };
// Act
repository.Create(feedback);
// Assert
Assert.GreaterEqualThan(DateTime.UtcNow, feedback.DateCreatedUtc);
Assert.GreaterEqualThan(DateTime.UtcNow, feedback.DateModifiedUtc);
Assert.GreaterEqualThan(feedback.DateCreatedUtc, now);
Assert.GreaterEqualThan(feedback.DateModifiedUtc, now);
}
示例2: CreateSetsDateCreated
public void CreateSetsDateCreated()
{
//arrange
var blog = new Mock<Blog>();
DateTime dateCreatedUtc = DateTime.UtcNow;
blog.Object.Id = 1;
var entry = new Entry(PostType.BlogPost, blog.Object) { Id = 123, BlogId = 1, CommentingClosed = false };
var repository = new Mock<ObjectRepository>();
repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns(entry);
var context = new Mock<ISubtextContext>();
context.SetupGet(c => c.Repository).Returns(repository.Object);
context.SetupGet(c => c.Blog).Returns(blog.Object);
context.SetupGet(c => c.HttpContext.Items).Returns(new Hashtable());
context.SetupGet(c => c.Cache).Returns(new TestCache());
var service = new CommentService(context.Object, null);
var comment = new FeedbackItem(FeedbackType.Comment) { EntryId = 123, BlogId = 1, Body = "test", Title = "title" };
//act
service.Create(comment, true/*runFilters*/);
//assert
Assert.GreaterEqualThan(comment.DateCreatedUtc, dateCreatedUtc);
Assert.GreaterEqualThan(DateTime.UtcNow, comment.DateCreatedUtc);
}
示例3: FilterAfterPersist
/// <summary>
/// Filters the comment. Throws an exception should the comment not be allowed.
/// Otherwise returns true. This interface may be changed.
/// </summary>
/// <remarks>
/// <p>
/// The first filter examines whether comments are coming in too quickly
/// from the same SourceUrl. Looks at the <see cref="BlogInfo.CommentDelayInMinutes"/>.
/// </p>
/// <p>
/// The second filter checks for duplicate comments. It only looks at the body
/// of the comment.
/// </p>
/// </remarks>
/// <param name="feedbackItem">Entry.</param>
public void FilterAfterPersist(FeedbackItem feedbackItem)
{
if (!SecurityHelper.IsAdmin)
{
if (!Config.CurrentBlog.ModerationEnabled)
{
//Akismet Check...
if (Config.CurrentBlog.FeedbackSpamServiceEnabled)
{
if (Config.CurrentBlog.FeedbackSpamService.IsSpam(feedbackItem))
{
FlagAsSpam(feedbackItem);
return;
}
}
//Note, we need to explicitely set the status flag here.
//Just setting Approved = true would not reset any other bits in the flag that may be set.
feedbackItem.Status = FeedbackStatusFlag.Approved;
}
else //Moderated!
{
//Note, we need to explicitely set the status flag here.
//Just setting NeedsModeration = true would not reset any other bits in the flag that may be set.
feedbackItem.Status = FeedbackStatusFlag.NeedsModeration;
}
}
else
{
//Note, we need to explicitely set the status flag here.
//Just setting Approved = true would not reset any other bits in the flag that may be set.
feedbackItem.Status = FeedbackStatusFlag.Approved;
}
FeedbackItem.Update(feedbackItem);
}
示例4: CreateDoesNotChangeDateCreatedAndDateModifiedIfAlreadySpecified
public void CreateDoesNotChangeDateCreatedAndDateModifiedIfAlreadySpecified()
{
//arrange
var blog = new Mock<Blog>();
DateTime dateCreated = DateTime.Now;
blog.Object.Id = 1;
blog.Setup(b => b.TimeZone.Now).Returns(dateCreated);
var entry = new Entry(PostType.BlogPost, blog.Object) {Id = 123, BlogId = 1, CommentingClosed = false};
var repository = new Mock<ObjectProvider>();
repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns(entry);
var context = new Mock<ISubtextContext>();
context.SetupGet(c => c.Repository).Returns(repository.Object);
context.SetupGet(c => c.Blog).Returns(blog.Object);
context.SetupGet(c => c.HttpContext.Items).Returns(new Hashtable());
context.SetupGet(c => c.Cache).Returns(new TestCache());
var service = new CommentService(context.Object, null);
var comment = new FeedbackItem(FeedbackType.Comment)
{
EntryId = 123,
BlogId = 1,
Body = "test",
Title = "title",
DateCreated = dateCreated.AddDays(-2),
DateModified = dateCreated.AddDays(-1)
};
//act
service.Create(comment, true/*runFilters*/);
//assert
Assert.AreEqual(dateCreated.AddDays(-2), comment.DateCreated);
Assert.AreEqual(dateCreated.AddDays(-1), comment.DateModified);
}
示例5: Create
public override int Create(FeedbackItem feedbackItem)
{
if (feedbackItem == null)
throw new ArgumentNullException("feedbackItem");
string ipAddress = null;
if (feedbackItem.IpAddress != null)
ipAddress = feedbackItem.IpAddress.ToString();
string sourceUrl = null;
if (feedbackItem.SourceUrl != null)
sourceUrl = feedbackItem.SourceUrl.ToString();
return _procedures.InsertFeedback(feedbackItem.Title,
feedbackItem.Body,
BlogId,
feedbackItem.EntryId.NullIfMinValue(),
feedbackItem.Author,
feedbackItem.IsBlogAuthor,
feedbackItem.Email,
sourceUrl,
(int)feedbackItem.FeedbackType,
(int)feedbackItem.Status,
feedbackItem.CreatedViaCommentApi,
feedbackItem.Referrer,
ipAddress,
feedbackItem.UserAgent,
feedbackItem.ChecksumHash,
feedbackItem.DateCreated,
feedbackItem.DateModified,
CurrentDateTime);
}
示例6: ProcessRequest
/// <summary>
/// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
/// </summary>
/// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
if(Request.RequestType == "POST" && Request.ContentType == "text/xml")
{
XmlDocument doc = new XmlDocument();
doc.Load(Request.InputStream);
FeedbackItem comment = new FeedbackItem(FeedbackType.Comment);
comment.CreatedViaCommentAPI = true;
string name = doc.SelectSingleNode("//item/author").InnerText;
if(name.IndexOf("<") != -1)
{
name = name.Substring(0, name.IndexOf("<"));
}
comment.Author = name.Trim();
comment.Body = doc.SelectSingleNode("//item/description").InnerText;
comment.Title = doc.SelectSingleNode("//item/title").InnerText;
comment.SourceUrl = HtmlHelper.CheckForUrl(doc.SelectSingleNode("//item/link").InnerText);
comment.EntryId = UrlFormats.GetPostIDFromUrl(Request.Path);
// [ 1644691 ] Closing comments didn't stop the CommentAPI
if(!Subtext.Framework.Data.Cacher.GetEntry(comment.EntryId,CacheDuration.Medium).CommentingClosed)
FeedbackItem.Create(comment, new CommentFilter(HttpContext.Current.Cache));
}
}
示例7: EmailCommentToBlogAuthor_WithBlog_UsesBlogEmailForToEmail
public void EmailCommentToBlogAuthor_WithBlog_UsesBlogEmailForToEmail()
{
//arrange
var comment = new FeedbackItem(FeedbackType.Comment)
{Id = 121, Author = "me", Title = "the subject", FlaggedAsSpam = false};
var emailProvider = new Mock<EmailProvider>();
var templateEngine = new Mock<ITemplateEngine>();
var template = new Mock<ITextTemplate>();
templateEngine.Setup(t => t.GetTemplate(It.IsAny<string>())).Returns(template.Object);
template.Setup(t => t.Format(It.IsAny<object>())).Returns("message");
var urlHelper = new Mock<BlogUrlHelper>();
urlHelper.Setup(u => u.FeedbackUrl(comment)).Returns("/");
var context = new Mock<ISubtextContext>();
context.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
context.Setup(c => c.Blog).Returns(new Blog
{Email = "[email protected]", Author = "to", Host = "localhost", Title = "the blog"});
string toEmail = null;
emailProvider.Setup(
e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback
<string, string, string, string>((to, from, title, message) => toEmail = to);
var emailService = new EmailService(emailProvider.Object, templateEngine.Object, context.Object);
//act
emailService.EmailCommentToBlogAuthor(comment);
//assert
Assert.AreEqual("[email protected]", toEmail);
}
示例8: FeedbackCreateCallsCommentService
public void FeedbackCreateCallsCommentService(bool isSpam, bool isAdmin)
{
Assert.IsTrue(Config.CreateBlog("", "username", "password", _hostName, string.Empty));
MockRepository mocks = new MockRepository();
IFeedbackSpamService service = (IFeedbackSpamService)mocks.CreateMock(typeof(IFeedbackSpamService));
Config.CurrentBlog.FeedbackSpamService = service;
Config.CurrentBlog.DuplicateCommentsEnabled = true;
Config.CurrentBlog.FeedbackSpamServiceKey = "my-secret-key";
Config.CurrentBlog.ModerationEnabled = false;
FeedbackItem feedback = new FeedbackItem(FeedbackType.Comment);
Expect.Call(service.IsSpam(feedback)).Return(isSpam);
feedback.Title = "blah";
feedback.Body = UnitTestHelper.GenerateRandomString();
mocks.ReplayAll();
Assert.AreEqual(isAdmin, SecurityHelper.IsAdmin);
try
{
FeedbackItem.Create(feedback, new CommentFilter(new Cache()));
}
catch(BaseCommentException)
{
}
Assert.AreEqual(!isSpam, feedback.Approved);
}
示例9: Create
public int Create(FeedbackItem comment, bool runFilters)
{
Entry entry = Cacher.GetEntry(comment.EntryId, SubtextContext);
if(entry != null && entry.CommentingClosed)
{
return NullValue.NullInt32;
}
ISubtextContext context = SubtextContext;
HttpContextBase httpContext = context.HttpContext;
if(httpContext != null && httpContext.Request != null)
{
comment.UserAgent = httpContext.Request.UserAgent;
comment.IpAddress = HttpHelper.GetUserIpAddress(httpContext);
}
if(runFilters)
{
comment.FlaggedAsSpam = true; //We're going to start with this assumption.
}
comment.Author = HtmlHelper.SafeFormat(comment.Author, context.HttpContext.Server);
comment.Body = HtmlHelper.ConvertUrlsToHyperLinks(HtmlHelper.ConvertToAllowedHtml(comment.Body));
comment.Title = HtmlHelper.SafeFormat(comment.Title, context.HttpContext.Server);
// If we are creating this feedback item as part of an import, we want to
// be sure to use the item's datetime, and not set it to the current time.
if(NullValue.NullDateTime.Equals(comment.DateCreated))
{
comment.DateCreated = context.Blog.TimeZone.Now;
comment.DateModified = comment.DateCreated;
}
else if(NullValue.NullDateTime.Equals(comment.DateModified))
{
comment.DateModified = comment.DateCreated;
}
comment.Entry = entry;
if(runFilters)
{
OnBeforeCreate(comment);
}
comment.Id = Repository.Create(comment);
if(runFilters)
{
OnAfterCreate(comment);
}
return comment.Id;
}
示例10: Delete
/// <summary>
/// Confirms the feedback as spam and moves it to the trash.
/// </summary>
/// <param name="feedback">The feedback.</param>
public static void Delete(this ObjectRepository repository, FeedbackItem feedback)
{
if (feedback == null)
{
throw new ArgumentNullException("feedback");
}
feedback.SetStatus(FeedbackStatusFlag.Approved, false);
feedback.SetStatus(FeedbackStatusFlag.Deleted, true);
repository.Update(feedback);
}
示例11: EmailCommentToBlogAuthor_WithAuthor_SetsAuthorName
public void EmailCommentToBlogAuthor_WithAuthor_SetsAuthorName()
{
//arrange
var comment = new FeedbackItem(FeedbackType.Comment)
{Id = 121, Author = "me", Title = "subject", Email = null};
string sentMessage = null;
EmailService emailService = SetupEmailService(comment, "{comment.author}", sent => sentMessage = sent);
//act
emailService.EmailCommentToBlogAuthor(comment);
//assert
Assert.AreEqual("me", sentMessage);
}
示例12: CannotCreateDuplicateComments
public void CannotCreateDuplicateComments()
{
Assert.IsTrue(Config.CreateBlog("", "username", "password", _hostName, string.Empty));
BlogInfo blog = Config.CurrentBlog;
blog.CommentDelayInMinutes = 0;
FeedbackItem feedbackItem = new FeedbackItem(FeedbackType.Comment);
feedbackItem.DateCreated = DateTime.Now;
feedbackItem.SourceUrl = new Uri("http://localhost/ThisUrl/");
feedbackItem.Title = "Some Title";
feedbackItem.Body = "Some Body";
FeedbackItem.Create(feedbackItem, new CommentFilter(HttpContext.Current.Cache));
FeedbackItem.Create(feedbackItem, new CommentFilter(HttpContext.Current.Cache));
}
示例13: EmailCommentToBlogAuthor
public void EmailCommentToBlogAuthor(FeedbackItem comment)
{
if(String.IsNullOrEmpty(Blog.Email)
|| comment.FeedbackType == FeedbackType.PingTrack
|| Context.User.IsAdministrator())
{
return;
}
string fromEmail = comment.Email;
if(String.IsNullOrEmpty(fromEmail))
{
fromEmail = null;
}
var commentForTemplate = new
{
blog = Blog,
comment = new
{
author = comment.Author,
title = comment.Title,
source = Url.FeedbackUrl(comment).ToFullyQualifiedUrl(Blog),
email = fromEmail ?? "none given",
authorUrl = comment.SourceUrl,
ip = comment.IpAddress,
// we're sending plain text email by default, but body includes <br />s for crlf
body =
(comment.Body ?? string.Empty).Replace("<br />", Environment.NewLine).Replace("<br />",
Environment.
NewLine)
},
spamFlag = comment.FlaggedAsSpam ? "Spam Flagged " : ""
};
ITextTemplate template = TemplateEngine.GetTemplate("CommentReceived");
string message = template.Format(commentForTemplate);
string subject = String.Format(CultureInfo.InvariantCulture, Resources.Email_CommentVia, comment.Title,
Blog.Title);
if(comment.FlaggedAsSpam)
{
subject = "[SPAM Flagged] " + subject;
}
string from = EmailProvider.UseCommentersEmailAsFromAddress
? (fromEmail ?? EmailProvider.AdminEmail)
: EmailProvider.AdminEmail;
EmailProvider.Send(Blog.Email, from, subject, message);
}
示例14: ConvertToAkismetItem_WithContactPageFeedback_DoesNotSetPermalink
public void ConvertToAkismetItem_WithContactPageFeedback_DoesNotSetPermalink()
{
// arrange
var feedback = new FeedbackItem(FeedbackType.ContactPage);
var urlHelper = new Mock<BlogUrlHelper>();
urlHelper.Setup(helper => helper.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns((VirtualPath)null);
urlHelper.Setup(helper => helper.BlogUrl()).Returns("/");
var service = new AkismetSpamService("abracadabra", new Blog {Host = "localhost"}, null, urlHelper.Object);
// act
var comment = service.ConvertToAkismetItem(feedback);
// assert
Assert.IsNull(comment.Permalink);
}
示例15: Approve
/// <summary>
/// Approves the comment, and removes it from the SPAM folder or from the
/// Trash folder.
/// </summary>
/// <param name="feedback"></param>
/// <param name="spamService"></param>
/// <returns></returns>
public static void Approve(this ObjectRepository repository, FeedbackItem feedback, ICommentSpamService spamService)
{
if (feedback == null)
{
throw new ArgumentNullException("feedback");
}
feedback.SetStatus(FeedbackStatusFlag.Approved, true);
feedback.SetStatus(FeedbackStatusFlag.Deleted, false);
if (spamService != null)
{
spamService.SubmitGoodFeedback(feedback);
}
repository.Update(feedback);
}