diff --git a/GitHubVS.sln b/GitHubVS.sln
index 62e80d446..106002f94 100644
--- a/GitHubVS.sln
+++ b/GitHubVS.sln
@@ -141,6 +141,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Octokit.GraphQL.Core", "sub
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Octokit.GraphQL", "submodules\octokit.graphql.net\Octokit.GraphQL\Octokit.GraphQL.csproj", "{791B408C-0ABC-465B-9EB1-A2422D67F418}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.StartPage.UnitTests", "test\GitHub.StartPage.UnitTests\GitHub.StartPage.UnitTests.csproj", "{B467682B-9F0E-42D8-8A20-1DE78F798793}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -493,6 +495,14 @@ Global
{791B408C-0ABC-465B-9EB1-A2422D67F418}.Release|Any CPU.Build.0 = Release|Any CPU
{791B408C-0ABC-465B-9EB1-A2422D67F418}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{791B408C-0ABC-465B-9EB1-A2422D67F418}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.DebugWithoutVsix|Any CPU.ActiveCfg = Debug|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.DebugWithoutVsix|Any CPU.Build.0 = Debug|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
+ {B467682B-9F0E-42D8-8A20-1DE78F798793}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -527,6 +537,7 @@ Global
{65542DEE-D3BE-4810-B85A-08E970413A21} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
{3321CE72-26ED-4D1E-A8F5-6901FB783007} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC0}
{791B408C-0ABC-465B-9EB1-A2422D67F418} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC0}
+ {B467682B-9F0E-42D8-8A20-1DE78F798793} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {556014CF-5B35-4CE5-B3EF-6AB0007001AC}
diff --git a/src/GitHub.StartPage/GitHub.StartPage.csproj b/src/GitHub.StartPage/GitHub.StartPage.csproj
index 82e75798d..e3a4648d9 100644
--- a/src/GitHub.StartPage/GitHub.StartPage.csproj
+++ b/src/GitHub.StartPage/GitHub.StartPage.csproj
@@ -99,9 +99,6 @@
15.8.33
-
- 15.8.122
-
15.8.3252
runtime; build; native; contentfiles; analyzers
diff --git a/src/GitHub.StartPage/StartPagePackage.cs b/src/GitHub.StartPage/StartPagePackage.cs
index 8d3a4703d..a5fe1e093 100644
--- a/src/GitHub.StartPage/StartPagePackage.cs
+++ b/src/GitHub.StartPage/StartPagePackage.cs
@@ -36,9 +36,20 @@ namespace GitHub.StartPage
{
static readonly ILogger log = LogManager.ForContext();
+ readonly Lazy gitHubServiceProvider;
+
+ public GitHubContainerProvider() : this(
+ new Lazy(() => Package.GetGlobalService(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider))
+ {
+ }
+
+ public GitHubContainerProvider(Lazy gitHubServiceProvider)
+ {
+ this.gitHubServiceProvider = gitHubServiceProvider;
+ }
+
public async Task AcquireCodeContainerAsync(IProgress downloadProgress, CancellationToken cancellationToken)
{
-
return await RunAcquisition(downloadProgress, null, cancellationToken);
}
@@ -55,7 +66,7 @@ namespace GitHub.StartPage
try
{
- var uiProvider = await Task.Run(() => Package.GetGlobalService(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider);
+ var uiProvider = await Task.Run(() => gitHubServiceProvider.Value);
request = await ShowCloneDialog(uiProvider, downloadProgress, cancellationToken, repository);
}
catch (Exception e)
diff --git a/test/GitHub.StartPage.UnitTests/GitHub.StartPage.UnitTests.csproj b/test/GitHub.StartPage.UnitTests/GitHub.StartPage.UnitTests.csproj
new file mode 100644
index 000000000..aa9d10927
--- /dev/null
+++ b/test/GitHub.StartPage.UnitTests/GitHub.StartPage.UnitTests.csproj
@@ -0,0 +1,20 @@
+
+
+
+ net46
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/GitHub.StartPage.UnitTests/GitHubContainerProviderTests.cs b/test/GitHub.StartPage.UnitTests/GitHubContainerProviderTests.cs
new file mode 100644
index 000000000..b75691b5b
--- /dev/null
+++ b/test/GitHub.StartPage.UnitTests/GitHubContainerProviderTests.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using GitHub.Models;
+using GitHub.Services;
+using GitHub.StartPage;
+using Microsoft.VisualStudio.Shell.CodeContainerManagement;
+using NSubstitute;
+using NUnit.Framework;
+using Task = System.Threading.Tasks.Task;
+
+public class GitHubContainerProviderTests
+{
+ public class TheAcquireCodeContainerAsyncMethod
+ {
+ [Test]
+ public async Task CloneOrOpenRepository_CloneDialogResult_Returned_By_ShowCloneDialog()
+ {
+ var downloadProgress = Substitute.For>();
+ var cancellationToken = CancellationToken.None;
+ var dialogService = Substitute.For();
+ var result = new CloneDialogResult(@"x:\repo", "https://github.com/owner/repo");
+ dialogService.ShowCloneDialog(null).ReturnsForAnyArgs(result);
+ var cloneService = Substitute.For();
+ var target = CreateGitHubContainerProvider(dialogService: dialogService, cloneService: cloneService);
+
+ await target.AcquireCodeContainerAsync(downloadProgress, cancellationToken);
+
+ await cloneService.Received(1).CloneOrOpenRepository(result, downloadProgress, cancellationToken);
+ }
+
+ [Test]
+ public async Task Pass_DisplayUrl_To_ShowCloneDialog()
+ {
+ var displayUrl = "https://github.com/owner/displayUrl";
+ var browseOnlineUrl = "https://github.com/owner/browseOnlineUrl";
+ var remoteCodeContainer = new RemoteCodeContainer("Name", Guid.NewGuid(), new Uri(displayUrl), new Uri(browseOnlineUrl),
+ DateTimeOffset.Now, new Dictionary());
+ var downloadProgress = Substitute.For>();
+ var cancellationToken = CancellationToken.None;
+ var dialogService = Substitute.For();
+ var result = new CloneDialogResult(@"x:\repo", "https://github.com/owner/repo");
+ dialogService.ShowCloneDialog(null).ReturnsForAnyArgs(result);
+ var cloneService = Substitute.For();
+ var target = CreateGitHubContainerProvider(dialogService: dialogService, cloneService: cloneService);
+
+ await target.AcquireCodeContainerAsync(remoteCodeContainer, downloadProgress, cancellationToken);
+
+ await dialogService.Received(1).ShowCloneDialog(Arg.Any(), displayUrl);
+ }
+
+ static GitHubContainerProvider CreateGitHubContainerProvider(IDialogService dialogService = null,
+ IRepositoryCloneService cloneService = null, IUsageTracker usageTracker = null)
+ {
+ dialogService = dialogService ?? Substitute.For();
+ cloneService = cloneService ?? Substitute.For();
+ usageTracker = usageTracker ?? Substitute.For();
+
+ var sp = Substitute.For();
+ sp.GetService().Returns(dialogService);
+ sp.GetService().Returns(cloneService);
+ sp.GetService().Returns(usageTracker);
+
+ var gitHubServiceProvider = new Lazy(() => sp);
+ return new GitHubContainerProvider(gitHubServiceProvider);
+ }
+ }
+}