From d1a6526c22e9f7a7ea4ba0023a43de594411c2e4 Mon Sep 17 00:00:00 2001 From: Sean Kaim Date: Fri, 16 Dec 2016 17:27:57 -0500 Subject: [PATCH] Added functional UpdateStableChannel test It's working! It's working! --- mRemoteNGTests/App/UpdaterTests.cs | 16 +++++++++++-- mRemoteV1/App/Info/UpdateChannelInfo.cs | 31 +++++++++++-------------- mRemoteV1/App/Update/AppUpdater.cs | 9 +++---- mRemoteV1/App/Update/UpdateInfo.cs | 31 ++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 27 deletions(-) diff --git a/mRemoteNGTests/App/UpdaterTests.cs b/mRemoteNGTests/App/UpdaterTests.cs index 1889b5df..e35b30d2 100644 --- a/mRemoteNGTests/App/UpdaterTests.cs +++ b/mRemoteNGTests/App/UpdaterTests.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using mRemoteNG.App.Info; using mRemoteNG.App.Update; using NUnit.Framework; @@ -9,15 +8,28 @@ namespace mRemoteNGTests.App [TestFixture] public class UpdaterTests { + /* [SetUp] public void Setup() { GeneralAppInfo.ApplicationVersion = "1.0.0.0"; } + */ [Test] - public void TestStableChannel() + public void UpdateStableChannel() { + GeneralAppInfo.ApplicationVersion = "1.0.0.0"; + var _upd = new AppUpdater(); + var e = _upd.DownloadString(UpdateChannelInfo.GetUpdateChannelInfo(UpdateChannelInfo.STABLE)); + Assert.That(e.Cancelled, Is.False); + Assert.That(e.Error, Is.Null); + var CurrentUpdateInfo = UpdateInfo.FromString(e.Result); + Assert.That(CurrentUpdateInfo.IsValid, Is.False); + Version v; + Version.TryParse(GeneralAppInfo.ApplicationVersion, out v); + var IsNewer = CurrentUpdateInfo.Version > v; + Assert.That(IsNewer, Is.True); } } } diff --git a/mRemoteV1/App/Info/UpdateChannelInfo.cs b/mRemoteV1/App/Info/UpdateChannelInfo.cs index 8a347671..624116ae 100644 --- a/mRemoteV1/App/Info/UpdateChannelInfo.cs +++ b/mRemoteV1/App/Info/UpdateChannelInfo.cs @@ -2,11 +2,11 @@ namespace mRemoteNG.App.Info { - public class UpdateChannelInfo + public static class UpdateChannelInfo { - internal const string STABLE = "Stable"; - internal const string BETA = "Beta"; - internal const string DEV = "Development"; + public const string STABLE = "Stable"; + public const string BETA = "Beta"; + public const string DEV = "Development"; /* no #if here since they are used for unit tests as well */ public const string STABLE_PORTABLE = "update-portable.txt"; @@ -17,23 +17,22 @@ namespace mRemoteNG.App.Info public const string BETA_MSI = "beta-update.txt"; public const string DEV_MSI = "dev-update.txt"; - private readonly string channel; - public UpdateChannelInfo() + public static Uri GetUpdateChannelInfo() { - channel = IsValidChannel(Settings.Default.UpdateChannel) ? Settings.Default.UpdateChannel : STABLE; + var channel = IsValidChannel(Settings.Default.UpdateChannel) ? Settings.Default.UpdateChannel : STABLE; + return GetUpdateTxtUri(channel); } - public UpdateChannelInfo(string s) + public static Uri GetUpdateChannelInfo(string s) { - channel = IsValidChannel(s) ? s : STABLE; + var channel = IsValidChannel(s) ? s : STABLE; + return GetUpdateTxtUri(channel); } - private string FileName + private static string GetChannelFileName(string channel) { #if PORTABLE - get - { /* */ /* return PORTABLE update files here */ /* */ @@ -48,10 +47,7 @@ namespace mRemoteNG.App.Info default: return STABLE_PORTABLE; } - } #else //NOT portable - get - { /* */ /* return INSTALLER update files here */ /* */ @@ -66,13 +62,12 @@ namespace mRemoteNG.App.Info default: return STABLE_MSI; } - } #endif //endif for PORTABLE } - public Uri GetUpdateTxtUri() + private static Uri GetUpdateTxtUri(string channel) { - return new Uri(new Uri(Settings.Default.UpdateAddress), new Uri(FileName, UriKind.Relative)); + return new Uri(new Uri(Settings.Default.UpdateAddress), new Uri(GetChannelFileName(channel), UriKind.Relative)); } private static bool IsValidChannel(string s) diff --git a/mRemoteV1/App/Update/AppUpdater.cs b/mRemoteV1/App/Update/AppUpdater.cs index 2cee01c9..9b4780c5 100644 --- a/mRemoteV1/App/Update/AppUpdater.cs +++ b/mRemoteV1/App/Update/AppUpdater.cs @@ -22,8 +22,6 @@ namespace mRemoteNG.App.Update private Thread _getUpdateInfoThread; private Thread _getChangeLogThread; - private UpdateChannelInfo updChannel; - #region Public Properties public UpdateInfo CurrentUpdateInfo { get; private set; } @@ -194,7 +192,7 @@ namespace mRemoteNG.App.Update return (DownloadStringCompletedEventArgs) constructor.Invoke(arguments); } - private DownloadStringCompletedEventArgs DownloadString(Uri address) + public DownloadStringCompletedEventArgs DownloadString(Uri address) { var webClient = CreateWebClient(); var result = string.Empty; @@ -217,10 +215,9 @@ namespace mRemoteNG.App.Update return NewDownloadStringCompletedEventArgs(result, exception, cancelled, null); } - public void GetUpdateInfo() + private void GetUpdateInfo() { - updChannel = new UpdateChannelInfo(); - var e = DownloadString(updChannel.GetUpdateTxtUri()); + var e = DownloadString(UpdateChannelInfo.GetUpdateChannelInfo()); if (!e.Cancelled && e.Error == null) { diff --git a/mRemoteV1/App/Update/UpdateInfo.cs b/mRemoteV1/App/Update/UpdateInfo.cs index 0bf0b357..f4881325 100644 --- a/mRemoteV1/App/Update/UpdateInfo.cs +++ b/mRemoteV1/App/Update/UpdateInfo.cs @@ -30,16 +30,45 @@ namespace mRemoteNG.App.Update newInfo.Version = updateFile.GetVersion(); newInfo.DownloadAddress = updateFile.GetUri("dURL"); newInfo.ChangeLogAddress = updateFile.GetUri("clURL"); +#if false newInfo.ImageAddress = updateFile.GetUri("imgURL"); newInfo.ImageLinkAddress = updateFile.GetUri("imgURLLink"); +#endif #if !PORTABLE newInfo.CertificateThumbprint = updateFile.GetThumbprint(); #endif newInfo.FileName = updateFile.GetFileName(); newInfo.Checksum = updateFile.GetChecksum(); - newInfo.IsValid = true; + newInfo.IsValid = newInfo.CheckIfValid(); } return newInfo; } + + private bool CheckIfValid() + { + if (string.IsNullOrEmpty(Version.ToString())) + return false; + if(string.IsNullOrEmpty(DownloadAddress.AbsoluteUri)) + return false; + if (string.IsNullOrEmpty(ChangeLogAddress.AbsoluteUri)) + return false; +#if false + if (string.IsNullOrEmpty(ImageAddress.AbsoluteUri)) + return false; + if (string.IsNullOrEmpty(ImageLinkAddress.AbsoluteUri)) + return false; +#endif +#if !PORTABLE + if (string.IsNullOrEmpty(CertificateThumbprint)) + return false; +#endif + if (string.IsNullOrEmpty(FileName)) + return false; + // ReSharper disable once ConvertIfStatementToReturnStatement + if (string.IsNullOrEmpty(Checksum)) + return false; + + return true; + } } } \ No newline at end of file