当前位置: 首页>>代码示例>>C#>>正文


C# Mock.SetupUrlHelper方法代码示例

本文整理汇总了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);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:30,代码来源:OpmlHandlerTests.cs

示例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}"));
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:31,代码来源:InstallationManagerTests.cs

示例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);
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:17,代码来源:OpmlHandlerTests.cs

示例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}"));
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:23,代码来源:InstallationManagerTests.cs

示例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);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:24,代码来源:OpmlHandlerTests.cs

示例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}"));
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:24,代码来源:InstallationManagerTests.cs


注:本文中的Mock.SetupUrlHelper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。