提交 60f8761c 编写于 作者: C Cyrus Najmabadi

Add test to verify linked file updating works properly.

上级 37f8ac24
...@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics ...@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Optional codeActionIndex As Integer = 0, Optional codeActionIndex As Integer = 0,
Optional verifyTokens As Boolean = True, Optional verifyTokens As Boolean = True,
Optional fileNameToExpected As Dictionary(Of String, String) = Nothing, Optional fileNameToExpected As Dictionary(Of String, String) = Nothing,
Optional verifySolutions As Action(Of Solution, Solution) = Nothing, Optional verifySolutions As Func(Of Solution, Solution, Task) = Nothing,
Optional onAfterWorkspaceCreated As Action(Of TestWorkspace) = Nothing) As Task Optional onAfterWorkspaceCreated As Action(Of TestWorkspace) = Nothing) As Task
Using workspace = TestWorkspace.CreateWorkspace(definition) Using workspace = TestWorkspace.CreateWorkspace(definition)
onAfterWorkspaceCreated?.Invoke(workspace) onAfterWorkspaceCreated?.Invoke(workspace)
...@@ -65,16 +65,20 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics ...@@ -65,16 +65,20 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Dim updatedSolution = workspace.CurrentSolution Dim updatedSolution = workspace.CurrentSolution
verifySolutions?.Invoke(oldSolution, updatedSolution) If verifySolutions IsNot Nothing Then
Await verifySolutions(oldSolution, updatedSolution)
End If
If expected Is Nothing AndAlso fileNameToExpected Is Nothing Then If expected Is Nothing AndAlso
fileNameToExpected Is Nothing AndAlso
verifySolutions Is Nothing Then
Dim projectChanges = SolutionUtilities.GetSingleChangedProjectChanges(oldSolution, updatedSolution) Dim projectChanges = SolutionUtilities.GetSingleChangedProjectChanges(oldSolution, updatedSolution)
Assert.Empty(projectChanges.GetChangedDocuments()) Assert.Empty(projectChanges.GetChangedDocuments())
ElseIf expected IsNot Nothing Then ElseIf expected IsNot Nothing Then
Dim updatedDocument = SolutionUtilities.GetSingleChangedDocument(oldSolution, updatedSolution) Dim updatedDocument = SolutionUtilities.GetSingleChangedDocument(oldSolution, updatedSolution)
Await VerifyAsync(expected, verifyTokens, updatedDocument) Await VerifyAsync(expected, verifyTokens, updatedDocument)
Else ElseIf fileNameToExpected IsNot Nothing Then
For Each kvp In fileNameToExpected For Each kvp In fileNameToExpected
Dim updatedDocument = updatedSolution.Projects.SelectMany(Function(p) p.Documents).Single(Function(d) d.Name = kvp.Key) Dim updatedDocument = updatedSolution.Projects.SelectMany(Function(p) p.Documents).Single(Function(d) d.Name = kvp.Key)
Await VerifyAsync(kvp.Value, verifyTokens, updatedDocument) Await VerifyAsync(kvp.Value, verifyTokens, updatedDocument)
...@@ -134,7 +138,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics ...@@ -134,7 +138,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Dim hostDocument = GetHostDocument(workspace) Dim hostDocument = GetHostDocument(workspace)
Dim invocationBuffer = hostDocument.TextBuffer Dim invocationBuffer = hostDocument.TextBuffer
Dim invocationPoint = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue).CursorPosition.Value Dim invocationPoint = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue AndAlso Not d.IsLinkFile).CursorPosition.Value
Dim document = workspace.CurrentSolution.GetDocument(hostDocument.Id) Dim document = workspace.CurrentSolution.GetDocument(hostDocument.Id)
......
...@@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.IncrementalCaches ...@@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.IncrementalCaches
Imports Microsoft.CodeAnalysis.SolutionCrawler Imports Microsoft.CodeAnalysis.SolutionCrawler
Imports Microsoft.CodeAnalysis.UnitTests Imports Microsoft.CodeAnalysis.UnitTests
Imports Microsoft.CodeAnalysis.VisualBasic.AddImport Imports Microsoft.CodeAnalysis.VisualBasic.AddImport
Imports Roslyn.Utilities
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.AddImport Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.AddImport
...@@ -509,12 +510,12 @@ namespace CSAssembly2 ...@@ -509,12 +510,12 @@ namespace CSAssembly2
Optional codeActionIndex As Integer = 0, Optional codeActionIndex As Integer = 0,
Optional addedReference As String = Nothing, Optional addedReference As String = Nothing,
Optional onAfterWorkspaceCreated As Action(Of TestWorkspace) = Nothing) As Task Optional onAfterWorkspaceCreated As Action(Of TestWorkspace) = Nothing) As Task
Dim verifySolutions As Action(Of Solution, Solution) = Nothing Dim verifySolutions As Func(Of Solution, Solution, Task) = Nothing
Dim workspace As TestWorkspace = Nothing Dim workspace As TestWorkspace = Nothing
If addedReference IsNot Nothing Then If addedReference IsNot Nothing Then
verifySolutions = verifySolutions =
Sub(oldSolution As Solution, newSolution As Solution) Function(oldSolution As Solution, newSolution As Solution)
Dim initialDocId = workspace.DocumentWithCursor.Id Dim initialDocId = workspace.DocumentWithCursor.Id
Dim oldProject = oldSolution.GetDocument(initialDocId).Project Dim oldProject = oldSolution.GetDocument(initialDocId).Project
Dim newProject = newSolution.GetDocument(initialDocId).Project Dim newProject = newSolution.GetDocument(initialDocId).Project
...@@ -529,7 +530,8 @@ namespace CSAssembly2 ...@@ -529,7 +530,8 @@ namespace CSAssembly2
Select p.Name Select p.Name
Assert.True(newProjectReferences.Contains(addedReference)) Assert.True(newProjectReferences.Contains(addedReference))
End Sub Return SpecializedTasks.EmptyTask
End Function
End If End If
Await TestAsync(definition, expected, codeActionIndex, Await TestAsync(definition, expected, codeActionIndex,
......
...@@ -94,5 +94,54 @@ end class ...@@ -94,5 +94,54 @@ end class
</text>.Value.Trim()} </text>.Value.Trim()}
}) })
End Function End Function
<Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)>
Public Async Function TestLinkedFile() As System.Threading.Tasks.Task
Dim input =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="LinkedProj" Name="CSProj.1">
<Document FilePath='C.cs'>
partial class C
{
$$int i;
public int P { get { return i; } }
public C()
{
this.i = 0;
}
}
</Document>
</Project>
<Project Language="C#" CommonReferences="true" AssemblyName="LinkedProj" Name="CSProj.2">
<Document IsLinkFile="true" LinkProjectName="CSProj.1" LinkFilePath="C.cs"/>
</Project>
</Workspace>
Dim expectedText = "
partial class C
{
public int P { get; private set; }
public C()
{
this.P = 0;
}
}".Trim()
Await TestAsync(input, verifySolutions:=
Async Function(oldSolution, newSolution)
Dim documents = newSolution.Projects.SelectMany(Function(p) p.Documents).
Where(Function(d) d.Name = "C.cs")
Assert.Equal(2, documents.Count())
For Each doc In documents
Dim text = (Await doc.GetTextAsync()).ToString().Trim()
Assert.Equal(expectedText, text)
Next
End Function)
End Function
End Class End Class
End Namespace End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册