diff --git a/src/Magpie/Magpie.Example/Properties/AssemblyInfo.cs b/src/Magpie/Magpie.Example/Properties/AssemblyInfo.cs index 8c7860c..40c405d 100644 --- a/src/Magpie/Magpie.Example/Properties/AssemblyInfo.cs +++ b/src/Magpie/Magpie.Example/Properties/AssemblyInfo.cs @@ -54,5 +54,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.2.0")] -[assembly: AssemblyFileVersion("0.0.2.0")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.3.0")] +[assembly: AssemblyFileVersion("0.0.3.0")] \ No newline at end of file diff --git a/src/Magpie/Magpie.Tests/Services/MagpieTest.cs b/src/Magpie/Magpie.Tests/Services/MagpieTest.cs index 3196df8..ec96d08 100644 --- a/src/Magpie/Magpie.Tests/Services/MagpieTest.cs +++ b/src/Magpie/Magpie.Tests/Services/MagpieTest.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Magpie.Tests.Mocks; using MagpieUpdater.Interfaces; using MagpieUpdater.Models; @@ -194,7 +195,7 @@ public void SwitchingChannel_FailingToEnroll_DoesNotUpdateSubscribedChannel() } [TestMethod] - public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChannel() + public void SwitchingChannel_ChannelDoesNotRequireEnrollment_UpdatesSubscribedChannel() { var updateDecider = Substitute.For(new DebuggingWindowViewModel()); updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); @@ -203,5 +204,46 @@ public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChan Assert.AreEqual(3, _mockMagpie.AppInfo.SubscribedChannel); } + + [TestMethod] + public async Task SwitchingChannelAsync_SuccessfullyEnrolled_ReturnsTrue() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + _mockMagpie.UpdateDecider = updateDecider; + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = true }; + var success = await _mockMagpie.SwitchSubscribedChannelAsync(4); + + Assert.IsTrue(success); + } + + [TestMethod] + public async Task SwitchingAsync_ChannelDoesNotRequireEnrollment_ReturnsTrue() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie.UpdateDecider = updateDecider; + var success = await _mockMagpie.SwitchSubscribedChannelAsync(3); + + Assert.IsTrue(success); + } + + [TestMethod] + public async Task SwitchingChannelAsync_FailingToEnroll_ReturnsFalse() + { + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = false }; + var success = await _mockMagpie.SwitchSubscribedChannelAsync(4); + + Assert.IsFalse(success); + } + + [TestMethod] + public async Task SwitchingAsync_AppCastIsEmpty_ReturnsFalse() + { + _mockMagpie.RemoteContentDownloader.DownloadStringContent(Arg.Any(), Arg.Any()).Returns(Task.FromResult(string.Empty)); + var success = await _mockMagpie.SwitchSubscribedChannelAsync(3); + + Assert.IsFalse(success); + } } } \ No newline at end of file diff --git a/src/Magpie/Magpie.latest.nupkg b/src/Magpie/Magpie.latest.nupkg index 9f5d077..3a87655 100644 Binary files a/src/Magpie/Magpie.latest.nupkg and b/src/Magpie/Magpie.latest.nupkg differ diff --git a/src/Magpie/Magpie/Models/Enrollment.cs b/src/Magpie/Magpie/Models/Enrollment.cs index b56afc4..140e76a 100644 --- a/src/Magpie/Magpie/Models/Enrollment.cs +++ b/src/Magpie/Magpie/Models/Enrollment.cs @@ -3,9 +3,9 @@ public class Enrollment { public Channel Channel { get; private set; } - public bool IsRequired { get; internal set; } - public bool IsEnrolled { get; internal set; } - public string Email { get; internal set; } + public bool IsRequired { get; set; } + public bool IsEnrolled { get; set; } + public string Email { get; set; } public Enrollment(Channel channel) { diff --git a/src/Magpie/Magpie/Properties/AssemblyInfo.cs b/src/Magpie/Magpie/Properties/AssemblyInfo.cs index 5496495..c675e6c 100644 --- a/src/Magpie/Magpie/Properties/AssemblyInfo.cs +++ b/src/Magpie/Magpie/Properties/AssemblyInfo.cs @@ -54,7 +54,7 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.2.0")] -[assembly: AssemblyFileVersion("0.2.2.0")] +[assembly: AssemblyVersion("0.3.2.0")] +[assembly: AssemblyFileVersion("0.3.2.0")] [assembly: InternalsVisibleTo("Magpie.Tests")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/src/Magpie/Magpie/Resources/Strings.xaml b/src/Magpie/Magpie/Resources/Strings.xaml index 4fd81b1..f4a00cd 100644 --- a/src/Magpie/Magpie/Resources/Strings.xaml +++ b/src/Magpie/Magpie/Resources/Strings.xaml @@ -6,7 +6,8 @@ Skip this Version Remind Me Later I don't want to - I don't want to + Enroll Please provide your email address to join the {0} Program By enrolling in this program you agree with our + Terms and Condtions \ No newline at end of file diff --git a/src/Magpie/Magpie/Services/AnalyticsLogger.cs b/src/Magpie/Magpie/Services/AnalyticsLogger.cs index 326caa5..c3c861a 100644 --- a/src/Magpie/Magpie/Services/AnalyticsLogger.cs +++ b/src/Magpie/Magpie/Services/AnalyticsLogger.cs @@ -41,7 +41,7 @@ public virtual void LogUpdateAvailable(Channel channel) { } - public void LogEnrollment(Enrollment enrollment) + public virtual void LogEnrollment(Enrollment enrollment) { } } diff --git a/src/Magpie/Magpie/Services/DefaultRemoteContentDownloader.cs b/src/Magpie/Magpie/Services/DefaultRemoteContentDownloader.cs index c020b92..e7a601c 100644 --- a/src/Magpie/Magpie/Services/DefaultRemoteContentDownloader.cs +++ b/src/Magpie/Magpie/Services/DefaultRemoteContentDownloader.cs @@ -7,6 +7,11 @@ namespace MagpieUpdater.Services { internal class DefaultRemoteContentDownloader : IRemoteContentDownloader { + public DefaultRemoteContentDownloader() + { + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; + } public async Task DownloadStringContent(string url, IDebuggingInfoLogger logger = null) { try @@ -48,4 +53,4 @@ public async Task DownloadFile(string sourceUrl, string destinationPath, } } } -} \ No newline at end of file +} diff --git a/src/Magpie/Magpie/Services/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index a108a3d..0ecd164 100644 --- a/src/Magpie/Magpie/Services/Magpie.cs +++ b/src/Magpie/Magpie/Services/Magpie.cs @@ -52,7 +52,12 @@ await Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggi .ConfigureAwait(false); } - private async Task Check(string appcastUrl, CheckState checkState, int channelId = 1, bool showDebuggingWindow = false) + public Task SwitchSubscribedChannelAsync(int channelId, bool showDebuggingWindow = false) + { + return Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggingWindow); + } + + private async Task Check(string appcastUrl, CheckState checkState, int channelId = 1, bool showDebuggingWindow = false) { _logger.Log(string.Format("Starting fetching remote channel content from address: {0}", appcastUrl)); try @@ -64,12 +69,15 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId { ShowErrorWindow(); } - return; + return false; } var appcast = ParseAppcast(data); - if (checkState == CheckState.ChannelSwitch && FailedToEnroll(appcast, channelId)) return; + if (checkState == CheckState.ChannelSwitch && CheckIfFailedToEnroll(appcast, channelId)) + { + return false; + } var channelToUpdateFrom = BestChannelFinder.Find(channelId, appcast.Channels); @@ -83,10 +91,12 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId ShowNoUpdatesWindow(); } AppInfo.SubscribedChannel = channelId; + return true; } catch (Exception ex) { _logger.Log(string.Format("Error parsing remote channel: {0}", ex.Message)); + return false; } finally { @@ -94,7 +104,7 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId } } - private bool FailedToEnroll(RemoteAppcast appcast, int channelId) + private bool CheckIfFailedToEnroll(RemoteAppcast appcast, int channelId) { var channel = appcast.Channels.FirstOrDefault(c => c.Id == channelId); var enrollment = new Enrollment(channel); @@ -103,7 +113,6 @@ private bool FailedToEnroll(RemoteAppcast appcast, int channelId) enrollment.IsRequired = true; ShowEnrollmentWindow(enrollment); } - _analyticsLogger.LogEnrollment(enrollment); OnEnrollmentAvailableEvent(new SingleEventArgs(enrollment)); return enrollment.IsRequired && !enrollment.IsEnrolled; } @@ -266,6 +275,7 @@ protected virtual void OnArtifactDownloadedEvent(SingleEventArgs args) protected virtual void OnEnrollmentAvailableEvent(SingleEventArgs args) { + _analyticsLogger.LogEnrollment(args.Payload); var handler = EnrollmentAvailableEvent; if (handler != null) handler(this, args); } diff --git a/src/Magpie/Magpie/Views/EnrollmentWindow.xaml b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml index 42335f3..8e758cf 100644 --- a/src/Magpie/Magpie/Views/EnrollmentWindow.xaml +++ b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml @@ -63,7 +63,7 @@ Text="{DynamicResource _eulaMsg}" TextWrapping="Wrap"> - +