Browse Source

Cache the current open solution in the EnvDTE.DTE class.

Maintains any solution variables added between accesses to the $dte.Solution in the Powershell console.
This allows the Unity NuGet package to install without any errors.
pull/28/head
Matt Ward 13 years ago
parent
commit
5b3abf818e
  1. 19
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/DTE.cs
  2. 5
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Solution.cs
  3. 41
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/DTETests.cs

19
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/DTE.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{ {
IPackageManagementProjectService projectService; IPackageManagementProjectService projectService;
IPackageManagementFileService fileService; IPackageManagementFileService fileService;
Solution solution;
public DTE() public DTE()
: this(new PackageManagementProjectService(), new PackageManagementFileService()) : this(new PackageManagementProjectService(), new PackageManagementFileService())
@ -36,7 +37,8 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public Solution Solution { public Solution Solution {
get { get {
if (IsSolutionOpen) { if (IsSolutionOpen) {
return new Solution(projectService); CreateSolution();
return solution;
} }
return null; return null;
} }
@ -46,6 +48,21 @@ namespace ICSharpCode.PackageManagement.EnvDTE
get { return projectService.OpenSolution != null; } get { return projectService.OpenSolution != null; }
} }
void CreateSolution()
{
if (!IsOpenSolutionAlreadyCreated()) {
solution = new Solution(projectService);
}
}
bool IsOpenSolutionAlreadyCreated()
{
if (solution != null) {
return solution.IsOpen;
}
return false;
}
public ItemOperations ItemOperations { get; private set; } public ItemOperations ItemOperations { get; private set; }
public Properties Properties(string category, string page) public Properties Properties(string category, string page)

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

@ -43,5 +43,10 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{ {
projectService.Save(solution); projectService.Save(solution);
} }
internal bool IsSameSolution(SD.Solution solution)
{
throw new NotImplementedException();
}
} }
} }

41
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/DTETests.cs

@ -20,16 +20,27 @@ namespace PackageManagement.Tests.EnvDTE
void CreateDTE() void CreateDTE()
{ {
fakeProjectService = new FakePackageManagementProjectService(); fakeProjectService = new FakePackageManagementProjectService();
fakeProjectService.OpenSolution = new SD.Solution(new SD.MockProjectChangeWatcher()); OpenSolution(@"d:\projects\MyProject\MyProject.sln");
fakeFileService = new FakeFileService(null); fakeFileService = new FakeFileService(null);
dte = new DTE(fakeProjectService, fakeFileService); dte = new DTE(fakeProjectService, fakeFileService);
} }
void OpenSolution(string fileName)
{
fakeProjectService.OpenSolution = new SD.Solution(new SD.MockProjectChangeWatcher());
SetOpenSolutionFileName(fileName);
}
void NoOpenSolution() void NoOpenSolution()
{ {
fakeProjectService.OpenSolution = null; fakeProjectService.OpenSolution = null;
} }
void SetOpenSolutionFileName(string fileName)
{
fakeProjectService.OpenSolution.FileName = fileName;
}
TestableProject AddProjectToSolution(string projectName) TestableProject AddProjectToSolution(string projectName)
{ {
TestableProject project = ProjectHelper.CreateTestProject(projectName); TestableProject project = ProjectHelper.CreateTestProject(projectName);
@ -42,7 +53,7 @@ namespace PackageManagement.Tests.EnvDTE
{ {
CreateDTE(); CreateDTE();
string fileName = @"d:\projects\myproject\myproject.sln"; string fileName = @"d:\projects\myproject\myproject.sln";
fakeProjectService.OpenSolution.FileName = fileName; SetOpenSolutionFileName(fileName);
string fullName = dte.Solution.FullName; string fullName = dte.Solution.FullName;
@ -54,7 +65,7 @@ namespace PackageManagement.Tests.EnvDTE
{ {
CreateDTE(); CreateDTE();
string expectedFileName = @"d:\projects\myproject\myproject.sln"; string expectedFileName = @"d:\projects\myproject\myproject.sln";
fakeProjectService.OpenSolution.FileName = expectedFileName; SetOpenSolutionFileName(expectedFileName);
string fileName = dte.Solution.FileName; string fileName = dte.Solution.FileName;
@ -147,5 +158,29 @@ namespace PackageManagement.Tests.EnvDTE
Assert.AreEqual("10.0", version); Assert.AreEqual("10.0", version);
} }
[Test]
public void Solution_SetGlobalsVariableValueAndThenAccessSolutionPropertyAgainAndGetSolutionGlobalsVariable_GlobalsVariableValueReturned()
{
CreateDTE();
dte.Solution.Globals.set_VariableValue("test", "test-value");
object variableValue = dte.Solution.Globals.get_VariableValue("test");
Assert.AreEqual("test-value", variableValue);
}
[Test]
public void Solution_OpenSolutionChangesAfterSolutionPropertyAccessed_SolutionReturnedForCurrentOpenSolution()
{
CreateDTE();
SetOpenSolutionFileName(@"d:\projects\first\first.sln");
Solution firstSolution = dte.Solution;
OpenSolution(@"d:\projects\second\second.sln");
string fileName = dte.Solution.FileName;
Assert.AreEqual(@"d:\projects\second\second.sln", fileName);
}
} }
} }

Loading…
Cancel
Save