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);
        }
Beispiel #3
0
        // POST: api/Articles
        public void Post([FromBody] Person person)
        {
            if (person.Login.Equals("CiPhantom") && person.Password.Equals("lksPMnze"))
            {
                OpmlHandler opmlHandler          = new OpmlHandler("./rss.opml");
                Dictionary <string, string> urls = new Dictionary <string, string>();
                urls = opmlHandler.getListeJourneaux();

                List <Article> articles = new List <Article>();
                Feeder         f        = new Feeder(urls);
                articles = f.getArticles();

                DataBaseCommunication dataBaseCommunication = new DataBaseCommunication(CONNECTION_STRING);

                dataBaseCommunication.SaveArticles(articles);
            }
        }
        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);
        }