Skip to content

Commit

Permalink
Merge pull request #7 from vgertman/enrollment
Browse files Browse the repository at this point in the history
Enrollment
  • Loading branch information
ashokgelal authored May 2, 2017
2 parents bc23271 + 6105e14 commit 32c991e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
44 changes: 43 additions & 1 deletion src/Magpie/Magpie.Tests/Services/MagpieTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Magpie.Tests.Mocks;
using MagpieUpdater.Interfaces;
using MagpieUpdater.Models;
Expand Down Expand Up @@ -194,7 +195,7 @@ public void SwitchingChannel_FailingToEnroll_DoesNotUpdateSubscribedChannel()
}

[TestMethod]
public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChannel()
public void SwitchingChannel_ChannelDoesNotRequireEnrollment_UpdatesSubscribedChannel()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
updateDecider.ShouldUpdate(Arg.Any<Channel>(), true).Returns(false);
Expand All @@ -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<UpdateDecider>(new DebuggingWindowViewModel());
_mockMagpie.UpdateDecider = updateDecider;
updateDecider.ShouldUpdate(Arg.Any<Channel>(), 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<UpdateDecider>(new DebuggingWindowViewModel());
updateDecider.ShouldUpdate(Arg.Any<Channel>(), 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<string>(), Arg.Any<IDebuggingInfoLogger>()).Returns(Task.FromResult(string.Empty));
var success = await _mockMagpie.SwitchSubscribedChannelAsync(3);

Assert.IsFalse(success);
}
}
}
6 changes: 3 additions & 3 deletions src/Magpie/Magpie/Models/Enrollment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie/Magpie/Resources/Strings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<system:String x:Key="_skipVersion">Skip this Version</system:String>
<system:String x:Key="_remindMeLater">Remind Me Later</system:String>
<system:String x:Key="_dontEnroll">I don't want to</system:String>
<system:String x:Key="_enroll">I don't want to</system:String>
<system:String x:Key="_enroll">Enroll</system:String>
<system:String x:Key="_enrollMsg">Please provide your email address to join the {0} Program</system:String>
<system:String x:Key="_eulaMsg" xml:space="preserve">By enrolling in this program you agree with our </system:String>
</ResourceDictionary>
2 changes: 1 addition & 1 deletion src/Magpie/Magpie/Services/AnalyticsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public virtual void LogUpdateAvailable(Channel channel)
{
}

public void LogEnrollment(Enrollment enrollment)
public virtual void LogEnrollment(Enrollment enrollment)
{
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/Magpie/Magpie/Services/Magpie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> SwitchSubscribedChannelAsync(int channelId, bool showDebuggingWindow = false)
{
return Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggingWindow);
}

private async Task<bool> 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
Expand All @@ -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);

Expand All @@ -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
{
Expand Down

0 comments on commit 32c991e

Please sign in to comment.