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

Commit 67815ea

Browse files
committed
WIP: Add integration tests for VSGitExt
Problems quickly switching between solutions.
1 parent f641768 commit 67815ea

File tree

4 files changed

+131
-1
lines changed

4 files changed

+131
-1
lines changed

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public void RefreshActiveRepositories()
8989
gitService.GetHashCode(),
9090
gitService.ActiveRepositories.Select(x => x.RepositoryPath));
9191

92-
ActiveRepositories = gitService?.ActiveRepositories.Select(x => repositoryFactory.Create(x.RepositoryPath)).ToList();
92+
if (gitService != null)
93+
{
94+
ActiveRepositories = gitService.ActiveRepositories.Select(x => repositoryFactory.Create(x.RepositoryPath)).ToList();
95+
}
9396
}
9497
}
9598
catch (Exception e)

test/IntegrationTests/IntegrationTests.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
<HintPath>..\..\packages\EnvDTE.8.0.2\lib\net10\EnvDTE.dll</HintPath>
4343
<EmbedInteropTypes>True</EmbedInteropTypes>
4444
</Reference>
45+
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
46+
<HintPath>..\..\packages\EnvDTE80.8.0.3\lib\net10\EnvDTE80.dll</HintPath>
47+
<EmbedInteropTypes>True</EmbedInteropTypes>
48+
</Reference>
49+
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
50+
<HintPath>..\..\packages\Microsoft.VisualStudio.ComponentModelHost.14.0.25424\lib\net45\Microsoft.VisualStudio.ComponentModelHost.dll</HintPath>
51+
</Reference>
4552
<Reference Include="Microsoft.VisualStudio.Imaging, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
4653
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll</HintPath>
4754
</Reference>
@@ -135,6 +142,7 @@
135142
<ItemGroup>
136143
<Compile Include="GitHubPaneIntegrationTests.cs" />
137144
<Compile Include="Properties\AssemblyInfo.cs" />
145+
<Compile Include="VSGitExtIntegrationTests.cs" />
138146
</ItemGroup>
139147
<ItemGroup>
140148
<ProjectReference Include="..\..\src\GitHub.Exports\GitHub.Exports.csproj">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using EnvDTE;
2+
using EnvDTE80;
3+
using GitHub.Services;
4+
using Microsoft.VisualStudio.ComponentModelHost;
5+
using Microsoft.VisualStudio.Shell;
6+
using System;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
using Xunit;
11+
using Xunit.Abstractions;
12+
using Task = System.Threading.Tasks.Task;
13+
14+
namespace IntegrationTests
15+
{
16+
public class VSGitExtIntegrationTests
17+
{
18+
public class TheActiveRepositoriesProperty
19+
{
20+
readonly ITestOutputHelper output;
21+
22+
public TheActiveRepositoriesProperty(ITestOutputHelper output)
23+
{
24+
this.output = output;
25+
}
26+
27+
[VsFact(UIThread = true, Version = "2015-")]
28+
public async Task SolutionNotOnGit_NoActiveRepositoriesAsync()
29+
{
30+
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
31+
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
32+
var gitExt = componentModel.GetService<IVSGitExt>();
33+
34+
dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
35+
Assert.True(await WaitForLocalPath(gitExt, null));
36+
}
37+
38+
[VsFact(UIThread = true, Version = "2015-")]
39+
public async Task ClassLibraryInGit_HasActiveRepositoriesAsync()
40+
{
41+
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
42+
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
43+
var gitExt = componentModel.GetService<IVSGitExt>();
44+
45+
dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
46+
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));
47+
}
48+
49+
[VsFact(UIThread = true, Version = "2015-")]
50+
public async Task OpenClassLibraryNotInGitThenClassLibraryInGit_ActiveRepositoriesChangesAsync()
51+
{
52+
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
53+
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
54+
var gitExt = componentModel.GetService<IVSGitExt>();
55+
56+
dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
57+
Assert.True(await WaitForLocalPath(gitExt, null));
58+
59+
dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
60+
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));
61+
62+
dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
63+
Assert.True(await WaitForLocalPath(gitExt, null));
64+
65+
dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
66+
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));
67+
}
68+
69+
async Task AddSolutionToSourceControlAsync()
70+
{
71+
var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
72+
dte.ExecuteCommand("Team.Git.AddSolutionToSourceControl");
73+
await Task.Yield();
74+
}
75+
76+
async Task<Solution> CreateSolutionAsync()
77+
{
78+
var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
79+
var solution = (Solution2)dte.Solution;
80+
var templatePath = solution.GetProjectTemplate("ClassLibrary.zip", "CSharp");
81+
var tempDir = Path.Combine(@"c:\test", Guid.NewGuid().ToString());
82+
var solutionPath = Path.Combine(tempDir, "test.sln");
83+
solution.Create(tempDir, "test");
84+
solution.AddFromTemplate(templatePath, tempDir, "MyClassLibrary", false);
85+
solution.SaveAs(solutionPath);
86+
output.WriteLine(solutionPath);
87+
await Task.Yield();
88+
return (Solution)solution;
89+
}
90+
91+
Task<bool> WaitForLocalPath(IVSGitExt gitExt, string expectLocalPath)
92+
{
93+
return WaitFor(() =>
94+
{
95+
var localPath = gitExt.ActiveRepositories.FirstOrDefault()?.LocalPath;
96+
output.WriteLine($"found {localPath}, looking for {expectLocalPath}");
97+
return localPath == expectLocalPath;
98+
});
99+
}
100+
101+
async Task<bool> WaitFor(Func<bool> condition, int timeout = 20000, int delay = 100)
102+
{
103+
for (int count = 0; count < timeout; count += delay)
104+
{
105+
if (condition())
106+
{
107+
return true;
108+
}
109+
110+
await Task.Delay(delay);
111+
}
112+
113+
return false;
114+
}
115+
}
116+
}
117+
}

test/IntegrationTests/packages.config

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<packages>
33
<package id="Ben.Demystifier" version="0.1.1" targetFramework="net461" />
44
<package id="EnvDTE" version="8.0.2" targetFramework="net461" />
5+
<package id="EnvDTE80" version="8.0.3" targetFramework="net461" />
6+
<package id="Microsoft.VisualStudio.ComponentModelHost" version="14.0.25424" targetFramework="net461" />
57
<package id="Microsoft.VisualStudio.Imaging" version="14.3.25407" targetFramework="net461" />
68
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net461" />
79
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.21" targetFramework="net461" />

0 commit comments

Comments
 (0)