9 changed files with 185 additions and 9 deletions
@ -0,0 +1,37 @@ |
|||||||
|
// 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 ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class SolutionProperty : Property |
||||||
|
{ |
||||||
|
Solution solution; |
||||||
|
|
||||||
|
public SolutionProperty(Solution solution, string name) |
||||||
|
: base(name) |
||||||
|
{ |
||||||
|
this.solution = solution; |
||||||
|
} |
||||||
|
|
||||||
|
protected override object GetValue() |
||||||
|
{ |
||||||
|
if (Name == "StartupProject") { |
||||||
|
return GetStartupProjectName(); |
||||||
|
} else if (Name == "Path") { |
||||||
|
return solution.FileName; |
||||||
|
} |
||||||
|
return String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
string GetStartupProjectName() |
||||||
|
{ |
||||||
|
Project project = solution.GetStartupProject(); |
||||||
|
if (project != null) { |
||||||
|
return solution.GetStartupProject().Name; |
||||||
|
} |
||||||
|
return String.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
// 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; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class SolutionPropertyFactory : IPropertyFactory |
||||||
|
{ |
||||||
|
Solution solution; |
||||||
|
|
||||||
|
public SolutionPropertyFactory(Solution solution) |
||||||
|
{ |
||||||
|
this.solution = solution; |
||||||
|
} |
||||||
|
|
||||||
|
public Property CreateProperty(string name) |
||||||
|
{ |
||||||
|
return new SolutionProperty(solution, name); |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerator<Property> GetEnumerator() |
||||||
|
{ |
||||||
|
List<Property> properties = GetProperties().ToList(); |
||||||
|
return properties.GetEnumerator(); |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<Property> GetProperties() |
||||||
|
{ |
||||||
|
foreach (string propertyName in solution.GetAllPropertyNames()) { |
||||||
|
yield return CreateProperty(propertyName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
using SD = ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests.EnvDTE |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class SolutionPropertyTests |
||||||
|
{ |
||||||
|
Properties properties; |
||||||
|
Solution solution; |
||||||
|
SD.Solution msbuildSolution; |
||||||
|
SolutionHelper solutionHelper; |
||||||
|
|
||||||
|
void CreateProperties() |
||||||
|
{ |
||||||
|
solutionHelper = new SolutionHelper(); |
||||||
|
solution = solutionHelper.Solution; |
||||||
|
msbuildSolution = solutionHelper.MSBuildSolution; |
||||||
|
properties = (Properties)solution.Properties; |
||||||
|
} |
||||||
|
|
||||||
|
void AddStartupProject(string name, string fileName) |
||||||
|
{ |
||||||
|
TestableProject project = solutionHelper.AddProjectToSolutionWithFileName(name, fileName); |
||||||
|
solutionHelper.SetStartupProject(project); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Value_GetPathProperty_ReturnsSolutionFileName() |
||||||
|
{ |
||||||
|
CreateProperties(); |
||||||
|
msbuildSolution.FileName = @"d:\projects\MyProject\MySolution.sln"; |
||||||
|
|
||||||
|
global::EnvDTE.Property property = properties.Item("Path"); |
||||||
|
object path = property.Value; |
||||||
|
|
||||||
|
Assert.AreEqual(@"d:\projects\MyProject\MySolution.sln", path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetEnumerator_GetPathProperty_ReturnsSolutionFileName() |
||||||
|
{ |
||||||
|
CreateProperties(); |
||||||
|
msbuildSolution.FileName = @"d:\projects\MyProject\MySolution.sln"; |
||||||
|
|
||||||
|
global::EnvDTE.Property property = PropertiesHelper.FindProperty(properties, "Path"); |
||||||
|
object path = property.Value; |
||||||
|
|
||||||
|
Assert.AreEqual(@"d:\projects\MyProject\MySolution.sln", path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetEnumerator_GetStartupProjectPropertyWhenSolutionHasOneStartableProject_ReturnsStartupProjectName() |
||||||
|
{ |
||||||
|
CreateProperties(); |
||||||
|
msbuildSolution.FileName = @"d:\projects\MyProject\MySolution.sln"; |
||||||
|
AddStartupProject("MyProject", @"d:\projects\MyProject\MyProject.csproj"); |
||||||
|
|
||||||
|
global::EnvDTE.Property property = PropertiesHelper.FindProperty(properties, "StartupProject"); |
||||||
|
object projectName = property.Value; |
||||||
|
|
||||||
|
Assert.AreEqual("MyProject", projectName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetEnumerator_GetStartupProjectPropertyWhenSolutionHasNoProjects_ReturnsPropertyWithEmptyStringAsValue() |
||||||
|
{ |
||||||
|
CreateProperties(); |
||||||
|
msbuildSolution.FileName = @"d:\projects\MyProject\MySolution.sln"; |
||||||
|
|
||||||
|
global::EnvDTE.Property property = PropertiesHelper.FindProperty(properties, "StartupProject"); |
||||||
|
object projectName = property.Value; |
||||||
|
|
||||||
|
Assert.AreEqual(String.Empty, projectName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue