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

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-10-23 15:36:41 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-10-23 15:36:41 +0300
commit8d0cf6c4a14bf027703c273eecf69d7f4748dc08 (patch)
tree442f61fb5731151e9c58acf6b7daa525cd58dafb
parent3d42df3c46a81bdd8062815773a0afa8737f9b1a (diff)
Fixes VSTS User Story 980492: Create unit test suite formaster-vsts980492
DocumentRegistry https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980492
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentRegistry.cs55
-rw-r--r--main/tests/Ide.Tests/MonoDevelop.Ide.Gui.Documents/DocumentRegistryTests.cs147
-rw-r--r--main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj1
3 files changed, 178 insertions, 25 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentRegistry.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentRegistry.cs
index ffeb87f4e9..82f43c257e 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentRegistry.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentRegistry.cs
@@ -27,6 +27,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading.Tasks;
using MonoDevelop.Core;
namespace MonoDevelop.Ide.Gui
@@ -53,28 +54,32 @@ namespace MonoDevelop.Ide.Gui
FileService.FileChanged += HandleFileServiceChange;
}
- static void HandleFileServiceChange (object sender, FileEventArgs e)
+ static async void HandleFileServiceChange (object sender, FileEventArgs e)
{
- bool foundOneChange = false;
- foreach (var file in e) {
- if (skipFiles.Contains (file.FileName)) {
- skipFiles.Remove (file.FileName);
- continue;
- }
- foreach (var view in openFiles) {
- if (SkipView (view.Document) || !string.Equals (view.Document.FileName, file.FileName, FilePath.PathComparison))
+ try {
+ bool foundOneChange = false;
+ foreach (var file in e) {
+ if (skipFiles.Contains (file.FileName)) {
+ skipFiles.Remove (file.FileName);
continue;
- if (view.LastSaveTimeUtc == File.GetLastWriteTimeUtc (file.FileName))
- continue;
- if (!view.Document.IsDirty)
- view.Document.Reload ();
- else
- foundOneChange = true;
+ }
+ foreach (var view in openFiles) {
+ if (SkipView (view.Document) || !string.Equals (view.Document.FileName, file.FileName, FilePath.PathComparison))
+ continue;
+ if (view.LastSaveTimeUtc == File.GetLastWriteTimeUtc (file.FileName))
+ continue;
+ if (!view.Document.IsDirty)
+ await view.Document.Reload ();
+ else
+ foundOneChange = true;
+ }
}
- }
- if (foundOneChange)
- CommitViewChange (GetAllChangedFiles ());
+ if (foundOneChange)
+ CommitViewChange (await GetAllChangedFiles ());
+ } catch (Exception ex) {
+ LoggingService.LogInternalError (ex);
+ }
}
internal static bool SkipView (Document view)
@@ -127,25 +132,25 @@ namespace MonoDevelop.Ide.Gui
// UpdateEolMessages ();
}
- public static void IgnoreAllChangedFiles ()
+ public static async Task IgnoreAllChangedFiles ()
{
- foreach (var view in GetAllChangedFiles ()) {
+ foreach (var view in await GetAllChangedFiles ()) {
view.LastSaveTimeUtc = File.GetLastWriteTimeUtc (view.Document.FileName);
view.Document.GetContent<IDocumentReloadPresenter> ()?.RemoveMessageBar ();
view.Document.Window.ShowNotification = false;
}
}
- public static void ReloadAllChangedFiles ()
+ public static async Task ReloadAllChangedFiles ()
{
- foreach (var view in GetAllChangedFiles ()) {
+ foreach (var view in await GetAllChangedFiles ()) {
view.Document.GetContent<IDocumentReloadPresenter> ()?.RemoveMessageBar ();
- view.Document.Reload ();
+ await view.Document.Reload ();
view.Document.Window.ShowNotification = false;
}
}
- static List<DocumentInfo> GetAllChangedFiles ()
+ static async Task<List<DocumentInfo>> GetAllChangedFiles ()
{
var changedViews = new List<DocumentInfo> ();
foreach (var view in openFiles) {
@@ -154,7 +159,7 @@ namespace MonoDevelop.Ide.Gui
if (view.LastSaveTimeUtc == File.GetLastWriteTimeUtc (view.Document.FileName))
continue;
if (!view.Document.IsDirty)
- view.Document.Reload ();
+ await view.Document.Reload ();
else
changedViews.Add (view);
}
diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Gui.Documents/DocumentRegistryTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Gui.Documents/DocumentRegistryTests.cs
new file mode 100644
index 0000000000..7b0070ea95
--- /dev/null
+++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Gui.Documents/DocumentRegistryTests.cs
@@ -0,0 +1,147 @@
+//
+// DocumentRegistryTests.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// 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 IdeUnitTests;
+using MonoDevelop.Core;
+using MonoDevelop.Ide.Gui.Shell;
+using NUnit.Framework;
+using System;
+using System.Threading.Tasks;
+using UnitTests;
+using MonoDevelop.Components;
+using System.Threading;
+using System.Collections.Generic;
+using System.Linq;
+using System.IO;
+using ICSharpCode.Decompiler.TypeSystem;
+using MonoDevelop.Core.Logging;
+
+namespace MonoDevelop.Ide.Gui.Documents
+{
+ [TestFixture]
+ public class DocumentRegistryTests : IdeTestBase
+ {
+ DocumentManager documentManager;
+ DocumentControllerService documentControllerService;
+ MockShell shell;
+
+ [SetUp]
+ public async Task Setup ()
+ {
+ documentManager = await Runtime.GetService<DocumentManager> ();
+ documentControllerService = await Runtime.GetService<DocumentControllerService> ();
+ shell = (MockShell)await Runtime.GetService<IShell> ();
+ }
+
+ [Test]
+ public async Task TestVSTSBug8608 ()
+ {
+ var controller = new RootDisposableTestController ();
+ await controller.Initialize (new ModelDescriptor ());
+
+ var doc = await documentManager.OpenDocument (controller);
+
+ var path = Path.GetTempFileName ();
+ var logger = new LoggingServiceTestsLogger ();
+ try {
+ LoggingService.AddLogger (logger);
+ DocumentRegistry.Add (doc);
+ controller.DocumentTitle = "New Title";
+ Assert.AreEqual (0, logger.Messages.Count);
+ } finally {
+ DocumentRegistry.Remove (doc);
+ LoggingService.RemoveLogger (logger.Name);
+ File.Delete (path);
+ }
+ }
+
+
+ [Test]
+ public async Task IgnoreAllChangedFilesTest ()
+ {
+ var controller = new FileDocumentController ();
+ await controller.Initialize (new ModelDescriptor ());
+
+ var doc = await documentManager.OpenDocument (controller);
+ controller.FilePath = Path.GetTempFileName ();
+
+ try {
+ DocumentRegistry.Add (doc);
+ File.WriteAllText (controller.FilePath, "test");
+ doc.IsDirty = doc.Window.ShowNotification = true;
+ await DocumentRegistry.IgnoreAllChangedFiles ();
+ Assert.IsFalse (doc.Window.ShowNotification);
+ } finally {
+ DocumentRegistry.Remove (doc);
+ File.Delete (controller.FilePath);
+ }
+ }
+
+ [Test]
+ public async Task ReloadChangedFilesTest ()
+ {
+ var controller = new FileDocumentController ();
+ await controller.Initialize (new ModelDescriptor ());
+
+ var doc = await documentManager.OpenDocument (controller);
+ controller.FilePath = Path.GetTempFileName ();
+ bool reloaded = false;
+ doc.Reloaded += delegate {
+ reloaded = true;
+ };
+ try {
+ DocumentRegistry.Add (doc);
+ File.WriteAllText (controller.FilePath, "test");
+ await DocumentRegistry.ReloadAllChangedFiles ();
+ await Runtime.RunInMainThread (delegate {
+ Assert.IsTrue (reloaded);
+ });
+ } finally {
+ DocumentRegistry.Remove (doc);
+ File.Delete (controller.FilePath);
+ }
+ }
+
+
+
+ class LoggingServiceTestsLogger : ILogger
+ {
+ readonly object lockObj = new object ();
+ readonly List<Tuple<LogLevel, string>> messages = new List<Tuple<LogLevel, string>> ();
+
+ public IReadOnlyList<Tuple<LogLevel, string>> Messages => messages;
+
+ public void Log (LogLevel level, string message)
+ {
+ lock (lockObj)
+ messages.Add (new Tuple<LogLevel, string> (level, message));
+ }
+
+ public EnabledLoggingLevel EnabledLevel => EnabledLoggingLevel.All;
+
+ public string Name => "Logging tests logger";
+ }
+ }
+}
diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj b/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj
index 438d915dea..b26649e7af 100644
--- a/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj
+++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Tests.csproj
@@ -132,6 +132,7 @@
<Compile Include="MonoDevelop.Ide.Gui\GLibLoggingTests.cs" />
<Compile Include="MonoDevelop.Ide.Projects.OptionPanels\OutputOptionsPanelTests.cs" />
<Compile Include="MonoDevelop.Components.AutoTest\AppResultTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Gui.Documents\DocumentRegistryTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\core\MonoDevelop.Ide\MonoDevelop.Ide.csproj">