diff --git a/Source/Terminals/Forms/MainForm.cs b/Source/Terminals/Forms/MainForm.cs index f59fc39f..c3dca90e 100644 --- a/Source/Terminals/Forms/MainForm.cs +++ b/Source/Terminals/Forms/MainForm.cs @@ -509,7 +509,8 @@ private void SaveActiveConnections() private void CheckForNewRelease() { - Task downloadTask = UpdateManager.CheckForUpdates(false); + var updateManager = new UpdateManager(); + Task downloadTask = updateManager.CheckForUpdates(false); downloadTask.ContinueWith(this.CheckForNewRelease, TaskScheduler.FromCurrentSynchronizationContext()); } diff --git a/Source/Terminals/Updates/UpdateManager.cs b/Source/Terminals/Updates/UpdateManager.cs index a246ebfc..0268577e 100644 --- a/Source/Terminals/Updates/UpdateManager.cs +++ b/Source/Terminals/Updates/UpdateManager.cs @@ -13,17 +13,33 @@ internal class UpdateManager /// private const string RSS_URL = "http://terminals.codeplex.com/project/feeds/rss?ProjectRSSFeed=codeplex%3A%2F%2Frelease%2FTerminals&ProjectName=terminals"; + private readonly Func readReleases; + + public UpdateManager() : this(ReadReleases) + { + } + + internal UpdateManager(Func readReleases) + { + this.readReleases = readReleases; + } + + private static RssFeed ReadReleases() + { + return RssFeed.Read(RSS_URL); + } + /// /// Check for available application updates. /// - internal static Task CheckForUpdates(bool automaticallyUpdate) + internal Task CheckForUpdates(bool automaticallyUpdate) { - return Task.Factory.StartNew((autoUpdate) => PerformCheck((bool)autoUpdate), automaticallyUpdate); + return Task.Factory.StartNew((autoUpdate) => this.PerformCheck((bool)autoUpdate), automaticallyUpdate); } - private static ReleaseInfo PerformCheck(bool automaticallyUpdate) + private ReleaseInfo PerformCheck(bool automaticallyUpdate) { - ReleaseInfo downLoaded = CheckForCodeplexRelease(Program.Info.BuildDate); + ReleaseInfo downLoaded = this.CheckForCodeplexRelease(Program.Info.BuildDate); // todo the automatic updates point to wrong URL this feature is not working bool autoUpdate = automaticallyUpdate; // obtain from command line arguments @@ -35,11 +51,11 @@ private static ReleaseInfo PerformCheck(bool automaticallyUpdate) return downLoaded; } - internal static ReleaseInfo CheckForCodeplexRelease(DateTime buildDate) + internal ReleaseInfo CheckForCodeplexRelease(DateTime buildDate) { try { - return TryCheckForCodeplexRelease(buildDate); + return this.TryCheckForCodeplexRelease(buildDate); } catch (Exception exception) { @@ -53,20 +69,20 @@ internal static ReleaseInfo CheckForCodeplexRelease(DateTime buildDate) /// Returns not null info about obtained current release. /// ReleaseInfo.NotAvailable in a case, new version was not checked or current version is the latest. /// - private static ReleaseInfo TryCheckForCodeplexRelease(DateTime buildDate) + private ReleaseInfo TryCheckForCodeplexRelease(DateTime buildDate) { var checksFile = new UpdateChecksFile(); if (!checksFile.ShouldCheckForUpdate) return ReleaseInfo.NotAvailable; - ReleaseInfo downLoaded = DownLoadLatestReleaseInfo(buildDate); + ReleaseInfo downLoaded = this.DownLoadLatestReleaseInfo(buildDate); checksFile.WriteLastCheck(); return downLoaded; } - private static ReleaseInfo DownLoadLatestReleaseInfo(DateTime buildDate) + private ReleaseInfo DownLoadLatestReleaseInfo(DateTime buildDate) { - RssFeed feed = RssFeed.Read(RSS_URL); + RssFeed feed = this.readReleases(); if (feed != null) { RssItem newvestRssItem = SelectNewvestRssRssItem(feed, buildDate); diff --git a/Source/Tests/UpdateManagerTest.cs b/Source/Tests/UpdateManagerTest.cs index 54176472..6ef63c4c 100644 --- a/Source/Tests/UpdateManagerTest.cs +++ b/Source/Tests/UpdateManagerTest.cs @@ -68,7 +68,8 @@ public void TodayCheckedDate_CheckForCodeplexRelease_DoesnotUpdateCheckDate() private ReleaseInfo RunUpdateCheck() { - return UpdateManager.CheckForCodeplexRelease(this.buildDate); + var updateManager = new UpdateManager(); + return updateManager.CheckForCodeplexRelease(this.buildDate); } private void AssertLastUpdateCheck()