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()); }
/// <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(); }
/// <summary> /// Pull Html file from Windows Azure only once, store it, /// save file name. /// </summary> /// <returns>filename as string</returns> public static string RunBeforeTests() { Trace.TraceInformation("RunBeforeAnyTests a"); // if there is a file with today's date, don't do anything string fileName = @"..\..\..\Wp7AzureMgmt.DashboardFeeds.Test\Html_634871865298370572.html"; HttpContextBase httpContext = null; // file built today not found so go build it // runs inside same day can use today's html if (!File.Exists(fileName)) { Trace.TraceInformation("RunBeforeAnyTests b"); // initialize Uri UriDatasource uriDatasource = new UriDatasource(null, httpContext); DashboardHttp http = new DashboardHttp(uriDatasource.DashboardUri); uriDatasource.DashboardHttp = http; // get html and save to serialized file // set filename in config file as test uriDatasource.GetAndSaveHtml(fileName); // Save filename to config file so test run can use it for parsing FeedConfiguration dbconf = new FeedConfiguration(httpContext); dbconf.TestFileName = fileName; Trace.TraceInformation("RunBeforeAnyTests c"); } Trace.TraceInformation("RunBeforeAnyTests d"); return fileName; }
public void GetHtml() { // arrange int lastKnownLength = 300000; HttpContextBase httpContext = null; UriDatasource uriDatasource = new UriDatasource(null, httpContext); FeedConfiguration config = new FeedConfiguration(null); DashboardHttp http = new DashboardHttp(new Uri(config.AzureUri)); uriDatasource.DashboardHttp = http; // act string actual = uriDatasource.GetHtml(); // save to file File.WriteAllText("Html_" + DateTime.Now.Ticks + ".html", actual); // assert // if this length is wrong then the file Azure returns // has changed since the last test Assert.IsTrue(lastKnownLength <= actual.Length); }
public void Set() { // arrange HttpContextBase httpContext = null; UriDatasource uriDatasource = new UriDatasource(null, httpContext); // act try { uriDatasource.Set(); Assert.Fail("exception not thrown"); } catch (NotImplementedException) { } catch { Assert.Fail("Invalid exception"); } }