提交 67160f62 编写于 作者: G Gen Lu

Exclude unchangeable document from change namespace results

上级 fee56fea
......@@ -169,7 +169,6 @@ protected async Task TestMoveFileToMatchNamespace(string initialMarkup, List<str
var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution);
Assert.True(changedDocumentIds.Contains(originalDocumentId), "original document was not changed.");
Assert.True(expectedSourceReference == null || changedDocumentIds.Contains(refDocumentId), "reference document was not changed.");
var modifiedOriginalDocument = newSolution.GetDocument(originalDocumentId);
var modifiedOringinalRoot = await modifiedOriginalDocument.GetSyntaxRootAsync();
......@@ -195,8 +194,19 @@ protected async Task TestMoveFileToMatchNamespace(string initialMarkup, List<str
var actualText = (await modifiedOriginalDocument.GetTextAsync()).ToString();
Assert.Equal(expectedSourceOriginal, actualText);
if (expectedSourceReference != null)
if (expectedSourceReference == null)
{
// there shouldn't be any textual change
if (changedDocumentIds.Contains(refDocumentId))
{
var oldRefText = (await oldSolution.GetDocument(refDocumentId).GetTextAsync()).ToString();
var newRefText = (await newSolution.GetDocument(refDocumentId).GetTextAsync()).ToString();
Assert.Equal(oldRefText, newRefText);
}
}
else
{
Assert.True(changedDocumentIds.Contains(refDocumentId));
var actualRefText = (await newSolution.GetDocument(refDocumentId).GetTextAsync()).ToString();
Assert.Equal(expectedSourceReference, actualRefText);
}
......
......@@ -466,6 +466,62 @@ void M1()
await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference);
}
[WorkItem(963225, "https://dev.azure.com/devdiv/DevDiv/_workitems/edit/963225")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)]
public async Task ChangeNamespace_WithReferencesInUnchangeableDocument()
{
var defaultNamespace = "A";
var declaredNamespace = "Foo.Bar.Baz";
var documentPath1 = CreateDocumentFilePath(new[] { "B", "C" }, "File1.cs");
var documentPath2 = CreateDocumentFilePath(Array.Empty<string>(), "File2.cs");
var code =
$@"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" FilePath=""{ProjectFilePath}"" RootNamespace=""{defaultNamespace}"" CommonReferences=""true"">
<Document Folders=""{documentPath1.folder}"" FilePath=""{documentPath1.filePath}"">
namespace [||]{declaredNamespace}
{{
class Class1
{{
}}
class Class2
{{
}}
}}</Document>
<Document Folders=""{documentPath2.folder}"" FilePath=""{documentPath2.filePath}"" CanApplyChange=""false"">
using Foo.Bar.Baz;
namespace Foo
{{
class RefClass
{{
private Class1 c1;
void M1()
{{
Bar.Baz.Class2 c2 = null;
}}
}}
}}</Document>
</Project>
</Workspace>";
var expectedSourceOriginal =
@"namespace A.B.C
{
class Class1
{
}
class Class2
{
}
}";
await TestChangeNamespaceAsync(code, expectedSourceOriginal);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)]
public async Task ChangeNamespace_WithQualifiedReferencesInOtherDocument()
{
......
......@@ -188,7 +188,9 @@ await ChangeNamespaceInSingleDocumentAsync(solutionAfterNamespaceChange, documen
ImmutableArray.Create(declaredNamespace, targetNamespace),
cancellationToken).ConfigureAwait(false);
return await MergeDiffAsync(solutionAfterFirstMerge, solutionAfterImportsRemoved, cancellationToken).ConfigureAwait(false);
var mergedSolution = await MergeDiffAsync(solutionAfterFirstMerge, solutionAfterImportsRemoved, cancellationToken).ConfigureAwait(false);
return await mergedSolution.ExcludeDisallowedDocumentTextChangesAsync(solution, cancellationToken).ConfigureAwait(false);
}
finally
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册