Browse Source

Add support for EnvDTE.Solution.Globals.VariableExists

Checks the ExtensibilityGlobals section of a solution file for a variable. Used by the Unity NuGet package.
pull/28/head
Matt Ward 13 years ago
parent
commit
776d5d28b0
  1. 1
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 40
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Globals.cs
  3. 2
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Solution.cs
  4. 2
      src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  5. 83
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/SolutionGlobalsTests.cs
  6. 23
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/SolutionTests.cs
  7. 66
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/SolutionHelper.cs

1
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -119,6 +119,7 @@ @@ -119,6 +119,7 @@
<Compile Include="Src\EnvDTE\EditPoint.cs" />
<Compile Include="Src\EnvDTE\FileCodeModel2.cs" />
<Compile Include="Src\EnvDTE\FileCodeModelCodeElements.cs" />
<Compile Include="Src\EnvDTE\Globals.cs" />
<Compile Include="Src\EnvDTE\ImplementedInterfacesOnClass.cs" />
<Compile Include="Src\EnvDTE\IReturnTypeExtensions.cs" />
<Compile Include="Src\EnvDTE\NamespaceName.cs" />

40
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Globals.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
// 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.Collections.Generic;
using System.Linq;
using SD = ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class Globals
{
SD.Solution solution;
public Globals(SD.Solution solution)
{
this.solution = solution;
}
public virtual bool VariableExists(string name)
{
SD.ProjectSection section = GetExtensibilityGlobalsSection();
if (section != null) {
return section.Items.Any(item => IsMatchIgnoringCase(item.Name, name));
}
return false;
}
bool IsMatchIgnoringCase(string a, string b)
{
return String.Equals(a, b, StringComparison.OrdinalIgnoreCase);
}
SD.ProjectSection GetExtensibilityGlobalsSection()
{
return solution.Sections.SingleOrDefault(section => section.Name == "ExtensibilityGlobals");
}
}
}

2
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Solution.cs

@ -16,6 +16,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -16,6 +16,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
this.projectService = projectService;
this.solution = projectService.OpenSolution;
this.Projects = new Projects(projectService);
this.Globals = new Globals(solution);
}
public string FullName {
@ -31,5 +32,6 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -31,5 +32,6 @@ namespace ICSharpCode.PackageManagement.EnvDTE
}
public Projects Projects { get; private set; }
public Globals Globals { get; private set; }
}
}

2
src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

@ -96,6 +96,7 @@ @@ -96,6 +96,7 @@
<Compile Include="Src\EnvDTE\EditPointTests.cs" />
<Compile Include="Src\EnvDTE\FileCodeModel2Tests.cs" />
<Compile Include="Src\EnvDTE\NamespaceNameTests.cs" />
<Compile Include="Src\EnvDTE\SolutionGlobalsTests.cs" />
<Compile Include="Src\EnvDTE\SolutionTests.cs" />
<Compile Include="Src\Helpers\AttributeHelper.cs" />
<Compile Include="Src\Helpers\ClassHelper.cs" />
@ -114,6 +115,7 @@ @@ -114,6 +115,7 @@
<Compile Include="Src\Helpers\PropertyHelper.cs" />
<Compile Include="Src\Helpers\ReturnTypeHelper.cs" />
<Compile Include="Src\Helpers\SelectedProjectCollectionAssert.cs" />
<Compile Include="Src\Helpers\SolutionHelper.cs" />
<Compile Include="Src\Helpers\TestableInstalledPackageViewModel.cs" />
<Compile Include="Src\Helpers\TestablePackageFromRepository.cs" />
<Compile Include="Src\Helpers\TestableProjectBehaviour.cs" />

83
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/SolutionGlobalsTests.cs

@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
// 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.EnvDTE;
using NUnit.Framework;
using PackageManagement.Tests.Helpers;
namespace PackageManagement.Tests.EnvDTE
{
[TestFixture]
public class SolutionGlobalsTests
{
SolutionHelper solutionHelper;
Globals globals;
void CreateSolution()
{
solutionHelper = new SolutionHelper();
globals = solutionHelper.Solution.Globals;
}
void AddVariableToExtensibilityGlobals(string name)
{
AddVariableToExtensibilityGlobals(name, String.Empty);
}
void AddVariableToExtensibilityGlobals(string name, string value)
{
solutionHelper.AddVariableToExtensibilityGlobals(name, value);
}
void AddExtensibilityGlobalsSection()
{
solutionHelper.AddExtensibilityGlobalsSection();
}
[Test]
public void VariableExists_VariableExistsInExtensibilityGlobalsSection_ReturnsTrue()
{
CreateSolution();
AddExtensibilityGlobalsSection();
AddVariableToExtensibilityGlobals("test");
bool exists = globals.VariableExists("test");
Assert.IsTrue(exists);
}
[Test]
public void VariableExists_NoExtensibilityGlobalsSection_ReturnsFalse()
{
CreateSolution();
bool exists = globals.VariableExists("test");
Assert.IsFalse(exists);
}
[Test]
public void VariableExists_ExtensibilityGlobalsSectionExistsButHasNoVariables_ReturnsFalse()
{
CreateSolution();
AddExtensibilityGlobalsSection();
bool exists = globals.VariableExists("test");
Assert.IsFalse(exists);
}
[Test]
public void VariableExists_VariableExistsInExtensibilityGlobalsSectionWithDifferentCasing_ReturnsTrue()
{
CreateSolution();
AddExtensibilityGlobalsSection();
AddVariableToExtensibilityGlobals("TEST");
bool exists = globals.VariableExists("test");
Assert.IsTrue(exists);
}
}
}

23
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/SolutionTests.cs

@ -14,39 +14,28 @@ namespace PackageManagement.Tests.EnvDTE @@ -14,39 +14,28 @@ namespace PackageManagement.Tests.EnvDTE
[TestFixture]
public class SolutionTests
{
SolutionHelper solutionHelper;
Solution solution;
FakePackageManagementProjectService fakeProjectService;
SD.Solution sharpDevelopSolution;
void CreateSolution()
{
fakeProjectService = new FakePackageManagementProjectService();
sharpDevelopSolution = CreateSharpDevelopSolution();
fakeProjectService.OpenSolution = sharpDevelopSolution;
solution = new Solution(fakeProjectService);
}
SD.Solution CreateSharpDevelopSolution()
{
return new SD.Solution(new SD.MockProjectChangeWatcher());
solutionHelper = new SolutionHelper();
solution = solutionHelper.Solution;
}
SD.Solution OpenDifferentSolution()
{
SD.Solution solution = CreateSharpDevelopSolution();
fakeProjectService.OpenSolution = solution;
return solution;
return solutionHelper.OpenDifferentSolution();
}
void NoOpenSolution()
{
fakeProjectService.OpenSolution = null;
solutionHelper.CloseSolution();
}
void AddProjectToSolution(string projectName)
{
TestableProject project = ProjectHelper.CreateTestProject(projectName);
fakeProjectService.AddFakeProject(project);
solutionHelper.AddProjectToSolution(projectName);
}
[Test]

66
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/SolutionHelper.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
// 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.EnvDTE;
using SD = ICSharpCode.SharpDevelop.Project;
namespace PackageManagement.Tests.Helpers
{
public class SolutionHelper
{
public SolutionHelper()
{
OpenSolution();
}
public Solution Solution;
public FakePackageManagementProjectService FakeProjectService;
public SD.Solution MSBuildSolution;
public SD.ProjectSection ExtensibilityGlobalsSection;
void OpenSolution()
{
FakeProjectService = new FakePackageManagementProjectService();
MSBuildSolution = CreateSharpDevelopSolution();
FakeProjectService.OpenSolution = MSBuildSolution;
Solution = new Solution(FakeProjectService);
}
SD.Solution CreateSharpDevelopSolution()
{
return new SD.Solution(new SD.MockProjectChangeWatcher());
}
public SD.Solution OpenDifferentSolution()
{
SD.Solution solution = CreateSharpDevelopSolution();
FakeProjectService.OpenSolution = solution;
return solution;
}
public void CloseSolution()
{
FakeProjectService.OpenSolution = null;
}
public void AddProjectToSolution(string projectName)
{
TestableProject project = ProjectHelper.CreateTestProject(projectName);
FakeProjectService.AddFakeProject(project);
}
public void AddExtensibilityGlobalsSection()
{
ExtensibilityGlobalsSection = new SD.ProjectSection("ExtensibilityGlobals", "postSolution");
MSBuildSolution.Sections.Add(ExtensibilityGlobalsSection);
}
public void AddVariableToExtensibilityGlobals(string name, string value)
{
var solutionItem = new SD.SolutionItem(name, value);
ExtensibilityGlobalsSection.Items.Add(solutionItem);
}
}
}
Loading…
Cancel
Save