Esempio n. 1
0
        public void Get()
        {
            // arrange
            DashboardHttp httpRequest = null;
            HttpContextBase contextBase = null;
            UriDatasource uriDatasource = new UriDatasource(httpRequest, contextBase);

            // Has the entire fake html string read from file
            DashboardHttpFake dashboardHttpFake = new DashboardHttpFake();
            string fakeHtml = dashboardHttpFake.GetRequest();

            // set fake string to response of GetRequest
            var mockDashboardHttp = new Mock<IDashboardHttp>();
            mockDashboardHttp.Setup(f => f.GetRequest()).Returns(fakeHtml);

            uriDatasource.DashboardHttp = mockDashboardHttp.Object;

            // act
            RssFeeds actual = uriDatasource.Get();

            // assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(this.currentFeedCount, actual.Feeds.Count());

            // Simple check each field since there are other tests that do
            // deeper checking of RssFeeds
            var foundNSACSEAFeeds = actual.Feeds.Where(f => f.FeedCode == "NSACSEA").ToList();
            var foundEastAsiaFeeds = actual.Feeds.Where(f => f.LocationName == "East Asia").ToList();
            var foundAccessControl = actual.Feeds.Where(f => f.ServiceName == "Access Control").ToList();
            var foundLinks = actual.Feeds.Where(f => f.RSSLink.Contains(@"<a href")).ToList();

            // only 1 NSACSEA feed
            Assert.AreEqual(1, foundNSACSEAFeeds.Count());

            // several east asia feeds
            Assert.AreEqual(11, foundEastAsiaFeeds.Count());

            // several access control feeds
            Assert.AreEqual(11, foundEastAsiaFeeds.Count());

            // each/all should have a well-formed url
            Assert.AreEqual(88, foundLinks.Count());
        }
Esempio n. 2
0
        /// <summary>
        /// Serialize RssFeeds to disk. Make request across
        /// wire to Uri, grab response into RssFeeds,
        /// serialize RssFeeds.
        /// </summary>
        /// <param name="pathToFiles">Path to serialized files</param>
        public void SetRssFeedsFromUri(string pathToFiles)
        {
            DashboardHttp httpRequest = new DashboardHttp();

            UriDatasource uriDataSource = new UriDatasource(httpRequest, this.httpContext);
            RssFeeds feeds = uriDataSource.Get();

            if (feeds == null)
            {
                throw new Exception("feeds == null");
            }

            FileDatasource fileDatasource = new FileDatasource(pathToFiles, this.httpContext);
            fileDatasource.RssFeeds = feeds;
            fileDatasource.Set();
        }