Skip to content

Commit

Permalink
Only update SubscribedChannel if switching is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessagertman committed Apr 26, 2017
1 parent 2609164 commit bad3628
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
40 changes: 36 additions & 4 deletions src/Magpie/Magpie.Tests/Services/MagpieTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void SwitchingToChannelThatRequiresEnrollment_ShowsEnrollmentWindow()
}

[TestMethod]
public void FailingToEnroll_DoesNotCheckForUpdates()
public void SwitchingChannel_FailingToEnroll_DoesNotCheckForUpdates()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
_mockMagpie.UpdateDecider = updateDecider;
Expand All @@ -144,7 +144,7 @@ public void FailingToEnroll_DoesNotCheckForUpdates()
}

[TestMethod]
public void SuccessfullyEnrolled_CheckForUpdates()
public void SwitchingChannel_SuccessfullyEnrolled_CheckForUpdates()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
_mockMagpie.UpdateDecider = updateDecider;
Expand All @@ -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<Enrollment>());
}

[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<UpdateDecider>(new DebuggingWindowViewModel());
_mockMagpie.UpdateDecider = updateDecider;
updateDecider.ShouldUpdate(Arg.Any<Channel>(), 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<UpdateDecider>(new DebuggingWindowViewModel());
updateDecider.ShouldUpdate(Arg.Any<Channel>(), true).Returns(false);
_mockMagpie.UpdateDecider = updateDecider;
_mockMagpie.SwitchSubscribedChannel(3);

Assert.AreEqual(3, _mockMagpie.AppInfo.SubscribedChannel);
}
}
}
2 changes: 1 addition & 1 deletion src/Magpie/Magpie/Services/Magpie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -83,6 +82,7 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId
{
ShowNoUpdatesWindow();
}
AppInfo.SubscribedChannel = channelId;
}
catch (Exception ex)
{
Expand Down

0 comments on commit bad3628

Please sign in to comment.