mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Added functional UpdateStableChannel test
It's working! It's working!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user