Browse Source
Checks the ExtensibilityGlobals section of a solution file for a variable. Used by the Unity NuGet package.pull/28/head
7 changed files with 200 additions and 17 deletions
@ -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"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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…
Reference in new issue