本文整理汇总了C#中Mock.SetupUrlHelper方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetupUrlHelper方法的具体用法?C# Mock.SetupUrlHelper怎么用?C# Mock.SetupUrlHelper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.SetupUrlHelper方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpmlHandler_WithRequestForAggregateBlog_GetsGroupIdFromQueryString
public void OpmlHandler_WithRequestForAggregateBlog_GetsGroupIdFromQueryString()
{
//arrange
var queryString = new NameValueCollection { { "GroupID", "310" } };
var context = new Mock<ISubtextContext>();
context.Stub(c => c.HttpContext.Response.ContentType);
context.Setup(c => c.HttpContext.Response.Output).Returns(new StringWriter());
context.Setup(c => c.HttpContext.Request.QueryString).Returns(queryString);
context.Setup(c => c.HttpContext.Request.Url).Returns(new Uri("http://example.com/"));
context.SetupUrlHelper(new Mock<BlogUrlHelper>());
var repository = new Mock<ObjectRepository>();
int? parsedGroupId = null;
repository.Setup(r => r.GetBlogsByGroup("example.com", It.IsAny<int?>())).Callback<string, int?>(
(host, groupId) => parsedGroupId = groupId);
context.SetupRepository(repository);
var writer = new Mock<OpmlWriter>();
writer.Setup(w => w.Write(It.IsAny<IEnumerable<Blog>>(), It.IsAny<TextWriter>(), It.IsAny<BlogUrlHelper>()));
var appSettings = new NameValueCollection();
appSettings.Add("AggregateEnabled", "true");
var hostInfo = new HostInfo(appSettings);
var handler = new OpmlHandler(context.Object, writer.Object, new LazyNotNull<HostInfo>(() => hostInfo));
//act
handler.ProcessRequest();
//assert
Assert.AreEqual(310, parsedGroupId.Value);
}
示例2: CreateWelcomeContent_CreatesIntroBlogPostAndCategories
public void CreateWelcomeContent_CreatesIntroBlogPostAndCategories()
{
// arrange
var installationManager = new InstallationManager(new Mock<IInstaller>().Object, null);
var repository = new Mock<ObjectProvider>();
var entryPublisher = new Mock<IEntryPublisher>();
Entry entry = null;
entryPublisher.Setup(p => p.Publish(It.Is<Entry>(e => e.PostType == PostType.BlogPost))).Callback<Entry>(e => entry = e);
var urlHelper = new Mock<UrlHelper>();
urlHelper.Setup(u => u.AdminUrl("")).Returns("/admin/default.aspx");
urlHelper.Setup(u => u.EntryUrl(It.Is<Entry>(e => e.PostType == PostType.Story))).Returns<Entry>(e => "/articles/" + e.EntryName + ".aspx");
urlHelper.Setup(u => u.HostAdminUrl("default.aspx")).Returns("/hostadmin/default.aspx");
var context = new Mock<ISubtextContext>();
context.SetupUrlHelper(urlHelper);
context.Setup(c => c.Repository).Returns(repository.Object);
var blog = new Blog {Id = 123, Author = "TestAuthor"};
// act
installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);
// assert
Assert.AreEqual(entry.Title, "Welcome to Subtext!");
Assert.AreEqual(entry.EntryName, "welcome-to-subtext");
Assert.Contains(entry.Body, @"<a href=""/admin/default.aspx");
Assert.Contains(entry.Body, @"<a href=""/articles/welcome-to-subtext-article.aspx");
Assert.Contains(entry.Body, @"<a href=""/hostadmin/default.aspx");
Assert.IsTrue(entry.AllowComments);
Assert.IsTrue(!entry.Body.Contains(@"<a href=""{0}"));
Assert.IsTrue(!entry.Body.Contains(@"<a href=""{1}"));
Assert.IsTrue(!entry.Body.Contains(@"<a href=""{2}"));
}
示例3: OpmlHandler_WithRequest_SetsContentTypeToXml
public void OpmlHandler_WithRequest_SetsContentTypeToXml()
{
//arrange
var context = new Mock<ISubtextContext>();
context.Stub(c => c.HttpContext.Response.ContentType);
context.Setup(c => c.HttpContext.Response.Output).Returns(new StringWriter());
context.SetupUrlHelper(new Mock<UrlHelper>());
var writer = new Mock<OpmlWriter>();
writer.Setup(w => w.Write(It.IsAny<IEnumerable<Blog>>(), It.IsAny<TextWriter>(), It.IsAny<UrlHelper>()));
var handler = new OpmlHandler(context.Object, writer.Object);
//act
handler.ProcessRequest(new HostInfo());
//assert
Assert.AreEqual("text/xml", context.Object.HttpContext.Response.ContentType);
}
示例4: CreateWelcomeContent_CreatesIntroArticle
public void CreateWelcomeContent_CreatesIntroArticle()
{
// arrange
var installationManager = new InstallationManager(new Mock<IInstaller>().Object, null);
var repository = new Mock<ObjectProvider>();
var entryPublisher = new Mock<IEntryPublisher>();
Entry article = null;
entryPublisher.Setup(p => p.Publish(It.Is<Entry>(e => e.PostType == PostType.Story))).Callback<Entry>(e => article = e);
var urlHelper = new Mock<UrlHelper>();
urlHelper.Setup(u => u.AdminUrl("articles")).Returns("/admin/articles/default.aspx");
var context = new Mock<ISubtextContext>();
context.SetupUrlHelper(urlHelper);
context.Setup(c => c.Repository).Returns(repository.Object);
var blog = new Blog { Id = 123, Author = "TestAuthor" };
// act
installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);
// assert
Assert.AreEqual(article.Title, "Welcome to Subtext!");
Assert.Contains(article.Body, @"<a href=""/admin/articles/");
Assert.IsTrue(!article.Body.Contains(@"<a href=""{0}"));
}
示例5: OpmlHandler_WithRequest_SetsContentTypeToXml
public void OpmlHandler_WithRequest_SetsContentTypeToXml()
{
//arrange
var repository = new Mock<ObjectRepository>();
repository.Setup(r => r.GetBlogsByGroup("http://subtextproject.com/", 1)).Returns(new Blog[] { new Blog { } });
var queryString = new NameValueCollection();
queryString.Add("GroupID", "1");
var context = new Mock<ISubtextContext>();
context.Setup(c => c.Repository).Returns(repository.Object);
context.Setup(c => c.HttpContext.Request.Url).Returns(new Uri("http://subtextproject.com/"));
context.Setup(c => c.HttpContext.Request.QueryString).Returns(queryString);
context.Stub(c => c.HttpContext.Response.ContentType);
context.Setup(c => c.HttpContext.Response.Output).Returns(new StringWriter());
context.SetupUrlHelper(new Mock<BlogUrlHelper>());
var writer = new Mock<OpmlWriter>();
writer.Setup(w => w.Write(It.IsAny<IEnumerable<Blog>>(), It.IsAny<TextWriter>(), It.IsAny<BlogUrlHelper>()));
var handler = new OpmlHandler(context.Object, writer.Object, new LazyNotNull<HostInfo>(CreateHostInfo));
//act
handler.ProcessRequest();
//assert
Assert.AreEqual("text/xml", context.Object.HttpContext.Response.ContentType);
}
示例6: CreateWelcomeContent_CreatesIntroComment
public void CreateWelcomeContent_CreatesIntroComment()
{
// arrange
var installationManager = new InstallationManager(new Mock<IInstaller>().Object, null);
var repository = new Mock<ObjectProvider>();
var entryPublisher = new Mock<IEntryPublisher>();
var urlHelper = new Mock<UrlHelper>();
urlHelper.Setup(u => u.AdminUrl("feedback")).Returns("/admin/feedback/default.aspx");
var context = new Mock<ISubtextContext>();
context.SetupUrlHelper(urlHelper);
context.Setup(c => c.Repository).Returns(repository.Object);
var blog = new Blog { Id = 123, Author = "TestAuthor" };
FeedbackItem comment = null;
repository.Setup(r => r.Create(It.IsAny<FeedbackItem>())).Callback<FeedbackItem>(c => comment = c);
// act
installationManager.CreateWelcomeContent(context.Object, entryPublisher.Object, blog);
// assert
Assert.IsTrue(comment.Approved);
Assert.AreEqual(comment.Title, "re: Welcome to Subtext!");
Assert.Contains(comment.Body, @"<a href=""/admin/feedback/");
Assert.IsTrue(!comment.Body.Contains(@"<a href=""{1}"));
}