Skip to content

Commit

Permalink
Add unit tests for SwitchSubscribedChannelAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessagertman committed May 1, 2017
1 parent 6e89c2a commit 9be8211
Showing 1 changed file with 43 additions and 1 deletion.
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);
}
}
}

0 comments on commit 9be8211

Please sign in to comment.