Browse Source
Add Custom Tools project options panel that can be used to enable running custom tools when a build is started just before the build executes. Project options panel allows enabling/disabling this feature and specifying which files will have their custom tools run pre-build. Configuration is stored in IProject.ProjectSpecificProperties.pull/28/head
13 changed files with 838 additions and 0 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
<gui:OptionPanel |
||||
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.ProjectCustomToolOptionsPanel" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" |
||||
xmlns:project="clr-namespace:ICSharpCode.SharpDevelop.Project" |
||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui" |
||||
xmlns:optionpanels="clr-namespace:ICSharpCode.SharpDevelop.Gui"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="*" /> |
||||
</Grid.RowDefinitions> |
||||
|
||||
<CheckBox |
||||
Margin="10, 20, 10, 5" |
||||
IsChecked="{Binding RunCustomToolOnBuild}" |
||||
Content="Run on Build" /> |
||||
|
||||
<Label |
||||
Margin="5, 5, 5, 0" |
||||
Grid.Row="1" |
||||
Content="Filenames:" /> |
||||
|
||||
<TextBox |
||||
Margin="10, 0" |
||||
Grid.Row="2" |
||||
AcceptsReturn="True" |
||||
Text="{Binding Path=FileNames, UpdateSourceTrigger=PropertyChanged}" /> |
||||
</Grid> |
||||
</gui:OptionPanel> |
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
// 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.ComponentModel; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
public partial class ProjectCustomToolOptionsPanel : INotifyPropertyChanged, ICanBeDirty |
||||
{ |
||||
ProjectCustomToolOptions customToolsOptions; |
||||
bool runCustomToolOnBuild; |
||||
string fileNames; |
||||
bool isDirty; |
||||
|
||||
public ProjectCustomToolOptionsPanel() |
||||
{ |
||||
this.DataContext = this; |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public bool RunCustomToolOnBuild { |
||||
get { return runCustomToolOnBuild; } |
||||
set { |
||||
runCustomToolOnBuild = value; |
||||
OnChanged(); |
||||
} |
||||
} |
||||
|
||||
public string FileNames { |
||||
get { return fileNames; } |
||||
set { |
||||
fileNames = value; |
||||
OnChanged(); |
||||
} |
||||
} |
||||
|
||||
void OnChanged() |
||||
{ |
||||
IsDirty = OptionsHaveChanged(); |
||||
} |
||||
|
||||
bool OptionsHaveChanged() |
||||
{ |
||||
return |
||||
(runCustomToolOnBuild != customToolsOptions.RunCustomToolOnBuild) || |
||||
(fileNames != customToolsOptions.FileNames); |
||||
} |
||||
|
||||
public override void LoadOptions() |
||||
{ |
||||
var project = Owner as IProject; |
||||
|
||||
customToolsOptions = new ProjectCustomToolOptions(project); |
||||
RunCustomToolOnBuild = customToolsOptions.RunCustomToolOnBuild; |
||||
FileNames = customToolsOptions.FileNames; |
||||
|
||||
OnPropertyChanged(); |
||||
} |
||||
|
||||
public override bool SaveOptions() |
||||
{ |
||||
if (OptionsHaveChanged()) { |
||||
customToolsOptions.RunCustomToolOnBuild = runCustomToolOnBuild; |
||||
customToolsOptions.FileNames = fileNames; |
||||
} |
||||
IsDirty = false; |
||||
return true; |
||||
} |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
void OnPropertyChanged() |
||||
{ |
||||
OnPropertyChanged(null); |
||||
} |
||||
|
||||
void OnPropertyChanged(string propertyName) |
||||
{ |
||||
if (PropertyChanged != null) { |
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler IsDirtyChanged; |
||||
|
||||
void OnIsDirtyChanged() |
||||
{ |
||||
if (IsDirtyChanged != null) { |
||||
IsDirtyChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
public bool IsDirty { |
||||
get { return isDirty; } |
||||
|
||||
private set { |
||||
if (isDirty != value) { |
||||
isDirty = value; |
||||
OnIsDirtyChanged(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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.IO; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public class BeforeBuildCustomToolFileNameFilter |
||||
{ |
||||
List<string> fileNames; |
||||
|
||||
public BeforeBuildCustomToolFileNameFilter(IProject project) |
||||
{ |
||||
var customToolOptions = new ProjectCustomToolOptions(project); |
||||
if (customToolOptions.RunCustomToolOnBuild) { |
||||
fileNames = customToolOptions.SplitFileNames().ToList(); |
||||
} else { |
||||
fileNames = new List<string>(); |
||||
} |
||||
} |
||||
|
||||
public bool IsMatch(string fullPath) |
||||
{ |
||||
string fileNameToMatch = Path.GetFileName(fullPath); |
||||
return fileNames.Any(fileName => String.Equals(fileName, fileNameToMatch, StringComparison.OrdinalIgnoreCase)); |
||||
} |
||||
|
||||
public bool Any() |
||||
{ |
||||
return fileNames.Any(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// 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.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public class BeforeBuildCustomToolProjectItems |
||||
{ |
||||
IBuildable buildable; |
||||
|
||||
public BeforeBuildCustomToolProjectItems(IBuildable buildable) |
||||
{ |
||||
this.buildable = buildable; |
||||
} |
||||
|
||||
public IEnumerable<FileProjectItem> GetProjectItems() |
||||
{ |
||||
return GetProjects() |
||||
.SelectMany(p => GetConfiguredCustomToolProjectItems(p)) |
||||
.ToList(); |
||||
} |
||||
|
||||
IEnumerable<IProject> GetProjects() |
||||
{ |
||||
IProject project = buildable as IProject; |
||||
if (project != null) { |
||||
return new IProject[] { project }; |
||||
} |
||||
|
||||
var solution = buildable as Solution; |
||||
return solution.Projects; |
||||
} |
||||
|
||||
IEnumerable<FileProjectItem> GetConfiguredCustomToolProjectItems(IProject project) |
||||
{ |
||||
var fileNameFilter = new BeforeBuildCustomToolFileNameFilter(project); |
||||
if (!fileNameFilter.Any()) { |
||||
return new FileProjectItem[0]; |
||||
} |
||||
|
||||
return project |
||||
.Items |
||||
.OfType<FileProjectItem>() |
||||
.Where(item => fileNameFilter.IsMatch(item.Include)); |
||||
} |
||||
} |
||||
} |
@ -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 System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public class BeforeBuildCustomToolRunner |
||||
{ |
||||
public BeforeBuildCustomToolRunner() |
||||
{ |
||||
ProjectService.BuildStarted += ProjectBuildStarted; |
||||
} |
||||
|
||||
void ProjectBuildStarted(object sender, BuildEventArgs e) |
||||
{ |
||||
var projectItems = new BeforeBuildCustomToolProjectItems(e.Buildable); |
||||
RunCustomTool(projectItems.GetProjectItems()); |
||||
} |
||||
|
||||
void RunCustomTool(IEnumerable<FileProjectItem> projectItems) |
||||
{ |
||||
foreach (FileProjectItem projectItem in projectItems) { |
||||
CustomToolsService.RunCustomTool(projectItem, false); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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 System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public class ProjectCustomToolOptions |
||||
{ |
||||
Properties properties; |
||||
|
||||
public ProjectCustomToolOptions(IProject project) |
||||
{ |
||||
GetCustomToolProperties(project); |
||||
} |
||||
|
||||
void GetCustomToolProperties(IProject project) |
||||
{ |
||||
properties = project.ProjectSpecificProperties.Get("customTool", new Properties()); |
||||
} |
||||
|
||||
public bool RunCustomToolOnBuild { |
||||
get { return properties.Get("runOnBuild", false); } |
||||
set { properties.Set("runOnBuild", value); } |
||||
} |
||||
|
||||
public string FileNames { |
||||
get { return properties.Get("fileNames", String.Empty); } |
||||
set { properties.Set("fileNames", value); } |
||||
} |
||||
|
||||
public IList<string> SplitFileNames() |
||||
{ |
||||
return |
||||
FileNames |
||||
.Replace("\r\n", ";") |
||||
.Split(';', ',') |
||||
.Select(fileName => fileName.Trim()) |
||||
.Where(fileName => !String.IsNullOrEmpty(fileName)) |
||||
.ToList(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,267 @@
@@ -0,0 +1,267 @@
|
||||
// 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.Linq; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Tests.Utils; |
||||
using NUnit.Framework; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class BeforeBuildCustomToolProjectItemsTests |
||||
{ |
||||
ProjectHelper projectHelper; |
||||
BeforeBuildCustomToolProjectItems beforeBuildCustomToolProjectItems; |
||||
Solution solution; |
||||
|
||||
IProject CreateProject(string fileName = @"d:\MyProject\MyProject.csproj") |
||||
{ |
||||
projectHelper = new ProjectHelper(fileName); |
||||
return projectHelper.Project; |
||||
} |
||||
|
||||
void CreateSolution(params IProject[] projects) |
||||
{ |
||||
IProjectChangeWatcher watcher = MockRepository.GenerateStub<IProjectChangeWatcher>(); |
||||
solution = new Solution(watcher); |
||||
projects.ForEach(p => solution.Folders.Add(p)); |
||||
} |
||||
|
||||
void ConfigureCustomToolFileNamesForProject(string fileNames) |
||||
{ |
||||
var customToolOptions = new ProjectCustomToolOptions(projectHelper.Project); |
||||
customToolOptions.FileNames = fileNames; |
||||
} |
||||
|
||||
void EnableCustomToolRunForProject() |
||||
{ |
||||
SetCustomToolRunForProject(true); |
||||
} |
||||
|
||||
void SetCustomToolRunForProject(bool enabled) |
||||
{ |
||||
var customToolOptions = new ProjectCustomToolOptions(projectHelper.Project); |
||||
customToolOptions.RunCustomToolOnBuild = enabled; |
||||
} |
||||
|
||||
void DisableCustomToolRunForProject() |
||||
{ |
||||
SetCustomToolRunForProject(false); |
||||
} |
||||
|
||||
List<FileProjectItem> GetProjectItems() |
||||
{ |
||||
return beforeBuildCustomToolProjectItems.GetProjectItems().ToList(); |
||||
} |
||||
|
||||
void CreateBeforeBuildCustomToolProjectItems() |
||||
{ |
||||
CreateBeforeBuildCustomToolProjectItems(projectHelper.Project as IBuildable); |
||||
} |
||||
|
||||
void CreateBeforeBuildCustomToolProjectItems(IBuildable buildable) |
||||
{ |
||||
beforeBuildCustomToolProjectItems = new BeforeBuildCustomToolProjectItems(buildable); |
||||
} |
||||
|
||||
void CreateBeforeBuildCustomToolProjectItemsUsingSolution() |
||||
{ |
||||
CreateBeforeBuildCustomToolProjectItems(solution as IBuildable); |
||||
} |
||||
|
||||
FileProjectItem AddFileToProject(string include) |
||||
{ |
||||
var projectItem = new FileProjectItem(projectHelper.Project, ItemType.Compile, include); |
||||
projectHelper.AddProjectItem(projectItem); |
||||
return projectItem; |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectNotConfiguredToRunCustomToolsOnBuild_ReturnsNoItems() |
||||
{ |
||||
CreateProject(); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
Assert.AreEqual(0, projectItems.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_OneProjectItemReturned() |
||||
{ |
||||
CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("template.tt"); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolFileNamesConfigured_NoProjectItemsReturnedWhenRunCustomToolIsDisabledForProject() |
||||
{ |
||||
CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
AddFileToProject("template.tt"); |
||||
DisableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("template.tt"); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
Assert.AreEqual(0, projectItems.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_OtherNonMatchingProjectItemsNotReturned() |
||||
{ |
||||
CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.t4"); |
||||
AddFileToProject("test.cs"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("template.t4"); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_ProjectItemInSubdirectoryReturned() |
||||
{ |
||||
CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject(@"Model\template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("template.tt"); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_BuildSingleProjectWithOneFileMatchingCustomToolRunConfiguration_ProjectItemReturnedWhenFileNameCaseIsDifferent() |
||||
{ |
||||
CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); |
||||
CreateBeforeBuildCustomToolProjectItems(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_SolutionContainingOneProjectWithMatchingCustomToolFileName_ReturnsOneProjectItem() |
||||
{ |
||||
IProject project = CreateProject(@"d:\MyProject\MyProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); |
||||
CreateSolution(project); |
||||
CreateBeforeBuildCustomToolProjectItemsUsingSolution(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_SolutionWithNoProjects_ReturnsNoProjectItems() |
||||
{ |
||||
CreateSolution(); |
||||
CreateBeforeBuildCustomToolProjectItemsUsingSolution(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
Assert.AreEqual(0, projectItems.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_SolutionContainingTwoProjectsWithMatchingCustomToolFileNameInSecondProject_ReturnsOneProjectItem() |
||||
{ |
||||
IProject project1 = CreateProject(@"d:\MyProject\FirstProject.csproj"); |
||||
IProject project2 = CreateProject(@"d:\MyProject\SecondProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); |
||||
CreateSolution(project1, project2); |
||||
CreateBeforeBuildCustomToolProjectItemsUsingSolution(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_SolutionContainingTwoProjectsWithMatchingCustomToolFileNameInFirstProject_ReturnsOneProjectItem() |
||||
{ |
||||
IProject project1 = CreateProject(@"d:\MyProject\FirstProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); |
||||
IProject project2 = CreateProject(@"d:\MyProject\SecondProject.csproj"); |
||||
CreateSolution(project1, project2); |
||||
CreateBeforeBuildCustomToolProjectItemsUsingSolution(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectItems_SolutionContainingTwoProjectsBothWithFilesAndMatchingCustomToolFileNameInFirstProject_ReturnsOneProjectItem() |
||||
{ |
||||
IProject project1 = CreateProject(@"d:\MyProject\FirstProject.csproj"); |
||||
FileProjectItem projectItem = AddFileToProject("template.tt"); |
||||
EnableCustomToolRunForProject(); |
||||
ConfigureCustomToolFileNamesForProject("TEMPLATE.TT"); |
||||
IProject project2 = CreateProject(@"d:\MyProject\SecondProject.csproj"); |
||||
AddFileToProject("test.cs"); |
||||
CreateSolution(project1, project2); |
||||
CreateBeforeBuildCustomToolProjectItemsUsingSolution(); |
||||
|
||||
List<FileProjectItem> projectItems = GetProjectItems(); |
||||
|
||||
FileProjectItem[] expectedProjectItems = new FileProjectItem[] { |
||||
projectItem |
||||
}; |
||||
CollectionAssert.AreEqual(expectedProjectItems, projectItems); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,212 @@
@@ -0,0 +1,212 @@
|
||||
// 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.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class ProjectCustomToolOptionsTests |
||||
{ |
||||
IProject project; |
||||
Properties projectSpecificProperties; |
||||
ProjectCustomToolOptions projectCustomToolOptions; |
||||
Properties properties; |
||||
|
||||
void CreateProject() |
||||
{ |
||||
projectSpecificProperties = new Properties(); |
||||
project = MockRepository.GenerateStub<IProject>(); |
||||
project.Stub(p => p.ProjectSpecificProperties).Return(projectSpecificProperties); |
||||
} |
||||
|
||||
void CreateProjectWithExistingCustomToolProperties(string fileNames) |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(false, fileNames); |
||||
} |
||||
|
||||
void CreateProjectWithExistingCustomToolProperties(bool runOnBuild, string fileNames = "") |
||||
{ |
||||
CreateProject(); |
||||
properties = new Properties(); |
||||
properties.Set("runOnBuild", runOnBuild); |
||||
properties.Set("fileNames", fileNames); |
||||
projectSpecificProperties.Set("customTool", properties); |
||||
} |
||||
|
||||
void CreateProjectCustomToolsOptions() |
||||
{ |
||||
projectCustomToolOptions = new ProjectCustomToolOptions(project); |
||||
} |
||||
|
||||
[Test] |
||||
public void RunCustomToolOnBuild_ProjectHasNoExistingProjectCustomToolProperties_ReturnsFalse() |
||||
{ |
||||
CreateProject(); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
bool run = projectCustomToolOptions.RunCustomToolOnBuild; |
||||
|
||||
Assert.IsFalse(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNames_ProjectHasNoExistingProjectCustomToolProperties_ReturnsEmptyString() |
||||
{ |
||||
CreateProject(); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
string fileNames = projectCustomToolOptions.FileNames; |
||||
|
||||
Assert.AreEqual(String.Empty, fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void RunCustomToolOnBuild_ProjectPropertyRunCustomToolOnBuildIsTrue_ReturnsTrue() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(runOnBuild: true); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
bool run = projectCustomToolOptions.RunCustomToolOnBuild; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNames_ProjectPropertyFileNamesIsNotEmptyString_ReturnsFileName() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(fileNames: "T4MVC.tt"); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
string fileNames = projectCustomToolOptions.FileNames; |
||||
|
||||
Assert.AreEqual("T4MVC.tt", fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void RunCustomToolOnBuild_ChangeRunCustomToolOnBuildToTrue_StoredInProjectProperties() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(runOnBuild: false); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
projectCustomToolOptions.RunCustomToolOnBuild = true; |
||||
|
||||
CreateProjectCustomToolsOptions(); |
||||
bool run = projectCustomToolOptions.RunCustomToolOnBuild; |
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void RunCustomToolOnBuild_ChangeRunCustomToolOnBuildToFalse_StoredInProjectProperties() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(runOnBuild: true); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
projectCustomToolOptions.RunCustomToolOnBuild = false; |
||||
|
||||
CreateProjectCustomToolsOptions(); |
||||
bool run = projectCustomToolOptions.RunCustomToolOnBuild; |
||||
Assert.IsFalse(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNames_ChangeFileNamesFromEmptyStringToFileName_StoredInProjectProperties() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(fileNames: String.Empty); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
projectCustomToolOptions.FileNames = "abc.tt"; |
||||
|
||||
CreateProjectCustomToolsOptions(); |
||||
string fileNames = projectCustomToolOptions.FileNames; |
||||
Assert.AreEqual("abc.tt", fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void SplitFileNames_FileNamesIsSemiColonSeparatedOfTwoFiles_ReturnsTwoFiles() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties("a.t4;b.t4"); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
IList<string> fileNames = projectCustomToolOptions.SplitFileNames(); |
||||
|
||||
string[] expectedFileNames = new string[] { |
||||
"a.t4", |
||||
"b.t4" |
||||
}; |
||||
CollectionAssert.AreEqual(expectedFileNames, fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void SplitFileNames_FileNamesIsCommaSeparatedOfTwoFiles_ReturnsTwoFiles() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties("a.t4,b.t4"); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
IList<string> fileNames = projectCustomToolOptions.SplitFileNames(); |
||||
|
||||
string[] expectedFileNames = new string[] { |
||||
"a.t4", |
||||
"b.t4" |
||||
}; |
||||
CollectionAssert.AreEqual(expectedFileNames, fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void SplitFileNames_FileNamesIsSemiColonSeparatedOfTwoFilesWithWhitespace_ReturnsTwoFilesWithWhitespaceRemoved() |
||||
{ |
||||
CreateProjectWithExistingCustomToolProperties(" a.t4 ; b.t4 "); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
IList<string> fileNames = projectCustomToolOptions.SplitFileNames(); |
||||
|
||||
string[] expectedFileNames = new string[] { |
||||
"a.t4", |
||||
"b.t4" |
||||
}; |
||||
CollectionAssert.AreEqual(expectedFileNames, fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void SplitFileNames_FileNamesIsTwoFilesEachOnSeparateLine_ReturnsTwoFiles() |
||||
{ |
||||
string text = |
||||
"a.t4\r\n" + |
||||
"b.t4"; |
||||
CreateProjectWithExistingCustomToolProperties(text); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
IList<string> fileNames = projectCustomToolOptions.SplitFileNames(); |
||||
|
||||
string[] expectedFileNames = new string[] { |
||||
"a.t4", |
||||
"b.t4" |
||||
}; |
||||
CollectionAssert.AreEqual(expectedFileNames, fileNames); |
||||
} |
||||
|
||||
[Test] |
||||
public void SplitFileNames_FileNamesIsTwoFilesEachOnSeparateLineWithEmptyLineBetweenThemAndOneAtEnd_ReturnsTwoFiles() |
||||
{ |
||||
string text = |
||||
"a.t4\r\n" + |
||||
"\r\n" + |
||||
"b.t4\r\n"; |
||||
CreateProjectWithExistingCustomToolProperties(text); |
||||
CreateProjectCustomToolsOptions(); |
||||
|
||||
IList<string> fileNames = projectCustomToolOptions.SplitFileNames(); |
||||
|
||||
string[] expectedFileNames = new string[] { |
||||
"a.t4", |
||||
"b.t4" |
||||
}; |
||||
CollectionAssert.AreEqual(expectedFileNames, fileNames); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Tests.Utils |
||||
{ |
||||
public class ProjectHelper |
||||
{ |
||||
public IProject Project = MockRepository.GenerateMock<IProject, IBuildable>(); |
||||
public List<ProjectItem> ProjectItems = new List<ProjectItem>(); |
||||
public Properties ProjectSpecificProperties = new Properties(); |
||||
|
||||
public ProjectHelper(string fileName) |
||||
{ |
||||
Project.Stub(p => p.FileName).Return(fileName); |
||||
|
||||
Project |
||||
.Stub(p => p.Items) |
||||
.Return(null) |
||||
.WhenCalled(mi => mi.ReturnValue = new ReadOnlyCollection<ProjectItem>(ProjectItems)); |
||||
|
||||
Project.Stub(p => p.ProjectSpecificProperties).Return(ProjectSpecificProperties); |
||||
Project.Stub(p => p.SyncRoot).Return(new Object()); |
||||
} |
||||
|
||||
public void AddProjectItem(ProjectItem projectItem) |
||||
{ |
||||
ProjectItems.Add(projectItem); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue