20 changed files with 246 additions and 2 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
// 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.Threading.Tasks; |
||||
using NuGetConsole; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class ConsoleInitializer : IConsoleInitializer |
||||
{ |
||||
IPackageManagementConsoleHost consoleHost; |
||||
|
||||
public ConsoleInitializer(IPackageManagementConsoleHost consoleHost) |
||||
{ |
||||
this.consoleHost = consoleHost; |
||||
} |
||||
|
||||
public Task<Action> Initialize() |
||||
{ |
||||
return Task.Factory.StartNew(() => new Action(consoleHost.SetDefaultRunspace)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
// 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.Scripting; |
||||
using Microsoft.VisualStudio.ComponentModelHost; |
||||
using NuGetConsole; |
||||
|
||||
namespace ICSharpCode.PackageManagement.VisualStudio |
||||
{ |
||||
public class ComponentModel : SComponentModel, IComponentModel |
||||
{ |
||||
IPackageManagementConsoleHost consoleHost; |
||||
|
||||
public ComponentModel(IPackageManagementConsoleHost consoleHost) |
||||
{ |
||||
this.consoleHost = consoleHost; |
||||
} |
||||
|
||||
public ComponentModel() |
||||
{ |
||||
} |
||||
|
||||
public T GetService<T>() |
||||
where T : class |
||||
{ |
||||
return GetService(typeof(T)) as T; |
||||
} |
||||
|
||||
object GetService(Type type) |
||||
{ |
||||
if (type.FullName == typeof(IConsoleInitializer).FullName) { |
||||
return new ConsoleInitializer(GetConsoleHost()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected virtual IPackageManagementConsoleHost GetConsoleHost() |
||||
{ |
||||
if (consoleHost != null) { |
||||
return consoleHost; |
||||
} |
||||
return PackageManagementServices.ConsoleHost; |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
|
||||
namespace Microsoft.VisualStudio.ComponentModelHost |
||||
{ |
||||
public interface IComponentModel |
||||
{ |
||||
T GetService<T>() |
||||
where T : class; |
||||
} |
||||
} |
||||
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
// 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.ComponentModelHost |
||||
{ |
||||
public interface SComponentModel |
||||
{ |
||||
} |
||||
} |
||||
Binary file not shown.
@ -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 ICSharpCode.PackageManagement.Scripting; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class ConsoleInitializerTests |
||||
{ |
||||
ConsoleInitializer initializer; |
||||
FakePackageManagementConsoleHost fakeConsoleHost; |
||||
|
||||
void CreateConsoleInitializer() |
||||
{ |
||||
fakeConsoleHost = new FakePackageManagementConsoleHost(); |
||||
initializer = new ConsoleInitializer(fakeConsoleHost); |
||||
} |
||||
|
||||
[Test] |
||||
public void Initialize_RunInitializeTask_SetsDefaultRunspaceForConsoleHost() |
||||
{ |
||||
CreateConsoleInitializer(); |
||||
|
||||
initializer.Initialize().Result(); |
||||
|
||||
Assert.IsTrue(fakeConsoleHost.IsSetDefaultRunspaceCalled); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// 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.VisualStudio; |
||||
using NuGetConsole; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.VisualStudio |
||||
{ |
||||
[TestFixture] |
||||
public class ComponentModelTests |
||||
{ |
||||
ComponentModel model; |
||||
FakePackageManagementConsoleHost fakeConsoleHost; |
||||
|
||||
void CreateComponentModel() |
||||
{ |
||||
fakeConsoleHost = new FakePackageManagementConsoleHost(); |
||||
model = new ComponentModel(fakeConsoleHost); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetService_GetIConsoleInitializer_ReturnsConsoleInitializer() |
||||
{ |
||||
CreateComponentModel(); |
||||
|
||||
IConsoleInitializer initializer = model.GetService<IConsoleInitializer>(); |
||||
|
||||
Assert.IsNotNull(initializer); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue