static Document Setup (string input)
		{
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();

			var project = new DotNetAssemblyProject ("C#");
			project.Name = "test";
			project.References.Add (new ProjectReference (ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
			project.References.Add (new ProjectReference (ReferenceType.Package, "System.Core"));

			project.FileName = "test.csproj";

			TypeSystemService.LoadProject (project);
			TypeSystemService.GetProjectContentWrapper (project).ReconnectAssemblyReferences (); 
			content.Project = project;

			tww.ViewContent = content;
			content.ContentName = "a.cs";
			content.GetTextEditorData ().Document.MimeType = "text/x-csharp";
			var doc = new Document (tww);

			var text = input;
			int endPos = text.IndexOf ('$');
			if (endPos >= 0)
				text = text.Substring (0, endPos) + text.Substring (endPos + 1);

			content.Text = text;
			content.CursorPosition = Math.Max (0, endPos);

			var compExt = new CSharpCompletionTextEditorExtension ();
			compExt.Initialize (doc);
			content.Contents.Add (compExt);
			doc.UpdateParseDocument ();
			return doc;
		}
예제 #2
0
        public void CheckProjectContainsItself()
        {
            var folder = new SolutionFolder ();
            var project = new DotNetAssemblyProject { Name = "foo" };
            folder.AddItem (project);

            Assert.IsNotNull (folder.GetProjectContainingFile (project.FileName), "#1");
        }
		static void ProcessReferences (DotNetAssemblyProject project, MonoIsland update)
		{
			var referencesToAdd = update.References.Where (r => project.References.All(r2 => r2.Reference != r)).ToArray ();
			foreach (var reference in referencesToAdd)
				project.References.Add (ProjectReferenceFor (reference));

			var referencesToRemove = project.References.Where (r => update.References.All(r2 => r.Reference != r2)).ToArray ();
			project.References.RemoveRange (referencesToRemove);
		}
		static void ProcessDefines (DotNetAssemblyProject project, MonoIsland update)
		{
			var compilationParameters = (CSharpCompilerParameters)((DotNetProjectConfiguration)project.DefaultConfiguration).CompilationParameters;
			var toAdd = update.Defines.Where (d => !compilationParameters.HasDefineSymbol (d)).ToArray ();
			var toRemove = compilationParameters.GetDefineSymbols().Where (d => !update.Defines.Contains (d)).ToArray ();
			foreach (var define in toAdd)
				compilationParameters.AddDefineSymbol (define);
			foreach (var define in toRemove)
				compilationParameters.RemoveDefineSymbol (define);
		}
		public void TestSetup()
		{
			_project = new DotNetAssemblyProject ("C#");
			var p = new CSharpCompilerParameters ();
			var config = new DotNetProjectConfiguration () { CompilationParameters = p };
			_project.DefaultConfiguration = config;

			_update = new MonoIsland ();
			_update.BaseDirectory = "/mybase";
		}
		static CompletionDataList CreateProvider (string text, bool isCtrlSpace)
		{
			string parsedText;
			string editorText;
			int cursorPosition = text.IndexOf ('$');
			int endPos = text.IndexOf ('$', cursorPosition + 1);
			if (endPos == -1)
				parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			else {
				parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1);
				editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1);
				cursorPosition = endPos - 1; 
			}
			
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			TestViewContent sev = new TestViewContent ();
			DotNetProject project = new DotNetAssemblyProject ("C#");
			project.FileName = GetTempFile (".csproj");
			
			string file = GetTempFile (".cs");
			project.AddFile (file);
			
			ProjectDomService.Load (project);
			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			dom.ForceUpdate (true);
			ProjectDomService.Parse (project, file, null, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, null, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			tww.ViewContent = sev;
			Document doc = new Document (tww);
			doc.ParsedDocument = new NRefactoryParser ().Parse (null, sev.ContentName, parsedText);
			foreach (var e in doc.ParsedDocument.Errors)
				Console.WriteLine (e);
			CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion (doc);
			
			int triggerWordLength = 1;
			CodeCompletionContext ctx = new CodeCompletionContext ();
			ctx.TriggerOffset = sev.CursorPosition;
			int line, column;
			sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
			ctx.TriggerLine = line;
			ctx.TriggerLineOffset = column;
			
			if (isCtrlSpace)
				return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList;
			else
				return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList;
		}
		static void ProcessFiles (DotNetAssemblyProject project, MonoIsland update)
		{
			var updateFiles = update.Files.Select (f => Path.GetFullPath(project.BaseDirectory + "/" + f)).ToArray();

			var toRemove = project.Files.Where (f => updateFiles.All(f2 => f.FilePath.FullPath != f2)).ToArray ();
			var toAdd = updateFiles.Where(f => project.Files.All(f2 => f2.FilePath.FullPath != f)).ToArray();

			if(toRemove.Length > 0)
				project.Files.RemoveRange (toRemove);

			if(toAdd.Length > 0)
				project.AddFiles (toAdd.Select (f => new FilePath (f)));
		}
		public static void Update (DotNetAssemblyProject project, MonoIsland update)
		{
			if (update.BaseDirectory != project.BaseDirectory)
				project.BaseDirectory = update.BaseDirectory;

			ProcessFiles (project, update);
			ProcessDefines (project, update);
			ProcessReferences (project, update);
			project.Name = update.Name;

			var dotNetProjectConfiguration = ((DotNetProjectConfiguration)project.DefaultConfiguration);
			dotNetProjectConfiguration.OutputAssembly = project.Name + ".dll";
		}
        public void IncludingProjectAddedAfterShared()
        {
            var sol = new Solution ();
            var shared = new SharedAssetsProject ("C#");
            shared.AddFile ("Foo.cs");

            sol.RootFolder.AddItem (shared);

            // Reference to shared is added before adding project to solution
            var main = new DotNetAssemblyProject ("C#");
            main.References.Add (new ProjectReference (shared));
            sol.RootFolder.AddItem (main);

            Assert.IsNotNull (main.Files.GetFile ("Foo.cs"));
        }
		internal static IParameterDataProvider CreateProvider (string text)
		{
			string parsedText;
			string editorText;
			int cursorPosition = text.IndexOf ('$');
			int endPos = text.IndexOf ('$', cursorPosition + 1);
			if (endPos == -1)
				parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			else {
				parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1);
				editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1);
				cursorPosition = endPos - 1; 
			}
			
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			TestViewContent sev = new TestViewContent ();
			DotNetProject project = new DotNetAssemblyProject ("C#");
			project.FileName = GetTempFile (".csproj");
			
			string file = GetTempFile (".cs");
			project.AddFile (file);
			
			ProjectDomService.Load (project);
//			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			tww.ViewContent = sev;
			Document doc = new Document (tww);
			doc.ParsedDocument = new NRefactoryParser ().Parse (null, sev.ContentName, parsedText);
			CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion (doc);
			
			CodeCompletionContext ctx = new CodeCompletionContext ();
			ctx.TriggerOffset = sev.CursorPosition;
			int line, column;
			sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
			ctx.TriggerLine = line;
			ctx.TriggerLineOffset = column - 1;
			
			IParameterDataProvider result = textEditorCompletion.HandleParameterCompletion (ctx, editorText[cursorPosition - 1]);
			ProjectDomService.Unload (project);
			return result;
		}
		static DotNetAssemblyProject CreateMonoDevelopProjectFromProjectUpdate (UnitySolution solution, MonoIsland projectUpdate)
		{
			var p = new DotNetAssemblyProject (projectUpdate.Language);

			// FIXME
			switch (projectUpdate.Language)
			{
				default: 
					var dotNetProjectConfig = (DotNetProjectConfiguration)p.AddNewConfiguration ("Debug");
					dotNetProjectConfig.CompilationParameters = new CSharpCompilerParameters();
					p.DefaultConfiguration = dotNetProjectConfig;
					break;
			}
		
			var rootFolder = solution.RootFolder;
			rootFolder.AddItem (p);
			solution.DefaultConfiguration.AddItem (p).Build = true;
			return p;
		}
예제 #12
0
        public void TestSaveWorkspace()
        {
            // Saving a workspace must save all solutions and projects it contains

            string dir = Util.CreateTmpDir ("TestSaveWorkspace");
            Workspace ws = new Workspace ();
            ws.FileName = Path.Combine (dir, "workspace");

            Solution sol = new Solution ();
            sol.FileName = Path.Combine (dir, "thesolution");
            ws.Items.Add (sol);

            DotNetAssemblyProject p = new DotNetAssemblyProject ("C#");
            p.FileName = Path.Combine (dir, "theproject");
            sol.RootFolder.Items.Add (p);

            ws.Save (Util.GetMonitor ());

            Assert.IsTrue (File.Exists (ws.FileName));
            Assert.IsTrue (File.Exists (sol.FileName));
            Assert.IsTrue (File.Exists (p.FileName));
        }
예제 #13
0
		public void ProjectFilePaths ()
		{
			DotNetProject project = new DotNetAssemblyProject ("C#");
			string dir = Environment.CurrentDirectory;
			
			ProjectFile file1 = project.AddFile (Util.Combine (dir, "test1.cs"), BuildAction.Compile);
			Assert.AreEqual (Util.Combine (dir, "test1.cs"), file1.Name);
			
			ProjectFile file2 = project.AddFile (Util.Combine (dir, "aaa", "..", "bbb", "test2.cs"), BuildAction.Compile);
			Assert.AreEqual (Util.Combine (dir, "bbb", "test2.cs"), file2.Name);
			
			ProjectFile file = project.Files.GetFile (Util.Combine (dir, "test1.cs"));
			Assert.AreEqual (file1, file);
			
			file = project.Files.GetFile (Util.Combine (dir, "aaa", "..", "test1.cs"));
			Assert.AreEqual (file1, file);
			
			file = project.Files.GetFile (Util.Combine (dir, "bbb", "test2.cs"));
			Assert.AreEqual (file2, file);
			
			file = project.Files.GetFile (Util.Combine (dir, "aaa", "..", "bbb", "test2.cs"));
			Assert.AreEqual (file2, file);
		}
예제 #14
0
		internal static RefactoringOptions CreateRefactoringOptions (string text)
		{
			int cursorPosition = -1;
			int endPos = text.IndexOf ('$');
			if (endPos >= 0) {
				cursorPosition = endPos;
				text = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			}
			
			int selectionStart = -1;
			int selectionEnd   = -1;
			int idx = text.IndexOf ("<-");
			if (idx >= 0) {
				selectionStart = idx;
				text = text.Substring (0, idx) + text.Substring (idx + 2);
				selectionEnd = idx = text.IndexOf ("->");
				
				text = text.Substring (0, idx) + text.Substring (idx + 2);
				if (cursorPosition < 0)
					cursorPosition = selectionEnd - 1;
			}
			
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			TestViewContent sev = new TestViewContent ();
	//		return new RefactoringOptions ();
			
			DotNetProject project = new DotNetAssemblyProject ("C#");
			Solution solution = new Solution ();
			solution.RootFolder.Items.Add (project);
			project.FileName = GetTempFile (".csproj");
			string file = GetTempFile (".cs");
			project.AddFile (file);
			string parsedText = text;
			string editorText = text;
			ProjectDomService.Load (project);
			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			dom.ForceUpdate (true);
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			
			tww.ViewContent = sev;
			var doc = new MonoDevelop.Ide.Gui.Document (tww);
			doc.Editor.Document.MimeType = "text/x-csharp";
			doc.Editor.Document.FileName = file;
			doc.ParsedDocument = new McsParser ().Parse (null, sev.ContentName, parsedText);
			foreach (var e in doc.ParsedDocument.Errors)
				Console.WriteLine (e);
			if (cursorPosition >= 0)
				doc.Editor.Caret.Offset = cursorPosition;
			if (selectionStart >= 0) 
				doc.Editor.SetSelection (selectionStart, selectionEnd);
			
			NRefactoryResolver resolver = new NRefactoryResolver (dom, 
			                                                      doc.ParsedDocument.CompilationUnit, 
			                                                      sev.Data, 
			                                                      file);
			
			ExpressionResult expressionResult;
			if (selectionStart >= 0) {
				expressionResult = new ExpressionResult (editorText.Substring (selectionStart, selectionEnd - selectionStart).Trim ());
				endPos = selectionEnd;
			} else {
				expressionResult = new NewCSharpExpressionFinder (dom).FindFullExpression (doc.Editor, cursorPosition + 1);
			}
			ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve (expressionResult, new DomLocation (doc.Editor.Caret.Line, doc.Editor.Caret.Column)) : null;
			
			RefactoringOptions result = new RefactoringOptions {
				Document = doc,
				Dom = dom,
				ResolveResult = resolveResult,
				SelectedItem = null
			};
			if (resolveResult is MemberResolveResult)
				result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember;
			if (resolveResult is LocalVariableResolveResult)
				result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable;
			if (resolveResult is ParameterResolveResult)
				result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter;
			result.TestFileProvider = new FileProvider (result);
			return result;
		}
예제 #15
0
		public void CustomCommands ()
		{
			DotNetProject p = new DotNetAssemblyProject ("C#");
			p.Name = "SomeProject";
			DotNetProjectConfiguration c = (DotNetProjectConfiguration) p.CreateConfiguration ("First");
			
			CustomCommand cmd = new CustomCommand ();
			cmd.Command = "aa bb cc";
			Assert.AreEqual ("aa", cmd.GetCommandFile (p, c.Selector));
			Assert.AreEqual ("bb cc", cmd.GetCommandArgs (p, c.Selector));
			
			cmd.Command = "\"aa bb\" cc dd";
			Assert.AreEqual ("aa bb", cmd.GetCommandFile (p, c.Selector));
			Assert.AreEqual ("cc dd", cmd.GetCommandArgs (p, c.Selector));
			
			cmd.Command = "\"aa ${ProjectName}\" cc ${ProjectName}";
			Assert.AreEqual ("aa SomeProject", cmd.GetCommandFile (p, c.Selector));
			Assert.AreEqual ("cc SomeProject", cmd.GetCommandArgs (p, c.Selector));
			
			cmd.WorkingDir = NormalizePath ("/some/${ProjectName}/place");
			Assert.AreEqual (Path.GetFullPath (NormalizePath ("/some/SomeProject/place")), (string)cmd.GetCommandWorkingDir (p, c.Selector));
		}
        public static void TestLoadSaveSolutionFolders(string fileFormat)
        {
            List <string> ids = new List <string> ();

            Solution sol = new Solution();

            sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true);
            string dir = Util.CreateTmpDir("solution-folders-" + fileFormat);

            sol.FileName = Path.Combine(dir, "TestSolutionFolders");
            sol.Name     = "TheSolution";

            DotNetAssemblyProject p1 = new DotNetAssemblyProject("C#");

            p1.FileName = Path.Combine(dir, "p1");
            sol.RootFolder.Items.Add(p1);
            string idp1 = p1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp1));
            Assert.IsFalse(ids.Contains(idp1));
            ids.Add(idp1);

            SolutionFolder f1 = new SolutionFolder();

            f1.Name = "f1";
            sol.RootFolder.Items.Add(f1);
            string idf1 = f1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf1));
            Assert.IsFalse(ids.Contains(idf1));
            ids.Add(idf1);

            DotNetAssemblyProject p2 = new DotNetAssemblyProject("C#");

            p2.FileName = Path.Combine(dir, "p2");
            f1.Items.Add(p2);
            string idp2 = p2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp2));
            Assert.IsFalse(ids.Contains(idp2));
            ids.Add(idp2);

            SolutionFolder f2 = new SolutionFolder();

            f2.Name = "f2";
            f1.Items.Add(f2);
            string idf2 = f2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf2));
            Assert.IsFalse(ids.Contains(idf2));
            ids.Add(idf2);

            DotNetAssemblyProject p3 = new DotNetAssemblyProject("C#");

            p3.FileName = Path.Combine(dir, "p3");
            f2.Items.Add(p3);
            string idp3 = p3.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp3));
            Assert.IsFalse(ids.Contains(idp3));
            ids.Add(idp3);

            DotNetAssemblyProject p4 = new DotNetAssemblyProject("C#");

            p4.FileName = Path.Combine(dir, "p4");
            f2.Items.Add(p4);
            string idp4 = p4.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp4));
            Assert.IsFalse(ids.Contains(idp4));
            ids.Add(idp4);

            sol.Save(Util.GetMonitor());

            Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName);

            Assert.AreEqual(4, sol2.Items.Count);
            Assert.AreEqual(2, sol2.RootFolder.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), sol2.RootFolder.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType());
            Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name);
            Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name);
            Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
            Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1");

            f1 = (SolutionFolder)sol2.RootFolder.Items [1];
            Assert.AreEqual(2, f1.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), f1.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType());
            Assert.AreEqual("p2", f1.Items [0].Name);
            Assert.AreEqual("f2", f1.Items [1].Name);
            Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2");
            Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2");

            f2 = (SolutionFolder)f1.Items [1];
            Assert.AreEqual(2, f2.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [0].GetType());
            Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [1].GetType());
            Assert.AreEqual("p3", f2.Items [0].Name);
            Assert.AreEqual("p4", f2.Items [1].Name);
            Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4");
            Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4");
        }
예제 #17
0
		public void SolutionItemsEvents()
		{
			int countFileAddedToProject = 0;
			int countFileRemovedFromProject = 0;
			int countFileRenamedInProject = 0;
			int countReferenceAddedToProject = 0;
			int countReferenceRemovedFromProject = 0;
			int countSolutionItemAdded = 0;
			int countSolutionItemRemoved = 0;
			
			Solution sol = new Solution ();
			sol.FileAddedToProject += delegate {
				countFileAddedToProject++;
			};
			sol.FileRemovedFromProject += delegate {
				countFileRemovedFromProject++;
			};
			sol.FileRenamedInProject += delegate {
				countFileRenamedInProject++;
			};
			sol.ReferenceAddedToProject += delegate {
				countReferenceAddedToProject++;
			};
			sol.ReferenceRemovedFromProject += delegate {
				countReferenceRemovedFromProject++;
			};
			sol.SolutionItemAdded += delegate {
				countSolutionItemAdded++;
			};
			sol.SolutionItemRemoved += delegate {
				countSolutionItemRemoved++;
			};
			
			Assert.AreEqual (0, countFileAddedToProject);
			Assert.AreEqual (0, countFileRemovedFromProject);
			Assert.AreEqual (0, countFileRenamedInProject);
			Assert.AreEqual (0, countReferenceAddedToProject);
			Assert.AreEqual (0, countReferenceRemovedFromProject);
			Assert.AreEqual (0, countSolutionItemAdded);
			Assert.AreEqual (0, countSolutionItemRemoved);
			
			SolutionFolder folder = new SolutionFolder ();
			folder.Name = "Folder1";
			sol.RootFolder.Items.Add (folder);
			
			Assert.AreEqual (1, countSolutionItemAdded);
			Assert.AreEqual (0, sol.Items.Count);
			
			DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
			project.Name = "project1";
			sol.RootFolder.Items.Add (project);
			
			Assert.AreEqual (2, countSolutionItemAdded);
			Assert.AreEqual (1, sol.Items.Count);
			
			DotNetAssemblyProject project2 = new DotNetAssemblyProject ("C#");
			project2.Name = "project2";
			folder.Items.Add (project2);
			
			Assert.AreEqual (3, countSolutionItemAdded);
			Assert.AreEqual (2, sol.Items.Count);
			
			ProjectFile p1 = new ProjectFile ("test1.cs");
			project2.Files.Add (p1);
			Assert.AreEqual (1, countFileAddedToProject);
			
			ProjectFile p2 = new ProjectFile ("test1.cs");
			project.Files.Add (p2);
			Assert.AreEqual (2, countFileAddedToProject);
			
			p1.Name = "test2.cs";
			Assert.AreEqual (1, countFileRenamedInProject);
			
			p2.Name = "test2.cs";
			Assert.AreEqual (2, countFileRenamedInProject);
			
			project2.Files.Remove (p1);
			Assert.AreEqual (1, countFileRemovedFromProject);
			
			project.Files.Remove ("test2.cs");
			Assert.AreEqual (2, countFileRemovedFromProject);
			
			ProjectReference pr1 = new ProjectReference (ReferenceType.Package, "SomeTest");
			project.References.Add (pr1);
			Assert.AreEqual (1, countReferenceAddedToProject);
			
			ProjectReference pr2 = new ProjectReference (project);
			project2.References.Add (pr2);
			Assert.AreEqual (2, countReferenceAddedToProject);
			
			project.References.Remove (pr1);
			Assert.AreEqual (1, countReferenceRemovedFromProject);
			
			sol.RootFolder.Items.Remove (project);
			Assert.AreEqual (2, countReferenceRemovedFromProject, "Removing a project must remove all references to it");
			Assert.AreEqual (1, countSolutionItemRemoved);
			Assert.AreEqual (1, sol.Items.Count);
			
			folder.Items.Remove (project2);
			Assert.AreEqual (2, countSolutionItemRemoved);
			Assert.AreEqual (0, sol.Items.Count);
			
			sol.RootFolder.Items.Remove (folder);
			
			Assert.AreEqual (2, countFileAddedToProject);
			Assert.AreEqual (2, countFileRemovedFromProject);
			Assert.AreEqual (2, countFileRenamedInProject);
			Assert.AreEqual (2, countReferenceAddedToProject);
			Assert.AreEqual (2, countReferenceRemovedFromProject);
			Assert.AreEqual (3, countSolutionItemAdded);
			Assert.AreEqual (3, countSolutionItemRemoved);
		}
예제 #18
0
        public void ModelQueries()
        {
            DotNetProject it2, it3, it4;
            DummySolutionItem it1;
            string someFile, someId;

            Workspace ws = new Workspace ();
            Workspace cws = new Workspace ();
            ws.Items.Add (cws);

            Solution sol1 = new Solution ();
            cws.Items.Add (sol1);
            sol1.RootFolder.Items.Add (it1 = new DummySolutionItem ());
            sol1.RootFolder.Items.Add (it2 = new DotNetAssemblyProject ("C#"));

            Solution sol2 = new Solution ();
            cws.Items.Add (sol2);
            SolutionFolder f = new SolutionFolder ();
            sol2.RootFolder.Items.Add (f);
            f.Items.Add (it3 = new DotNetAssemblyProject ("C#"));
            f.Items.Add (it4 = new DotNetAssemblyProject ("C#"));

            it3.Name = "it3";
            it4.FileName = "/test/it4";
            someFile = it4.FileName;
            someId = it3.ItemId;
            Assert.IsFalse (string.IsNullOrEmpty (someId));

            Assert.AreEqual (2, sol1.Items.Count);
            Assert.IsTrue (sol1.Items.Contains (it1));
            Assert.IsTrue (sol1.Items.Contains (it2));

            Assert.AreEqual (2, sol2.Items.Count);
            Assert.IsTrue (sol2.Items.Contains (it3));
            Assert.IsTrue (sol2.Items.Contains (it4));

            ReadOnlyCollection<SolutionItem> its = ws.GetAllSolutionItems ();
            Assert.AreEqual (7, its.Count);
            Assert.IsTrue (its.Contains (it1));
            Assert.IsTrue (its.Contains (it2));
            Assert.IsTrue (its.Contains (it3));
            Assert.IsTrue (its.Contains (it4));
            Assert.IsTrue (its.Contains (sol1.RootFolder));
            Assert.IsTrue (its.Contains (sol2.RootFolder));
            Assert.IsTrue (its.Contains (f));

            ReadOnlyCollection<DotNetProject> its2 = ws.GetAllSolutionItems<DotNetProject> ();
            Assert.AreEqual (3, its2.Count);
            Assert.IsTrue (its2.Contains (it2));
            Assert.IsTrue (its2.Contains (it3));
            Assert.IsTrue (its2.Contains (it4));

            ReadOnlyCollection<Project> its3 = ws.GetAllProjects ();
            Assert.AreEqual (3, its3.Count);
            Assert.IsTrue (its3.Contains (it2));
            Assert.IsTrue (its3.Contains (it3));
            Assert.IsTrue (its3.Contains (it4));

            ReadOnlyCollection<Solution> its4 = ws.GetAllSolutions ();
            Assert.AreEqual (2, its4.Count);
            Assert.IsTrue (its4.Contains (sol1));
            Assert.IsTrue (its4.Contains (sol2));

            ReadOnlyCollection<WorkspaceItem> its5= ws.GetAllItems ();
            Assert.AreEqual (4, its5.Count);
            Assert.IsTrue (its5.Contains (ws));
            Assert.IsTrue (its5.Contains (cws));
            Assert.IsTrue (its5.Contains (sol2));
            Assert.IsTrue (its5.Contains (sol2));

            ReadOnlyCollection<Workspace> its6 = ws.GetAllItems<Workspace> ();
            Assert.AreEqual (2, its6.Count);
            Assert.IsTrue (its6.Contains (ws));
            Assert.IsTrue (its6.Contains (cws));

            SolutionEntityItem fi = ws.FindSolutionItem (someFile);
            Assert.AreEqual (it4, fi);

            fi = ws.FindSolutionItem (someFile + ".wrong");
            Assert.IsNull (fi);

            SolutionItem si = sol2.GetSolutionItem (someId);
            Assert.AreEqual (it3, si);

            fi = sol2.FindSolutionItem (someFile);
            Assert.AreEqual (it4, fi);

            fi = sol2.FindProjectByName ("it3");
            Assert.AreEqual (it3, fi);

            fi = sol2.FindProjectByName ("it4");
            Assert.AreEqual (it4, fi);

            fi = sol2.FindProjectByName ("it2");
            Assert.IsNull (fi);
        }
		public object ReadFile (FilePath fileName, bool hasParentSolution, IProgressMonitor monitor)
		{
			FilePath basePath = fileName.ParentDirectory;
			MonoMakefile mkfile = new MonoMakefile (fileName);
			string aname = mkfile.GetVariable ("LIBRARY");
			if (aname == null) aname = mkfile.GetVariable ("PROGRAM");
			
			try {
				ProjectExtensionUtil.BeginLoadOperation ();
				if (aname != null) {
					// It is a project
					monitor.BeginTask ("Loading '" + fileName + "'", 0);
					DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
					MonoSolutionItemHandler handler = new MonoSolutionItemHandler (project);
					ProjectExtensionUtil.InstallHandler (handler, project);
					project.Name = Path.GetFileName (basePath);
					handler.Read (mkfile);
					monitor.EndTask ();
					return project;
				} else {
					string subdirs;
					StringBuilder subdirsBuilder = new StringBuilder ();
					subdirsBuilder.Append (mkfile.GetVariable ("common_dirs"));
					if (subdirsBuilder.Length != 0) {
						subdirsBuilder.Append ("\t");
						subdirsBuilder.Append (mkfile.GetVariable ("net_2_0_dirs"));
					}
					if (subdirsBuilder.Length == 0)
						subdirsBuilder.Append (mkfile.GetVariable ("SUBDIRS"));
	
					subdirs = subdirsBuilder.ToString ();
					if (subdirs != null && (subdirs = subdirs.Trim (' ','\t')) != "")
					{
						object retObject;
						SolutionFolder folder;
						if (!hasParentSolution) {
							Solution sol = new Solution ();
							sol.ConvertToFormat (Services.ProjectService.FileFormats.GetFileFormat ("MonoMakefile"), false);
							sol.FileName = fileName;
							folder = sol.RootFolder;
							retObject = sol;
							
							foreach (string conf in MonoMakefileFormat.Configurations) {
								SolutionConfiguration sc = new SolutionConfiguration (conf);
								sol.Configurations.Add (sc);
							}
						} else {
							folder = new SolutionFolder ();
							folder.Name = Path.GetFileName (Path.GetDirectoryName (fileName));
							retObject = folder;
						}
						
						subdirs = subdirs.Replace ('\t',' ');
						string[] dirs = subdirs.Split (' ');
						
						monitor.BeginTask ("Loading '" + fileName + "'", dirs.Length);
						Hashtable added = new Hashtable ();
						foreach (string dir in dirs) {
							if (added.Contains (dir)) continue;
							added.Add (dir, dir);
							monitor.Step (1);
							if (dir == null) continue;
							string tdir = dir.Trim ();
							if (tdir == "") continue;
							string mfile = Path.Combine (Path.Combine (basePath, tdir), "Makefile");
							if (File.Exists (mfile) && CanReadFile (mfile, typeof(SolutionItem))) {
								SolutionItem it = (SolutionItem) ReadFile (mfile, true, monitor);
								folder.Items.Add (it);
							}
						}
						monitor.EndTask ();
						return retObject;
					}
				}
			} finally {
				ProjectExtensionUtil.EndLoadOperation ();
			}
			return null;
		}
예제 #20
0
		public void SanitizeProjectNamespace ()
		{
			var info = new ProjectCreateInformation {
				ProjectBasePath = "/tmp/test",
				ProjectName = "abc.0"
			};
			var project = new DotNetAssemblyProject ("C#", info, null);
			Assert.AreEqual ("abc", project.DefaultNamespace);

			info.ProjectName = "a.";
			project = new DotNetAssemblyProject ("C#", info, null);
			Assert.AreEqual ("a", project.DefaultNamespace);
		}
        public void RemoveSharedProjectFromSolution()
        {
            var sol = new Solution ();

            var shared = new SharedAssetsProject ("C#");
            shared.AddFile ("Foo.cs");

            var main = new DotNetAssemblyProject ("C#");
            var pref = new ProjectReference (shared);
            main.References.Add (pref);

            sol.RootFolder.AddItem (main);
            sol.RootFolder.AddItem (shared);

            Assert.IsNotNull (main.Files.GetFile ("Foo.cs"));
            Assert.IsTrue (main.References.Contains (pref));

            sol.RootFolder.Items.Remove (shared);

            // The shared file and the reference must be gone.

            Assert.IsNull (main.Files.GetFile ("Foo.cs"));
            Assert.IsFalse (main.References.Contains (pref));
        }
		public SolutionEntityItem CreatePrjxFromCsproj (string csprojFileName, IProgressMonitor monitor)
		{
			try {
				FileFormat format = Services.ProjectService.FileFormats.GetFileFormatForFile (csprojFileName, typeof(SolutionEntityItem));
				if (format != null && format.Id != "VS2003ProjectFileFormat")
					return (SolutionEntityItem) Services.ProjectService.ReadSolutionItem (monitor, csprojFileName);
				
				MonoDevelop.Prj2Make.Schema.Csproj.VisualStudioProject csprojObj = null;
				
				monitor.BeginTask (GettextCatalog.GetString ("Importing project: ") + csprojFileName, 4);
				
				DotNetAssemblyProject prjxObj = new DotNetAssemblyProject ("C#", null, null);
				
				prjxFileName = String.Format ("{0}.mdp",
					Path.Combine (Path.GetDirectoryName (csprojFileName),
					Path.GetFileNameWithoutExtension (csprojFileName))
					);

				// Load the csproj
				using (TextFileReader fsIn = new TextFileReader (csprojFileName)) {
					XmlSerializer xmlDeSer = new XmlSerializer (typeof(VisualStudioProject));
					csprojObj = (VisualStudioProject) xmlDeSer.Deserialize (fsIn);
				}
				
				monitor.Step (1);

				// Begin prjxObj population
				prjxObj.FileName = prjxFileName;
				prjxObj.Name = Path.GetFileNameWithoutExtension(csprojFileName);
				prjxObj.Description = "";
				prjxObj.NewFileSearch = NewFileSearch.None;
				prjxObj.DefaultNamespace = csprojObj.CSHARP.Build.Settings.RootNamespace;

				GetContents (prjxObj, csprojObj.CSHARP.Files.Include, prjxObj.Files, monitor);
				monitor.Step (1);
				
				GetReferences (prjxObj, csprojObj.CSHARP.Build.References, prjxObj.References, monitor);
				monitor.Step (1);
				
				prjxObj.Configurations.Clear ();
				foreach (Config cblock in csprojObj.CSHARP.Build.Settings.Config)
				{
					prjxObj.Configurations.Add (CreateConfigurationBlock (
						prjxObj,
						cblock,
						csprojObj.CSHARP.Build.Settings.AssemblyName,
						csprojObj.CSHARP.Build.Settings.OutputType,
						monitor
						));
				}
				monitor.Step (1);
				return prjxObj;

			} catch (Exception ex) {
				monitor.ReportError (GettextCatalog.GetString ("Could not import project:") + csprojFileName, ex);
				throw;
			} finally {
				monitor.EndTask ();
			}
		}
		static void TestInsertionPoints (string text)
		{
			
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			TestViewContent sev = new TestViewContent ();
			DotNetProject project = new DotNetAssemblyProject ("C#");
			project.FileName = GetTempFile (".csproj");
			
			string file = GetTempFile (".cs");
			project.AddFile (file);
			sev.Project = project;
			sev.ContentName = file;
			tww.ViewContent = sev;
			var doc = new MonoDevelop.Ide.Gui.Document (tww);
			var data = doc.Editor;
			List<InsertionPoint> loc = new List<InsertionPoint> ();
			for (int i = 0; i < text.Length; i++) {
				char ch = text[i];
				if (ch == '@') {
					i++;
					ch = text[i];
					NewLineInsertion insertBefore = NewLineInsertion.None;
					NewLineInsertion insertAfter  = NewLineInsertion.None;
					
					switch (ch) {
					case 'n':
						break;
					case 'd':
						insertAfter = NewLineInsertion.Eol;
						break;
					case 'D':
						insertAfter = NewLineInsertion.BlankLine;
						break;
					case 'u':
						insertBefore = NewLineInsertion.Eol;
						break;
					case 'U':
						insertBefore = NewLineInsertion.BlankLine;
						break;
					case 's':
						insertBefore = insertAfter = NewLineInsertion.Eol;
						break;
					case 'S':
						insertBefore = insertAfter = NewLineInsertion.BlankLine;
						break;
						
					case 't':
						insertBefore = NewLineInsertion.Eol;
						insertAfter = NewLineInsertion.BlankLine;
						break;
					case 'T':
						insertBefore = NewLineInsertion.None;
						insertAfter = NewLineInsertion.BlankLine;
						break;
					case 'v':
						insertBefore = NewLineInsertion.BlankLine;
						insertAfter = NewLineInsertion.Eol;
						break;
					case 'V':
						insertBefore = NewLineInsertion.None;
						insertAfter = NewLineInsertion.Eol;
						break;
					default:
						Assert.Fail ("unknown insertion point:" + ch);
						break;
					}
					loc.Add (new InsertionPoint (data.Document.OffsetToLocation (data.Document.Length), insertBefore, insertAfter));
				} else {
					data.Insert (data.Document.Length, ch.ToString ());
				}
			}
			
			
			doc.ParsedDocument =  new NRefactoryParser ().Parse (null, "a.cs", data.Document.Text);
			
			var foundPoints = HelperMethods.GetInsertionPoints (doc, doc.ParsedDocument.CompilationUnit.Types[0]);
			Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match");
			for (int i = 0; i < loc.Count; i++) {
				Assert.AreEqual (loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
				Assert.AreEqual (loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
				Assert.AreEqual (loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
			}
		}
예제 #24
0
		public static DotNetProject CreateProject (string dir, string lang, string name)
		{
			DotNetAssemblyProject project = new DotNetAssemblyProject (lang);
			InitializeProject (dir, project, name);
			return project;
		}
예제 #25
0
		public static Solution CreateConsoleSolution (string hint)
		{
			string dir = Util.CreateTmpDir (hint);
			
			Solution sol = new Solution ();
			SolutionConfiguration scDebug = sol.AddConfiguration ("Debug", true);
			
			DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
			sol.RootFolder.Items.Add (project);
			Assert.AreEqual (0, project.Configurations.Count);
			
			InitializeProject (dir, project, "TestProject");
			project.References.Add (new ProjectReference (ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
			project.References.Add (new ProjectReference (ReferenceType.Package, "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
			project.References.Add (new ProjectReference (ReferenceType.Package, "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
			project.Files.Add (new ProjectFile (Path.Combine (dir, "Program.cs")));
			project.Files.Add (new ProjectFile (Path.Combine (dir, "Resource.xml"), BuildAction.EmbeddedResource));
			project.Files.Add (new ProjectFile (Path.Combine (dir, "Excluded.xml"), BuildAction.Content));
			ProjectFile pf = new ProjectFile (Path.Combine (dir, "Copy.xml"), BuildAction.Content);
			pf.CopyToOutputDirectory = FileCopyMode.Always;
			project.Files.Add (pf);
			project.Files.Add (new ProjectFile (Path.Combine (dir, "Nothing.xml"), BuildAction.None));
			
			Assert.IsFalse (scDebug.GetEntryForItem (project).Build);
			scDebug.GetEntryForItem (project).Build = true;
			
			SolutionConfiguration scRelease = sol.AddConfiguration ("Release", true);
			
			string file = Path.Combine (dir, "TestSolution.sln");
			sol.FileName = file;
			
			Assert.AreEqual (2, sol.Configurations.Count);
			Assert.AreEqual (1, scDebug.Configurations.Count);
			Assert.AreEqual (1, scRelease.Configurations.Count);
			Assert.AreEqual (2, project.Configurations.Count);
			foreach (var v in project.Files) {
				if (v.FilePath.FileName == "Program.cs") {
				File.WriteAllText (v.FilePath,
				                   @"
using System;

namespace Foo {
	public class MainClass {
		public static void Main (string [] args)
		{
		}
	}
}");
				} else {
					File.WriteAllText (v.FilePath, v.Name);
				}
			}
			return sol;
		}
예제 #26
0
		public void SharedProjectCantBeStartup ()
		{
			var sol = new Solution ();
			var shared = new SharedAssetsProject ();

			// Shared projects are not executable
			Assert.IsFalse (shared.SupportsExecute ());

			sol.RootFolder.AddItem (shared);

			// The shared project is not executable, so it shouldn't be set as startup by default
			Assert.IsNull (sol.StartupItem);

			// An executable project is set as startup by default when there is no startup project
			DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
			sol.RootFolder.AddItem (project);
			Assert.IsTrue (sol.StartupItem == project);
		}
예제 #27
0
		public static void TestLoadSaveSolutionFolders (string fileFormat)
		{
			List<string> ids = new List<string> ();
			
			Solution sol = new Solution ();
			sol.ConvertToFormat (Services.ProjectService.FileFormats.GetFileFormat (fileFormat), true);
			string dir = Util.CreateTmpDir ("solution-folders-" + fileFormat);
			sol.FileName = Path.Combine (dir, "TestSolutionFolders");
			sol.Name = "TheSolution";
			
			DotNetAssemblyProject p1 = new DotNetAssemblyProject ("C#");
			p1.FileName = Path.Combine (dir, "p1");
			sol.RootFolder.Items.Add (p1);
			string idp1 = p1.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp1));
			Assert.IsFalse (ids.Contains (idp1));
			ids.Add (idp1);

			SolutionFolder f1 = new SolutionFolder ();
			f1.Name = "f1";
			sol.RootFolder.Items.Add (f1);
			string idf1 = f1.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idf1));
			Assert.IsFalse (ids.Contains (idf1));
			ids.Add (idf1);
			
			DotNetAssemblyProject p2 = new DotNetAssemblyProject ("C#");
			p2.FileName = Path.Combine (dir, "p2");
			f1.Items.Add (p2);
			string idp2 = p2.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp2));
			Assert.IsFalse (ids.Contains (idp2));
			ids.Add (idp2);

			SolutionFolder f2 = new SolutionFolder ();
			f2.Name = "f2";
			f1.Items.Add (f2);
			string idf2 = f2.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idf2));
			Assert.IsFalse (ids.Contains (idf2));
			ids.Add (idf2);
			
			DotNetAssemblyProject p3 = new DotNetAssemblyProject ("C#");
			p3.FileName = Path.Combine (dir, "p3");
			f2.Items.Add (p3);
			string idp3 = p3.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp3));
			Assert.IsFalse (ids.Contains (idp3));
			ids.Add (idp3);
			
			DotNetAssemblyProject p4 = new DotNetAssemblyProject ("C#");
			p4.FileName = Path.Combine (dir, "p4");
			f2.Items.Add (p4);
			string idp4 = p4.ItemId;
			Assert.IsFalse (string.IsNullOrEmpty (idp4));
			Assert.IsFalse (ids.Contains (idp4));
			ids.Add (idp4);
			
			sol.Save (Util.GetMonitor ());
			
			Solution sol2 = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
			Assert.AreEqual (4, sol2.Items.Count);
			Assert.AreEqual (2, sol2.RootFolder.Items.Count);
			Assert.AreEqual (typeof(DotNetAssemblyProject), sol2.RootFolder.Items [0].GetType ());
			Assert.AreEqual (typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType ());
			Assert.AreEqual ("p1", sol2.RootFolder.Items [0].Name);
			Assert.AreEqual ("f1", sol2.RootFolder.Items [1].Name);
			Assert.AreEqual (idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
			Assert.AreEqual (idf1, sol2.RootFolder.Items [1].ItemId, "idf1");
			
			f1 = (SolutionFolder) sol2.RootFolder.Items [1];
			Assert.AreEqual (2, f1.Items.Count);
			Assert.AreEqual (typeof(DotNetAssemblyProject), f1.Items [0].GetType ());
			Assert.AreEqual (typeof(SolutionFolder), f1.Items [1].GetType ());
			Assert.AreEqual ("p2", f1.Items [0].Name);
			Assert.AreEqual ("f2", f1.Items [1].Name);
			Assert.AreEqual (idp2, f1.Items [0].ItemId, "idp2");
			Assert.AreEqual (idf2, f1.Items [1].ItemId, "idf2");
			
			f2 = (SolutionFolder) f1.Items [1];
			Assert.AreEqual (2, f2.Items.Count);
			Assert.AreEqual (typeof(DotNetAssemblyProject), f2.Items [0].GetType ());
			Assert.AreEqual (typeof(DotNetAssemblyProject), f2.Items [1].GetType ());
			Assert.AreEqual ("p3", f2.Items [0].Name);
			Assert.AreEqual ("p4", f2.Items [1].Name);
			Assert.AreEqual (idp3, f2.Items [0].ItemId, "idp4");
			Assert.AreEqual (idp4, f2.Items [1].ItemId, "idp4");
		}
예제 #28
0
		public void ProjectNameWithDots ()
		{
			// Test case for bug #437392

			ProjectCreateInformation info = new ProjectCreateInformation ();
			info.ProjectName = "Some.Test";
			info.ProjectBasePath = "/tmp/test";
			DotNetProject p = new DotNetAssemblyProject ("C#", info, null);

			Assert.AreEqual (2, p.Configurations.Count);
			Assert.AreEqual ("Debug", p.Configurations [0].Name);
			Assert.AreEqual ("Release", p.Configurations [1].Name);
			
			Assert.AreEqual ("Some.Test", ((DotNetProjectConfiguration) p.Configurations [0]).OutputAssembly);
			Assert.AreEqual ("Some.Test", ((DotNetProjectConfiguration) p.Configurations [1]).OutputAssembly);
		}
예제 #29
0
		public void ProjectName ()
		{
			int nameChanges = 0;
			
			DotNetAssemblyProject prj = new DotNetAssemblyProject ("C#");
			prj.FileFormat = Util.FileFormatMSBuild05;
			prj.NameChanged += delegate {
				nameChanges++;
			};
			
			prj.Name = "test1";
			Assert.AreEqual ("test1", prj.Name);
			Assert.AreEqual ("test1.csproj", (string) prj.FileName);
			Assert.AreEqual (1, nameChanges);
			
			prj.Name = "test2";
			Assert.AreEqual ("test2", prj.Name);
			Assert.AreEqual ("test2.csproj", (string) prj.FileName);
			Assert.AreEqual (2, nameChanges);
			
			string fname = Path.Combine (Path.GetTempPath (), "test3.csproj");
			prj.FileName = fname;
			Assert.AreEqual ("test3", prj.Name);
			Assert.AreEqual (fname, (string) prj.FileName);
			Assert.AreEqual (3, nameChanges);
			
			prj.Name = "test4";
			Assert.AreEqual ("test4", prj.Name);
			Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
			Assert.AreEqual (4, nameChanges);
			
			prj.FileFormat = Util.FileFormatMD1;
			Assert.AreEqual ("test4", prj.Name);
			Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.mdp"), (string) prj.FileName);
			Assert.AreEqual (4, nameChanges);
			Assert.AreEqual ("MD1", prj.FileFormat.Id);
			
			// Projects inherit the file format from the parent solution
			Solution sol = new Solution ();
			sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
			sol.RootFolder.Items.Add (prj);
			Assert.AreEqual ("test4", prj.Name);
			Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
			Assert.AreEqual (4, nameChanges);
			Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);

			// Removing the project from the solution should not restore the old format
			sol.RootFolder.Items.Remove (prj);
			Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);
			Assert.AreEqual ("test4", prj.Name);
			Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
			Assert.AreEqual (4, nameChanges);
		}
예제 #30
0
		public void NewConfigurationsHaveAnAssemblyName ()
		{
			DotNetProject p = new DotNetAssemblyProject ("C#");
			p.Name = "HiThere";
			DotNetProjectConfiguration c = (DotNetProjectConfiguration) p.CreateConfiguration ("First");
			Assert.AreEqual ("HiThere", c.OutputAssembly);
		}
예제 #31
0
		public void FormatConversions ()
		{
			Solution sol = TestProjectsChecks.CreateConsoleSolution ("reloading");
			Project p = (Project) sol.Items [0];
			
			Assert.AreEqual (Services.ProjectService.DefaultFileFormatId, sol.FileFormat.Id);
			Assert.AreEqual (Services.ProjectService.DefaultFileFormatId, p.FileFormat.Id);
			
			// Change solution format of unsaved solution
			
			sol.ConvertToFormat (Util.FileFormatMD1, true);
			
			Assert.AreEqual ("MD1", sol.FileFormat.Id);
			Assert.AreEqual ("MD1", p.FileFormat.Id);
			
			sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
			
			Assert.AreEqual ("MSBuild05", sol.FileFormat.Id);
			Assert.AreEqual ("MSBuild05", p.FileFormat.Id);
			
			// Change solution format of saved solution
			
			sol.Save (Util.GetMonitor ());

			sol.ConvertToFormat (Util.FileFormatMD1, false);
			
			Assert.AreEqual ("MD1", sol.FileFormat.Id);
			Assert.AreEqual ("MSBuild05", p.FileFormat.Id);
			
			p.FileFormat = Util.FileFormatMD1;
			Assert.AreEqual ("MD1", p.FileFormat.Id);
			
			// Add new project
			
			Project newp = new DotNetAssemblyProject ("C#");
			Assert.AreEqual ("MSBuild10", newp.FileFormat.Id);
			
			sol.RootFolder.Items.Add (newp);
			Assert.AreEqual ("MD1", newp.FileFormat.Id);
			
			// Add saved project
			
			string solFile = Util.GetSampleProject ("console-project", "ConsoleProject.sln");
			Solution msol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			
			Project mp = (Project) msol.Items [0];
			Assert.AreEqual ("MSBuild05", mp.FileFormat.Id);
			
			sol.RootFolder.Items.Add (newp);
			Assert.AreEqual ("MSBuild05", mp.FileFormat.Id);
		}
        public static Solution CreateConsoleSolution(string hint)
        {
            string dir = Util.CreateTmpDir(hint);

            Solution sol = new Solution();
            SolutionConfiguration scDebug = sol.AddConfiguration("Debug", true);

            DotNetAssemblyProject project = new DotNetAssemblyProject("C#");

            sol.RootFolder.Items.Add(project);
            Assert.AreEqual(0, project.Configurations.Count);

            InitializeProject(dir, project, "TestProject");
            project.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.References.Add(new ProjectReference(ReferenceType.Package, "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.References.Add(new ProjectReference(ReferenceType.Package, "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Program.cs")));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Resource.xml"), BuildAction.EmbeddedResource));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Excluded.xml"), BuildAction.Content));
            ProjectFile pf = new ProjectFile(Path.Combine(dir, "Copy.xml"), BuildAction.Content);

            pf.CopyToOutputDirectory = FileCopyMode.Always;
            project.Files.Add(pf);
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Nothing.xml"), BuildAction.None));

            Assert.IsFalse(scDebug.GetEntryForItem(project).Build);
            scDebug.GetEntryForItem(project).Build = true;

            SolutionConfiguration scRelease = sol.AddConfiguration("Release", true);

            string file = Path.Combine(dir, "TestSolution.sln");

            sol.FileName = file;

            Assert.AreEqual(2, sol.Configurations.Count);
            Assert.AreEqual(1, scDebug.Configurations.Count);
            Assert.AreEqual(1, scRelease.Configurations.Count);
            Assert.AreEqual(2, project.Configurations.Count);
            foreach (var v in project.Files)
            {
                if (v.FilePath.FileName == "Program.cs")
                {
                    File.WriteAllText(v.FilePath,
                                      @"
using System;

namespace Foo {
	public class MainClass {
		public static void Main (string [] args)
		{
		}
	}
}");
                }
                else
                {
                    File.WriteAllText(v.FilePath, v.Name);
                }
            }
            return(sol);
        }