diff options
25 files changed, 243 insertions, 637 deletions
diff --git a/main/src/addins/AspNet/Tests/Razor/RazorParserTests.cs b/main/src/addins/AspNet/Tests/Razor/RazorParserTests.cs index fc714ebaf8..4e02e75af2 100644 --- a/main/src/addins/AspNet/Tests/Razor/RazorParserTests.cs +++ b/main/src/addins/AspNet/Tests/Razor/RazorParserTests.cs @@ -31,7 +31,9 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using MonoDevelop.AspNet.Razor; using MonoDevelop.Core.Text; using MonoDevelop.Ide; +using MonoDevelop.Ide.Editor; using MonoDevelop.Ide.Gui; +using MonoDevelop.Ide.Gui.Documents; using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Projects; using NUnit.Framework; @@ -47,7 +49,10 @@ namespace MonoDevelop.AspNet.Tests.Razor [TearDown] public override void TearDown () { - TypeSystemServiceTestExtensions.UnloadSolution (solution); + if (solution != null) { + TypeSystemServiceTestExtensions.UnloadSolution (solution); + solution.Dispose (); + } base.TearDown (); } @@ -75,16 +80,9 @@ namespace MonoDevelop.AspNet.Tests.Razor projectFile.Generator = "RazorTemplatePreprocessor"; var sev = new TestViewContent (); - sev.Project = project; - sev.ContentName = file; + await sev.Initialize (new FileDescriptor (file, null, project), null); sev.Text = text; - - var tww = new TestWorkbenchWindow (); - tww.ViewContent = sev; - - var doc = new TestDocument (tww); - doc.Editor.FileName = sev.ContentName; - doc.UpdateProject (project); + sev.Editor.FileName = sev.FilePath; solution = new MonoDevelop.Projects.Solution (); solution.DefaultSolutionFolder.AddItem (project); @@ -92,7 +90,7 @@ namespace MonoDevelop.AspNet.Tests.Razor await TypeSystemServiceTestExtensions.LoadSolution (solution); var parser = new RazorTestingParser { - Doc = doc + Editor = sev.Editor }; var options = new ParseOptions { Project = project, @@ -102,5 +100,17 @@ namespace MonoDevelop.AspNet.Tests.Razor return (RazorCSharpParsedDocument)parser.Parse (options, default(CancellationToken)).Result; } } + + public class RazorTestingParser : RazorCSharpParser + { + public TextEditor Editor { get; set; } + + public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) + { + Editor.FileName = parseOptions.FileName; + OpenDocuments.Add (new OpenRazorDocument (Editor)); + return base.Parse (parseOptions, cancellationToken); + } + } } diff --git a/main/src/addins/AspNet/Tests/WebForms/WebFormsTesting.cs b/main/src/addins/AspNet/Tests/WebForms/WebFormsTesting.cs index a27a72e24f..29edd623d8 100644 --- a/main/src/addins/AspNet/Tests/WebForms/WebFormsTesting.cs +++ b/main/src/addins/AspNet/Tests/WebForms/WebFormsTesting.cs @@ -32,6 +32,8 @@ using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Projects; +using MonoDevelop.Ide.Gui.Documents; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AspNet.Tests.WebForms { @@ -89,27 +91,26 @@ namespace MonoDevelop.AspNet.Tests.WebForms project.AddFile (file); sev = new TestViewContent (); - sev.Project = project; - sev.ContentName = file; + await sev.Initialize (new FileDescriptor (file, null, project), null); + sev.Text = editorText; sev.CursorPosition = cursorPosition; - var tww = new TestWorkbenchWindow (); - tww.ViewContent = sev; - - var doc = new TestDocument (tww); - doc.Editor.FileName = sev.ContentName; var parser = new WebFormsParser (); var options = new ParseOptions { Project = project, - FileName = sev.ContentName, + FileName = file, Content = new StringTextSource (parsedText) }; + sev.Editor.FileName = sev.FilePath; + var parsedDoc = await parser.Parse (options, default(CancellationToken)) as WebFormsParsedDocument; - doc.HiddenParsedDocument = parsedDoc; + + var documentContext = sev.GetContent<RoslynDocumentContext> (); + documentContext.SetParsedDocument (parsedDoc); return new CreateEditorResult { - Extension = new WebFormsTestingEditorExtension (doc), + Extension = new WebFormsTestingEditorExtension (sev.Editor, documentContext), EditorText = editorText, ViewContent = sev }; @@ -117,9 +118,9 @@ namespace MonoDevelop.AspNet.Tests.WebForms public class WebFormsTestingEditorExtension : WebFormsEditorExtension { - public WebFormsTestingEditorExtension (Document doc) + public WebFormsTestingEditorExtension (TextEditor editor, DocumentContext documentContext) { - Initialize (doc.Editor, doc); + Initialize (editor, documentContext); } public CodeCompletionContext GetCodeCompletionContext (TestViewContent sev) diff --git a/main/src/addins/AspNet/WebForms/ILanguageCompletionBuilder.cs b/main/src/addins/AspNet/WebForms/ILanguageCompletionBuilder.cs index 41a22f1779..abe4f016af 100644 --- a/main/src/addins/AspNet/WebForms/ILanguageCompletionBuilder.cs +++ b/main/src/addins/AspNet/WebForms/ILanguageCompletionBuilder.cs @@ -47,8 +47,7 @@ namespace MonoDevelop.AspNet.WebForms public ParsedDocument ParsedLocalDocument { get; set; } public int CaretPosition { get; set; } public int OriginalCaretPosition { get; set; } - public HiddenDocument HiddenDocument { get; set; } - + public List<OffsetInfo> OffsetInfos = new List<OffsetInfo> (); public class OffsetInfo @@ -207,18 +206,4 @@ namespace MonoDevelop.AspNet.WebForms return null; } } - - public class HiddenDocument : MonoDevelop.Ide.Gui.Document - { - internal ParsedDocument HiddenParsedDocument; - public override ParsedDocument ParsedDocument { - get { - return HiddenParsedDocument; - } - } - - public HiddenDocument (MonoDevelop.Ide.Gui.IWorkbenchWindow window) : base(window) - { - } - } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.JSon/JSonIndentEngine.cs b/main/src/addins/CSharpBinding/MonoDevelop.JSon/JSonIndentEngine.cs index 3294fa2c4d..968adc6dd6 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.JSon/JSonIndentEngine.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.JSon/JSonIndentEngine.cs @@ -37,7 +37,6 @@ namespace MonoDevelop.JSon class JSonIndentEngine : IStateMachineIndentEngine { TextEditor editor; - DocumentContext ctx; int offset, line, column; internal int thisLineIndent, nextLineIndent; StringBuilder currentIndent; @@ -46,21 +45,17 @@ namespace MonoDevelop.JSon bool isLineStart; bool isInString; - public JSonIndentEngine (TextEditor editor, DocumentContext ctx) + public JSonIndentEngine (TextEditor editor) { if (editor == null) throw new ArgumentNullException ("editor"); - if (ctx == null) - throw new ArgumentNullException ("ctx"); this.editor = editor; - this.ctx = ctx; Reset (); } JSonIndentEngine (JSonIndentEngine jSonIndentEngine) { this.editor = jSonIndentEngine.editor; - this.ctx = jSonIndentEngine.ctx; this.offset = jSonIndentEngine.offset; this.line = jSonIndentEngine.line; this.column = jSonIndentEngine.column; diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishProfileTests.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishProfileTests.cs index 85bb331d83..b99c63db14 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishProfileTests.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishProfileTests.cs @@ -1,4 +1,4 @@ -// +// // PublishProfileTests.cs // // Author: @@ -40,16 +40,9 @@ using MonoDevelop.Core; namespace MonoDevelop.AspNetCore.Tests { [TestFixture] - class PublishProfileTests + [RequireService(typeof(RootWorkspace))] + class PublishProfileTests: TestBase { - [SetUp] - public void SetUp () - { - DesktopService.Initialize (); - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); - } - [TestCase ("Debug", "Any CPU", "netcoreapp2.0", "bin/Debug/netcoreapp2.0/publish")] [TestCase ("Release", "x86", "netcoreapp2.1", "bin/Debug/netcoreapp2.1/publish")] public void PublishProfilesCanBeRead (string configuration, string platform, string targetFramework, string publishDir) @@ -87,16 +80,13 @@ namespace MonoDevelop.AspNetCore.Tests //if there is NOT a Release configuration id, the expected relative path should follow: "bin/<CurrentActiveConfig>/<netcore-version>/publish" project.Configurations.Remove ("Release"); - IdeApp.Workspace.ActiveConfigurationId = "Debug"; + IdeServices.Workspace.ActiveConfigurationId = "Debug"; expected = $"bin/{project.GetActiveConfiguration ()}/{GetShortFrameworkIdentifier (project.TargetFramework.Id)}/publish"; Assert.That (resolver.GetDefaultFolder (UriKind.Relative) == expected); solution.Dispose (); } - [TearDown] - public async Task TearDown () => await IdeApp.Workspace.Close (); - string GetShortFrameworkIdentifier (TargetFrameworkMoniker framework) { string shortFrameworkIdentifier = framework.Identifier; diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/BasicTests.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/BasicTests.cs index 7cf847e987..150248ee3e 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/BasicTests.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/BasicTests.cs @@ -35,14 +35,6 @@ namespace MonoDevelop.UnitTesting.Tests { Solution sol; - [TestFixtureSetUp] - public void Start() - { - DesktopService.Initialize(); - IdeApp.Initialize(new ProgressMonitor()); - IdeApp.Workspace.ActiveConfigurationId = "Debug"; - } - [TearDown] public override void TearDown () { diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/TestResultBuilderTests.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/TestResultBuilderTests.cs index 0a764153c9..cb4a794837 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/TestResultBuilderTests.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/TestResultBuilderTests.cs @@ -31,11 +31,12 @@ using MonoDevelop.Core.Execution; using MonoDevelop.Projects;
using MonoDevelop.UnitTesting.VsTest; using NUnit.Framework; +using UnitTests; namespace MonoDevelop.UnitTesting.Tests { [TestFixture] - public class TestResultBuilderTests + public class TestResultBuilderTests : TestBase { TestResultBuilder builder; TestContext context; diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/UnitTestGroupTests.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/UnitTestGroupTests.cs index 42d4f93ed8..3ffd37a62e 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/UnitTestGroupTests.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/UnitTestGroupTests.cs @@ -29,11 +29,12 @@ using System.Linq; using MonoDevelop.Core.Execution; using MonoDevelop.Projects; using NUnit.Framework; +using UnitTests; namespace MonoDevelop.UnitTesting.Tests { [TestFixture] - public class UnitTestGroupTests + public class UnitTestGroupTests : TestBase { [Test] public void TestStatusUpdateCount () diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs index eb3a3f208c..a0748216f1 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs @@ -28,11 +28,12 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using MonoDevelop.UnitTesting.VsTest;
using NUnit.Framework; using System; +using UnitTests; namespace MonoDevelop.UnitTesting.Tests { [TestFixture] - class VsTestUnitTestTests + class VsTestUnitTestTests : TestBase { VsTestUnitTest CreateVsUnitTest (string fullyQualifiedName) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenTextEditorViewContent.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenTextEditorViewContent.cs deleted file mode 100644 index 0bfd0a0563..0000000000 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenTextEditorViewContent.cs +++ /dev/null @@ -1,236 +0,0 @@ -// -// HiddenTextEditorViewContent.cs -// -// Author: -// Mike Krüger <mkrueger@novell.com> -// -// Copyright (c) 2009 Novell, Inc (http://www.novell.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; -using MonoDevelop.Ide.Gui.Content; -using MonoDevelop.Components; -using MonoDevelop.Core; -using MonoDevelop.Ide.Editor; -using MonoDevelop.Core.Text; -using System.Threading.Tasks; - -namespace MonoDevelop.Ide.Gui -{ - public class HiddenTextEditorViewContent : MonoDevelop.Ide.Gui.ViewContent, IServiceProvider - { - readonly TextEditor editor; - - public TextEditor Editor { - get { - return editor; - } - } - - public override Control Control { - get { - return null; - } - } - - public HiddenTextEditorViewContent () - { - editor = TextEditorFactory.CreateNewEditor (); - Name = ""; - } - - public HiddenTextEditorViewContent (TextEditor editor) - { - this.editor = editor; - Name = editor.FileName; - } - - public FilePath Name { - get; - set; - } - - public bool HasInputFocus { - get { return false; } - } - - public int LineCount { - get { - return editor.LineCount; - } - } - - public string Text { - get { - return editor.Text; - } - set { - editor.Text = value; - } - } - - public int InsertText (int position, string text) - { - editor.InsertText (position, text); - return text.Length; - } - - public void DeleteText (int position, int length) - { - editor.ReplaceText (position, length, ""); - } - - public int Length { - get { - return editor.Length; - } - } - - public string GetText (int startPosition, int endPosition) - { - return editor.GetTextBetween (startPosition, endPosition); - } - public char GetCharAt (int position) - { - return editor.GetCharAt (position); - } - - public int GetPositionFromLineColumn (int line, int column) - { - return editor.LocationToOffset (line, column); - } - - public void GetLineColumnFromPosition (int position, out int line, out int column) - { - var loc = editor.OffsetToLocation (position); - line = loc.Line; - column = loc.Column; - } - - public string SelectedText { get { return ""; } set { } } - - public int CursorPosition { - get { - return editor.CaretOffset; - } - set { - editor.CaretOffset = value; - } - } - - public int SelectionStartPosition { - get { - if (!editor.IsSomethingSelected) - return editor.CaretOffset; - return editor.SelectionRange.Offset; - } - } - - public int SelectionEndPosition { - get { - if (!editor.IsSomethingSelected) - return editor.CaretOffset; - return editor.SelectionRange.EndOffset; - } - } - - public void Select (int startPosition, int endPosition) - { - editor.SelectionRange = new TextSegment (startPosition, endPosition - startPosition); - } - - public void ShowPosition (int position) - { - } - - public bool EnableUndo { - get { - return false; - } - } - public bool EnableRedo { - get { - return false; - } - } - - public void SetCaretTo (int line, int column) - { - } - public void SetCaretTo (int line, int column, bool highlightCaretLine) - { - } - public void SetCaretTo (int line, int column, bool highlightCaretLine, bool centerCaretLine) - { - } - - public void Undo() - { - } - public void Redo() - { - } - - class DisposeStub : IDisposable - { - public void Dispose () - { - } - } - - public void RunWhenLoaded (System.Action action) - { - action (); - } - - public IDisposable OpenUndoGroup () - { - return new DisposeStub (); - } - - #region IServiceProvider implementation - - object IServiceProvider.GetService (Type serviceType) - { - if (serviceType.IsInstanceOfType (editor)) - return editor; - return null; - } - - #endregion - - public event EventHandler CaretPositionSet; - - protected virtual void OnCaretPositionSet (EventArgs e) - { - var handler = CaretPositionSet; - if (handler != null) - handler (this, e); - } - - protected override object OnGetContent (Type type) - { - if (type.IsAssignableFrom (typeof(TextEditor))) - return Editor; - else - return base.OnGetContent (type); - } - } -} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenWorkbenchWindow.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenWorkbenchWindow.cs deleted file mode 100644 index b5e3110a4e..0000000000 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/HiddenWorkbenchWindow.cs +++ /dev/null @@ -1,121 +0,0 @@ -// -// HiddenWorkbenchWindow.cs -// -// Author: -// Mike Krüger <mkrueger@novell.com> -// -// Copyright (c) 2009 Novell, Inc (http://www.novell.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; -using System.Collections.Generic; -using System.Threading.Tasks; -using Mono.Addins; - -namespace MonoDevelop.Ide.Gui -{ - public class HiddenWorkbenchWindow : MonoDevelop.Ide.Gui.IWorkbenchWindow - { - string title; - public string Title { - get { - return title; - } - set { - title = value; - } - } - - public string DocumentType { - get { return ""; } - set {} - } - - public MonoDevelop.Ide.Gui.Document Document { - get; - set; - } - - public bool ShowNotification { - get { return false; } - set {} - } - - public ExtensionContext ExtensionContext { - get { return AddinManager.AddinEngine; } - } - - MonoDevelop.Ide.Gui.ViewContent viewContent; - public MonoDevelop.Ide.Gui.ViewContent ViewContent { - get { return viewContent; } - set { viewContent = value; } - } - - public IEnumerable<BaseViewContent> SubViewContents { get { return new BaseViewContent[0]; } } - - public MonoDevelop.Ide.Gui.BaseViewContent ActiveViewContent { - get { return ViewContent;} - set {} - } - - public Task<bool> CloseWindow (bool force) - { - return Task.FromResult (true); - } - - public void SelectWindow () - { - } - - public void SwitchView (int viewNumber) - { - } - public void SwitchView (MonoDevelop.Ide.Gui.BaseViewContent subViewContent) - { - } - - public int FindView<T> () - { - return -1; - } - - public void AttachViewContent (MonoDevelop.Ide.Gui.BaseViewContent subViewContent) - { - - } - - public void InsertViewContent (int index, MonoDevelop.Ide.Gui.BaseViewContent subViewContent) - { - - } - - public DocumentToolbar GetToolbar (BaseViewContent targetView) - { - return null; - } - - public event EventHandler TitleChanged { add {} remove {} } - public event EventHandler DocumentChanged { add {} remove {} } - public event MonoDevelop.Ide.Gui.WorkbenchWindowAsyncEventHandler Closing { add {} remove {} } - public event MonoDevelop.Ide.Gui.WorkbenchWindowEventHandler Closed { add {} remove {} } - public event MonoDevelop.Ide.Gui.ActiveViewContentEventHandler ActiveViewContentChanged { add {} remove {} } - public event EventHandler ViewsChanged { add {} remove {} } - } -} diff --git a/main/tests/Ide.Tests/FileTransferTests.cs b/main/tests/Ide.Tests/FileTransferTests.cs index 548b37736c..f4ab9e9182 100644 --- a/main/tests/Ide.Tests/FileTransferTests.cs +++ b/main/tests/Ide.Tests/FileTransferTests.cs @@ -33,6 +33,7 @@ using System.Threading.Tasks; namespace MonoDevelop.Ide { + [RequireService(typeof(RootWorkspace))] public class FileTransferTests: IdeTestBase { [Test] diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.FindInFiles/SearchResultWidgetTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.FindInFiles/SearchResultWidgetTests.cs index a0df94216f..bb6d17b181 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.FindInFiles/SearchResultWidgetTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.FindInFiles/SearchResultWidgetTests.cs @@ -29,18 +29,19 @@ using MonoDevelop.Components; using System.IO; using System.Text; using MonoDevelop.Core; +using System.Threading.Tasks; +using UnitTests; +using MonoDevelop.Ide.TextEditing; namespace MonoDevelop.Ide.FindInFiles { [TestFixture] + [RequireService (typeof(TextEditorService))] class SearchResultWidgetTests : IdeTestBase { [SetUp] - public void SetUp () + public async Task SetUp () { - //Initialize IdeApp so IdeApp.Workspace is not null, comment tasks listen to root workspace events. - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); } [Test] diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs index 24c4d7d135..6ef45712c4 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/NewProjectDialogTests.cs @@ -28,6 +28,7 @@ using UnitTests; using NUnit.Framework; using MonoDevelop.Core; using MonoDevelop.Projects; +using System.Threading.Tasks; namespace MonoDevelop.Ide.Projects { @@ -38,9 +39,9 @@ namespace MonoDevelop.Ide.Projects bool useGitOriginalValue; bool useGitIgnoreOriginalValue; - protected override void InternalSetup (string rootDir) + protected override async Task InternalSetup (string rootDir) { - base.InternalSetup (rootDir); + await base.InternalSetup (rootDir); createProjectDirectoryOriginalValue = PropertyService.Get ( NewProjectDialogController.CreateProjectSubDirectoryPropertyName, diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ProjectOperationsTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ProjectOperationsTests.cs index ba3b48343d..343c0d7df0 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ProjectOperationsTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ProjectOperationsTests.cs @@ -27,20 +27,14 @@ using System.Threading.Tasks; using MonoDevelop.Core; using MonoDevelop.Projects; using NUnit.Framework; +using UnitTests; namespace MonoDevelop.Ide.Projects { [TestFixture] + [RequireService(typeof(ProjectOperations))] public class ProjectOperationsTests : IdeTestBase { - [TestFixtureSetUp] - public void SetUp () - { - if (!IdeApp.IsInitialized) { - IdeApp.Initialize (new ProgressMonitor ()); - } - } - Solution CreateSimpleSolutionWithItems (params SolutionItem[] items) { var sln = new Solution (); @@ -61,7 +55,7 @@ namespace MonoDevelop.Ide.Projects using (var executing = new ProjectWithExecutionDeps ("Executing")) using (var sln = CreateSimpleSolutionWithItems (other, executing)) { - var success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); + var success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.IsFalse (other.WasBuilt); @@ -78,7 +72,7 @@ namespace MonoDevelop.Ide.Projects executing.OverrideExecutionDependencies = new [] { executionDep }; - var success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); + var success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.IsTrue (executionDep.WasBuilt); @@ -96,7 +90,7 @@ namespace MonoDevelop.Ide.Projects executing.OverrideExecutionDependencies = new [] { executionDep }; executionDep.ItemDependencies.Add (executing); - var success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); + var success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.IsTrue (executionDep.WasBuilt); Assert.IsTrue (executing.WasBuilt); @@ -114,7 +108,7 @@ namespace MonoDevelop.Ide.Projects executing.OverrideExecutionDependencies = new [] { executionDep }; executionDep.ItemDependencies.Add (executing); - var success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); + var success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.IsTrue (executionDep.WasBuilt); @@ -123,7 +117,7 @@ namespace MonoDevelop.Ide.Projects executionDep.WasBuilt = executing.WasBuilt = false; - success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); + success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { executing }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.IsFalse (executionDep.WasBuilt); Assert.IsFalse (executing.WasBuilt); @@ -257,7 +251,7 @@ namespace MonoDevelop.Ide.Projects Assert.AreEqual (null, proj.BuildPropertyValue); Assert.AreEqual (null, proj.CheckPropertyValue); - var success = await IdeApp.ProjectOperations.CheckAndBuildForExecute (new [] { proj }, ConfigurationSelector.Default); + var success = await IdeServices.ProjectOperations.CheckAndBuildForExecute (new [] { proj }, ConfigurationSelector.Default); Assert.IsTrue (success); Assert.AreEqual (true, proj.BuildPropertyValue); Assert.AreEqual (true, proj.CheckPropertyValue); @@ -265,7 +259,7 @@ namespace MonoDevelop.Ide.Projects proj.CheckPropertyValue = null; proj.BuildPropertyValue = null; - var result = await IdeApp.ProjectOperations.Build (proj).Task; + var result = await IdeServices.ProjectOperations.Build (proj).Task; Assert.IsFalse (result.Failed); Assert.AreEqual (false, proj.BuildPropertyValue); Assert.AreEqual (false, proj.CheckPropertyValue); diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Tasks/CommentTasksProviderTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Tasks/CommentTasksProviderTests.cs index 93a27ff4b2..1ffc274cf2 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Tasks/CommentTasksProviderTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Tasks/CommentTasksProviderTests.cs @@ -28,20 +28,15 @@ using System.Linq; using System.Threading.Tasks; using MonoDevelop.Core; using NUnit.Framework; +using UnitTests; namespace MonoDevelop.Ide.Tasks { [TestFixture] + [RequireService(typeof(RootWorkspace))] + [RequireService (typeof (TaskService))] partial class CommentTasksProviderTests : Ide.IdeTestBase { - [SetUp] - public void SetUp () - { - //Initialize IdeApp so IdeApp.Workspace is not null, comment tasks listen to root workspace events. - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); - } - static async Task RunTest (Func<Controller, Task> act) { // Keep the current special comment tags and restore them after. @@ -56,6 +51,12 @@ namespace MonoDevelop.Ide.Tasks } } + [TearDown] + public void TearDown () + { + CommentTasksProvider.ResetCachedContents (null); + } + [TestCase(false)] [TestCase(true)] public async Task TestToDoCommentsAreReported (bool withToDos) @@ -89,7 +90,7 @@ namespace MonoDevelop.Ide.Tasks await helper.SetupProject (withToDos); await helper.LoadProject (); - await IdeApp.Workspace.Close (); + await IdeApp.Workspace.Close (false, false, true); await helper.LoadProject (); }); @@ -188,7 +189,7 @@ namespace MonoDevelop.Ide.Tasks await tcs.Task; Assert.AreEqual (options.ExpectedFiles.Length, CommentTasksProvider.GetCachedContentsCount ()); - await IdeApp.Workspace.Close (); + await IdeApp.Workspace.Close (false, false, true); Assert.AreEqual (0, CommentTasksProvider.GetCachedContentsCount ()); done = true; diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj b/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj index d57f65f521..25de2b71a6 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj @@ -105,7 +105,6 @@ <Compile Include="MonoDevelop.Components.PropertyGrid\EditorManagerTests.cs" /> <Compile Include="MonoDevelop.SourceEditor\DebugTooltipTests.cs" /> <Compile Include="MonoDevelop.SourceEditor\JSonIndentEngineTests.cs" /> - <Compile Include="MonoDevelop.SourceEditor\SourceEditorTests.cs" /> <Compile Include="MonoDevelop.Ide\UserPreferencesTests.cs" /> <Compile Include="MonoDevelop.Ide.Projects\ResourcesTests.cs" /> <Compile Include="MonoDevelop.Ide.Editor\SkipCharSessionTests.cs" /> @@ -146,6 +145,15 @@ <Compile Include="MonoDevelop.Ide.TypeSystem\TypeSystemServiceTests.cs" /> <Compile Include="MonoDevelop.Ide.RoslynServices\MonoDevelopFrameworkAssemblyPathResolverFactoryTests.cs" /> <Compile Include="MonoDevelop.Ide.TypeSystem\MonoDevelopWorkspaceTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.DocumentModels\DocumentModelRegistryTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.DocumentModels\DocumentModelTestsBase.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.DocumentModels\TextFileModelTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.DocumentModels\FileModelTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.DocumentModels\TextBufferFileModelTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.Documents\DocumentManagerTests.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.Documents\FileDocumentControllerTests.cs" /> + <Compile Include="TestHelper.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.Documents\DocumentViewTests.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\src\core\MonoDevelop.Ide\MonoDevelop.Ide.csproj"> @@ -206,5 +214,9 @@ <Name>IdeUnitTests</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Folder Include="MonoDevelop.Ide.Gui.DocumentModels\" /> + <Folder Include="MonoDevelop.Ide.Gui.Documents\" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </Project> diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopMetadataReferenceManager.MetadataReferenceCacheTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopMetadataReferenceManager.MetadataReferenceCacheTests.cs index 9c3fdf0c50..b3284874d0 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopMetadataReferenceManager.MetadataReferenceCacheTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopMetadataReferenceManager.MetadataReferenceCacheTests.cs @@ -10,6 +10,7 @@ using UnitTests; namespace MonoDevelop.Ide.TypeSystem { [TestFixture] + [RequireService(typeof(RootWorkspace))] public class MonoDevelopMetadataReferenceManagerMetadataReferenceCacheTests : IdeTestBase { [Test] diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopWorkspaceTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopWorkspaceTests.cs index ada621fff6..a3b9ddda2f 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopWorkspaceTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.TypeSystem/MonoDevelopWorkspaceTests.cs @@ -36,14 +36,12 @@ using UnitTests; namespace MonoDevelop.Ide.TypeSystem { [TestFixture] + [RequireService(typeof(RootWorkspace))] public class MonoDevelopWorkspaceTests : IdeTestBase { [Test] public async Task MetadataReferencesToFrameworkAssembliesAreProperlyFound () { - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); - FilePath projFile = Util.GetSampleProject ("workspace-metadata-references", "workspace-metadata-references.sln"); using (var sol = (MonoDevelop.Projects.Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), projFile)) { diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide/TypeSystemServiceTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide/TypeSystemServiceTests.cs index dc65094cbf..a1a3d497fd 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide/TypeSystemServiceTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide/TypeSystemServiceTests.cs @@ -44,6 +44,7 @@ using System.Collections.Immutable; namespace MonoDevelop.Ide { [TestFixture] + [RequireService(typeof(RootWorkspace))] class TypeSystemServiceTests : IdeTestBase { class TrackTestProject : DotNetProject @@ -75,18 +76,18 @@ namespace MonoDevelop.Ide [Test] public void TestOuptutTracking_ProjectType () { - TypeSystemService.AddOutputTrackingNode (new TypeSystemOutputTrackingNode { ProjectType = "TestProjectType" }); + IdeApp.TypeSystemService.AddOutputTrackingNode (new TypeSystemOutputTrackingNode { ProjectType = "TestProjectType" }); - Assert.IsFalse (TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("C#", "Bar"))); - Assert.IsTrue (TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("C#", "TestProjectType"))); + Assert.IsFalse (IdeApp.TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("C#", "Bar"))); + Assert.IsTrue (IdeApp.TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("C#", "TestProjectType"))); } [Test] public void TestOuptutTracking_LanguageName () { - TypeSystemService.AddOutputTrackingNode (new TypeSystemOutputTrackingNode { LanguageName = "IL" }); + IdeApp.TypeSystemService.AddOutputTrackingNode (new TypeSystemOutputTrackingNode { LanguageName = "IL" }); - Assert.IsTrue (TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("IL", "Bar"))); + Assert.IsTrue (IdeApp.TypeSystemService.IsOutputTrackedProject (new TrackTestProject ("IL", "Bar"))); } [Test] @@ -95,7 +96,7 @@ namespace MonoDevelop.Ide string solFile = Util.GetSampleProject("csharp-app-fsharp-lib", "csappfslib.sln"); using (Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile)) { var fsharpLibrary = sol.Items.FirstOrDefault (pr => pr.Name == "fslib") as DotNetProject; - Assert.IsTrue (TypeSystemService.IsOutputTrackedProject (fsharpLibrary)); + Assert.IsTrue (IdeApp.TypeSystemService.IsOutputTrackedProject (fsharpLibrary)); } } @@ -127,7 +128,7 @@ namespace MonoDevelop.Ide if (System.IO.File.Exists (storageLocation)) System.IO.File.Delete (storageLocation); - var solutionSizeTracker = (IIncrementalAnalyzerProvider)Composition.CompositionManager.GetExportedValue<ISolutionSizeTracker> (); + var solutionSizeTracker = (IIncrementalAnalyzerProvider)Composition.CompositionManager.Instance.GetExportedValue<ISolutionSizeTracker> (); // This will return the tracker, since it's a singleton. var analyzer = solutionSizeTracker.CreateIncrementalAnalyzer (ws); @@ -153,23 +154,23 @@ namespace MonoDevelop.Ide [Test] public async Task TestWorkspaceImmediatelyAvailable () { - //Initialize IdeApp so IdeApp.Workspace is not null - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); + await IdeServices.Workspace.Close (false, true, true); string solFile = Util.GetSampleProject ("console-project", "ConsoleProject.sln"); var tcs = new TaskCompletionSource<bool> (); - IdeApp.Workspace.SolutionLoaded += (s, e) => { - var workspace = TypeSystemService.GetWorkspace (e.Solution); + IdeServices.Workspace.SolutionLoaded += (s, e) => { + var workspace = IdeApp.TypeSystemService.GetWorkspace (e.Solution); Assert.IsNotNull (workspace); - Assert.AreNotSame (workspace, TypeSystemService.emptyWorkspace); + Assert.AreNotSame (workspace, IdeApp.TypeSystemService.emptyWorkspace); workspace.Dispose (); tcs.SetResult (true); }; try { - await IdeApp.Workspace.OpenWorkspaceItem (solFile); - await tcs.Task; + if (!await IdeServices.Workspace.OpenWorkspaceItem (solFile)) + Assert.Fail ("Solution load failed"); + if (await Task.WhenAny (tcs.Task, Task.Delay (10000)) != tcs.Task) + Assert.Fail ("Solution did not load"); } finally { - await IdeApp.Workspace.Close (false); + await IdeServices.Workspace.Close (false); } } @@ -178,16 +179,15 @@ namespace MonoDevelop.Ide { // Fix for VSTS 603762 - LoadProject is called twice on solution load due to configuration change. - if (!IdeApp.IsInitialized) - IdeApp.Initialize (new ProgressMonitor ()); - MonoDevelopWorkspace workspace; bool reloaded = false; bool solutionLoaded = false; bool workspaceLoaded = false; - IdeApp.Workspace.SolutionLoaded += (s, e) => { - workspace = TypeSystemService.GetWorkspace (e.Solution); + await IdeServices.Workspace.Close (saveWorkspacePreferencies: false, closeProjectFiles: false, force: true); + + IdeServices.Workspace.SolutionLoaded += (s, e) => { + workspace = IdeServices.TypeSystemService.GetWorkspace (e.Solution); workspace.WorkspaceChanged += (sender, ea) => { // If SolutionReloaded event is raised while opening the solution, we are doing something wrong if (ea.Kind == Microsoft.CodeAnalysis.WorkspaceChangeKind.SolutionReloaded) @@ -206,17 +206,21 @@ namespace MonoDevelop.Ide File.WriteAllText (Path.Combine (prefsPath, "UserPrefs.xml"), "<Properties><MonoDevelop.Ide.Workspace ActiveConfiguration='Release' /></Properties>"); try { - await IdeApp.Workspace.OpenWorkspaceItem (solFile); + await IdeServices.Workspace.OpenWorkspaceItem (solFile); // Check that the user prefs file has been loaded - Assert.AreEqual ("Release", IdeApp.Workspace.ActiveConfiguration.ToString ()); + Assert.AreEqual ("Release", IdeServices.Workspace.ActiveConfiguration.ToString ()); // Wait for the roslyn workspace to be loaded - while (!workspaceLoaded) + int timeout = 100; + while (!workspaceLoaded && --timeout > 0) await Task.Delay (100); + if (timeout <= 0) + Assert.Fail ("Workspace did not load"); + } finally { - await IdeApp.Workspace.Close (false); + await IdeServices.Workspace.Close (false); } Assert.IsTrue (solutionLoaded); @@ -278,7 +282,7 @@ namespace MonoDevelop.Ide { string solFile = Util.GetSampleProject ("console-project", "ConsoleProject.sln"); - var parsers = TypeSystemService.Parsers; + var parsers = IdeApp.TypeSystemService.Parsers; try { var projectionParser = new TypeSystemParserNode (); projectionParser.BuildActions = new [] { "Compile" }; @@ -290,7 +294,7 @@ namespace MonoDevelop.Ide var newParsers = new List<TypeSystemParserNode> (); newParsers.Add (projectionParser); - TypeSystemService.Parsers = newParsers; + IdeApp.TypeSystemService.Parsers = newParsers; using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile)) { using (var ws = await TypeSystemServiceTestExtensions.LoadSolution (sol)) { @@ -301,13 +305,13 @@ namespace MonoDevelop.Ide var options = new ParseOptions { FileName = "first.xaml.cs" }; - var task1 = TypeSystemService.ParseProjection (options, "text/csharp", source1.Token); + var task1 = IdeApp.TypeSystemService.ParseProjection (options, "text/csharp", source1.Token); source1.Cancel (); options = new ParseOptions { FileName = "second.xaml.cs" }; - var task2 = TypeSystemService.ParseProjection (options, "text/csharp", source2.Token); + var task2 = IdeApp.TypeSystemService.ParseProjection (options, "text/csharp", source2.Token); var result1 = await task1; var result2 = await task2; @@ -317,7 +321,7 @@ namespace MonoDevelop.Ide } } } finally { - TypeSystemService.Parsers = parsers; + IdeApp.TypeSystemService.Parsers = parsers; } } diff --git a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/DebugTooltipTests.cs b/main/tests/Ide.Tests/MonoDevelop.SourceEditor/DebugTooltipTests.cs index 1b0d4a4324..311da421c3 100644 --- a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/DebugTooltipTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.SourceEditor/DebugTooltipTests.cs @@ -55,7 +55,7 @@ namespace MonoDevelop.SourceEditor text = text.Substring (0, endPos) + text.Substring (endPos + 1); var testCase = await SetupTestCase (text, Math.Max (0, endPos)); - await testCase.Document.UpdateParseDocument (); + await testCase.Document.DocumentContext.UpdateParseDocument (); return testCase; } @@ -167,7 +167,7 @@ namespace DebuggerTooltipTests var loc = editor.OffsetToLocation (offset); var resolver = doc.GetContent<IDebuggerExpressionResolver> (); - return resolver.ResolveExpressionAsync (editor, doc, offset, default(System.Threading.CancellationToken)).Result.Text; + return resolver.ResolveExpressionAsync (editor, doc.DocumentContext, offset, default(System.Threading.CancellationToken)).Result.Text; } int GetBasicOffset (string expr) diff --git a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs b/main/tests/Ide.Tests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs index 0a6e31e772..15baddeff8 100644 --- a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs @@ -30,118 +30,146 @@ using MonoDevelop.Ide; using MonoDevelop.Ide.Gui; using MonoDevelop.JSon; using ICSharpCode.NRefactory6.CSharp; +using System; +using System.Threading.Tasks; +using UnitTests; +using MonoDevelop.Ide.TextEditing; +using MonoDevelop.Ide.Gui.Documents; namespace MonoDevelop.SourceEditor { [TestFixture] + [RequireService(typeof(TextEditorService))] public class JSonIndentEngineTests : IdeTestBase { const string indentString = "\t"; - internal static IDocumentIndentEngine CreateEngine (string text, bool tabsToSpaces = false) + class TestCase : IDisposable { - var sb = new StringBuilder (); - int offset = 0; - for (int i = 0; i < text.Length; i++) { - var ch = text [i]; - if (ch == '$') { - offset = i; - continue; + TextEditorExtensionTestCase testCase; + + public IDocumentIndentEngine Engine { get; set; } + + public static async Task<TestCase> Create (string text, bool tabsToSpaces = false) + { + var test = new TestCase (); + var sb = new StringBuilder (); + int offset = 0; + for (int i = 0; i < text.Length; i++) { + var ch = text [i]; + if (ch == '$') { + offset = i; + continue; + } + sb.Append (ch); } - sb.Append (ch); + + var content = new TestViewContent (); + await content.Initialize (new FileDescriptor ("/a.json", null, null)); + content.Editor.MimeType = "application/json"; + + content.Editor.Text = sb.ToString (); + + test.testCase = await TextEditorExtensionTestCase.Create (content, null, false); + + test.testCase.Document.Editor.Options = new CustomEditorOptions { + TabsToSpaces = tabsToSpaces, + TabSize = 4 + }; + + var csi = new JSonIndentEngine (content.Editor); + var result = new CacheIndentEngine (csi); + result.Update (content.Editor, offset); + test.Engine = result; + + return test; } - var tww = new TestWorkbenchWindow (); - var content = new TestViewContent (); - tww.ViewContent = content; - content.ContentName = "/a.json"; - content.Data.MimeType = "application/json"; - - content.Data.Text = sb.ToString (); - var doc = new MonoDevelop.Ide.Gui.Document (tww); - doc.Editor.Options = new CustomEditorOptions { - TabsToSpaces = tabsToSpaces, - TabSize = 4 - }; - var csi = new JSonIndentEngine (content.Data, doc); - var result = new CacheIndentEngine (csi); - result.Update (content.Data, offset); - return result; + public void Dispose () + { + testCase.Dispose (); + } } [Test] - public void TestBracketIndentation () + public async Task TestBracketIndentation () { - var engine = CreateEngine ( + using (var testCase = await TestCase.Create ( @" { $ -"); - Assert.AreEqual (indentString, engine.ThisLineIndent); - Assert.AreEqual (indentString, engine.NextLineIndent); +")) { + Assert.AreEqual (indentString, testCase.Engine.ThisLineIndent); + Assert.AreEqual (indentString, testCase.Engine.NextLineIndent); + } } [Test] - public void TestBodyIndentation () + public async Task TestBodyIndentation () { - var engine = CreateEngine ( + using (var testCase = await TestCase.Create ( @" { " + indentString + @"""foo"":""bar"", $ -"); - Assert.AreEqual (indentString, engine.ThisLineIndent); - Assert.AreEqual (indentString, engine.NextLineIndent); +")) { + Assert.AreEqual (indentString, testCase.Engine.ThisLineIndent); + Assert.AreEqual (indentString, testCase.Engine.NextLineIndent); + } } [Test] - public void TestArrayIndentation () + public async Task TestArrayIndentation () { - var engine = CreateEngine ( + using (var testCase = await TestCase.Create ( @" { " + indentString + @"""test"":[ $ -"); - Assert.AreEqual (indentString + indentString, engine.ThisLineIndent); - Assert.AreEqual (indentString + indentString, engine.NextLineIndent); +")) { + Assert.AreEqual (indentString + indentString, testCase.Engine.ThisLineIndent); + Assert.AreEqual (indentString + indentString, testCase.Engine.NextLineIndent); + } } [Test] - public void TestWindowsEOL () + public async Task TestWindowsEOL () { - var engine = CreateEngine ("\r\n{\r\n$\r\n"); - Assert.AreEqual (indentString, engine.ThisLineIndent); - Assert.AreEqual (indentString, engine.NextLineIndent); + using (var testCase = await TestCase.Create ("\r\n{\r\n$\r\n")) { + Assert.AreEqual (indentString, testCase.Engine.ThisLineIndent); + Assert.AreEqual (indentString, testCase.Engine.NextLineIndent); + } } /// <summary> /// Bug 40892 - json indenter should not indent multi-line strings /// </summary> [Test] - public void TestBug40892 () + public async Task TestBug40892 () { - var engine = CreateEngine ( + using (var testCase = await TestCase.Create ( @" { " + indentString + @"""test"":"" $ -"); - Assert.AreEqual ("", engine.ThisLineIndent); - Assert.AreEqual ("", engine.NextLineIndent); +")) { + Assert.AreEqual ("", testCase.Engine.ThisLineIndent); + Assert.AreEqual ("", testCase.Engine.NextLineIndent); + } } [Test] - public void TestSpaceIndentation() + public async Task TestSpaceIndentation () { - var engine = CreateEngine( + using (var testCase = await TestCase.Create ( @" { $ -", true); - Assert.AreEqual(" ", engine.ThisLineIndent); - Assert.AreEqual(engine.ThisLineIndent, engine.NextLineIndent); +", true)) { + Assert.AreEqual (" ", testCase.Engine.ThisLineIndent); + Assert.AreEqual (testCase.Engine.ThisLineIndent, testCase.Engine.NextLineIndent); + } } } diff --git a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/SourceEditorTests.cs b/main/tests/Ide.Tests/MonoDevelop.SourceEditor/SourceEditorTests.cs deleted file mode 100644 index f9ff5074da..0000000000 --- a/main/tests/Ide.Tests/MonoDevelop.SourceEditor/SourceEditorTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// SourceEditorTests.cs -// -// Author: -// Mike Krüger <mkrueger@xamarin.com> -// -// Copyright (c) 2012 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; -using NUnit.Framework; -using MonoDevelop.Ide.CodeCompletion; - -namespace MonoDevelop.SourceEditor -{ -// [TestFixture()] -// public class SourceEditorTests : Mono.TextEditor.Tests.TextEditorTestBase -// { -// /// <summary> -// /// Bug 4764 - Event handler completion puts caret in wrong place -// /// </summary> -// [Test] -// public void TestBug4764 () -// { -// var data = Create ("foo = $"); -// var ctx = new CodeCompletionContext (); -// ctx.TriggerOffset = data.Caret.Offset; -// SourceEditorView.SetCompletionText (data, ctx, "", "(o,s) |;", 0); -// Check (data, "foo = (o,s) $;"); -// } -// } -} - diff --git a/main/tests/Ide.Tests/TypeForwarders.cs b/main/tests/Ide.Tests/TypeForwarders.cs index 1a9b20bef0..d699f5181f 100644 --- a/main/tests/Ide.Tests/TypeForwarders.cs +++ b/main/tests/Ide.Tests/TypeForwarders.cs @@ -31,6 +31,4 @@ using System.Runtime.CompilerServices; [assembly: TypeForwardedTo (typeof (MonoDevelop.Ide.TextEditorExtensionTestBase))] [assembly: TypeForwardedTo (typeof (MonoDevelop.Ide.TypeSystemServiceTestExtensions))] -[assembly: TypeForwardedTo (typeof (MonoDevelop.Ide.Gui.TestDocument))] [assembly: TypeForwardedTo (typeof (MonoDevelop.Ide.Gui.TestViewContent))] -[assembly: TypeForwardedTo (typeof (MonoDevelop.Ide.Gui.TestWorkbenchWindow))]
\ No newline at end of file diff --git a/main/tests/MonoDevelop.CSharpBinding.Tests/MonoDevelop.CSharpBinding/AutoFormatIntegrationTests.cs b/main/tests/MonoDevelop.CSharpBinding.Tests/MonoDevelop.CSharpBinding/AutoFormatIntegrationTests.cs index 9a5f785e19..b850b041bc 100644 --- a/main/tests/MonoDevelop.CSharpBinding.Tests/MonoDevelop.CSharpBinding/AutoFormatIntegrationTests.cs +++ b/main/tests/MonoDevelop.CSharpBinding.Tests/MonoDevelop.CSharpBinding/AutoFormatIntegrationTests.cs @@ -27,18 +27,17 @@ using System; using NUnit.Framework; using System.Text; -using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Ide.Gui; using MonoDevelop.CSharp.Formatting; using MonoDevelop.CSharp.Completion; -using MonoDevelop.CSharpBinding.Tests; using MonoDevelop.Ide.Editor; using MonoDevelop.Ide.Editor.Extension; using MonoDevelop.Projects; -using MonoDevelop.Core.ProgressMonitoring; using MonoDevelop.Core; using System.Threading.Tasks; using MonoDevelop.Ide.Gui.Content; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui.Documents; namespace MonoDevelop.CSharpBinding { @@ -47,17 +46,14 @@ namespace MonoDevelop.CSharpBinding { static async Task Simulate (string input, Action<TestViewContent, EditorFormattingServiceTextEditorExtension> act, CSharpFormattingPolicy formattingPolicy = null, EolMarker eolMarker = EolMarker.Unix) { - TestWorkbenchWindow tww = new TestWorkbenchWindow (); var content = new TestViewContent (); - content.Data.Options = new CustomEditorOptions { + await content.Initialize (new FileDescriptor ("/a.cs", null, null)); + + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Auto }; - tww.ViewContent = content; - content.ContentName = "/a.cs"; - content.Data.MimeType = "text/x-csharp"; - - var doc = new Document (tww); + content.Editor.MimeType = "text/x-csharp"; var sb = new StringBuilder (); int cursorPosition = 0, selectionStart = -1, selectionEnd = -1; @@ -95,36 +91,37 @@ namespace MonoDevelop.CSharpBinding content.Text = sb.ToString (); content.CursorPosition = cursorPosition; - var project = Services.ProjectService.CreateProject ("C#"); + var project = IdeServices.ProjectService.CreateProject ("C#"); project.Name = "test"; project.FileName = "test.csproj"; - project.Files.Add (new ProjectFile (content.ContentName, BuildAction.Compile)); + project.Files.Add (new ProjectFile (content.FilePath, BuildAction.Compile)); var textStylePolicy = Projects.Policies.PolicyService.InvariantPolicies.Get<TextStylePolicy> ().WithTabsToSpaces (false) .WithEolMarker (eolMarker); - project.Policies.Set (textStylePolicy, content.Data.MimeType); - project.Policies.Set (formattingPolicy ?? Projects.Policies.PolicyService.InvariantPolicies.Get<CSharpFormattingPolicy> (), content.Data.MimeType); + project.Policies.Set (textStylePolicy, content.Editor.MimeType); + project.Policies.Set (formattingPolicy ?? Projects.Policies.PolicyService.InvariantPolicies.Get<CSharpFormattingPolicy> (), content.Editor.MimeType); var solution = new MonoDevelop.Projects.Solution (); solution.AddConfiguration ("", true); solution.DefaultSolutionFolder.AddItem (project); using (var monitor = new ProgressMonitor ()) - await TypeSystemService.Load (solution, monitor); - content.Project = project; - doc.SetProject (project); - var compExt = new CSharpCompletionTextEditorExtension (); - compExt.Initialize (doc.Editor, doc); - content.Contents.Add (compExt); - - var ext = new EditorFormattingServiceTextEditorExtension (); - ext.Initialize (doc.Editor, doc); - content.Contents.Add (ext); - - await doc.UpdateParseDocument (); - if (selectionStart >= 0 && selectionEnd >= 0) - content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd); - - using (var testCase = new Ide.TextEditorExtensionTestCase (doc, content, tww, null, false)) { + await IdeApp.TypeSystemService.Load (solution, monitor); + content.Owner = project; + + using (var testCase = await Ide.TextEditorExtensionTestCase.Create (content, null, false)) { + var doc = testCase.Document; + var compExt = new CSharpCompletionTextEditorExtension (); + compExt.Initialize (doc.Editor, doc.DocumentContext); + content.AddContent (compExt); + + var ext = new EditorFormattingServiceTextEditorExtension (); + ext.Initialize (doc.Editor, doc.DocumentContext); + content.AddContent (ext); + + await doc.DocumentContext.UpdateParseDocument (); + if (selectionStart >= 0 && selectionEnd >= 0) + content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd); + act (content, ext); } } @@ -249,14 +246,14 @@ namespace MonoDevelop.CSharpBinding public async Task TestBug14686Case2 () { await Simulate ("$\"\\\"", (content, ext) => { - content.Data.InsertText (0, "@"); + content.Editor.InsertText (0, "@"); ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None)); var newText = content.Text; Assert.AreEqual ("@\"\\\"", newText); }); await Simulate ("$\"\\\"a", (content, ext) => { - content.Data.InsertText (0, "@"); + content.Editor.InsertText (0, "@"); ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'@', '@', Gdk.ModifierType.None)); var newText = content.Text; Assert.AreEqual ("@\"\\\"a", newText); @@ -298,7 +295,7 @@ namespace MonoDevelop.CSharpBinding Console.WriteLine () ;$ } }", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual }; ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.semicolon, ';', Gdk.ModifierType.None)); @@ -326,7 +323,7 @@ namespace MonoDevelop.CSharpBinding #$ } }", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual }; ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'#', '#', Gdk.ModifierType.None)); @@ -352,7 +349,7 @@ namespace MonoDevelop.CSharpBinding #region$ } }", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual }; ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'n', 'n', Gdk.ModifierType.None)); @@ -375,7 +372,7 @@ namespace MonoDevelop.CSharpBinding #endregion$ } }", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual }; ext.KeyPress (KeyDescriptor.FromGtk ((Gdk.Key)'n', 'n', Gdk.ModifierType.None)); @@ -418,7 +415,7 @@ namespace MonoDevelop.CSharpBinding }$ } }", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual }; ext.KeyPress (KeyDescriptor.FromGtk (Gdk.Key.braceright, '}', Gdk.ModifierType.None)); @@ -456,7 +453,7 @@ namespace MonoDevelop.CSharpBinding public async Task TestBug46817 () { await Simulate ("public class Application\r\n{\r\n\tstatic void Main (string[] args)\r\n\t{\r\n\t\t// abcd\r\n\t\t{\r\n\t\t\t\t}$\r\n", (content, ext) => { - content.Data.Options = new CustomEditorOptions { + content.Editor.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Virtual, DefaultEolMarker = "\r\n" }; |