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/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/Resources/Strings.xaml b/src/Magpie/Magpie/Resources/Strings.xaml index 4fd81b1..5a19d7f 100644 --- a/src/Magpie/Magpie/Resources/Strings.xaml +++ b/src/Magpie/Magpie/Resources/Strings.xaml @@ -6,7 +6,7 @@ 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 \ 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/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index a108a3d..3fa794f 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 && FailedToEnroll(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 {