Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: icsharpcode/SharpDevelop
...
head fork: icsharpcode/SharpDevelop
  • 3 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
Showing with 637 additions and 26 deletions.
  1. +2 −0  src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. +11 −1 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/DirectoryProjectItem.cs
  3. +66 −12 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Project.cs
  4. +9 −1 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs
  5. +5 −3 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItems.cs
  6. +6 −0 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectType.cs
  7. +2 −0  src/AddIns/Misc/PackageManagement/Project/Src/IPackageManagementFileService.cs
  8. +23 −1 src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementFileService.cs
  9. +27 −2 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/FlavoredProject.cs
  10. +4 −2 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/Package.cs
  11. +14 −0 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/VsConstants.cs
  12. +57 −0 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/VsSolution.cs
  13. +2 −0  src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  14. +165 −3 src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/ProjectItemsTests.cs
  15. +14 −1 src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/ProjectTests.cs
  16. +44 −0 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeFileService.cs
  17. +75 −0 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/FlavoredProjectTests.cs
  18. +9 −0 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/PackageTests.cs
  19. +102 −0 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/VsSolutionTests.cs
2  src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
View
@@ -405,6 +405,8 @@
<Compile Include="Src\VisualStudio\Package.cs" />
<Compile Include="Src\VisualStudio\SVsExtensionManager.cs" />
<Compile Include="Src\VisualStudio\ThreadHelper.cs" />
+ <Compile Include="Src\VisualStudio\VsConstants.cs" />
+ <Compile Include="Src\VisualStudio\VsSolution.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\ManagePackagesView.xaml" />
12 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/DirectoryProjectItem.cs
View
@@ -3,6 +3,7 @@
using System;
using System.IO;
+using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using SD = ICSharpCode.SharpDevelop.Project;
@@ -29,7 +30,10 @@ static FileProjectItem CreateFileProjectItem(Project project, string relativePat
static string GetLastDirectoryName(string relativePath)
{
string[] directoryNames = relativePath.Split('\\');
- return directoryNames[1];
+ if (directoryNames.Length > 1) {
+ return directoryNames[1];
+ }
+ return relativePath;
}
public DirectoryProjectItem(Project project, FileProjectItem projectItem)
@@ -45,5 +49,11 @@ internal override bool IsChildItem(SD.ProjectItem msbuildProjectItem)
}
return false;
}
+
+ public static DirectoryProjectItem CreateDirectoryProjectItemFromFullPath(Project project, string directory)
+ {
+ string relativePath = project.GetRelativePath(directory);
+ return new DirectoryProjectItem(project, relativePath);
+ }
}
}
78 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/Project.cs
View
@@ -4,7 +4,9 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
+using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using Microsoft.Build.Construction;
using SD = ICSharpCode.SharpDevelop.Project;
@@ -54,7 +56,12 @@ void CreateProperties()
}
public virtual string UniqueName {
- get { return Path.GetFileName(FileName); }
+ get { return GetUniqueName(); }
+ }
+
+ string GetUniqueName()
+ {
+ return FileUtility.GetRelativePath(MSBuildProject.ParentSolution.Directory, FileName);
}
public virtual string FileName {
@@ -107,7 +114,7 @@ internal virtual void AddReference(string path)
{
if (!HasReference(path)) {
var referenceItem = new ReferenceProjectItem(MSBuildProject, path);
- projectService.AddProjectItem(MSBuildProject, referenceItem);
+ AddProjectItemToMSBuildProject(referenceItem);
}
}
@@ -121,6 +128,11 @@ bool HasReference(string include)
return false;
}
+ void AddProjectItemToMSBuildProject(SD.ProjectItem projectItem)
+ {
+ projectService.AddProjectItem(MSBuildProject, projectItem);
+ }
+
internal IEnumerable<SD.ProjectItem> GetReferences()
{
return MSBuildProject.GetItemsOfType(ItemType.Reference);
@@ -136,17 +148,17 @@ internal void RemoveReference(ReferenceProjectItem referenceItem)
projectService.RemoveProjectItem(MSBuildProject, referenceItem);
}
- internal void AddFileUsingPathRelativeToProject(string include)
+ internal void AddFileProjectItemUsingPathRelativeToProject(string include)
{
- var fileProjectItem = CreateFileProjectItemUsingPathRelativeToProject(include);
- projectService.AddProjectItem(MSBuildProject, fileProjectItem);
+ FileProjectItem fileProjectItem = CreateFileProjectItemUsingPathRelativeToProject(include);
+ AddProjectItemToMSBuildProject(fileProjectItem);
}
- internal ProjectItem AddFileUsingFullPath(string path)
+ internal ProjectItem AddFileProjectItemUsingFullPath(string path)
{
FileProjectItem fileProjectItem = CreateFileProjectItemUsingFullPath(path);
fileProjectItem.FileName = path;
- projectService.AddProjectItem(MSBuildProject, fileProjectItem);
+ AddProjectItemToMSBuildProject(fileProjectItem);
return new ProjectItem(this, fileProjectItem);
}
@@ -158,19 +170,20 @@ FileProjectItem CreateFileProjectItemUsingPathRelativeToProject(string include)
ItemType GetDefaultItemType(string include)
{
- return MSBuildProject.GetDefaultItemType(include);
+ return MSBuildProject.GetDefaultItemType(Path.GetFileName(include));
}
FileProjectItem CreateFileProjectItemUsingPathRelativeToProject(ItemType itemType, string include)
{
- var fileProjectItem = new FileProjectItem(MSBuildProject, itemType);
- fileProjectItem.Include = include;
- return fileProjectItem;
+ return new FileProjectItem(MSBuildProject, itemType) {
+ Include = include
+ };
}
FileProjectItem CreateFileProjectItemUsingFullPath(string path)
{
- return CreateFileProjectItemUsingPathRelativeToProject(Path.GetFileName(path));
+ string relativePath = GetRelativePath(path);
+ return CreateFileProjectItemUsingPathRelativeToProject(relativePath);
}
internal IList<string> GetAllPropertyNames()
@@ -202,5 +215,46 @@ internal virtual void DeleteFile(string fileName)
{
fileService.RemoveFile(fileName);
}
+
+ public ProjectItem AddDirectoryProjectItemUsingFullPath(string directory)
+ {
+ AddDirectoryProjectItemsRecursively(directory);
+ return DirectoryProjectItem.CreateDirectoryProjectItemFromFullPath(this, directory);
+ }
+
+ void AddDirectoryProjectItemsRecursively(string directory)
+ {
+ string[] files = fileService.GetFiles(directory);
+ string[] childDirectories = fileService.GetDirectories(directory);
+ if (files.Any()) {
+ foreach (string file in files) {
+ AddFileProjectItemUsingFullPath(file);
+ }
+ } else if (!childDirectories.Any()) {
+ AddDirectoryProjectItemToMSBuildProject(directory);
+ }
+
+ foreach (string childDirectory in childDirectories) {
+ AddDirectoryProjectItemsRecursively(childDirectory);
+ }
+ }
+
+ void AddDirectoryProjectItemToMSBuildProject(string directory)
+ {
+ FileProjectItem projectItem = CreateMSBuildProjectItemForDirectory(directory);
+ AddProjectItemToMSBuildProject(projectItem);
+ }
+
+ FileProjectItem CreateMSBuildProjectItemForDirectory(string directory)
+ {
+ return new FileProjectItem(MSBuildProject, ItemType.Folder) {
+ FileName = directory
+ };
+ }
+
+ internal string GetRelativePath(string path)
+ {
+ return FileUtility.GetRelativePath(MSBuildProject.Directory, path);
+ }
}
}
10 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs
View
@@ -24,7 +24,15 @@ public ProjectItem(Project project, FileProjectItem projectItem)
this.ContainingProject = project;
this.ProjectItems = new DirectoryProjectItems(this);
CreateProperties();
- Kind = Constants.VsProjectItemKindPhysicalFile;
+ Kind = GetKindFromFileProjectItemType();
+ }
+
+ string GetKindFromFileProjectItemType()
+ {
+ if (projectItem.ItemType == ItemType.Folder) {
+ return Constants.VsProjectItemKindPhysicalFolder;
+ }
+ return Constants.VsProjectItemKindPhysicalFile;
}
public ProjectItem()
8 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItems.cs
View
@@ -34,7 +34,7 @@ public virtual void AddFromFileCopy(string filePath)
{
string include = Path.GetFileName(filePath);
CopyFileIntoProject(filePath, include);
- project.AddFileUsingPathRelativeToProject(include);
+ project.AddFileProjectItemUsingPathRelativeToProject(include);
project.Save();
}
@@ -89,12 +89,14 @@ public virtual ProjectItem Item(object index)
public virtual ProjectItem AddFromDirectory(string directory)
{
- throw new NotImplementedException();
+ ProjectItem directoryItem = project.AddDirectoryProjectItemUsingFullPath(directory);
+ project.Save();
+ return directoryItem;
}
public virtual ProjectItem AddFromFile(string fileName)
{
- ProjectItem projectItem = project.AddFileUsingFullPath(fileName);
+ ProjectItem projectItem = project.AddFileProjectItemUsingFullPath(fileName);
project.Save();
return projectItem;
}
6 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectType.cs
View
@@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.PackageManagement.EnvDTE
{
@@ -15,6 +16,11 @@ public ProjectType(Project project)
this.Type = GetProjectType(project);
}
+ public ProjectType(MSBuildBasedProject project)
+ : this(new Project(project))
+ {
+ }
+
string GetProjectType(Project project)
{
string extension = project.GetLowercaseFileExtension();
2  src/AddIns/Misc/PackageManagement/Project/Src/IPackageManagementFileService.cs
View
@@ -12,5 +12,7 @@ public interface IPackageManagementFileService
void OpenFile(string fileName);
void CopyFile(string oldFileName, string newFileName);
bool FileExists(string fileName);
+ string[] GetFiles(string path);
+ string[] GetDirectories(string path);
}
}
24 src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementFileService.cs
View
@@ -52,7 +52,29 @@ public void CopyFile(string oldFileName, string newFileName)
public bool FileExists(string fileName)
{
- return File.Exists(fileName);
+ if (WorkbenchSingleton.InvokeRequired) {
+ return WorkbenchSingleton.SafeThreadFunction(() => FileExists(fileName));
+ } else {
+ return File.Exists(fileName);
+ }
+ }
+
+ public string[] GetFiles(string path)
+ {
+ if (WorkbenchSingleton.InvokeRequired) {
+ return WorkbenchSingleton.SafeThreadFunction(() => GetFiles(path));
+ } else {
+ return Directory.GetFiles(path);
+ }
+ }
+
+ public string[] GetDirectories(string path)
+ {
+ if (WorkbenchSingleton.InvokeRequired) {
+ return WorkbenchSingleton.SafeThreadFunction(() => GetDirectories(path));
+ } else {
+ return Directory.GetDirectories(path);
+ }
}
}
}
29 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/FlavoredProject.cs
View
@@ -2,19 +2,44 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using ICSharpCode.PackageManagement.EnvDTE;
+using ICSharpCode.SharpDevelop.Project;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.Shell.Flavor
{
public class FlavoredProject : MarshalByRefObject, IVsAggregatableProject, IVsHierarchy
{
- public FlavoredProject()
+ MSBuildBasedProject project;
+
+ public FlavoredProject(MSBuildBasedProject project)
{
+ this.project = project;
}
public int GetAggregateProjectTypeGuids(out string projTypeGuids)
{
- throw new NotImplementedException();
+ projTypeGuids = GetProjectTypeGuidsFromProject();
+ if (projTypeGuids == null) {
+ projTypeGuids = GetProjectTypeGuidsBasedOnProjectFileExtension();
+ }
+ return VsConstants.S_OK;
}
+
+ string GetProjectTypeGuidsFromProject()
+ {
+ return project.GetUnevalatedProperty("ProjectTypeGuids");
+ }
+
+ string GetProjectTypeGuidsBasedOnProjectFileExtension()
+ {
+ var projectType = new ProjectType(project);
+ if (projectType.Type == ProjectType.CSharp) {
+ return ProjectTypeGuids.CSharp;
+ } else if (projectType.Type == ProjectType.VBNet) {
+ return ProjectTypeGuids.VBNet;
+ }
+ return String.Empty;
+ }
}
}
6 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/Package.cs
View
@@ -3,7 +3,9 @@
using System;
using ICSharpCode.PackageManagement.EnvDTE;
+using ICSharpCode.PackageManagement.VisualStudio;
using Microsoft.VisualStudio.ExtensionManager;
+using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.Shell
{
@@ -11,13 +13,13 @@ public abstract class Package
{
public static object GetGlobalService(Type serviceType)
{
- //typeof(IVsSolution)
//typeof(SComponentModel) --> not used - console initializer.
- //typeof(SVsExtensionManager)
if (serviceType == typeof(DTE)) {
return new DTE();
} else if (serviceType == typeof(SVsExtensionManager)) {
return new SVsExtensionManager();
+ } else if (serviceType == typeof(IVsSolution)) {
+ return new VsSolution();
}
return null;
}
14 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/VsConstants.cs
View
@@ -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;
+ }
+}
57 src/AddIns/Misc/PackageManagement/Project/Src/VisualStudio/VsSolution.cs
View
@@ -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);
+ }
+ }
+}
2  src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
View
@@ -268,8 +268,10 @@
<Compile Include="Src\UpdatePackageActionTests.cs" />
<Compile Include="Src\UpdatePackageInAllProjectsTests.cs" />
<Compile Include="Src\ViewModelBaseTests.cs" />
+ <Compile Include="Src\VisualStudio\FlavoredProjectTests.cs" />
<Compile Include="Src\VisualStudio\PackageTests.cs" />
<Compile Include="Src\VisualStudio\SVsExtensionManagerTests.cs" />
+ <Compile Include="Src\VisualStudio\VsSolutionTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
168 src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/ProjectItemsTests.cs
View
@@ -30,6 +30,16 @@ void CreateProjectItems()
fakeFileService = project.FakeFileService;
}
+ void AddFileToFakeFileSystem(string directory, string relativeFileName)
+ {
+ fakeFileService.AddFilesToFakeFileSystem(directory, relativeFileName);
+ }
+
+ void AddDirectoryToFakeFileSystem(string parentDirectory, string childDirectory)
+ {
+ fakeFileService.AddDirectoryToFakeFileSystem(parentDirectory, childDirectory);
+ }
+
[Test]
public void AddFromFileCopy_AddFileNameOutsideProjectFolder_FileIsIncludedInProjectInProjectFolder()
{
@@ -390,7 +400,7 @@ public void AddFromFile_FullFileNameIsInsideProject_FileIsAddedToProject()
public void AddFromFile_FullFileNameIsInsideProject_ProjectIsSaved()
{
CreateProjectItems();
- msbuildProject.FileName = @"d:\projects\myproject\myproject\myproject.csproj";
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
string fileName = @"d:\projects\myproject\packages\tools\test.cs";
projectItems.AddFromFile(fileName);
@@ -404,7 +414,7 @@ public void AddFromFile_FullFileNameIsInsideProject_ProjectIsSaved()
public void AddFromFile_FullFileNameIsInsideProject_ProjectItemReturned()
{
CreateProjectItems();
- msbuildProject.FileName = @"d:\projects\myproject\myproject\myproject.csproj";
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
string fileName = @"d:\projects\myproject\tools\test.cs";
msbuildProject.ItemTypeToReturnFromGetDefaultItemType = ItemType.Page;
@@ -420,7 +430,7 @@ public void AddFromFile_FullFileNameIsInsideProject_ProjectItemReturned()
public void AddFromFile_FullFileNameIsInsideProject_FileNameUsedToDetermineProjectItemType()
{
CreateProjectItems();
- msbuildProject.FileName = @"d:\projects\myproject\myproject\myproject.csproj";
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
string fileName = @"d:\projects\myproject\tools\test.cs";
projectItems.AddFromFile(fileName);
@@ -428,5 +438,157 @@ public void AddFromFile_FullFileNameIsInsideProject_FileNameUsedToDetermineProje
Assert.AreEqual("test.cs", msbuildProject.FileNamePassedToGetDefaultItemType);
}
+ [Test]
+ public void AddFromDirectory_EmptyDirectoryInsideProject_ProjectIsSaved()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools";
+
+ projectItems.AddFromDirectory(directory);
+
+ bool saved = msbuildProject.IsSaved;
+
+ Assert.IsTrue(saved);
+ }
+
+ [Test]
+ public void AddFromDirectory_EmptyDirectoryInsideProject_ProjectItemIsReturnedForNewDirectory()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools";
+
+ DTE.ProjectItem item = projectItems.AddFromDirectory(directory);
+ string name = item.Name;
+
+ Assert.AreEqual("tools", name);
+ Assert.AreEqual(project, item.ContainingProject);
+ Assert.AreEqual(Constants.VsProjectItemKindPhysicalFolder, item.Kind);
+ }
+
+ [Test]
+ public void AddFromDirectory_EmptyDirectoryInsideProject_FolderProjectItemAddedToProject()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools";
+
+ projectItems.AddFromDirectory(directory);
+
+ var item = msbuildProject.Items[0] as FileProjectItem;
+
+ Assert.AreEqual("tools", item.Include);
+ Assert.AreEqual(ItemType.Folder, item.ItemType);
+ }
+
+ [Test]
+ public void AddFromDirectory_EmptyDirectoryIsTwoLevelsInsideProject_FolderProjectItemAddedToProject()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools\packages";
+
+ projectItems.AddFromDirectory(directory);
+
+ var item = msbuildProject.Items[0] as FileProjectItem;
+
+ Assert.AreEqual(@"tools\packages", item.Include);
+ Assert.AreEqual(ItemType.Folder, item.ItemType);
+ }
+
+ [Test]
+ public void AddFromDirectory_DirectoryContainsOneFile_FileAddedToMSBuildProjectButNoFolder()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools";
+ AddFileToFakeFileSystem(directory, "a.txt");
+ project.TestableProject.ItemTypeToReturnFromGetDefaultItemType = ItemType.None;
+
+ projectItems.AddFromDirectory(directory);
+
+ var item = msbuildProject.Items[0] as FileProjectItem;
+
+ Assert.AreEqual(@"tools\a.txt", item.Include);
+ Assert.AreEqual(ItemType.None, item.ItemType);
+ Assert.AreEqual(@"d:\projects\myproject\tools\a.txt", item.FileName);
+ Assert.AreEqual(1, msbuildProject.Items.Count);
+ }
+
+ [Test]
+ public void AddFromDirectory_DirectoryContainsOneFile_ProjectItemReturnedHasDirectoryName()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string directory = @"d:\projects\myproject\tools";
+ AddFileToFakeFileSystem(directory, "a.txt");
+
+ DTE.ProjectItem item = projectItems.AddFromDirectory(directory);
+ string name = item.Name;
+
+ Assert.AreEqual("tools", name);
+ Assert.AreEqual(project, item.ContainingProject);
+ Assert.AreEqual(Constants.VsProjectItemKindPhysicalFolder, item.Kind);
+ }
+
+ [Test]
+ public void AddFromDirectory_DirectoryContainsChildDirectoryWithNoFiles_DirectoryProjectItemReturnedForParentDirectory()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string parentDirectory = @"d:\projects\myproject\tools";
+ AddDirectoryToFakeFileSystem(parentDirectory, "packages");
+
+ DTE.ProjectItem item = projectItems.AddFromDirectory(parentDirectory);
+ string name = item.Name;
+
+ DTE.ProjectItem childItem = item.ProjectItems.Item("packages");
+
+ Assert.AreEqual("tools", name);
+ Assert.AreEqual(project, item.ContainingProject);
+ Assert.AreEqual(Constants.VsProjectItemKindPhysicalFolder, item.Kind);
+ Assert.AreEqual(1, item.ProjectItems.Count);
+ Assert.AreEqual(Constants.VsProjectItemKindPhysicalFolder, childItem.Kind);
+ }
+
+ [Test]
+ public void AddFromDirectory_DirectoryContainsChildDirectoryWithNoFiles_MSBuildProjectItemAddedForChildDirectoryButNotParent()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string parentDirectory = @"d:\projects\myproject\tools";
+ AddDirectoryToFakeFileSystem(parentDirectory, "packages");
+
+ projectItems.AddFromDirectory(parentDirectory);
+
+ var item = msbuildProject.Items[0] as FileProjectItem;
+
+ Assert.AreEqual(@"tools\packages", item.Include);
+ Assert.AreEqual(ItemType.Folder, item.ItemType);
+ Assert.AreEqual(@"d:\projects\myproject\tools\packages", item.FileName);
+ Assert.AreEqual(1, msbuildProject.Items.Count);
+ }
+
+ [Test]
+ public void AddFromDirectory_DirectoryContainsChildDirectoryWithOneFile_MSBuildProjectItemAddedForFileButNotForParentNorChildDirectory()
+ {
+ CreateProjectItems();
+ msbuildProject.FileName = @"d:\projects\myproject\myproject.csproj";
+ string parentDirectory = @"d:\projects\myproject\tools";
+ string childDirectory = @"d:\projects\myproject\tools\packages";
+ AddDirectoryToFakeFileSystem(parentDirectory, "packages");
+ AddFileToFakeFileSystem(childDirectory, "a.txt");
+ project.TestableProject.ItemTypeToReturnFromGetDefaultItemType = ItemType.None;
+
+ projectItems.AddFromDirectory(parentDirectory);
+
+ var item = msbuildProject.Items[0] as FileProjectItem;
+
+ Assert.AreEqual(@"tools\packages\a.txt", item.Include);
+ Assert.AreEqual(ItemType.None, item.ItemType);
+ Assert.AreEqual(@"d:\projects\myproject\tools\packages\a.txt", item.FileName);
+ Assert.AreEqual(1, msbuildProject.Items.Count);
+ }
}
}
15 src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/ProjectTests.cs
View
@@ -134,9 +134,10 @@ public void Kind_ProjectHasUnknownFileExtension_ReturnsEmptyString()
}
[Test]
- public void UniqueName_ProjectFileNameHasFullPath_ReturnsProjectFileNameWithoutDirectoryPart()
+ public void UniqueName_ProjectInSameFolderAsSolution_ReturnsProjectFileNameWithoutDirectoryPart()
{
CreateProject();
+ msbuildProject.ParentSolution.FileName = @"d:\projects\myproject\MyProject.sln";
msbuildProject.FileName = @"d:\projects\myproject\MyProject.csproj";
string name = project.UniqueName;
@@ -145,6 +146,18 @@ public void UniqueName_ProjectFileNameHasFullPath_ReturnsProjectFileNameWithoutD
}
[Test]
+ public void UniqueName_ProjectInSubDirectoryOfSolutionFolder_ReturnsProjectFileNameWithContainsSubFolder()
+ {
+ CreateProject();
+ msbuildProject.ParentSolution.FileName = @"d:\projects\myproject\MyProject.sln";
+ msbuildProject.FileName = @"d:\projects\myproject\SubFolder\MyProject.csproj";
+
+ string name = project.UniqueName;
+
+ Assert.AreEqual(@"SubFolder\MyProject.csproj", name);
+ }
+
+ [Test]
public void ProjectItemsParent_ParentOfProjectsProjectItems_ReturnsTheProject()
{
CreateProject();
44 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeFileService.cs
View
@@ -3,6 +3,9 @@
using System;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
using ICSharpCode.PackageManagement;
using ICSharpCode.SharpDevelop.Project;
@@ -62,5 +65,46 @@ public bool FileExists(string fileName)
{
return ExistingFileNames.Contains(fileName);
}
+
+ Dictionary<string, string[]> directoryFiles = new Dictionary<string, string[]>();
+
+ public void AddFilesToFakeFileSystem(string directory, params string[] filePathsRelativeToDirectory)
+ {
+ string[] fullPathFiles = ConvertToFullPaths(directory, filePathsRelativeToDirectory);
+ directoryFiles.Add(directory, fullPathFiles);
+ }
+
+ string[] ConvertToFullPaths(string directory, string[] pathsRelativeToDirectory)
+ {
+ return pathsRelativeToDirectory
+ .Select(relativePath => Path.Combine(directory, relativePath))
+ .ToArray();
+ }
+
+ public string[] GetFiles(string path)
+ {
+ string[] files;
+ if (directoryFiles.TryGetValue(path, out files)) {
+ return files;
+ }
+ return new string[0];
+ }
+
+ Dictionary<string, string[]> directories = new Dictionary<string, string[]>();
+
+ public void AddDirectoryToFakeFileSystem(string parentDirectory, params string[] childDirectoryPathsRelativeToParent)
+ {
+ string[] fullPathChildDirectories = ConvertToFullPaths(parentDirectory, childDirectoryPathsRelativeToParent);
+ directories.Add(parentDirectory, fullPathChildDirectories);
+ }
+
+ public string[] GetDirectories(string path)
+ {
+ string[] childDirectories;
+ if (directories.TryGetValue(path, out childDirectories)) {
+ return childDirectories;
+ }
+ return new string[0];
+ }
}
}
75 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/FlavoredProjectTests.cs
View
@@ -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);
+ }
+ }
+}
9 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/PackageTests.cs
View
@@ -5,6 +5,7 @@
using ICSharpCode.PackageManagement.EnvDTE;
using Microsoft.VisualStudio.ExtensionManager;
using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Interop;
using NUnit.Framework;
namespace PackageManagement.Tests.VisualStudio
@@ -35,5 +36,13 @@ public void GetGlobalService_UnknownType_ReturnsNull()
Assert.IsNull(instance);
}
+
+ [Test]
+ public void GetGlobalService_GetIVsSolution_ReturnsIVsSolution()
+ {
+ object solution = Package.GetGlobalService(typeof(IVsSolution)) as IVsSolution;
+
+ Assert.IsInstanceOf(typeof(IVsSolution), solution);
+ }
}
}
102 src/AddIns/Misc/PackageManagement/Test/Src/VisualStudio/VsSolutionTests.cs
View
@@ -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);
+ }
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.