forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test almost directly from dotnet#74716
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/VisualStudio/Core/Test/ProjectSystemShim/FileChangeWatcherTests.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
' Licensed to the .NET Foundation under one or more agreements. | ||
' The .NET Foundation licenses this file to you under the MIT license. | ||
' See the LICENSE file in the project root for more information. | ||
|
||
Imports System.Collections.Immutable | ||
Imports System.IO | ||
Imports Microsoft.CodeAnalysis.ProjectSystem | ||
Imports Microsoft.CodeAnalysis.Shared.TestHooks | ||
Imports Microsoft.CodeAnalysis.Test.Utilities | ||
Imports Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem | ||
Imports Roslyn.Test.Utilities | ||
Imports IVsAsyncFileChangeEx2 = Microsoft.VisualStudio.Shell.IVsAsyncFileChangeEx2 | ||
|
||
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim | ||
<UseExportProvider> | ||
Public Class FileChangeWatcherTests | ||
Implements IDisposable | ||
|
||
Private ReadOnly _tempPath As String | ||
|
||
Public Sub New() | ||
_tempPath = Path.Combine(TempRoot.Root, Path.GetRandomFileName()) | ||
Directory.CreateDirectory(_tempPath) | ||
End Sub | ||
|
||
Private Sub Dispose() Implements IDisposable.Dispose | ||
Directory.Delete(_tempPath, recursive:=True) | ||
End Sub | ||
|
||
<WpfFact> | ||
Public Async Function WatchingMultipleContexts() As Task | ||
Using workspace = New EditorTestWorkspace() | ||
Dim fileChangeService = New MockVsFileChangeEx | ||
Dim fileChangeWatcher = New FileChangeWatcher(workspace.GetService(Of IAsynchronousOperationListenerProvider)(), Task.FromResult(Of IVsAsyncFileChangeEx2)(fileChangeService)) | ||
|
||
Dim context1 = fileChangeWatcher.CreateContext(ImmutableArray.Create(New WatchedDirectory(_tempPath, ImmutableArray(Of String).Empty))) | ||
Dim context2 = fileChangeWatcher.CreateContext(ImmutableArray.Create(New WatchedDirectory(_tempPath, ImmutableArray(Of String).Empty))) | ||
|
||
Dim handler1Called As Boolean = False | ||
Dim handler2Called As Boolean = False | ||
|
||
AddHandler context1.FileChanged, Sub(sender, args) handler1Called = True | ||
AddHandler context2.FileChanged, Sub(sender, args) handler2Called = True | ||
|
||
Dim watchedFile1 = context1.EnqueueWatchingFile("file1.txt") | ||
Dim watchedFile2 = context2.EnqueueWatchingFile("file2.txt") | ||
|
||
Await workspace.GetService(Of AsynchronousOperationListenerProvider)().GetWaiter(FeatureAttribute.Workspace).ExpeditedWaitAsync() | ||
|
||
fileChangeService.FireUpdate("file2.txt") | ||
|
||
Assert.False(handler1Called) | ||
Assert.True(handler2Called) | ||
End Using | ||
End Function | ||
End Class | ||
End Namespace |