提交 d58c646a 编写于 作者: C Cyrus Najmabadi

Add multi file tests.

上级 08b3602c
......@@ -19,9 +19,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Friend MustOverride Function CreateDiagnosticProviderAndFixer(workspace As Workspace, language As String) As Tuple(Of DiagnosticAnalyzer, CodeFixProvider)
Protected Sub Test(definition As XElement,
expected As String,
Optional expected As String = Nothing,
Optional codeActionIndex As Integer = 0,
Optional verifyTokens As Boolean = True)
Optional verifyTokens As Boolean = True,
Optional fileNameToExpected As Dictionary(Of String, String) = Nothing)
Using workspace = TestWorkspaceFactory.CreateWorkspace(definition)
Dim diagnosticAndFix = GetDiagnosticAndFix(workspace)
Dim codeAction = diagnosticAndFix.Item2.Fixes.ElementAt(codeActionIndex).Action
......@@ -31,19 +32,29 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Dim oldSolution = workspace.CurrentSolution
Dim updatedSolution = edit.ChangedSolution
Dim updatedDocument = SolutionUtilities.GetSingleChangedDocument(oldSolution, updatedSolution)
If fileNameToExpected Is Nothing Then
Dim updatedDocument = SolutionUtilities.GetSingleChangedDocument(oldSolution, updatedSolution)
Dim actual = updatedDocument.GetTextAsync().Result.ToString().Trim()
If verifyTokens Then
Utilities.AssertEx.TokensAreEqual(expected, actual, updatedDocument.Project.Language)
Verify(expected, verifyTokens, updatedDocument)
Else
AssertEx.Equal(expected, actual)
For Each kvp In fileNameToExpected
Dim updatedDocument = updatedSolution.Projects.SelectMany(Function(p) p.Documents).Single(Function(d) d.Name = kvp.Key)
Verify(kvp.Value, verifyTokens, updatedDocument)
Next
End If
End Using
End Sub
Private Shared Sub Verify(expected As String, verifyTokens As Boolean, updatedDocument As Document)
Dim actual = updatedDocument.GetTextAsync().Result.ToString().Trim()
If verifyTokens Then
Utilities.AssertEx.TokensAreEqual(expected, actual, updatedDocument.Project.Language)
Else
AssertEx.Equal(expected, actual)
End If
End Sub
Friend Function GetDiagnosticAndFix(workspace As TestWorkspace) As Tuple(Of Diagnostic, CodeFixCollection)
Return GetDiagnosticAndFixes(workspace).FirstOrDefault()
End Function
......

Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.UseAutoProperty
Public Class UseAutoPropertyTests
Inherits AbstractCrossLanguageUserDiagnosticTest
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace, language As String) As Tuple(Of DiagnosticAnalyzer, CodeFixProvider)
If language = LanguageNames.CSharp Then
Return New Tuple(Of DiagnosticAnalyzer, CodeFixProvider)(New CSharp.UseAutoProperty.UseAutoPropertyAnalyzer(), New CSharp.UseAutoProperty.UseAutoPropertyCodeFixProvider())
ElseIf language = LanguageNames.VisualBasic
Return New Tuple(Of DiagnosticAnalyzer, CodeFixProvider)(New VisualBasic.UseAutoProperty.UseAutoPropertyAnalyzer(), New VisualBasic.UseAutoProperty.UseAutoPropertyCodeFixProvider())
Else
Throw New Exception()
End If
End Function
<Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)>
Public Sub TestMultiFile_CSharp()
Dim input =
<Workspace>
<Project Language='C#' AssemblyName='CSharpAssembly1' CommonReferences='true'>
<Document FilePath='Test1.cs'>
partial class C
{
int $$i;
}
</Document>
<Document FilePath='Test2.cs'>
partial class C
{
int P { get { return i; } }
}
</Document>
</Project>
</Workspace>
Test(input, fileNameToExpected:=
New Dictionary(Of String, String) From {
{"Test1.cs",
<text>
partial class C
{
}
</text>.Value.Trim()},
{"Test2.cs",
<text>
partial class C
{
int P { get; }
}
</text>.Value.Trim()}
})
End Sub
<Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)>
Public Sub TestMultiFile_VisualBasic()
Dim input =
<Workspace>
<Project Language='Visual Basic' AssemblyName='CSharpAssembly1' CommonReferences='true'>
<Document FilePath='Test1.vb'>
partial class C
dim $$i as Integer
end class
</Document>
<Document FilePath='Test2.vb'>
partial class C
property P as Integer
get
return i
end get
end property
end class
</Document>
</Project>
</Workspace>
Test(input, fileNameToExpected:=
New Dictionary(Of String, String) From {
{"Test1.vb",
<text>
partial class C
end class
</text>.Value.Trim()},
{"Test2.vb",
<text>
partial class C
ReadOnly property P as Integer
end class
</text>.Value.Trim()}
})
End Sub
End Class
End Namespace
\ No newline at end of file
......@@ -173,6 +173,7 @@
<ItemGroup>
<Compile Include="CallHierarchy\CallHierarchyTests.vb" />
<Compile Include="Diagnostics\InMemoryAssemblyLoader.vb" />
<Compile Include="Diagnostics\UseAutoProperty\UseAutoPropertyTests.vb" />
<Compile Include="LanguageServices\SyntaxFactsServiceTests.vb" />
<Compile Include="Utilities\MockDocumentNavigationServiceProvider.vb" />
<Compile Include="Utilities\MockSymbolNavigationServiceProvider.vb" />
......@@ -320,4 +321,4 @@
<Import Project="..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -85,7 +85,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename
Dim locations = RenameLocations.FindAsync(symbol, workspace.CurrentSolution, optionSet, CancellationToken.None).Result
Dim originalName = symbol.Name.Split("."c).Last()
Dim result = ConflictResolver.ResolveConflictsAsync(locations, originalName, renameTo, optionSet, CancellationToken.None).Result
Dim result = ConflictResolver.ResolveConflictsAsync(locations, originalName, renameTo, optionSet, hasConflict:=Nothing, cancellationToken:=CancellationToken.None).Result
engineResult = New RenameEngineResult(workspace, result, renameTo)
engineResult.AssertUnlabeledSpansRenamedAndHaveNoConflicts()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册