Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
[Ide] Add tests to ensure we can always create projects
Browse files Browse the repository at this point in the history
We should never ship a Xamarin Studio which cannot create projects
from it's own project templates now.
  • Loading branch information
alanmcgovern committed Aug 29, 2013
1 parent acdd984 commit 466fc7f
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 11 deletions.
15 changes: 15 additions & 0 deletions main/Main.sln
Expand Up @@ -250,6 +250,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestRunner", "tests\TestRun
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoDevelop.TextEditor.Tests", "src\core\MonoDevelop.TextEditor.Tests\MonoDevelop.TextEditor.Tests.csproj", "{9E4BA410-8338-42EC-AF9C-422C35ECED81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ide.Tests", "tests\Ide.Tests\Ide.Tests.csproj", "{73D4CC8B-BAB9-4A29-841B-F25C6311F067}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -637,6 +639,18 @@ Global
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.net_4_5_Release|Any CPU.ActiveCfg = Debug|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.net_4_5_Release|Any CPU.Build.0 = Debug|Any CPU
{72944A6C-45FF-4EF8-B349-8C9CABF519D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.DebugMac|Any CPU.Build.0 = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.DebugWin32|Any CPU.ActiveCfg = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.DebugWin32|Any CPU.Build.0 = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.net_4_5_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.net_4_5_Debug|Any CPU.Build.0 = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.net_4_5_Release|Any CPU.ActiveCfg = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.net_4_5_Release|Any CPU.Build.0 = Debug|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73D4CC8B-BAB9-4A29-841B-F25C6311F067}.Release|Any CPU.Build.0 = Release|Any CPU
{7525BB88-6142-4A26-93B9-A30C6983390A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7525BB88-6142-4A26-93B9-A30C6983390A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7525BB88-6142-4A26-93B9-A30C6983390A}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1446,6 +1460,7 @@ Global
{C05AAB7A-523F-4109-966B-6675BE0975BA} = {78C10DAE-D3D7-44FC-93DF-831D8D54ECF9}
{EBFC7F90-C2E5-4A4C-A327-E35021BEC181} = {78C10DAE-D3D7-44FC-93DF-831D8D54ECF9}
{9E4BA410-8338-42EC-AF9C-422C35ECED81} = {78C10DAE-D3D7-44FC-93DF-831D8D54ECF9}
{73D4CC8B-BAB9-4A29-841B-F25C6311F067} = {78C10DAE-D3D7-44FC-93DF-831D8D54ECF9}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = src\core\MonoDevelop.Startup\MonoDevelop.Startup.csproj
Expand Down
5 changes: 3 additions & 2 deletions main/src/addins/CBinding/Project/CProject.cs
Expand Up @@ -93,8 +93,9 @@ public class CProject : Project, IDeployable
private void Init ()
{
packages.Project = this;

IdeApp.Workspace.ItemAddedToSolution += OnEntryAddedToCombine;

if (IdeApp.IsInitialized)
IdeApp.Workspace.ItemAddedToSolution += OnEntryAddedToCombine;
}

public CProject ()
Expand Down
Expand Up @@ -84,14 +84,18 @@ static GuiBuilderService ()

static void InitializeService ()
{
IdeApp.ProjectOperations.EndBuild += OnProjectCompiled;
IdeApp.Workbench.ActiveDocumentChanged += OnActiveDocumentChanged;
if (IdeApp.IsInitialized) {
IdeApp.ProjectOperations.EndBuild += OnProjectCompiled;
IdeApp.Workbench.ActiveDocumentChanged += OnActiveDocumentChanged;
}
}

static void ShutdownService ()
{
IdeApp.ProjectOperations.EndBuild -= OnProjectCompiled;
IdeApp.Workbench.ActiveDocumentChanged -= OnActiveDocumentChanged;
if (IdeApp.IsInitialized) {
IdeApp.ProjectOperations.EndBuild -= OnProjectCompiled;
IdeApp.Workbench.ActiveDocumentChanged -= OnActiveDocumentChanged;
}
if (steticApp != null) {
StoreConfiguration ();
steticApp.Dispose ();
Expand Down
Expand Up @@ -93,7 +93,7 @@ public class GtkDesignInfo: IDisposable

void OnFileEvent (object o, ProjectFileEventArgs args)
{
if (!IdeApp.Workspace.IsOpen || !File.Exists (ObjectsFile))
if (!IdeApp.IsInitialized || !IdeApp.Workspace.IsOpen || !File.Exists (ObjectsFile))
return;

UpdateObjectsFile ();
Expand Down
1 change: 1 addition & 0 deletions main/src/core/MonoDevelop.Ide/AssemblyInfo.cs
Expand Up @@ -12,3 +12,4 @@
[assembly: InternalsVisibleTo("MacPlatform")]
[assembly: InternalsVisibleTo("MonoDevelop.Debugger")]
[assembly: InternalsVisibleTo("MonoDevelop.DesignerSupport")]
[assembly: InternalsVisibleTo("Ide.Tests")]
Expand Up @@ -177,6 +177,8 @@ public static void ShowException (Gtk.Window parent, Exception e, string message

public static AlertButton ShowException (Gtk.Window parent, Exception e, string message, string title, params AlertButton[] buttons)
{
if (!IdeApp.IsInitialized)
throw new Exception ("IdeApp has not been initialized. Progagating the exception.", e);
return messageService.ShowException (parent, title, message, e, buttons);
}
#endregion
Expand Down
Expand Up @@ -2045,10 +2045,12 @@ public void DeleteText (int position, int length)

public IEditableTextFile GetEditableTextFile (FilePath filePath)
{
foreach (var doc in IdeApp.Workbench.Documents) {
if (doc.FileName == filePath) {
IEditableTextFile ef = doc.GetContent<IEditableTextFile> ();
if (ef != null) return ef;
if (IdeApp.IsInitialized) {
foreach (var doc in IdeApp.Workbench.Documents) {
if (doc.FileName == filePath) {
IEditableTextFile ef = doc.GetContent<IEditableTextFile> ();
if (ef != null) return ef;
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions main/tests/Ide.Tests/Ide.Tests.csproj
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{73D4CC8B-BAB9-4A29-841B-F25C6311F067}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Ide.Tests</RootNamespace>
<AssemblyName>Ide.Tests</AssemblyName>
<TestRunnerCommand>..\..\build\bin\mdtool.exe</TestRunnerCommand>
<TestRunnerArgs>run-md-tests</TestRunnerArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="ProjectTemplateTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\core\MonoDevelop.Ide\MonoDevelop.Ide.csproj">
<Project>{27096E7F-C91C-4AC6-B289-6897A701DF21}</Project>
<Name>MonoDevelop.Ide</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\src\core\MonoDevelop.Core\MonoDevelop.Core.csproj">
<Project>{7525BB88-6142-4A26-93B9-A30C6983390A}</Project>
<Name>MonoDevelop.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\external\guiunit\src\framework\GuiUnit_NET_4_0.csproj">
<Project>{E13A0A7B-4DE6-43ED-A139-41052D065A9B}</Project>
<Name>GuiUnit_NET_4_0</Name>
</ProjectReference>
</ItemGroup>
</Project>
80 changes: 80 additions & 0 deletions main/tests/Ide.Tests/ProjectTemplateTests.cs
@@ -0,0 +1,80 @@
//
// MyClass.cs
//
// Author:
// alan <>
//
// Copyright (c) 2013 alan
//
// 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;
using MonoDevelop.Ide.Templates;
using MonoDevelop.Projects;
using NUnit.Framework;
using System.IO;
using System.Text;

namespace MonoDevelop.Ide
{
[TestFixture]
public class ProjectTemplateTests
{
string TempDir {
get; set;
}

[SetUp]
public void Setup ()
{
var currentDir = Path.GetDirectoryName (typeof(ProjectTemplateTests).Assembly.Location);
TempDir = Path.GetFullPath (Path.Combine (currentDir, "TempDirForTests"));
}

[TearDown]
public void Teardown ()
{
try { Directory.Delete (TempDir, true); } catch { }
}

[Test]
public void CreateEveryProjectTemplate ()
{
var builder = new StringBuilder ();
foreach (var template in ProjectTemplate.ProjectTemplates) {
try {
try { Directory.Delete (TempDir, true); } catch { }
var cinfo = new ProjectCreateInformation {
ProjectBasePath = TempDir,
ProjectName = "ProjectName",
SolutionName = "SolutionName",
SolutionPath = TempDir
};
template.CreateWorkspaceItem (cinfo);
} catch {
builder.AppendFormat ("Could not create a project from the template '{0} / {1}'", template.Category, template.Name);
builder.AppendLine ();
}
}

if (builder.Length > 0)
Assert.Fail (builder.ToString ());
}
}
}

0 comments on commit 466fc7f

Please sign in to comment.