40 changed files with 2025 additions and 28 deletions
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// 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 ICSharpCode.PackageManagement; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Design |
||||
{ |
||||
public class FakePackageManagementProjectService : IPackageManagementProjectService |
||||
{ |
||||
public bool IsRefreshProjectBrowserCalled; |
||||
|
||||
public IProject CurrentProject { get; set; } |
||||
public Solution OpenSolution { get; set; } |
||||
|
||||
public event ProjectEventHandler ProjectAdded; |
||||
public event SolutionFolderEventHandler SolutionFolderRemoved; |
||||
public event EventHandler SolutionClosed; |
||||
public event EventHandler<SolutionEventArgs> SolutionLoaded; |
||||
|
||||
public void RefreshProjectBrowser() |
||||
{ |
||||
IsRefreshProjectBrowserCalled = true; |
||||
} |
||||
|
||||
public void FireProjectAddedEvent(IProject project) |
||||
{ |
||||
if (ProjectAdded != null) { |
||||
ProjectAdded(this, new ProjectEventArgs(project)); |
||||
} |
||||
} |
||||
|
||||
public void FireSolutionClosedEvent() |
||||
{ |
||||
if (SolutionClosed != null) { |
||||
SolutionClosed(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
public void FireSolutionLoadedEvent(Solution solution) |
||||
{ |
||||
if (SolutionLoaded != null) { |
||||
SolutionLoaded(this, new SolutionEventArgs(solution)); |
||||
} |
||||
} |
||||
|
||||
public void FireSolutionFolderRemoved(ISolutionFolder solutionFolder) |
||||
{ |
||||
if (SolutionFolderRemoved != null) { |
||||
SolutionFolderRemoved(this, new SolutionFolderEventArgs(solutionFolder)); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// 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.AvalonEdit; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IPackageManagementConsoleHost : IDisposable |
||||
{ |
||||
IProject DefaultProject { get; set; } |
||||
PackageSource ActivePackageSource { get; set; } |
||||
IScriptingConsole ScriptingConsole { get; set; } |
||||
|
||||
void Clear(); |
||||
void Run(); |
||||
} |
||||
} |
@ -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 ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IPowerShellHost |
||||
{ |
||||
void SetRemoteSignedExecutionPolicy(); |
||||
void ExecuteCommand(string command); |
||||
} |
||||
} |
@ -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 ICSharpCode.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IPowerShellHostFactory |
||||
{ |
||||
IPowerShellHost CreatePowerShellHost(IScriptingConsole scriptingConsole); |
||||
} |
||||
} |
@ -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 ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IThread |
||||
{ |
||||
void Start(); |
||||
void Join(); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// 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.AvalonEdit; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageManagementConsole : ThreadSafeScriptingConsole |
||||
{ |
||||
TextEditor textEditor; |
||||
|
||||
public PackageManagementConsole() |
||||
: this(CreateTextEditor()) |
||||
{ |
||||
} |
||||
|
||||
static TextEditor CreateTextEditor() |
||||
{ |
||||
object textEditor; |
||||
EditorControlService.CreateEditor(out textEditor); |
||||
return (TextEditor)textEditor; |
||||
} |
||||
|
||||
public PackageManagementConsole(TextEditor textEditor) |
||||
: this(new ScriptingConsoleTextEditor(textEditor), new ControlDispatcher(textEditor)) |
||||
{ |
||||
this.textEditor = textEditor; |
||||
} |
||||
|
||||
public PackageManagementConsole(IScriptingConsoleTextEditor textEditor, IControlDispatcher dispatcher) |
||||
: this(new ScriptingConsole(textEditor), dispatcher) |
||||
{ |
||||
} |
||||
|
||||
public PackageManagementConsole(IScriptingConsole scriptingConsole, IControlDispatcher dispatcher) |
||||
: base(scriptingConsole, dispatcher) |
||||
{ |
||||
} |
||||
|
||||
public TextEditor TextEditor { |
||||
get { return textEditor; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
// 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; |
||||
using ICSharpCode.AvalonEdit; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageManagementConsoleHost : IPackageManagementConsoleHost |
||||
{ |
||||
IThread thread; |
||||
IPowerShellHostFactory powerShellHostFactory; |
||||
IPowerShellHost powerShellHost; |
||||
int autoIndentSize = 0; |
||||
string prompt = "PM> "; |
||||
|
||||
public PackageManagementConsoleHost(IPowerShellHostFactory powerShellHostFactory) |
||||
{ |
||||
this.powerShellHostFactory = powerShellHostFactory; |
||||
} |
||||
|
||||
public PackageManagementConsoleHost() |
||||
: this(new PowerShellHostFactory()) |
||||
{ |
||||
} |
||||
|
||||
public IProject DefaultProject { get; set; } |
||||
public PackageSource ActivePackageSource { get; set; } |
||||
public IScriptingConsole ScriptingConsole { get; set; } |
||||
|
||||
public void Dispose() |
||||
{ |
||||
if (ScriptingConsole != null) { |
||||
ScriptingConsole.Dispose(); |
||||
} |
||||
|
||||
if (thread != null) { |
||||
thread.Join(); |
||||
thread = null; |
||||
} |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
} |
||||
|
||||
public void Run() |
||||
{ |
||||
thread = CreateThread(RunSynchronous); |
||||
thread.Start(); |
||||
} |
||||
|
||||
protected virtual IThread CreateThread(ThreadStart threadStart) |
||||
{ |
||||
return new PackageManagementThread(threadStart); |
||||
} |
||||
|
||||
void RunSynchronous() |
||||
{ |
||||
InitPowerShell(); |
||||
WritePrompt(); |
||||
ProcessUserCommands(); |
||||
} |
||||
|
||||
void InitPowerShell() |
||||
{ |
||||
CreatePowerShellHost(); |
||||
powerShellHost.SetRemoteSignedExecutionPolicy(); |
||||
} |
||||
|
||||
void CreatePowerShellHost() |
||||
{ |
||||
powerShellHost = powerShellHostFactory.CreatePowerShellHost(ScriptingConsole); |
||||
} |
||||
|
||||
void WritePrompt() |
||||
{ |
||||
ScriptingConsole.Write(prompt, ScriptingStyle.Prompt); |
||||
//textEditor.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { textEditor.ScrollToEnd(); }));
|
||||
} |
||||
|
||||
void ProcessUserCommands() |
||||
{ |
||||
while (true) { |
||||
string line = ScriptingConsole.ReadLine(autoIndentSize); |
||||
if (line != null) { |
||||
ProcessLine(line); |
||||
WritePrompt(); |
||||
} else { |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void ProcessLine(string line) |
||||
{ |
||||
powerShellHost.ExecuteCommand(line); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// 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.Gui; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageManagementConsolePad : AbstractPadContent |
||||
{ |
||||
PackageManagementConsoleView view; |
||||
PackageManagementConsoleViewModel viewModel; |
||||
|
||||
public override object Control { |
||||
get { |
||||
if (view == null) { |
||||
view = new PackageManagementConsoleView(); |
||||
viewModel = view.DataContext as PackageManagementConsoleViewModel; |
||||
} |
||||
return view; |
||||
} |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
if (viewModel != null) { |
||||
viewModel.Dispose(); |
||||
viewModel = null; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
<UserControl |
||||
x:Class="ICSharpCode.PackageManagement.Scripting.PackageManagementConsoleView" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:pmd="clr-namespace:ICSharpCode.PackageManagement" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
mc:Ignorable="d" |
||||
d:DesignHeight="300" |
||||
d:DesignWidth="500"> |
||||
|
||||
<UserControl.Resources> |
||||
<pmd:ViewModelLocator x:Key="ViewModelLocator"/> |
||||
|
||||
<DataTemplate x:Key="PackageSourceTemplate"> |
||||
<TextBlock Text="{Binding Name}"/> |
||||
</DataTemplate> |
||||
|
||||
<DataTemplate x:Key="ProjectTemplate"> |
||||
<TextBlock Text="{Binding Name}"/> |
||||
</DataTemplate> |
||||
|
||||
</UserControl.Resources> |
||||
|
||||
<UserControl.DataContext> |
||||
<Binding Path="PackageManagementConsoleViewModel" Source="{StaticResource ViewModelLocator}"/> |
||||
</UserControl.DataContext> |
||||
|
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="*"/> |
||||
</Grid.RowDefinitions> |
||||
|
||||
<ToolBar> |
||||
<TextBlock |
||||
Margin="4" |
||||
Text="Package Source:"/> |
||||
|
||||
<ComboBox |
||||
Grid.Column="1" |
||||
MinWidth="200" |
||||
SelectedItem="{Binding Path=ActivePackageSource}" |
||||
ItemTemplate="{StaticResource PackageSourceTemplate}" |
||||
ItemsSource="{Binding Path=PackageSources}"/> |
||||
|
||||
<TextBlock |
||||
Grid.Column="2" |
||||
Margin="4" |
||||
Text="Default Project:"/> |
||||
|
||||
<ComboBox |
||||
Grid.Column="3" |
||||
MinWidth="200" |
||||
SelectedItem="{Binding Path=DefaultProject}" |
||||
ItemTemplate="{StaticResource ProjectTemplate}" |
||||
ItemsSource="{Binding Path=Projects}"/> |
||||
|
||||
<Button |
||||
Grid.Column="4" |
||||
ToolTip="{core:Localize MainWindow.Windows.CompilerMessageView.ClearAllButton.ToolTip}" |
||||
Command="{Binding Path=ClearConsoleCommand}"> |
||||
<Image |
||||
Source="{core:GetBitmap OutputPad.Toolbar.ClearOutputWindow}" |
||||
Height="16" |
||||
Width="16"/> |
||||
</Button> |
||||
</ToolBar> |
||||
|
||||
<ContentPresenter |
||||
Grid.Row="1" |
||||
Margin="4, 0" |
||||
Content="{Binding TextEditor}"/> |
||||
</Grid> |
||||
</UserControl> |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// 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.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public partial class PackageManagementConsoleView : UserControl |
||||
{ |
||||
public PackageManagementConsoleView() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,200 @@
@@ -0,0 +1,200 @@
|
||||
// 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.Collections.ObjectModel; |
||||
using System.Collections.Specialized; |
||||
using System.Linq; |
||||
using System.Windows.Input; |
||||
|
||||
using ICSharpCode.AvalonEdit; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageManagementConsoleViewModel : ViewModelBase<PackageManagementConsoleViewModel> |
||||
{ |
||||
IPackageManagementService packageManagementService; |
||||
IPackageManagementProjectService projectService; |
||||
IPackageManagementConsoleHost consoleHost; |
||||
|
||||
DelegateCommand clearConsoleCommand; |
||||
|
||||
ObservableCollection<PackageSourceViewModel> packageSources = new ObservableCollection<PackageSourceViewModel>(); |
||||
PackageSourceViewModel activePackageSource; |
||||
|
||||
ObservableCollection<IProject> projects = new ObservableCollection<IProject>(); |
||||
|
||||
PackageManagementConsole packageManagementConsole; |
||||
|
||||
public PackageManagementConsoleViewModel( |
||||
IPackageManagementService packageManagementService, |
||||
IPackageManagementConsoleHost consoleHost) |
||||
{ |
||||
this.packageManagementService = packageManagementService; |
||||
this.projectService = packageManagementService.ProjectService; |
||||
this.consoleHost = consoleHost; |
||||
|
||||
Init(); |
||||
} |
||||
|
||||
void Init() |
||||
{ |
||||
CreateCommands(); |
||||
UpdatePackageSourceViewModels(); |
||||
ReceiveNotificationsWhenPackageSourcesUpdated(); |
||||
AddProjects(); |
||||
ReceiveNotificationsWhenSolutionIsUpdated(); |
||||
InitConsoleHost(); |
||||
} |
||||
|
||||
void InitConsoleHost() |
||||
{ |
||||
packageManagementConsole = CreateConsole(); |
||||
consoleHost.ScriptingConsole = packageManagementConsole; |
||||
consoleHost.Run(); |
||||
} |
||||
|
||||
protected virtual PackageManagementConsole CreateConsole() |
||||
{ |
||||
return new PackageManagementConsole(); |
||||
} |
||||
|
||||
void CreateCommands() |
||||
{ |
||||
clearConsoleCommand = new DelegateCommand(param => ClearConsole()); |
||||
} |
||||
|
||||
public ICommand ClearConsoleCommand { |
||||
get { return clearConsoleCommand; } |
||||
} |
||||
|
||||
public void ClearConsole() |
||||
{ |
||||
consoleHost.Clear(); |
||||
} |
||||
|
||||
void UpdatePackageSourceViewModels() |
||||
{ |
||||
packageSources.Clear(); |
||||
foreach (PackageSource packageSource in packageManagementService.Options.PackageSources) { |
||||
AddPackageSourceViewModel(packageSource); |
||||
} |
||||
SelectFirstActivePackageSource(); |
||||
} |
||||
|
||||
void AddPackageSourceViewModel(PackageSource packageSource) |
||||
{ |
||||
var viewModel = new PackageSourceViewModel(packageSource); |
||||
packageSources.Add(viewModel); |
||||
} |
||||
|
||||
void SelectFirstActivePackageSource() |
||||
{ |
||||
if (packageSources.Count > 0) { |
||||
ActivePackageSource = packageSources[0]; |
||||
} |
||||
} |
||||
|
||||
void ReceiveNotificationsWhenPackageSourcesUpdated() |
||||
{ |
||||
packageManagementService.Options.PackageSources.CollectionChanged += PackageSourcesChanged; |
||||
} |
||||
|
||||
void PackageSourcesChanged(object sender, NotifyCollectionChangedEventArgs e) |
||||
{ |
||||
UpdatePackageSourceViewModels(); |
||||
} |
||||
|
||||
void AddProjects() |
||||
{ |
||||
Solution solution = projectService.OpenSolution; |
||||
if (solution != null) { |
||||
AddProjects(solution); |
||||
} |
||||
UpdateDefaultProject(); |
||||
} |
||||
|
||||
void UpdateDefaultProject() |
||||
{ |
||||
DefaultProject = projects.FirstOrDefault(); |
||||
} |
||||
|
||||
void AddProjects(Solution solution) |
||||
{ |
||||
foreach (IProject project in solution.Projects) { |
||||
projects.Add(project); |
||||
} |
||||
} |
||||
|
||||
void ReceiveNotificationsWhenSolutionIsUpdated() |
||||
{ |
||||
projectService.ProjectAdded += ProjectAdded; |
||||
projectService.SolutionClosed += SolutionClosed; |
||||
projectService.SolutionLoaded += SolutionLoaded; |
||||
projectService.SolutionFolderRemoved += SolutionFolderRemoved; |
||||
} |
||||
|
||||
void ProjectAdded(object sender, ProjectEventArgs e) |
||||
{ |
||||
projects.Add(e.Project); |
||||
UpdateDefaultProject(); |
||||
} |
||||
|
||||
void SolutionClosed(object sender, EventArgs e) |
||||
{ |
||||
projects.Clear(); |
||||
DefaultProject = null; |
||||
} |
||||
|
||||
void SolutionLoaded(object sender, SolutionEventArgs e) |
||||
{ |
||||
AddProjects(e.Solution); |
||||
UpdateDefaultProject(); |
||||
} |
||||
|
||||
void SolutionFolderRemoved(object sender, SolutionFolderEventArgs e) |
||||
{ |
||||
IProject project = e.SolutionFolder as IProject; |
||||
projects.Remove(project); |
||||
UpdateDefaultProject(); |
||||
} |
||||
|
||||
public ObservableCollection<PackageSourceViewModel> PackageSources { |
||||
get { return packageSources; } |
||||
} |
||||
|
||||
public PackageSourceViewModel ActivePackageSource { |
||||
get { return activePackageSource; } |
||||
set { |
||||
activePackageSource = value; |
||||
consoleHost.ActivePackageSource = activePackageSource.GetPackageSource(); |
||||
OnPropertyChanged(viewModel => viewModel.ActivePackageSource); |
||||
} |
||||
} |
||||
|
||||
public ObservableCollection<IProject> Projects { |
||||
get { return projects; } |
||||
} |
||||
|
||||
public IProject DefaultProject { |
||||
get { return consoleHost.DefaultProject; } |
||||
set { |
||||
consoleHost.DefaultProject = value; |
||||
OnPropertyChanged(viewModel => viewModel.DefaultProject); |
||||
} |
||||
} |
||||
|
||||
public TextEditor TextEditor { |
||||
get { return packageManagementConsole.TextEditor; } |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
consoleHost.Dispose(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// 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; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageManagementThread : IThread |
||||
{ |
||||
Thread thread; |
||||
|
||||
public PackageManagementThread(ThreadStart threadStart) |
||||
{ |
||||
thread = new Thread(threadStart); |
||||
} |
||||
|
||||
public void Start() |
||||
{ |
||||
thread.Start(); |
||||
} |
||||
|
||||
public void Join() |
||||
{ |
||||
thread.Join(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,136 @@
@@ -0,0 +1,136 @@
|
||||
// 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.Globalization; |
||||
using System.Management.Automation.Host; |
||||
using System.Management.Automation.Runspaces; |
||||
using System.Threading; |
||||
|
||||
using ICSharpCode.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PowerShellHost : PSHost, IPowerShellHost |
||||
{ |
||||
IScriptingConsole scriptingConsole; |
||||
CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; |
||||
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; |
||||
Guid instanceId = Guid.NewGuid(); |
||||
Version version = new Version(0, 1); |
||||
Runspace runspace; |
||||
PowerShellHostUserInterface userInterface; |
||||
//SharpDevelopEnvDTE dte = new SharpDevelopEnvDTE();
|
||||
|
||||
public PowerShellHost(IScriptingConsole scriptingConsole) |
||||
{ |
||||
this.scriptingConsole = scriptingConsole; |
||||
userInterface = new PowerShellHostUserInterface(scriptingConsole); |
||||
} |
||||
|
||||
public void SetRemoteSignedExecutionPolicy() |
||||
{ |
||||
ExecuteCommand("Set-ExecutionPolicy RemoteSigned -Scope 0 -Force"); |
||||
} |
||||
|
||||
public void ExecuteCommand(string command) |
||||
{ |
||||
try { |
||||
CreateRunspace(); |
||||
|
||||
Pipeline pipeline = CreatePipeline(command); |
||||
pipeline.Invoke(); |
||||
|
||||
} catch (Exception ex) { |
||||
scriptingConsole.WriteLine(ex.Message, ScriptingStyle.Error); |
||||
} |
||||
} |
||||
|
||||
Pipeline CreatePipeline(string command) |
||||
{ |
||||
Pipeline pipeline = runspace.CreatePipeline(); |
||||
pipeline.Commands.AddScript(command); |
||||
pipeline.Commands.Add("out-default"); |
||||
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); |
||||
return pipeline; |
||||
} |
||||
|
||||
void CreateRunspace() |
||||
{ |
||||
if (runspace == null) { |
||||
var initialSessionState = InitialSessionState.CreateDefault(); |
||||
//var options = ScopedItemOptions.AllScope | ScopedItemOptions.Constant;
|
||||
//var variable = new SessionStateVariableEntry("DTE", dte, "SharpDevelop DTE object", options);
|
||||
//initialSessionState.Variables.Add(variable);
|
||||
|
||||
runspace = RunspaceFactory.CreateRunspace(this); //, initialSessionState);
|
||||
runspace.Open(); |
||||
} |
||||
} |
||||
|
||||
public override Version Version { |
||||
get { return version; } |
||||
} |
||||
|
||||
public override PSHostUserInterface UI { |
||||
get { return userInterface; } |
||||
} |
||||
|
||||
public override void SetShouldExit(int exitCode) |
||||
{ |
||||
} |
||||
|
||||
public override void NotifyEndApplication() |
||||
{ |
||||
} |
||||
|
||||
public override void NotifyBeginApplication() |
||||
{ |
||||
} |
||||
|
||||
public override string Name { |
||||
get { return "PowerShell Host"; } |
||||
} |
||||
|
||||
public override Guid InstanceId { |
||||
get { return instanceId; } |
||||
} |
||||
|
||||
public override void ExitNestedPrompt() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override void EnterNestedPrompt() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override CultureInfo CurrentUICulture { |
||||
get { return currentUICulture; } |
||||
} |
||||
|
||||
public override CultureInfo CurrentCulture { |
||||
get { return currentCulture; } |
||||
} |
||||
|
||||
public void RunScript(string fileName, IEnumerable<object> input) |
||||
{ |
||||
try { |
||||
CreateRunspace(); |
||||
|
||||
string command = |
||||
"$__args = @(); " + |
||||
"$input | ForEach-Object {$__args += $_}; " + |
||||
"& '" + fileName + "' $__args[0] $__args[1] $__args[2] $__args[3]" + |
||||
"Remove-Variable __args -Scope 0"; |
||||
Pipeline pipeline = CreatePipeline(command); |
||||
pipeline.Invoke(input); |
||||
|
||||
} catch (Exception ex) { |
||||
scriptingConsole.WriteLine(ex.Message, ScriptingStyle.Error); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// 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.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PowerShellHostFactory : IPowerShellHostFactory |
||||
{ |
||||
public IPowerShellHost CreatePowerShellHost(IScriptingConsole scriptingConsole) |
||||
{ |
||||
return new PowerShellHost(scriptingConsole); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
// 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.Collections.ObjectModel; |
||||
using System.Management.Automation; |
||||
using System.Management.Automation.Host; |
||||
using System.Security; |
||||
|
||||
using ICSharpCode.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PowerShellHostUserInterface : PSHostUserInterface |
||||
{ |
||||
IScriptingConsole scriptingConsole; |
||||
|
||||
public PowerShellHostUserInterface(IScriptingConsole scriptingConsole) |
||||
{ |
||||
this.scriptingConsole = scriptingConsole; |
||||
} |
||||
|
||||
public override void WriteWarningLine(string message) |
||||
{ |
||||
scriptingConsole.WriteLine(message, ScriptingStyle.Warning); |
||||
} |
||||
|
||||
public override void WriteVerboseLine(string message) |
||||
{ |
||||
scriptingConsole.WriteLine(message, ScriptingStyle.Out); |
||||
} |
||||
|
||||
public override void WriteProgress(long sourceId, ProgressRecord record) |
||||
{ |
||||
} |
||||
|
||||
public override void WriteLine(string value) |
||||
{ |
||||
scriptingConsole.WriteLine(value, ScriptingStyle.Out); |
||||
} |
||||
|
||||
public override void WriteErrorLine(string value) |
||||
{ |
||||
scriptingConsole.WriteLine(value, ScriptingStyle.Error); |
||||
} |
||||
|
||||
public override void WriteDebugLine(string message) |
||||
{ |
||||
scriptingConsole.WriteLine(message, ScriptingStyle.Out); |
||||
} |
||||
|
||||
public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) |
||||
{ |
||||
scriptingConsole.Write(value, ScriptingStyle.Out); |
||||
} |
||||
|
||||
public override void Write(string value) |
||||
{ |
||||
scriptingConsole.Write(value, ScriptingStyle.Out); |
||||
} |
||||
|
||||
public override SecureString ReadLineAsSecureString() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override string ReadLine() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override PSHostRawUserInterface RawUI { |
||||
get { return null; } |
||||
} |
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice) |
||||
{ |
||||
// No choice.
|
||||
return -1; |
||||
} |
||||
|
||||
public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// 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.AvalonEdit; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NuGet; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakePackageManagementConsoleHost : IPackageManagementConsoleHost |
||||
{ |
||||
public IProject DefaultProject { get; set; } |
||||
public PackageSource ActivePackageSource { get; set; } |
||||
public IScriptingConsole ScriptingConsole { get; set; } |
||||
|
||||
public bool IsDisposeCalled; |
||||
public bool IsClearCalled; |
||||
public bool IsRunCalled; |
||||
|
||||
public void Dispose() |
||||
{ |
||||
IsDisposeCalled = true; |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
IsClearCalled = true; |
||||
} |
||||
|
||||
public void Run() |
||||
{ |
||||
IsRunCalled = true; |
||||
} |
||||
} |
||||
} |
@ -1,21 +0,0 @@
@@ -1,21 +0,0 @@
|
||||
// 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 ICSharpCode.PackageManagement; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakePackageManagementProjectService : IPackageManagementProjectService |
||||
{ |
||||
public bool IsRefreshProjectBrowserCalled; |
||||
|
||||
public IProject CurrentProject { get; set; } |
||||
|
||||
public void RefreshProjectBrowser() |
||||
{ |
||||
IsRefreshProjectBrowserCalled = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// 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 ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakePowerShellHost : IPowerShellHost |
||||
{ |
||||
public bool IsSetRemoteSignedExecutionPolicyCalled; |
||||
|
||||
public void SetRemoteSignedExecutionPolicy() |
||||
{ |
||||
IsSetRemoteSignedExecutionPolicyCalled = true; |
||||
} |
||||
|
||||
public string CommandPassedToExecuteCommand; |
||||
public List<string> AllCommandsPassedToExecuteCommand = new List<string>(); |
||||
|
||||
public void ExecuteCommand(string command) |
||||
{ |
||||
CommandPassedToExecuteCommand = command; |
||||
AllCommandsPassedToExecuteCommand.Add(command); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// 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 ICSharpCode.Scripting; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakePowerShellHostFactory : IPowerShellHostFactory |
||||
{ |
||||
public IScriptingConsole ScriptingConsolePassedToCreatePowerShellHost; |
||||
public FakePowerShellHost FakePowerShellHost = new FakePowerShellHost(); |
||||
|
||||
public IPowerShellHost CreatePowerShellHost(IScriptingConsole scriptingConsole) |
||||
{ |
||||
ScriptingConsolePassedToCreatePowerShellHost = scriptingConsole; |
||||
return FakePowerShellHost; |
||||
} |
||||
} |
||||
} |
@ -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.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakeScriptingConsoleWithLinesToRead : FakeScriptingConsole |
||||
{ |
||||
public List<string> AllTextToReturnFromReadLine = new List<string>(); |
||||
|
||||
public override string ReadLine(int autoIndentSize) |
||||
{ |
||||
string line = AllTextToReturnFromReadLine.FirstOrDefault(); |
||||
if (AllTextToReturnFromReadLine.Any()) { |
||||
AllTextToReturnFromReadLine.RemoveAt(0); |
||||
} |
||||
return line; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
// 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; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakeThread : IThread |
||||
{ |
||||
public bool IsStartCalled; |
||||
public bool IsJoinCalled; |
||||
|
||||
public void Start() |
||||
{ |
||||
IsStartCalled = true; |
||||
} |
||||
|
||||
public void Join() |
||||
{ |
||||
IsJoinCalled = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// 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; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class TestablePackageManagementConsoleHost : PackageManagementConsoleHost |
||||
{ |
||||
public FakeScriptingConsoleWithLinesToRead FakeScriptingConsole; |
||||
public FakeThread FakeThread = new FakeThread(); |
||||
public ThreadStart ThreadStartPassedToCreateThread; |
||||
public FakePowerShellHostFactory FakePowerShellHostFactory; |
||||
|
||||
public TestablePackageManagementConsoleHost() |
||||
: this(new FakeScriptingConsoleWithLinesToRead(), new FakePowerShellHostFactory()) |
||||
{ |
||||
} |
||||
|
||||
public TestablePackageManagementConsoleHost( |
||||
FakeScriptingConsoleWithLinesToRead scriptingConsole, |
||||
FakePowerShellHostFactory powerShellHostFactory) |
||||
: base(powerShellHostFactory) |
||||
{ |
||||
this.FakeScriptingConsole = scriptingConsole; |
||||
this.ScriptingConsole = scriptingConsole; |
||||
this.FakePowerShellHostFactory = powerShellHostFactory; |
||||
} |
||||
|
||||
protected override IThread CreateThread(ThreadStart threadStart) |
||||
{ |
||||
ThreadStartPassedToCreateThread = threadStart; |
||||
return FakeThread; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// 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; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class TestablePackageManagementConsoleViewModel : PackageManagementConsoleViewModel |
||||
{ |
||||
public PackageManagementConsole FakeConsole = |
||||
new PackageManagementConsole(new FakeScriptingConsole(), new FakeControlDispatcher()); |
||||
|
||||
public TestablePackageManagementConsoleViewModel( |
||||
IPackageManagementService packageManagementService, |
||||
IPackageManagementConsoleHost consoleHost) |
||||
: base(packageManagementService, consoleHost) |
||||
{ |
||||
} |
||||
|
||||
protected override PackageManagementConsole CreateConsole() |
||||
{ |
||||
return FakeConsole; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,171 @@
@@ -0,0 +1,171 @@
|
||||
// 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 ICSharpCode.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class PackageManagementConsoleHostTests |
||||
{ |
||||
TestablePackageManagementConsoleHost host; |
||||
FakeScriptingConsoleWithLinesToRead scriptingConsole; |
||||
FakePowerShellHost powerShellHost; |
||||
|
||||
void CreateHost() |
||||
{ |
||||
host = new TestablePackageManagementConsoleHost(); |
||||
scriptingConsole = host.FakeScriptingConsole; |
||||
|
||||
powerShellHost = host.FakePowerShellHostFactory.FakePowerShellHost; |
||||
} |
||||
|
||||
void RunHost() |
||||
{ |
||||
host.Run(); |
||||
host.ThreadStartPassedToCreateThread.Invoke(); |
||||
} |
||||
|
||||
[Test] |
||||
public void Dispose_ScriptingConsoleIsNotNull_ScriptingConsoleIsDisposed() |
||||
{ |
||||
CreateHost(); |
||||
host.Dispose(); |
||||
|
||||
Assert.IsTrue(scriptingConsole.IsDisposeCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Dispose_ScriptingConsoleIsNull_NullReferenceExceptionIsNotThrown() |
||||
{ |
||||
CreateHost(); |
||||
host.ScriptingConsole = null; |
||||
|
||||
Assert.DoesNotThrow(() => host.Dispose()); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRun_StartsThreadToProcessCommandsEnteredIntoConsole() |
||||
{ |
||||
CreateHost(); |
||||
host.Run(); |
||||
|
||||
Assert.IsTrue(host.FakeThread.IsStartCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Dispose_ConsoleHostRunCalled_ThreadJoinIsCalled() |
||||
{ |
||||
CreateHost(); |
||||
host.Run(); |
||||
host.Dispose(); |
||||
|
||||
Assert.IsTrue(host.FakeThread.IsJoinCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Dispose_DisposeCalledTwiceAfterConsoleHostIsRun_ThreadJoinIsCalledOnce() |
||||
{ |
||||
CreateHost(); |
||||
host.Run(); |
||||
host.Dispose(); |
||||
host.FakeThread.IsJoinCalled = false; |
||||
|
||||
host.Dispose(); |
||||
|
||||
Assert.IsFalse(host.FakeThread.IsJoinCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleExitsOnFirstRead_PowerShellHostIsCreated() |
||||
{ |
||||
CreateHost(); |
||||
RunHost(); |
||||
|
||||
var actualConsole = host.FakePowerShellHostFactory.ScriptingConsolePassedToCreatePowerShellHost; |
||||
var expectedConsole = scriptingConsole; |
||||
|
||||
Assert.AreSame(expectedConsole, actualConsole); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleExitsOnFirstRead_InitialPowerShellExecutionPolicySet() |
||||
{ |
||||
CreateHost(); |
||||
RunHost(); |
||||
|
||||
Assert.IsTrue(powerShellHost.IsSetRemoteSignedExecutionPolicyCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleExitsOnFirstRead_PromptTextWrittenToConsole() |
||||
{ |
||||
CreateHost(); |
||||
RunHost(); |
||||
var expectedTextPassedToWrite = new String[] { "PM> "}; |
||||
var actualTextPassedToWrite = scriptingConsole.AllTextPassedToWrite; |
||||
|
||||
CollectionAssert.AreEqual(expectedTextPassedToWrite, actualTextPassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleExitsOnFirstRead_PromptTextWrittenWithPromptyStyleToConsole() |
||||
{ |
||||
CreateHost(); |
||||
RunHost(); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Prompt, scriptingConsole.ScriptingStylePassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_OneCommandEntered_CommandExecutedByPowerShellHost() |
||||
{ |
||||
CreateHost(); |
||||
scriptingConsole.AllTextToReturnFromReadLine.Add("RunThis"); |
||||
RunHost(); |
||||
|
||||
Assert.AreEqual("RunThis", powerShellHost.CommandPassedToExecuteCommand); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_OneCommandEntered_CommandPromptDisplayedAgain() |
||||
{ |
||||
CreateHost(); |
||||
scriptingConsole.AllTextToReturnFromReadLine.Add("RunThis"); |
||||
RunHost(); |
||||
|
||||
var expectedTextPassedToWrite = new String[] { "PM> ", "PM> "}; |
||||
var actualTextPassedToWrite = scriptingConsole.AllTextPassedToWrite; |
||||
|
||||
CollectionAssert.AreEqual(expectedTextPassedToWrite, actualTextPassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleExitsOnFirstRead_NoCommandsPassedToPowerShellHost() |
||||
{ |
||||
CreateHost(); |
||||
powerShellHost.CommandPassedToExecuteCommand = "test"; |
||||
RunHost(); |
||||
|
||||
Assert.AreEqual("test", powerShellHost.CommandPassedToExecuteCommand); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_TwoCommandsEnteredByUser_BothCommandsExecuted() |
||||
{ |
||||
CreateHost(); |
||||
var commands = new string[] { "one", "two" }; |
||||
scriptingConsole.AllTextToReturnFromReadLine.AddRange(commands); |
||||
|
||||
host.ScriptingConsole = scriptingConsole; |
||||
RunHost(); |
||||
|
||||
Assert.AreEqual(commands, powerShellHost.AllCommandsPassedToExecuteCommand); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,450 @@
@@ -0,0 +1,450 @@
|
||||
// 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.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class PackageManagementConsoleViewModelTests |
||||
{ |
||||
TestablePackageManagementConsoleViewModel viewModel; |
||||
FakePackageManagementService packageManagementService; |
||||
FakePackageManagementProjectService projectService; |
||||
FakePackageManagementConsoleHost consoleHost; |
||||
List<string> propertiesChanged; |
||||
|
||||
void CreatePackageManagementServices() |
||||
{ |
||||
packageManagementService = new FakePackageManagementService(); |
||||
projectService = packageManagementService.FakeProjectService; |
||||
consoleHost = new FakePackageManagementConsoleHost(); |
||||
} |
||||
|
||||
void CreateViewModel() |
||||
{ |
||||
CreatePackageManagementServices(); |
||||
CreateViewModel(packageManagementService); |
||||
} |
||||
|
||||
void CreateViewModel(IPackageManagementService packageManagementService) |
||||
{ |
||||
viewModel = new TestablePackageManagementConsoleViewModel(packageManagementService, consoleHost); |
||||
} |
||||
|
||||
void CreateViewModelWithOneRegisteredPackageSource() |
||||
{ |
||||
CreatePackageManagementServices(); |
||||
AddOnePackageSourceAndRemoveAnyExistingPackageSources(); |
||||
CreateViewModel(packageManagementService); |
||||
} |
||||
|
||||
Solution CreateViewModelWithOneProjectOpen() |
||||
{ |
||||
CreatePackageManagementServices(); |
||||
Solution solution = CreateSolutionWithOneProject(); |
||||
projectService.OpenSolution = solution; |
||||
CreateViewModel(packageManagementService); |
||||
|
||||
return solution; |
||||
} |
||||
|
||||
Solution CreateSolutionWithOneProject() |
||||
{ |
||||
TestableProject project = ProjectHelper.CreateTestProject(); |
||||
Solution solution = project.ParentSolution; |
||||
solution.AddFolder(project); |
||||
|
||||
return solution; |
||||
} |
||||
|
||||
void AddOnePackageSourceAndRemoveAnyExistingPackageSources() |
||||
{ |
||||
packageManagementService.ClearPackageSources(); |
||||
AddOnePackageSource(); |
||||
} |
||||
|
||||
void AddOnePackageSource() |
||||
{ |
||||
AddOnePackageSource("NewSource"); |
||||
} |
||||
|
||||
void AddOnePackageSource(string name) |
||||
{ |
||||
packageManagementService.AddOnePackageSource(name); |
||||
} |
||||
|
||||
PackageSourceViewModel SelectSecondPackageSource() |
||||
{ |
||||
var selectedPackageSource = viewModel.PackageSources[1]; |
||||
viewModel.ActivePackageSource = selectedPackageSource; |
||||
return selectedPackageSource; |
||||
} |
||||
|
||||
void RecordPropertyChangedEvents() |
||||
{ |
||||
propertiesChanged = new List<string>(); |
||||
viewModel.PropertyChanged += (sender, e) => propertiesChanged.Add(e.PropertyName); |
||||
} |
||||
|
||||
Solution CreatePackageManagementServiceWithEmptySolutionOpen() |
||||
{ |
||||
CreatePackageManagementServices(); |
||||
var solution = new Solution(); |
||||
projectService.OpenSolution = solution; |
||||
return solution; |
||||
} |
||||
|
||||
Solution CreateViewModelWithEmptySolutionOpen() |
||||
{ |
||||
var solution = CreatePackageManagementServiceWithEmptySolutionOpen(); |
||||
CreateViewModel(packageManagementService); |
||||
return solution; |
||||
} |
||||
|
||||
TestableProject AddProjectToSolution(Solution solution) |
||||
{ |
||||
var project = ProjectHelper.CreateTestProject(); |
||||
solution.AddFolder(project); |
||||
return project; |
||||
} |
||||
|
||||
void CloseSolution() |
||||
{ |
||||
projectService.OpenSolution = null; |
||||
projectService.FireSolutionClosedEvent(); |
||||
} |
||||
|
||||
void OpenSolution(Solution solution) |
||||
{ |
||||
projectService.OpenSolution = solution; |
||||
projectService.FireSolutionLoadedEvent(solution); |
||||
} |
||||
|
||||
IProject RemoveProjectFromSolution(Solution solution) |
||||
{ |
||||
var project = solution.Projects.FirstOrDefault(); |
||||
solution.RemoveFolder(project); |
||||
return project; |
||||
} |
||||
|
||||
[Test] |
||||
public void PackageSources_OneRegisteredPackageSourceWhenConsoleCreated_OnePackageSourceDisplayed() |
||||
{ |
||||
CreateViewModelWithOneRegisteredPackageSource(); |
||||
|
||||
var expectedPackageSources = packageManagementService.Options.PackageSources; |
||||
var actualPackageSources = viewModel.PackageSources; |
||||
|
||||
PackageSourceCollectionAssert.AreEqual(expectedPackageSources, actualPackageSources); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_OneRegisteredPackageSourceWhenConsoleCreated_SinglePackageSourceIsActivePackageSource() |
||||
{ |
||||
CreateViewModelWithOneRegisteredPackageSource(); |
||||
var expectedPackageSource = packageManagementService.Options.PackageSources[0]; |
||||
var actualPackageSource = viewModel.ActivePackageSource.GetPackageSource(); |
||||
|
||||
Assert.AreEqual(expectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void PackageSources_OriginalPackageSourceRemovedAndOnePackageSourceAddedAfterConsoleCreated_NewPackageSourceIsDisplayed() |
||||
{ |
||||
CreateViewModel(); |
||||
AddOnePackageSourceAndRemoveAnyExistingPackageSources(); |
||||
|
||||
var expectedPackageSources = packageManagementService.Options.PackageSources; |
||||
var actualPackageSources = viewModel.PackageSources; |
||||
|
||||
PackageSourceCollectionAssert.AreEqual(expectedPackageSources, actualPackageSources); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_OriginalPackageSourceRemovedAndOnePackageSourceAddedAfterConsoleCreated_ActivePackageSourceIsUpdatedToNewPackageSource() |
||||
{ |
||||
CreateViewModel(); |
||||
AddOnePackageSourceAndRemoveAnyExistingPackageSources(); |
||||
|
||||
var expectedPackageSource = packageManagementService.Options.PackageSources[0]; |
||||
var actualPackageSource = viewModel.ActivePackageSource.GetPackageSource(); |
||||
|
||||
Assert.AreEqual(expectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_OriginalPackageSourceRemovedAndOnePackageSourceAddedAfterConsoleCreated_PropertyChangedEventFiredForActivePackageSource() |
||||
{ |
||||
CreateViewModel(); |
||||
RecordPropertyChangedEvents(); |
||||
AddOnePackageSourceAndRemoveAnyExistingPackageSources(); |
||||
|
||||
bool result = propertiesChanged.Contains("ActivePackageSource"); |
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_TwoPackageSourcesAndActivePackageSourceChangedToSecondOne_ActivePackageSourceChoiceIsRemembered() |
||||
{ |
||||
CreateViewModel(); |
||||
AddOnePackageSource(); |
||||
var selectedPackageSource = SelectSecondPackageSource(); |
||||
|
||||
var actualPackageSource = viewModel.ActivePackageSource; |
||||
|
||||
Assert.AreEqual(selectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_OnePackageSourceAddedAfterSelectingSecondPackageSource_ActivePackageSourceIsChangedToFirstPackageSource() |
||||
{ |
||||
CreateViewModel(); |
||||
AddOnePackageSource(); |
||||
SelectSecondPackageSource(); |
||||
AddOnePackageSource("ThirdPackageSource"); |
||||
|
||||
var expectedPackageSource = viewModel.PackageSources[0]; |
||||
var actualPackageSource = viewModel.ActivePackageSource; |
||||
|
||||
Assert.AreEqual(expectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_SelectedPackageSourceIsRemoved_ActivePackageSourceIsChangedToFirstPackageSource() |
||||
{ |
||||
CreateViewModel(); |
||||
AddOnePackageSource(); |
||||
SelectSecondPackageSource(); |
||||
packageManagementService.Options.PackageSources.RemoveAt(1); |
||||
|
||||
var expectedPackageSource = viewModel.PackageSources[0]; |
||||
var actualPackageSource = viewModel.ActivePackageSource; |
||||
|
||||
Assert.AreEqual(expectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_OneProjectOpenWhenConsoleCreated_OpenProjectIsInProjectsCollection() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var expectedProjects = solution.Projects; |
||||
var actualProjects = viewModel.Projects; |
||||
|
||||
CollectionAssert.AreEqual(expectedProjects, actualProjects); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_OneProjectOpenWhenConsoleCreated_OpenProjectIsDefaultProject() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var expectedProject = solution.Projects.First(); |
||||
var actualProject = viewModel.DefaultProject; |
||||
|
||||
Assert.AreEqual(expectedProject, actualProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void Constructor_EmptySolutionOpenWhenConsoleCreated_DoesNotThrowException() |
||||
{ |
||||
CreatePackageManagementServiceWithEmptySolutionOpen(); |
||||
Assert.DoesNotThrow(() => CreateViewModel(packageManagementService)); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_ProjectAddedToEmptySolution_ProjectDisplayed() |
||||
{ |
||||
var solution = CreateViewModelWithEmptySolutionOpen(); |
||||
var project = AddProjectToSolution(solution); |
||||
projectService.FireProjectAddedEvent(project); |
||||
|
||||
var actualProjects = viewModel.Projects; |
||||
var expectedProjects = solution.Projects; |
||||
|
||||
CollectionAssert.AreEqual(expectedProjects, actualProjects); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_ProjectAddedToEmptySolution_ProjectAddedIsDefaultProject() |
||||
{ |
||||
var solution = CreateViewModelWithEmptySolutionOpen(); |
||||
var project = AddProjectToSolution(solution); |
||||
projectService.FireProjectAddedEvent(project); |
||||
|
||||
var actualProject = viewModel.DefaultProject; |
||||
|
||||
Assert.AreEqual(project, actualProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_SolutionClosed_ProjectsRemovedFromList() |
||||
{ |
||||
CreateViewModelWithOneProjectOpen(); |
||||
CloseSolution(); |
||||
|
||||
int count = viewModel.Projects.Count; |
||||
|
||||
Assert.AreEqual(0, count); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_SolutionClosed_DefaultProjectIsSetToNull() |
||||
{ |
||||
CreateViewModelWithOneProjectOpen(); |
||||
CloseSolution(); |
||||
|
||||
Assert.IsNull(viewModel.DefaultProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_SolutionClosed_PropertyChangedEventFiredForDefaultProject() |
||||
{ |
||||
CreateViewModelWithOneProjectOpen(); |
||||
RecordPropertyChangedEvents(); |
||||
CloseSolution(); |
||||
|
||||
bool result = propertiesChanged.Contains("DefaultProject"); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_SolutionWithOneProjectLoaded_ProjectsListUpdated() |
||||
{ |
||||
CreateViewModel(); |
||||
var solution = CreateSolutionWithOneProject(); |
||||
OpenSolution(solution); |
||||
|
||||
var actualProjects = viewModel.Projects; |
||||
var expectedProjects = solution.Projects; |
||||
|
||||
CollectionAssert.AreEqual(expectedProjects, actualProjects); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_SolutionWithOneProjectLoaded_DefaultProjectIsSetToProjectInSolution() |
||||
{ |
||||
CreateViewModel(); |
||||
var solution = CreateSolutionWithOneProject(); |
||||
OpenSolution(solution); |
||||
|
||||
var actualProject = viewModel.DefaultProject; |
||||
var expectedProject = viewModel.Projects[0]; |
||||
|
||||
Assert.AreEqual(expectedProject, actualProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_SolutionWithOneProjectLoaded_PropertyChangedEventFiredForDefaultProjectI() |
||||
{ |
||||
CreateViewModel(); |
||||
var solution = CreateSolutionWithOneProject(); |
||||
RecordPropertyChangedEvents(); |
||||
OpenSolution(solution); |
||||
|
||||
bool result = propertiesChanged.Contains("DefaultProject"); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_ProjectRemovedFromSolution_ProjectRemovedFromList() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var project = RemoveProjectFromSolution(solution); |
||||
projectService.FireSolutionFolderRemoved(project); |
||||
|
||||
var actualProjects = viewModel.Projects; |
||||
var expectedProjects = solution.Projects; |
||||
|
||||
CollectionAssert.AreEqual(expectedProjects, actualProjects); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_ProjectRemovedFromSolution_DefaultProjectIsUpdated() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var project = RemoveProjectFromSolution(solution); |
||||
projectService.FireSolutionFolderRemoved(project); |
||||
|
||||
var actualProject = viewModel.DefaultProject; |
||||
|
||||
Assert.IsNull(actualProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void Projects_SolutionFolderRemovedFromSolution_ProjectListIsUnchanged() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var solutionFolder = new SolutionFolder("Test", "Location", "Guid"); |
||||
projectService.FireSolutionFolderRemoved(solutionFolder); |
||||
|
||||
int count = viewModel.Projects.Count; |
||||
|
||||
Assert.AreEqual(1, count); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultProject_OneProjectOpenWhenConsoleCreated_DefaultProjectSetForConsole() |
||||
{ |
||||
var solution = CreateViewModelWithOneProjectOpen(); |
||||
var expectedProject = solution.Projects.First(); |
||||
var actualProject = consoleHost.DefaultProject; |
||||
|
||||
Assert.AreEqual(expectedProject, actualProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void ActivePackageSource_OneRegisteredPackageSourceWhenConsoleCreated_ActivePackageSourceSetForConsole() |
||||
{ |
||||
CreateViewModelWithOneRegisteredPackageSource(); |
||||
var expectedPackageSource = packageManagementService.Options.PackageSources[0]; |
||||
var actualPackageSource = consoleHost.ActivePackageSource; |
||||
|
||||
Assert.AreEqual(expectedPackageSource, actualPackageSource); |
||||
} |
||||
|
||||
[Test] |
||||
public void Dispose_ViewModelDisposed_ConsoleIsDisposed() |
||||
{ |
||||
CreateViewModel(); |
||||
viewModel.Dispose(); |
||||
|
||||
Assert.IsTrue(consoleHost.IsDisposeCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClearConsoleCommand_Executed_ClearsConsole() |
||||
{ |
||||
CreateViewModel(); |
||||
viewModel.ClearConsoleCommand.Execute(null); |
||||
|
||||
Assert.IsTrue(consoleHost.IsClearCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Constructor_NewViewModelCreated_ConsoleSetOnConsoleHost() |
||||
{ |
||||
CreateViewModel(); |
||||
|
||||
Assert.AreEqual(viewModel.FakeConsole, consoleHost.ScriptingConsole); |
||||
} |
||||
|
||||
[Test] |
||||
public void Constructor_NewViewModelCreated_ConsoleHostIsRun() |
||||
{ |
||||
CreateViewModel(); |
||||
|
||||
Assert.IsTrue(consoleHost.IsRunCalled); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
// 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.ObjectModel; |
||||
using System.Management.Automation.Host; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class PowerShellHostUserInterfaceTests |
||||
{ |
||||
PowerShellHostUserInterface hostUI; |
||||
FakeScriptingConsole scriptingConsole; |
||||
|
||||
void CreateHostUserInterface() |
||||
{ |
||||
scriptingConsole = new FakeScriptingConsole(); |
||||
hostUI = new PowerShellHostUserInterface(scriptingConsole); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteWarningLine_ShowWarningMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteWarningLine("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteWarningLine_ShowWarningMessage_ScriptingStyleIsWarning() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteWarningLine("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Warning, scriptingConsole.ScriptingStylePassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteVerboseLine_ShowVerboseMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteVerboseLine("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteVerboseLine_ShowVerboseMessage_ScriptingStyleIsOut() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteVerboseLine("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteLine_ShowMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteLine("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteLine_ShowMessage_ScriptingStyleIsOut() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteLine("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteErrorLine_ShowErrorMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteErrorLine("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteErrorLine_ShowErrorMessage_ScriptingStyleIsError() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteErrorLine("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Error, scriptingConsole.ScriptingStylePassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteDebugLine_ShowMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteDebugLine("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteDebugLine_ShowMessage_ScriptingStyleIsOut() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.WriteDebugLine("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void Write_ShowMessage_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.Write("Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Write_ShowMessage_ScriptingStyleIsOut() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.Write("Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Write_ConsoleColorsSpecified_MessageWrittenToConsole() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test"); |
||||
|
||||
Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void Write_ConsoleColorsSpecified_ScriptingStyleIsOut() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test"); |
||||
|
||||
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite); |
||||
} |
||||
|
||||
[Test] |
||||
public void PromptForChoice_NoChoices_ReturnsMinusOne() |
||||
{ |
||||
CreateHostUserInterface(); |
||||
var choices = new Collection<ChoiceDescription>(); |
||||
int result = hostUI.PromptForChoice("caption", "message", choices, 2); |
||||
|
||||
Assert.AreEqual(-1, result); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue