Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP: Add integration tests for VSGitExt
Problems quickly switching between solutions.
  • Loading branch information
jcansdale committed Sep 18, 2018
commit 67815ea9316d968b63983fd768d4a30f4aa52028
5 changes: 4 additions & 1 deletion src/GitHub.TeamFoundation.14/Services/VSGitExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public void RefreshActiveRepositories()
gitService.GetHashCode(),
gitService.ActiveRepositories.Select(x => x.RepositoryPath));

ActiveRepositories = gitService?.ActiveRepositories.Select(x => repositoryFactory.Create(x.RepositoryPath)).ToList();
if (gitService != null)
{
ActiveRepositories = gitService.ActiveRepositories.Select(x => repositoryFactory.Create(x.RepositoryPath)).ToList();
}
}
}
catch (Exception e)
Expand Down
8 changes: 8 additions & 0 deletions test/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
<HintPath>..\..\packages\EnvDTE.8.0.2\lib\net10\EnvDTE.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\..\packages\EnvDTE80.8.0.3\lib\net10\EnvDTE80.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.VisualStudio.ComponentModelHost.14.0.25424\lib\net45\Microsoft.VisualStudio.ComponentModelHost.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Imaging, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -135,6 +142,7 @@
<ItemGroup>
<Compile Include="GitHubPaneIntegrationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VSGitExtIntegrationTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\GitHub.Exports\GitHub.Exports.csproj">
Expand Down
117 changes: 117 additions & 0 deletions test/IntegrationTests/VSGitExtIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using EnvDTE;
using EnvDTE80;
using GitHub.Services;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Task = System.Threading.Tasks.Task;

namespace IntegrationTests
{
public class VSGitExtIntegrationTests
{
public class TheActiveRepositoriesProperty
{
readonly ITestOutputHelper output;

public TheActiveRepositoriesProperty(ITestOutputHelper output)
{
this.output = output;
}

[VsFact(UIThread = true, Version = "2015-")]
public async Task SolutionNotOnGit_NoActiveRepositoriesAsync()
{
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
var gitExt = componentModel.GetService<IVSGitExt>();

dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, null));
}

[VsFact(UIThread = true, Version = "2015-")]
public async Task ClassLibraryInGit_HasActiveRepositoriesAsync()
{
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
var gitExt = componentModel.GetService<IVSGitExt>();

dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));
}

[VsFact(UIThread = true, Version = "2015-")]
public async Task OpenClassLibraryNotInGitThenClassLibraryInGit_ActiveRepositoriesChangesAsync()
{
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
var componentModel = (IComponentModel)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SComponentModel));
var gitExt = componentModel.GetService<IVSGitExt>();

dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, null));

dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));

dte.Solution.Open(@"C:\test\ClassLibraryNotInGit\ClassLibraryNotInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, null));

dte.Solution.Open(@"C:\test\ClassLibraryInGit\ClassLibraryInGit.sln");
Assert.True(await WaitForLocalPath(gitExt, @"C:\test\ClassLibraryInGit"));
}

async Task AddSolutionToSourceControlAsync()
{
var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
dte.ExecuteCommand("Team.Git.AddSolutionToSourceControl");
await Task.Yield();
}

async Task<Solution> CreateSolutionAsync()
{
var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
var solution = (Solution2)dte.Solution;
var templatePath = solution.GetProjectTemplate("ClassLibrary.zip", "CSharp");
var tempDir = Path.Combine(@"c:\test", Guid.NewGuid().ToString());
var solutionPath = Path.Combine(tempDir, "test.sln");
solution.Create(tempDir, "test");
solution.AddFromTemplate(templatePath, tempDir, "MyClassLibrary", false);
solution.SaveAs(solutionPath);
output.WriteLine(solutionPath);
await Task.Yield();
return (Solution)solution;
}

Task<bool> WaitForLocalPath(IVSGitExt gitExt, string expectLocalPath)
{
return WaitFor(() =>
{
var localPath = gitExt.ActiveRepositories.FirstOrDefault()?.LocalPath;
output.WriteLine($"found {localPath}, looking for {expectLocalPath}");
return localPath == expectLocalPath;
});
}

async Task<bool> WaitFor(Func<bool> condition, int timeout = 20000, int delay = 100)
{
for (int count = 0; count < timeout; count += delay)
{
if (condition())
{
return true;
}

await Task.Delay(delay);
}

return false;
}
}
}
}
2 changes: 2 additions & 0 deletions test/IntegrationTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<packages>
<package id="Ben.Demystifier" version="0.1.1" targetFramework="net461" />
<package id="EnvDTE" version="8.0.2" targetFramework="net461" />
<package id="EnvDTE80" version="8.0.3" targetFramework="net461" />
<package id="Microsoft.VisualStudio.ComponentModelHost" version="14.0.25424" targetFramework="net461" />
<package id="Microsoft.VisualStudio.Imaging" version="14.3.25407" targetFramework="net461" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net461" />
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.21" targetFramework="net461" />
Expand Down