From 7ada9a539286178a6480cd69bad21c6887555bcd Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Wed, 26 Apr 2017 11:35:48 -0600 Subject: [PATCH 1/4] Add a link to the enrollment EULA in the enrollment window --- src/Magpie/Magpie/Models/Channel.cs | 3 +++ src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs | 12 ++++++++++++ src/Magpie/Magpie/Views/EnrollmentWindow.xaml | 9 +++++++-- src/Magpie/Magpie/Views/EnrollmentWindow.xaml.cs | 11 ++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Magpie/Magpie/Models/Channel.cs b/src/Magpie/Magpie/Models/Channel.cs index 6b832c7..35126e6 100644 --- a/src/Magpie/Magpie/Models/Channel.cs +++ b/src/Magpie/Magpie/Models/Channel.cs @@ -30,6 +30,9 @@ public class Channel [DataMember(Name = "requires_enrollment", IsRequired = false)] public bool RequiresEnrollment { get; private set; } + [DataMember(Name = "enrollment_eula_url", IsRequired = false)] + public string EnrollmentEulaUrl { get; private set; } + // Dates example: // e.g. January 30, 2015 18:15:00 +0200 // 10/03/2015 diff --git a/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs b/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs index 46808d7..7c18134 100644 --- a/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs +++ b/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs @@ -17,6 +17,7 @@ internal class EnrollmentViewModel : BindableBase private readonly Enrollment _enrollment; private string _channelName; private string _appIconPath; + private string _enrollmentEulaUrl; public string AppIconPath { @@ -46,6 +47,16 @@ public string ChannelName } } + public string EnrollmentEulaUrl + { + get { return _enrollmentEulaUrl; } + set + { + _enrollmentEulaUrl = value; + SetProperty(ref _enrollmentEulaUrl, value); + } + } + public DelegateCommand EnrollCommand { get; set; } public EnrollmentViewModel(Enrollment enrollment, AppInfo appInfo) @@ -53,6 +64,7 @@ public EnrollmentViewModel(Enrollment enrollment, AppInfo appInfo) _enrollment = enrollment; AppIconPath = appInfo.AppIconPath; ChannelName = _enrollment.Channel.Build; + EnrollmentEulaUrl = _enrollment.Channel.EnrollmentEulaUrl; EnrollCommand = new DelegateCommand(EnrollCommandHandler, CanEnroll); } diff --git a/src/Magpie/Magpie/Views/EnrollmentWindow.xaml b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml index cd1bce3..3d085cd 100644 --- a/src/Magpie/Magpie/Views/EnrollmentWindow.xaml +++ b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml @@ -61,8 +61,13 @@ + Text="By enrolling in this program you agree with our " + TextWrapping="Wrap"> + + + + Date: Wed, 26 Apr 2017 14:57:21 -0600 Subject: [PATCH 2/4] Refactor and add tests --- src/Magpie/Magpie.Tests/Magpie.Tests.csproj | 1 + src/Magpie/Magpie.Tests/Mocks/MockChannel.cs | 4 +- src/Magpie/Magpie.Tests/Mocks/MockMagpie.cs | 16 ++++- .../Magpie.Tests/Services/MagpieTest.cs | 64 ++++++++++++++++++- .../ViewModels/EnrollmentViewModelTest.cs | 63 ++++++++++++++++++ .../Magpie/Interfaces/IAnalyticsLogger.cs | 8 ++- src/Magpie/Magpie/Models/Channel.cs | 4 +- src/Magpie/Magpie/Services/AnalyticsLogger.cs | 4 ++ src/Magpie/Magpie/Services/Magpie.cs | 41 +++++------- .../Magpie/ViewModels/EnrollmentViewModel.cs | 22 +------ 10 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 src/Magpie/Magpie.Tests/ViewModels/EnrollmentViewModelTest.cs diff --git a/src/Magpie/Magpie.Tests/Magpie.Tests.csproj b/src/Magpie/Magpie.Tests/Magpie.Tests.csproj index f59b1de..6d686ad 100644 --- a/src/Magpie/Magpie.Tests/Magpie.Tests.csproj +++ b/src/Magpie/Magpie.Tests/Magpie.Tests.csproj @@ -61,6 +61,7 @@ + diff --git a/src/Magpie/Magpie.Tests/Mocks/MockChannel.cs b/src/Magpie/Magpie.Tests/Mocks/MockChannel.cs index 6fa4807..ee50ad5 100644 --- a/src/Magpie/Magpie.Tests/Mocks/MockChannel.cs +++ b/src/Magpie/Magpie.Tests/Mocks/MockChannel.cs @@ -5,13 +5,15 @@ namespace Magpie.Tests.Mocks { internal class MockChannel : Channel { - internal MockChannel(int id, string version = null) + internal MockChannel(int id, string version = null, string build = null, string enrollmentEula = null) { Id = id; if (version != null) { Version = new Version(version); } + Build = build; + EnrollmentEulaUrl = enrollmentEula; } internal void SetArtifactUrl(string url) diff --git a/src/Magpie/Magpie.Tests/Mocks/MockMagpie.cs b/src/Magpie/Magpie.Tests/Mocks/MockMagpie.cs index 0bb8e02..07facd7 100644 --- a/src/Magpie/Magpie.Tests/Mocks/MockMagpie.cs +++ b/src/Magpie/Magpie.Tests/Mocks/MockMagpie.cs @@ -10,16 +10,19 @@ namespace Magpie.Tests.Mocks internal class MockMagpie : MagpieUpdater.Services.Magpie { private readonly string VALID_JSON = - @"{'foo': 'bar', 'channels': [{ 'id': 2, 'version': '5.8.8', 'release_notes_url': 'release_notes_url_http', 'artifact_url': 'artifact_url_http', 'build_date': '01/28/2017'}, { 'id': 3, 'version': '6.8.8', 'release_notes_url': 'release_notes_url_http', 'artifact_url': 'artifact_url_http', 'build_date': '01/28/2017'}]}" + @"{'foo': 'bar', 'channels': [{ 'id': 2, 'version': '5.8.8', 'release_notes_url': 'release_notes_url_http', 'artifact_url': 'artifact_url_http', 'build_date': '01/28/2017'}, { 'id': 3, 'version': '6.8.8', 'release_notes_url': 'release_notes_url_http', 'artifact_url': 'artifact_url_http', 'build_date': '01/28/2017'}, { 'id': 4, 'version': '7.8.8', 'release_notes_url': 'release_notes_url_http', 'artifact_url': 'artifact_url_http', 'build_date': '01/28/2017', 'requires_enrollment': 'true', 'enrollment_eula_url': 'enrollment_url'}]}" .MakeJson(); + internal RemoteAppcast RemoteAppcast { get; private set; } internal bool _showUpdateWindowFlag; internal bool _showNoUpdatesWindowFlag; internal IRemoteContentDownloader _remoteContentDownloader; + internal bool _showEnrollmentWindow; + internal Enrollment _enrollmentToReturn; - public MockMagpie(string validUrl, IDebuggingInfoLogger infoLogger = null) - : base(new AppInfo(validUrl), infoLogger) + public MockMagpie(string validUrl, IDebuggingInfoLogger infoLogger = null, IAnalyticsLogger analyticsLogger = null) + : base(new AppInfo(validUrl), infoLogger, analyticsLogger) { _remoteContentDownloader = Substitute.For(); _remoteContentDownloader.DownloadStringContent(validUrl, Arg.Any()).Returns(Task.FromResult(VALID_JSON)); @@ -47,5 +50,12 @@ protected override void ShowNoUpdatesWindow() protected override void ShowErrorWindow() { } + + protected override void ShowEnrollmentWindow(Enrollment enrollment) + { + _showEnrollmentWindow = true; + enrollment.IsEnrolled = _enrollmentToReturn.IsEnrolled; + enrollment.Email = _enrollmentToReturn.Email; + } } } \ 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 88bc6b0..5f1a6bf 100644 --- a/src/Magpie/Magpie.Tests/Services/MagpieTest.cs +++ b/src/Magpie/Magpie.Tests/Services/MagpieTest.cs @@ -14,12 +14,14 @@ namespace Magpie.Tests.Services public class MagpieTest { private MockMagpie _mockMagpie; + private IAnalyticsLogger _analyticsLogger; [TestInitialize] public void Initialize() { AssemblyInjector.Inject(); - _mockMagpie = new MockMagpie("validContentUrl"); + _analyticsLogger = Substitute.For(); + _mockMagpie = new MockMagpie("validContentUrl", analyticsLogger: _analyticsLogger); } [TestMethod] @@ -109,5 +111,65 @@ public void SwitchingSubscribedThenCallingForceUpdateChecksNewChannel() _mockMagpie.ForceCheckInBackground(); updateDecider.Received(2).ShouldUpdate(Arg.Is(e => e.Id == 3), true); } + + [TestMethod] + public void SwitchingToChannelThatDoesNotRequireEnrollment_ChecksForUpdates() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie.UpdateDecider = updateDecider; + _mockMagpie.SwitchSubscribedChannel(3); + + Assert.IsFalse(_mockMagpie._showEnrollmentWindow); + updateDecider.Received(1).ShouldUpdate(Arg.Is(e => e.Id == 3), true); + } + + [TestMethod] + public void SwitchingToChannelThatRequiresEnrollment_ShowsEnrollmentWindow() + { + _mockMagpie.SwitchSubscribedChannel(4); + Assert.IsTrue(_mockMagpie._showEnrollmentWindow); + } + + [TestMethod] + public void FailingToEnroll_DoesNotCheckForUpdates() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + _mockMagpie.UpdateDecider = updateDecider; + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()){IsEnrolled = false}; + _mockMagpie.SwitchSubscribedChannel(4); + + Assert.IsTrue(_mockMagpie._showEnrollmentWindow); + updateDecider.DidNotReceive().ShouldUpdate(Arg.Any(), Arg.Any()); + } + + [TestMethod] + public void SuccessfullyEnrolled_CheckForUpdates() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + _mockMagpie.UpdateDecider = updateDecider; + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = true }; + _mockMagpie.SwitchSubscribedChannel(4); + + Assert.IsTrue(_mockMagpie._showEnrollmentWindow); + updateDecider.Received(1).ShouldUpdate(Arg.Is(e => e.Id == 4), true); + } + + [TestMethod] + public void SwitchChannel_LogsEnrollment() + { + _mockMagpie.SwitchSubscribedChannel(3); + _analyticsLogger.Received(1).LogEnrollment(Arg.Any()); + } + + [TestMethod] + public void SwitchChannel_EnrollmentAvailableEventGetsFired() + { + var raised = false; + _mockMagpie.EnrollmentAvailableEvent += (s, a) => { raised = true; }; + _mockMagpie.SwitchSubscribedChannel(3); + Assert.IsTrue(raised); + } } } \ No newline at end of file diff --git a/src/Magpie/Magpie.Tests/ViewModels/EnrollmentViewModelTest.cs b/src/Magpie/Magpie.Tests/ViewModels/EnrollmentViewModelTest.cs new file mode 100644 index 0000000..762f3ed --- /dev/null +++ b/src/Magpie/Magpie.Tests/ViewModels/EnrollmentViewModelTest.cs @@ -0,0 +1,63 @@ +using Magpie.Tests.Mocks; +using MagpieUpdater.Models; +using MagpieUpdater.Services; +using MagpieUpdater.ViewModels; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Magpie.Tests.ViewModels +{ + [TestClass] + public class EnrollmentViewModelTest + { + [TestMethod] + public void PropertiesAreInitializedCorrectly() + { + var channel = new MockChannel(1, build: "Test Build", enrollmentEula: "www.example.com"); + var enrollment = new Enrollment(channel); + var appInfo = new AppInfo("testString") {AppIconPath = "iconPath"}; + var sut = new EnrollmentViewModel(enrollment, appInfo); + Assert.AreEqual("Test Build", sut.ChannelName); + Assert.AreEqual("www.example.com", sut.EnrollmentEulaUrl); + Assert.AreEqual("iconPath", sut.AppIconPath); + } + + [TestMethod] + public void CanNotEnrollWithInvalidEmail() + { + var sut = new EnrollmentViewModel(new Enrollment(new Channel()), new AppInfo("testString")) + { + EmailAddress = "test" + }; + Assert.IsFalse(sut.EnrollCommand.CanExecute(null)); + sut.EmailAddress = null; + Assert.IsFalse(sut.EnrollCommand.CanExecute(null)); + sut.EmailAddress = string.Empty; + Assert.IsFalse(sut.EnrollCommand.CanExecute(null)); + sut.EmailAddress = "test@"; + Assert.IsFalse(sut.EnrollCommand.CanExecute(null)); + } + + [TestMethod] + public void CanEnrollWithValidEmail() + { + var sut = new EnrollmentViewModel(new Enrollment(new Channel()), new AppInfo("testString")) + { + EmailAddress = "test@example.com" + }; + Assert.IsTrue(sut.EnrollCommand.CanExecute(null)); + } + + [TestMethod] + public void ExecuteEnrollCommand_FillsInEnrollment() + { + var enrollment = new Enrollment(new Channel()); + var sut = new EnrollmentViewModel(enrollment, new AppInfo("testString")) + { + EmailAddress = "test@example.com" + }; + sut.EnrollCommand.Execute(null); + Assert.IsTrue(enrollment.IsEnrolled); + Assert.AreEqual("test@example.com", enrollment.Email); + } + } +} diff --git a/src/Magpie/Magpie/Interfaces/IAnalyticsLogger.cs b/src/Magpie/Magpie/Interfaces/IAnalyticsLogger.cs index ae34933..e569156 100644 --- a/src/Magpie/Magpie/Interfaces/IAnalyticsLogger.cs +++ b/src/Magpie/Magpie/Interfaces/IAnalyticsLogger.cs @@ -50,8 +50,14 @@ public interface IAnalyticsLogger /// /// Log analytics when update is available. - /// Channel that has the latest update available. + /// Channel that has the latest update available /// void LogUpdateAvailable(Channel channel); + + /// + /// Log enrollment status. + /// + /// Enrollment status + void LogEnrollment(Enrollment enrollment); } } \ No newline at end of file diff --git a/src/Magpie/Magpie/Models/Channel.cs b/src/Magpie/Magpie/Models/Channel.cs index 35126e6..aadd18d 100644 --- a/src/Magpie/Magpie/Models/Channel.cs +++ b/src/Magpie/Magpie/Models/Channel.cs @@ -13,7 +13,7 @@ public class Channel public int Id { get; protected set; } [DataMember(Name = "build", IsRequired = false)] - public string Build { get; private set; } + public string Build { get; protected set; } [DataMember(Name = "version", IsRequired = true)] private string _version; public Version Version { get; protected set; } @@ -31,7 +31,7 @@ public class Channel public bool RequiresEnrollment { get; private set; } [DataMember(Name = "enrollment_eula_url", IsRequired = false)] - public string EnrollmentEulaUrl { get; private set; } + public string EnrollmentEulaUrl { get; protected set; } // Dates example: // e.g. January 30, 2015 18:15:00 +0200 diff --git a/src/Magpie/Magpie/Services/AnalyticsLogger.cs b/src/Magpie/Magpie/Services/AnalyticsLogger.cs index ee36e2f..326caa5 100644 --- a/src/Magpie/Magpie/Services/AnalyticsLogger.cs +++ b/src/Magpie/Magpie/Services/AnalyticsLogger.cs @@ -40,5 +40,9 @@ public virtual void LogUpdateCancelled() public virtual void LogUpdateAvailable(Channel channel) { } + + public void LogEnrollment(Enrollment enrollment) + { + } } } \ No newline at end of file diff --git a/src/Magpie/Magpie/Services/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index 5ded570..e13e074 100644 --- a/src/Magpie/Magpie/Services/Magpie.cs +++ b/src/Magpie/Magpie/Services/Magpie.cs @@ -21,6 +21,7 @@ public class Magpie : ISoftwareUpdater internal IRemoteContentDownloader RemoteContentDownloader { get; set; } public event EventHandler> RemoteAppcastAvailableEvent; public event EventHandler> ArtifactDownloadedEvent; + public event EventHandler> EnrollmentAvailableEvent; public Magpie(AppInfo appInfo, IDebuggingInfoLogger debuggingInfoLogger = null, IAnalyticsLogger analyticsLogger = null) @@ -60,7 +61,7 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId var data = await RemoteContentDownloader.DownloadStringContent(appcastUrl, _logger).ConfigureAwait(true); if (string.IsNullOrWhiteSpace(data)) { - if (checkState == CheckState.Force) + if (checkState == CheckState.Force || checkState == CheckState.ChannelSwitch) { ShowErrorWindow(); } @@ -68,22 +69,12 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId } var appcast = ParseAppcast(data); - OnRemoteAppcastAvailableEvent(new SingleEventArgs(appcast)); - if (checkState == CheckState.ChannelSwitch) - { - var enrollment = Enroll(appcast, channelId); -// OnEnrolledEvent(enrollment); - if (enrollment.IsRequired && !enrollment.IsEnrolled) - { - // todo: return false - return; - } - } + if (checkState == CheckState.ChannelSwitch && FailedToEnroll(appcast, channelId)) return; var channelToUpdateFrom = BestChannelFinder.Find(channelId, appcast.Channels); - if (UpdateDecider.ShouldUpdate(channelToUpdateFrom, checkState == CheckState.Force)) + if (UpdateDecider.ShouldUpdate(channelToUpdateFrom, checkState == CheckState.Force || checkState == CheckState.ChannelSwitch)) { _analyticsLogger.LogUpdateAvailable(channelToUpdateFrom); await ShowUpdateWindow(channelToUpdateFrom); @@ -103,23 +94,18 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId } } - private Enrollment Enroll(RemoteAppcast appcast, int channelId) + private bool FailedToEnroll(RemoteAppcast appcast, int channelId) { var channel = appcast.Channels.FirstOrDefault(c => c.Id == channelId); var enrollment = new Enrollment(channel); - if (channel == null) - { - return enrollment; - } - - enrollment.IsRequired = channel.RequiresEnrollment; - if (enrollment.IsRequired) + if (channel != null && channel.RequiresEnrollment) { + enrollment.IsRequired = true; ShowEnrollmentWindow(enrollment); } - - // check enrollment - return enrollment; + _analyticsLogger.LogEnrollment(enrollment); + OnEnrollmentAvailableEvent(new SingleEventArgs(enrollment)); + return enrollment.IsRequired && !enrollment.IsEnrolled; } protected virtual void ShowEnrollmentWindow(Enrollment enrollment) @@ -262,6 +248,7 @@ private RemoteAppcast ParseAppcast(string content) _logger.Log("Started deserializing remote channel content"); var appcast = RemoteAppcast.MakeFromJson(content); _logger.Log("Finished deserializing remote channel content"); + OnRemoteAppcastAvailableEvent(new SingleEventArgs(appcast)); return appcast; } @@ -276,5 +263,11 @@ protected virtual void OnArtifactDownloadedEvent(SingleEventArgs args) var handler = ArtifactDownloadedEvent; if (handler != null) handler(this, args); } + + protected virtual void OnEnrollmentAvailableEvent(SingleEventArgs args) + { + var handler = EnrollmentAvailableEvent; + if (handler != null) handler(this, args); + } } } \ No newline at end of file diff --git a/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs b/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs index 7c18134..c11886f 100644 --- a/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs +++ b/src/Magpie/Magpie/ViewModels/EnrollmentViewModel.cs @@ -1,12 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Mail; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Input; using MagpieUpdater.Models; -using MagpieUpdater.Properties; using MagpieUpdater.Services; namespace MagpieUpdater.ViewModels @@ -30,7 +24,6 @@ public string EmailAddress get { return _emailAddress; } set { - _emailAddress = value; SetProperty(ref _emailAddress, value); EnrollCommand.RaiseCanExecuteChanged(); } @@ -39,25 +32,16 @@ public string EmailAddress public string ChannelName { get { return _channelName; } - set - { - _channelName = value; - SetProperty(ref _channelName, value); - - } + set { SetProperty(ref _channelName, value); } } public string EnrollmentEulaUrl { get { return _enrollmentEulaUrl; } - set - { - _enrollmentEulaUrl = value; - SetProperty(ref _enrollmentEulaUrl, value); - } + set { SetProperty(ref _enrollmentEulaUrl, value); } } - public DelegateCommand EnrollCommand { get; set; } + public DelegateCommand EnrollCommand { get; private set; } public EnrollmentViewModel(Enrollment enrollment, AppInfo appInfo) { From bad3628e725e440f9bb0842b1da80965544c920b Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Wed, 26 Apr 2017 15:25:24 -0600 Subject: [PATCH 3/4] Only update SubscribedChannel if switching is successful --- .../Magpie.Tests/Services/MagpieTest.cs | 40 +++++++++++++++++-- src/Magpie/Magpie/Services/Magpie.cs | 2 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Magpie/Magpie.Tests/Services/MagpieTest.cs b/src/Magpie/Magpie.Tests/Services/MagpieTest.cs index 5f1a6bf..3196df8 100644 --- a/src/Magpie/Magpie.Tests/Services/MagpieTest.cs +++ b/src/Magpie/Magpie.Tests/Services/MagpieTest.cs @@ -132,7 +132,7 @@ public void SwitchingToChannelThatRequiresEnrollment_ShowsEnrollmentWindow() } [TestMethod] - public void FailingToEnroll_DoesNotCheckForUpdates() + public void SwitchingChannel_FailingToEnroll_DoesNotCheckForUpdates() { var updateDecider = Substitute.For(new DebuggingWindowViewModel()); _mockMagpie.UpdateDecider = updateDecider; @@ -144,7 +144,7 @@ public void FailingToEnroll_DoesNotCheckForUpdates() } [TestMethod] - public void SuccessfullyEnrolled_CheckForUpdates() + public void SwitchingChannel_SuccessfullyEnrolled_CheckForUpdates() { var updateDecider = Substitute.For(new DebuggingWindowViewModel()); _mockMagpie.UpdateDecider = updateDecider; @@ -157,19 +157,51 @@ public void SuccessfullyEnrolled_CheckForUpdates() } [TestMethod] - public void SwitchChannel_LogsEnrollment() + public void SwitchingChannel_LogsEnrollment() { _mockMagpie.SwitchSubscribedChannel(3); _analyticsLogger.Received(1).LogEnrollment(Arg.Any()); } [TestMethod] - public void SwitchChannel_EnrollmentAvailableEventGetsFired() + public void SwitchingChannel_EnrollmentAvailableEventGetsFired() { var raised = false; _mockMagpie.EnrollmentAvailableEvent += (s, a) => { raised = true; }; _mockMagpie.SwitchSubscribedChannel(3); Assert.IsTrue(raised); } + + [TestMethod] + public void SwitchingChannel_SuccessfullyEnrolled_UpdatesSubscribedChannel() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + _mockMagpie.UpdateDecider = updateDecider; + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = true }; + _mockMagpie.SwitchSubscribedChannel(4); + + Assert.AreEqual(4, _mockMagpie.AppInfo.SubscribedChannel); + } + + [TestMethod] + public void SwitchingChannel_FailingToEnroll_DoesNotUpdateSubscribedChannel() + { + _mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = false }; + _mockMagpie.SwitchSubscribedChannel(4); + + Assert.AreNotEqual(4, _mockMagpie.AppInfo.SubscribedChannel); + } + + [TestMethod] + public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChannel() + { + var updateDecider = Substitute.For(new DebuggingWindowViewModel()); + updateDecider.ShouldUpdate(Arg.Any(), true).Returns(false); + _mockMagpie.UpdateDecider = updateDecider; + _mockMagpie.SwitchSubscribedChannel(3); + + Assert.AreEqual(3, _mockMagpie.AppInfo.SubscribedChannel); + } } } \ No newline at end of file diff --git a/src/Magpie/Magpie/Services/Magpie.cs b/src/Magpie/Magpie/Services/Magpie.cs index e13e074..a108a3d 100644 --- a/src/Magpie/Magpie/Services/Magpie.cs +++ b/src/Magpie/Magpie/Services/Magpie.cs @@ -48,7 +48,6 @@ await Check(appcastUrl ?? AppInfo.AppCastUrl, CheckState.Force, AppInfo.Subscrib public async void SwitchSubscribedChannel(int channelId, bool showDebuggingWindow = false) { - AppInfo.SubscribedChannel = channelId; await Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggingWindow) .ConfigureAwait(false); } @@ -83,6 +82,7 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId { ShowNoUpdatesWindow(); } + AppInfo.SubscribedChannel = channelId; } catch (Exception ex) { From 334f76b75270a0aff5006c7d8a30983ece5a6b4c Mon Sep 17 00:00:00 2001 From: Vanessa Gertman Date: Wed, 26 Apr 2017 15:43:41 -0600 Subject: [PATCH 4/4] Move enrollment strings to the resource file --- src/Magpie/Magpie/Resources/Strings.xaml | 4 ++++ src/Magpie/Magpie/Views/EnrollmentWindow.xaml | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Magpie/Magpie/Resources/Strings.xaml b/src/Magpie/Magpie/Resources/Strings.xaml index c94d95d..4fd81b1 100644 --- a/src/Magpie/Magpie/Resources/Strings.xaml +++ b/src/Magpie/Magpie/Resources/Strings.xaml @@ -5,4 +5,8 @@ Download Now Skip this Version Remind Me Later + I don't want to + I don't want to + 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/Views/EnrollmentWindow.xaml b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml index 3d085cd..42335f3 100644 --- a/src/Magpie/Magpie/Views/EnrollmentWindow.xaml +++ b/src/Magpie/Magpie/Views/EnrollmentWindow.xaml @@ -39,7 +39,7 @@ @@ -50,8 +50,7 @@ FontSize="14" Padding="32 4 4 6" SnapsToDevicePixels="True" - Text="{Binding EmailAddress, - UpdateSourceTrigger=PropertyChanged}" /> + Text="{Binding EmailAddress, UpdateSourceTrigger=PropertyChanged}" /> - + @@ -82,13 +80,13 @@ Orientation="Horizontal">