/// <summary> /// Initializes a new instance of the <see cref="UriDatasource" /> class. /// </summary> /// <param name="http">DashboardHttp object containing request</param> /// <param name="httpContext">Http web context or null if not a web request</param> public UriDatasource(DashboardHttp http, HttpContextBase httpContext) { this.configuration = new FeedConfiguration(httpContext); this.configurationContext = httpContext; this.httpRequest = http; this.GetConfigSettings(); }
/// <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); }