Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 474c3f0

Browse files
committed
Check AcquireCodeContainerAsync signals completion
When returning a container it should report all steps complete.
1 parent 4d034e4 commit 474c3f0

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

test/GitHub.StartPage.UnitTests/GitHubContainerProviderTests.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NSubstitute;
99
using NUnit.Framework;
1010
using Task = System.Threading.Tasks.Task;
11+
using ServiceProgressData = Microsoft.VisualStudio.Shell.ServiceProgressData;
1112

1213
public class GitHubContainerProviderTests
1314
{
@@ -16,7 +17,7 @@ public class TheAcquireCodeContainerAsyncMethod
1617
[Test]
1718
public async Task CloneOrOpenRepository_CloneDialogResult_Returned_By_ShowCloneDialog()
1819
{
19-
var downloadProgress = Substitute.For<IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData>>();
20+
var downloadProgress = Substitute.For<IProgress<ServiceProgressData>>();
2021
var cancellationToken = CancellationToken.None;
2122
var dialogService = Substitute.For<IDialogService>();
2223
var result = new CloneDialogResult(@"x:\repo", "https://github.com/owner/repo");
@@ -36,7 +37,7 @@ public async Task Pass_DisplayUrl_To_ShowCloneDialog()
3637
var browseOnlineUrl = "https://github.com/owner/browseOnlineUrl";
3738
var remoteCodeContainer = new RemoteCodeContainer("Name", Guid.NewGuid(), new Uri(displayUrl), new Uri(browseOnlineUrl),
3839
DateTimeOffset.Now, new Dictionary<string, string>());
39-
var downloadProgress = Substitute.For<IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData>>();
40+
var downloadProgress = Substitute.For<IProgress<ServiceProgressData>>();
4041
var cancellationToken = CancellationToken.None;
4142
var dialogService = Substitute.For<IDialogService>();
4243
var result = new CloneDialogResult(@"x:\repo", "https://github.com/owner/repo");
@@ -49,6 +50,42 @@ public async Task Pass_DisplayUrl_To_ShowCloneDialog()
4950
await dialogService.Received(1).ShowCloneDialog(Arg.Any<IConnection>(), displayUrl);
5051
}
5152

53+
[Test]
54+
public async Task Completes_When_Returning_CodeContainer()
55+
{
56+
var downloadProgress = Substitute.For<IProgress<ServiceProgressData>>();
57+
var cancellationToken = CancellationToken.None;
58+
var dialogService = Substitute.For<IDialogService>();
59+
var result = new CloneDialogResult(@"x:\repo", "https://github.com/owner/repo");
60+
dialogService.ShowCloneDialog(null).ReturnsForAnyArgs(result);
61+
var cloneService = Substitute.For<IRepositoryCloneService>();
62+
var target = CreateGitHubContainerProvider(dialogService: dialogService, cloneService: cloneService);
63+
64+
var codeContainer = await target.AcquireCodeContainerAsync(downloadProgress, cancellationToken);
65+
66+
Assert.That(codeContainer, Is.Not.Null);
67+
downloadProgress.Received(1).Report(
68+
Arg.Is<ServiceProgressData>(x => x.TotalSteps > 0 && x.CurrentStep == x.TotalSteps));
69+
}
70+
71+
[Test]
72+
public async Task Does_Not_Complete_When_CloneDialog_Canceled()
73+
{
74+
var downloadProgress = Substitute.For<IProgress<ServiceProgressData>>();
75+
var cancellationToken = CancellationToken.None;
76+
var dialogService = Substitute.For<IDialogService>();
77+
var result = (CloneDialogResult)null;
78+
dialogService.ShowCloneDialog(null).ReturnsForAnyArgs(result);
79+
var cloneService = Substitute.For<IRepositoryCloneService>();
80+
var target = CreateGitHubContainerProvider(dialogService: dialogService, cloneService: cloneService);
81+
82+
var codeContainer = await target.AcquireCodeContainerAsync(downloadProgress, cancellationToken);
83+
84+
await cloneService.ReceivedWithAnyArgs(0).CloneOrOpenRepository(null, null, null);
85+
downloadProgress.ReceivedWithAnyArgs(0).Report(null);
86+
Assert.That(codeContainer, Is.Null);
87+
}
88+
5289
static GitHubContainerProvider CreateGitHubContainerProvider(IDialogService dialogService = null,
5390
IRepositoryCloneService cloneService = null, IUsageTracker usageTracker = null)
5491
{

0 commit comments

Comments
 (0)