Exemple #1
0
        public void FeedManagerShouldReturnThrowIfGsaHostArgumentsAreFaulty()
        {
            var feed = new Feed();
            var record = new FeedRecord();
            record.Url = "http://www.claremont.se/test/";

            feed.Records.Add(record);

            var manager = new FeedManager();

            Assert.Throws<ArgumentException>(() => manager.PushFeed(feed));
        }
Exemple #2
0
        public void FeedManagerShouldReturnCorrectResult()
        {
            var feed = new Feed();
            var record = new FeedRecord();
            record.Url = "http://klaratest.domain.se/Info/Nyheter/Nyhet-Test-2-Reload/";

            feed.Records.Add(record);

            var manager = new FeedManager();
            manager.GsaHostAddress = "http://google03.domain.se";

            var succedingFeedClient = new Mock<IFeedClient>();
            succedingFeedClient.Setup(m => m.PushFeed(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(HttpStatusCode.OK);

            manager.FeedClient = succedingFeedClient.Object;

            var result = manager.PushFeed(feed);

            Assert.AreEqual(HttpStatusCode.OK, result);
        }
Exemple #3
0
        /// <summary>
        /// Push the specified feed to the Google Search Appliance
        /// </summary>
        /// <param name="feed">The feed to push</param>
        /// <param name="async">Should the request to GSA be sent asynchronously</param>
        /// <returns>a <see cref="HttpStatusCode"/> that indicates whether the request succeded or failed</returns>
        /// <exception cref="ArgumentException">Thrown if you have not specified a correct host adress or feed</exception>
        public HttpStatusCode PushFeed(Feed feed, bool async = false)
        {
            if (string.IsNullOrEmpty(GsaHostAddress))
            {
                throw new ArgumentException("You have not specified a correct host address");
            }

            if (feed == null)
            {
                throw new ArgumentException("You must specify a feed", "feed");
            }

            var xml = feed.ConstructXml();

            if (FeedClient == null)
            {
                FeedClient = new FeedClient();
            }

            return FeedClient.PushFeed(xml, GsaHostAddress, async);
        }
Exemple #4
0
        public void FeedShouldReturnCorrectXml()
        {
            var feed = new Feed();
            var record = new FeedRecord();
            record.Url = "http://www.sf.se/";

            feed.Records.Add(record);

            var xml = feed.ConstructXml();

            Assert.AreEqual("<!DOCTYPE gsafeed PUBLIC \"-//Google//DTD GSA Feeds//EN\" \"\"[]>\r\n<gsafeed>\r\n  <header>\r\n    <datasource>web</datasource>\r\n    <feedtype>incremental</feedtype>\r\n  </header>\r\n  <group>\r\n    <record url=\"http://www.sf.se/\" lock=\"false\" mimetype=\"requiredbutignored\" authmethod=\"none\" crawl-immediately=\"false\" crawl-once=\"false\" />\r\n  </group>\r\n</gsafeed>", xml);
        }