From ebb21b4ead46436e2c45d9704a9b8f81110e4551 Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Fri, 28 Apr 2017 16:58:05 -0600 Subject: [PATCH 1/6] Fix string --- src/Magpie/Magpie/Resources/Strings.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 121ea935ed127a0377f65b49c45906d18b2fc66e Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Fri, 28 Apr 2017 17:01:32 -0600 Subject: [PATCH 2/6] Make LogEnrollment virtual --- src/Magpie/Magpie/Services/AnalyticsLogger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { } } From 46ec4f192a0a121be661283d7bf06e02beb41650 Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Fri, 28 Apr 2017 17:02:44 -0600 Subject: [PATCH 3/6] Check returns true if check succeeded --- src/Magpie/Magpie/Services/Magpie.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Magpie/Magpie/Services/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index a108a3d..f59273a 100644 --- a/src/Magpie/Magpie/Services/Magpie.cs +++ b/src/Magpie/Magpie/Services/Magpie.cs @@ -53,6 +53,7 @@ await Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggi } private async Task Check(string appcastUrl, CheckState checkState, int channelId = 1, bool showDebuggingWindow = false) + 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 +65,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 +87,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 { From 6e89c2a6fc82a51281fae11ad34794d0230e87e5 Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Fri, 28 Apr 2017 17:03:57 -0600 Subject: [PATCH 4/6] Add an async SwitchSubscribedChannel method --- src/Magpie/Magpie/Services/Magpie.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Magpie/Magpie/Services/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index f59273a..3fa794f 100644 --- a/src/Magpie/Magpie/Services/Magpie.cs +++ b/src/Magpie/Magpie/Services/Magpie.cs @@ -52,7 +52,11 @@ 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)); From 9be8211c71a77d0fc45624d4e7a045eadf846de1 Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Mon, 1 May 2017 11:51:09 -0600 Subject: [PATCH 5/6] Add unit tests for SwitchSubscribedChannelAsync --- .../Magpie.Tests/Services/MagpieTest.cs | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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 From 6105e1439deee70ffcdf9bd70edc4567179066aa Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Mon, 1 May 2017 15:53:54 -0600 Subject: [PATCH 6/6] Allow Enrollment properties to be set by client apps --- src/Magpie/Magpie/Models/Enrollment.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) {