10 changed files with 298 additions and 3 deletions
@ -0,0 +1,14 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio |
||||||
|
{ |
||||||
|
public class VsConstants |
||||||
|
{ |
||||||
|
public const int S_OK = 0; |
||||||
|
|
||||||
|
public const int E_FAIL = -2147467259; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using Microsoft.VisualStudio; |
||||||
|
using Microsoft.VisualStudio.Shell.Flavor; |
||||||
|
using Microsoft.VisualStudio.Shell.Interop; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.VisualStudio |
||||||
|
{ |
||||||
|
public class VsSolution : MarshalByRefObject, IVsSolution |
||||||
|
{ |
||||||
|
IPackageManagementProjectService projectService; |
||||||
|
|
||||||
|
public VsSolution() |
||||||
|
: this(new PackageManagementProjectService()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public VsSolution(IPackageManagementProjectService projectService) |
||||||
|
{ |
||||||
|
this.projectService = projectService; |
||||||
|
} |
||||||
|
|
||||||
|
public int GetProjectOfUniqueName(string uniqueName, out IVsHierarchy hierarchy) |
||||||
|
{ |
||||||
|
hierarchy = null; |
||||||
|
MSBuildBasedProject project = FindProject(uniqueName); |
||||||
|
if (project != null) { |
||||||
|
hierarchy = new FlavoredProject(project); |
||||||
|
return VsConstants.S_OK; |
||||||
|
} |
||||||
|
return VsConstants.E_FAIL; |
||||||
|
} |
||||||
|
|
||||||
|
MSBuildBasedProject FindProject(string uniqueName) |
||||||
|
{ |
||||||
|
return projectService |
||||||
|
.GetOpenProjects() |
||||||
|
.SingleOrDefault(project => ProjectUniqueNameMatches(project, uniqueName)) as MSBuildBasedProject; |
||||||
|
} |
||||||
|
|
||||||
|
bool ProjectUniqueNameMatches(IProject project, string uniqueName) |
||||||
|
{ |
||||||
|
return IsCaseInsensitiveMatch(Path.GetFileName(project.FileName), uniqueName); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsCaseInsensitiveMatch(string a, string b) |
||||||
|
{ |
||||||
|
return String.Equals(a, b, StringComparison.OrdinalIgnoreCase); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,75 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using Microsoft.VisualStudio; |
||||||
|
using Microsoft.VisualStudio.Shell.Flavor; |
||||||
|
using NUnit.Framework; |
||||||
|
using PackageManagement.Tests.Helpers; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests.VisualStudio |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class FlavoredProjectTests |
||||||
|
{ |
||||||
|
FlavoredProject project; |
||||||
|
TestableProject msbuildProject; |
||||||
|
|
||||||
|
void CreateFlavoredProject(MSBuildBasedProject msbuildProject) |
||||||
|
{ |
||||||
|
project = new FlavoredProject(msbuildProject); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateMSBuildProject(string fileName) |
||||||
|
{ |
||||||
|
msbuildProject = ProjectHelper.CreateTestProject(); |
||||||
|
msbuildProject.FileName = fileName; |
||||||
|
} |
||||||
|
|
||||||
|
void AddProjectTypeGuidsToMSBuildProject(string guids) |
||||||
|
{ |
||||||
|
msbuildProject.SetProperty("ProjectTypeGuids", guids, false); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetAggregateProjectTypeGuids_VisualBasicProject_ReturnsVisualBasicProjectTypeGuid() |
||||||
|
{ |
||||||
|
CreateMSBuildProject(@"d:\projects\test\test.vbproj"); |
||||||
|
CreateFlavoredProject(msbuildProject); |
||||||
|
|
||||||
|
string guids; |
||||||
|
int result = project.GetAggregateProjectTypeGuids(out guids); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.S_OK, result); |
||||||
|
Assert.AreEqual(ProjectTypeGuids.VBNet, guids); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetAggregateProjectTypeGuids_UnknownProject_ReturnsEmptyString() |
||||||
|
{ |
||||||
|
CreateMSBuildProject(@"d:\projects\test\test.unknown"); |
||||||
|
CreateFlavoredProject(msbuildProject); |
||||||
|
|
||||||
|
string guids; |
||||||
|
int result = project.GetAggregateProjectTypeGuids(out guids); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.S_OK, result); |
||||||
|
Assert.AreEqual(String.Empty, guids); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetAggregateProjectTypeGuids_MSBuildProjectHasProjectTypeGuidsDefined_ReturnsGuidsFromMSBuildProject() |
||||||
|
{ |
||||||
|
CreateMSBuildProject(@"d:\projects\test\test.csproj"); |
||||||
|
string expectedGuids = "{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}"; |
||||||
|
AddProjectTypeGuidsToMSBuildProject(expectedGuids); |
||||||
|
CreateFlavoredProject(msbuildProject); |
||||||
|
|
||||||
|
string guids; |
||||||
|
project.GetAggregateProjectTypeGuids(out guids); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedGuids, guids); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,102 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.PackageManagement.Design; |
||||||
|
using ICSharpCode.PackageManagement.VisualStudio; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using Microsoft.VisualStudio; |
||||||
|
using Microsoft.VisualStudio.Shell.Interop; |
||||||
|
using NUnit.Framework; |
||||||
|
using PackageManagement.Tests.Helpers; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests.VisualStudio |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class VsSolutionTests |
||||||
|
{ |
||||||
|
VsSolution solution; |
||||||
|
IVsHierarchy hierarchy; |
||||||
|
FakePackageManagementProjectService fakeProjectService; |
||||||
|
|
||||||
|
void CreateVsSolution() |
||||||
|
{ |
||||||
|
fakeProjectService = new FakePackageManagementProjectService(); |
||||||
|
solution = new VsSolution(fakeProjectService); |
||||||
|
} |
||||||
|
|
||||||
|
int GetProjectOfUniqueName(string name) |
||||||
|
{ |
||||||
|
return solution.GetProjectOfUniqueName(name, out hierarchy); |
||||||
|
} |
||||||
|
|
||||||
|
void AddProjectToMSBuildSolution(string fileName) |
||||||
|
{ |
||||||
|
TestableProject project = ProjectHelper.CreateTestProject(); |
||||||
|
project.FileName = fileName; |
||||||
|
fakeProjectService.AddFakeProject(project); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProjectOfUniqueName_NoSolutionOpen_ReturnsError() |
||||||
|
{ |
||||||
|
CreateVsSolution(); |
||||||
|
|
||||||
|
int result = GetProjectOfUniqueName("Test.csproj"); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.E_FAIL, result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProjectOfUniqueName_SolutionHasProjectMatchingUniqueName_ReturnsSuccessAndVsHierarchy() |
||||||
|
{ |
||||||
|
CreateVsSolution(); |
||||||
|
AddProjectToMSBuildSolution(@"d:\projects\test\Test.csproj"); |
||||||
|
|
||||||
|
int result = GetProjectOfUniqueName("Test.csproj"); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.S_OK, result); |
||||||
|
Assert.IsNotNull(hierarchy); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProjectOfUniqueName_SolutionHasProjectButDoesNotMatchUniqueName_ReturnsError() |
||||||
|
{ |
||||||
|
CreateVsSolution(); |
||||||
|
AddProjectToMSBuildSolution(@"d:\projects\test\unknown.vbproj"); |
||||||
|
|
||||||
|
int result = GetProjectOfUniqueName("Test.csproj"); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.E_FAIL, result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProjectOfUniqueName_UniqueNameCaseIsIgnored_ReturnsSuccess() |
||||||
|
{ |
||||||
|
CreateVsSolution(); |
||||||
|
AddProjectToMSBuildSolution(@"d:\projects\test\test.csproj"); |
||||||
|
|
||||||
|
int result = GetProjectOfUniqueName("TEST.CSPROJ"); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.S_OK, result); |
||||||
|
Assert.IsNotNull(hierarchy); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProjectOfUniqueName_ProjectTypeGuidsRetrievedFromAggregatableCSharpProject_ReturnsCSharpProjectTypeGuid() |
||||||
|
{ |
||||||
|
CreateVsSolution(); |
||||||
|
AddProjectToMSBuildSolution(@"d:\projects\test\test.csproj"); |
||||||
|
|
||||||
|
GetProjectOfUniqueName("test.csproj"); |
||||||
|
|
||||||
|
var project = hierarchy as IVsAggregatableProject; |
||||||
|
|
||||||
|
string guids; |
||||||
|
int result = project.GetAggregateProjectTypeGuids(out guids); |
||||||
|
|
||||||
|
Assert.AreEqual(VsConstants.S_OK, result); |
||||||
|
Assert.AreEqual(ProjectTypeGuids.CSharp, guids); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue