Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMatt Ward <matt.ward@xamarin.com>2017-07-25 15:53:09 +0300
committerMatt Ward <matt.ward@xamarin.com>2017-07-25 15:53:09 +0300
commit770a22f794d928be9575bc8ba568eda172527b2a (patch)
tree2467bd440063866497557fdbad86cad3e4b41dd5 /main
parenta05fa40edec864b2c6c064cdf7cb21538199a4ab (diff)
[Ide] Add tests for New Project dialog's create directory check box
Added unit tests for the logic of whether the create directory check box on the final page of the New Project dialog is enabled and checked before fixing a bug in this logic.
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs28
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateImageProvider.cs6
-rw-r--r--main/tests/Ide.Tests/Ide.Tests.csproj3
-rw-r--r--main/tests/Ide.Tests/MonoDevelop.Ide.Projects/DummyNewProjectDialogBackend.cs50
-rw-r--r--main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs144
-rw-r--r--main/tests/Ide.Tests/MonoDevelop.Ide.Projects/TestableNewProjectDialogController.cs47
6 files changed, 270 insertions, 8 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs
index d906a3910a..4bab7ef0b5 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs
@@ -57,7 +57,7 @@ namespace MonoDevelop.Ide.Projects
const string UseGitPropertyName = "Dialogs.NewProjectDialog.UseGit";
const string CreateGitIgnoreFilePropertyName = "Dialogs.NewProjectDialog.CreateGitIgnoreFile";
- const string CreateProjectSubDirectoryPropertyName = "MonoDevelop.Core.Gui.Dialogs.NewProjectDialog.AutoCreateProjectSubdir";
+ internal const string CreateProjectSubDirectoryPropertyName = "MonoDevelop.Core.Gui.Dialogs.NewProjectDialog.AutoCreateProjectSubdir";
const string NewSolutionLastSelectedCategoryPropertyName = "Dialogs.NewProjectDialog.LastSelectedCategoryPath";
const string NewSolutionLastSelectedTemplatePropertyName = "Dialogs.NewProjectDialog.LastSelectedTemplate";
const string NewProjectLastSelectedCategoryPropertyName = "Dialogs.NewProjectDialog.AddNewProjectLastSelectedCategoryPath";
@@ -268,7 +268,7 @@ namespace MonoDevelop.Ide.Projects
PropertyService.Set (CreateGitIgnoreFilePropertyName, projectConfiguration.CreateGitIgnoreFile);
}
- INewProjectDialogBackend CreateNewProjectDialog ()
+ protected virtual INewProjectDialogBackend CreateNewProjectDialog ()
{
return new GtkNewProjectDialogBackend ();
}
@@ -315,11 +315,25 @@ namespace MonoDevelop.Ide.Projects
void LoadTemplateCategories ()
{
Predicate<SolutionTemplate> templateMatch = GetTemplateFilter ();
- templateCategories = IdeApp.Services.TemplatingService.GetProjectTemplateCategories (templateMatch).ToList ();
+ templateCategories = TemplatingService.GetProjectTemplateCategories (templateMatch).ToList ();
if (IsNewSolution)
- recentTemplates = IdeApp.Services.TemplatingService.RecentTemplates.GetTemplates (templateCategories).Where (t => t.IsMatch (SolutionTemplateVisibility.NewSolution)).ToList ();
+ recentTemplates = TemplatingService.RecentTemplates.GetTemplates (templateCategories).Where (t => t.IsMatch (SolutionTemplateVisibility.NewSolution)).ToList ();
else
- recentTemplates = IdeApp.Services.TemplatingService.RecentTemplates.GetTemplates (templateCategories).ToList ();
+ recentTemplates = TemplatingService.RecentTemplates.GetTemplates (templateCategories).ToList ();
+ }
+
+ // Allow testing of the controller by allowing tests to specific the
+ // TemplatingService. IdeApp.Services is not initialized during unit tests.
+ TemplatingService templatingService;
+
+ internal TemplatingService TemplatingService {
+ get {
+ if (templatingService != null)
+ return templatingService;
+
+ return IdeApp.Services.TemplatingService;
+ }
+ set { templatingService = value; }
}
Predicate<SolutionTemplate> GetTemplateFilter ()
@@ -480,7 +494,7 @@ namespace MonoDevelop.Ide.Projects
// Fallback to checking all templates that match the template id in the same category
// and support the condition.
- SolutionTemplate matchedTemplate = IdeApp.Services.TemplatingService.GetTemplate (
+ SolutionTemplate matchedTemplate = TemplatingService.GetTemplate (
templateCategories,
currentTemplate => IsTemplateMatch (currentTemplate, SelectedTemplate, language, finalConfigurationPage.Parameters),
category => true,
@@ -746,7 +760,7 @@ namespace MonoDevelop.Ide.Projects
DisposeExistingNewItems ();
try {
- result = await IdeApp.Services.TemplatingService.ProcessTemplate (template, projectConfiguration, ParentFolder);
+ result = await TemplatingService.ProcessTemplate (template, projectConfiguration, ParentFolder);
if (!result.WorkspaceItems.Any ())
return false;
} catch (UserException ex) {
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateImageProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateImageProvider.cs
index fb699a2907..9558d8849b 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateImageProvider.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateImageProvider.cs
@@ -52,7 +52,11 @@ namespace MonoDevelop.Ide.Templates
Image LoadImageFromResource (string imageId)
{
- return IdeApp.Services.TemplatingService.LoadTemplateImage (imageId);
+ if (IdeApp.IsInitialized)
+ return IdeApp.Services.TemplatingService.LoadTemplateImage (imageId);
+
+ // Should only happen when running unit tests.
+ return null;
}
public void Dispose ()
diff --git a/main/tests/Ide.Tests/Ide.Tests.csproj b/main/tests/Ide.Tests/Ide.Tests.csproj
index e70eb864bf..d03b6db42f 100644
--- a/main/tests/Ide.Tests/Ide.Tests.csproj
+++ b/main/tests/Ide.Tests/Ide.Tests.csproj
@@ -39,6 +39,9 @@
<ItemGroup>
<Compile Include="ProjectTemplateTests.cs" />
<Compile Include="FileTransferTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Projects\NewProjectDialogTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Projects\TestableNewProjectDialogController.cs" />
+ <Compile Include="MonoDevelop.Ide.Projects\DummyNewProjectDialogBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/DummyNewProjectDialogBackend.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/DummyNewProjectDialogBackend.cs
new file mode 100644
index 0000000000..d3f02862c3
--- /dev/null
+++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/DummyNewProjectDialogBackend.cs
@@ -0,0 +1,50 @@
+//
+// DummyNewProjectDialogBackend.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+namespace MonoDevelop.Ide.Projects
+{
+ class DummyNewProjectDialogBackend : INewProjectDialogBackend
+ {
+ public bool CanMoveToNextPage { get; set; }
+
+ public void CloseDialog ()
+ {
+ }
+
+ public void RegisterController (INewProjectDialogController controller)
+ {
+ }
+
+ public Action OnShowDialogCalled = () => { };
+
+ public void ShowDialog ()
+ {
+ OnShowDialogCalled ();
+ }
+ }
+}
diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs
new file mode 100644
index 0000000000..291fac4d29
--- /dev/null
+++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs
@@ -0,0 +1,144 @@
+//
+// NewProjectDialogTests.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using UnitTests;
+using NUnit.Framework;
+using MonoDevelop.Core;
+using MonoDevelop.Projects;
+
+namespace MonoDevelop.Ide.Projects
+{
+ class NewProjectDialogTests : TestBase
+ {
+ TestableNewProjectDialogController controller;
+ bool createProjectDirectoryOriginalValue;
+
+ [TestFixtureSetUp]
+ public void SetUp ()
+ {
+ Simulate ();
+
+ createProjectDirectoryOriginalValue = PropertyService.Get (
+ NewProjectDialogController.CreateProjectSubDirectoryPropertyName,
+ true);
+ }
+
+ public override void TearDown ()
+ {
+ // Reset original property values.
+ PropertyService.Set (
+ NewProjectDialogController.CreateProjectSubDirectoryPropertyName,
+ createProjectDirectoryOriginalValue);
+ }
+
+ void CreateDialog ()
+ {
+ controller = new TestableNewProjectDialogController ();
+
+ // Set base path to avoid use of IdeApp.Preferences which is not
+ // initialized during tests.
+ controller.BasePath = Util.TestsRootDir;
+ }
+
+ void CSharpLibraryTemplateSelectedByDefault ()
+ {
+ controller.SelectedTemplateId = "MonoDevelop.CSharp.Library";
+ }
+
+ void UseExistingSolution ()
+ {
+ var parentFolder = new SolutionFolder ();
+ controller.ParentFolder = parentFolder;
+ }
+
+ [Test]
+ public void Show_CSharpLibrary_NoItemsCreated ()
+ {
+ CreateDialog ();
+ CSharpLibraryTemplateSelectedByDefault ();
+
+ controller.Backend.OnShowDialogCalled = () => {
+ controller.MoveToNextPage ();
+ };
+
+ bool result = controller.Show ();
+
+ Assert.IsFalse (result);
+ }
+
+ [Test]
+ public void CreateProjectDirectorySetting_IsTrue_FinalPageHasCreateDirectoryEnabledAndChecked ()
+ {
+ CreateDialog ();
+ CSharpLibraryTemplateSelectedByDefault ();
+ PropertyService.Set (NewProjectDialogController.CreateProjectSubDirectoryPropertyName, true);
+
+ controller.Backend.OnShowDialogCalled = () => {
+ controller.MoveToNextPage ();
+ };
+
+ controller.Show ();
+
+ Assert.IsTrue (controller.FinalConfiguration.CreateProjectDirectoryInsideSolutionDirectory);
+ Assert.IsTrue (controller.FinalConfiguration.IsCreateProjectDirectoryInsideSolutionDirectoryEnabled);
+ }
+
+ [Test]
+ public void CreateProjectDirectorySetting_IsFalse_FinalPageHasCreateDirectoryEnabledAndNotChecked ()
+ {
+ CreateDialog ();
+ CSharpLibraryTemplateSelectedByDefault ();
+ PropertyService.Set (NewProjectDialogController.CreateProjectSubDirectoryPropertyName, false);
+
+ controller.Backend.OnShowDialogCalled = () => {
+ controller.MoveToNextPage ();
+ };
+
+ controller.Show ();
+
+ Assert.IsFalse (controller.FinalConfiguration.CreateProjectDirectoryInsideSolutionDirectory);
+ Assert.IsTrue (controller.FinalConfiguration.IsCreateProjectDirectoryInsideSolutionDirectoryEnabled);
+ }
+
+ [Test]
+ public void CreateProjectDirectorySetting_IsTrueAndAddingProjectToExistingSolution_FinalPageHasCreateDirectoryDisabledAndChecked ()
+ {
+ CreateDialog ();
+ CSharpLibraryTemplateSelectedByDefault ();
+ UseExistingSolution ();
+ PropertyService.Set (NewProjectDialogController.CreateProjectSubDirectoryPropertyName, true);
+
+ controller.Backend.OnShowDialogCalled = () => {
+ controller.MoveToNextPage ();
+ };
+
+ controller.Show ();
+
+ Assert.IsTrue (controller.FinalConfiguration.CreateProjectDirectoryInsideSolutionDirectory);
+ Assert.IsFalse (controller.FinalConfiguration.IsCreateProjectDirectoryInsideSolutionDirectoryEnabled);
+ }
+ }
+}
diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/TestableNewProjectDialogController.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/TestableNewProjectDialogController.cs
new file mode 100644
index 0000000000..40f11dc613
--- /dev/null
+++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/TestableNewProjectDialogController.cs
@@ -0,0 +1,47 @@
+//
+// TestableNewProjectDialogController.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2017 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using MonoDevelop.Ide.Projects;
+using MonoDevelop.Ide.Templates;
+
+namespace MonoDevelop.Ide
+{
+ class TestableNewProjectDialogController : NewProjectDialogController
+ {
+ public TestableNewProjectDialogController ()
+ {
+ Backend = new DummyNewProjectDialogBackend ();
+ TemplatingService = new TemplatingService ();
+ }
+
+ public DummyNewProjectDialogBackend Backend { get; private set; }
+
+ protected override INewProjectDialogBackend CreateNewProjectDialog ()
+ {
+ return Backend;
+ }
+ }
+}