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 <UrlHelper>());
            var repository    = new Mock <ObjectProvider>();
            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 <UrlHelper>()));
            var handler  = new OpmlHandler(context.Object, writer.Object);
            var hostInfo = new HostInfo {
                BlogAggregationEnabled = true, AggregateBlog = new Blog()
            };

            //act
            handler.ProcessRequest(hostInfo);

            //assert
            Assert.AreEqual(310, parsedGroupId.Value);
        }
Beispiel #2
0
        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);
        }
        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);
        }