Browse Source
Allows EntityFramework Enable-Migrations command to get the installed NuGet packages.pull/28/head
18 changed files with 248 additions and 11 deletions
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// 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.Management.Automation; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using Microsoft.VisualStudio.ComponentModelHost; |
||||
using Microsoft.VisualStudio.Shell; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Cmdlets |
||||
{ |
||||
[Cmdlet(VerbsCommon.Get, "VSComponentModel")] |
||||
[OutputType(typeof(IComponentModel))] |
||||
public class GetVSComponentModelCmdlet : PSCmdlet |
||||
{ |
||||
public GetVSComponentModelCmdlet() |
||||
{ |
||||
} |
||||
|
||||
protected override void ProcessRecord() |
||||
{ |
||||
object service = Package.GetGlobalService(typeof(SComponentModel)); |
||||
WriteObject(service); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
// 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; |
||||
|
||||
namespace NuGet.VisualStudio |
||||
{ |
||||
public interface IVsPackageInstallerServices |
||||
{ |
||||
IEnumerable<IVsPackageMetadata> GetInstalledPackages(); |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// 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 NuGet; |
||||
using NuGet.VisualStudio; |
||||
|
||||
namespace ICSharpCode.PackageManagement.VisualStudio |
||||
{ |
||||
public class VsPackageInstallerServices : IVsPackageInstallerServices |
||||
{ |
||||
IPackageManagementSolution solution; |
||||
|
||||
public VsPackageInstallerServices() |
||||
: this(PackageManagementServices.Solution) |
||||
{ |
||||
} |
||||
|
||||
public VsPackageInstallerServices(IPackageManagementSolution solution) |
||||
{ |
||||
this.solution = solution; |
||||
} |
||||
|
||||
public IEnumerable<IVsPackageMetadata> GetInstalledPackages() |
||||
{ |
||||
foreach (IPackage package in solution.GetPackages()) { |
||||
string installPath = solution.GetInstallPath(package); |
||||
yield return new VsPackageMetadata(package, installPath); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// 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 NuGet; |
||||
using NuGet.VisualStudio; |
||||
|
||||
namespace ICSharpCode.PackageManagement.VisualStudio |
||||
{ |
||||
public class VsPackageMetadata : IVsPackageMetadata |
||||
{ |
||||
IPackage package; |
||||
|
||||
public VsPackageMetadata(IPackage package, string installPath) |
||||
{ |
||||
this.package = package; |
||||
this.InstallPath = installPath; |
||||
} |
||||
|
||||
public string Id { |
||||
get { return package.Id; } |
||||
} |
||||
|
||||
public SemanticVersion Version { |
||||
get { return package.Version; } |
||||
} |
||||
|
||||
public string InstallPath { get; private set; } |
||||
} |
||||
} |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
' 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) |
||||
|
||||
Namespace Microsoft.VisualStudio.ComponentModelHost |
||||
Public Interface IComponentModel |
||||
Function GetService(Of T As Class) As T |
||||
End Interface |
||||
End Namespace |
@ -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 System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using ICSharpCode.PackageManagement.VisualStudio; |
||||
using NuGet; |
||||
using NuGet.VisualStudio; |
||||
using NUnit.Framework; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests.VisualStudio |
||||
{ |
||||
[TestFixture] |
||||
public class VsPackageInstallerServicesTests |
||||
{ |
||||
VsPackageInstallerServices installerServices; |
||||
IPackageManagementSolution fakeSolution; |
||||
List<IPackage> installedPackages; |
||||
|
||||
void CreatePackageInstallerServices() |
||||
{ |
||||
fakeSolution = MockRepository.GenerateStub<IPackageManagementSolution>(); |
||||
installedPackages = new List<IPackage>(); |
||||
fakeSolution.Stub(s => s.GetPackages()).Return(installedPackages.AsQueryable()); |
||||
installerServices = new VsPackageInstallerServices(fakeSolution); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetInstalledPackages_NoInstalledPackages_ReturnsNoPackages() |
||||
{ |
||||
CreatePackageInstallerServices(); |
||||
|
||||
List<IVsPackageMetadata> packages = installerServices.GetInstalledPackages().ToList(); |
||||
|
||||
Assert.AreEqual(0, packages.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetInstalledPackages_OneInstalledPackages_ReturnsOnePackage() |
||||
{ |
||||
CreatePackageInstallerServices(); |
||||
string installPath = @"d:\projects\MyProject\packages\TestPackage"; |
||||
IPackage installedPackage = AddPackage("Id", "1.1", installPath); |
||||
|
||||
List<IVsPackageMetadata> packages = installerServices.GetInstalledPackages().ToList(); |
||||
|
||||
IVsPackageMetadata package = packages[0]; |
||||
Assert.AreEqual(1, packages.Count); |
||||
Assert.AreEqual("Id", package.Id); |
||||
Assert.AreEqual("1.1", package.Version.ToString()); |
||||
Assert.AreEqual(@"d:\projects\MyProject\packages\TestPackage", package.InstallPath); |
||||
} |
||||
|
||||
IPackage AddPackage(string id, string version, string installPath) |
||||
{ |
||||
var package = new FakePackage(id, version); |
||||
installedPackages.Add(package); |
||||
fakeSolution.Stub(s => s.GetInstallPath(package)).Return(installPath); |
||||
return package; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue