提交 2174eee6 编写于 作者: I Ivan Basov

fix test infrastructure

上级 d6f6eaa4
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature; using Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature;
using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.ChangeSignature;
using Roslyn.Test.Utilities; using Roslyn.Test.Utilities;
using Xunit; using Xunit;
...@@ -315,7 +316,7 @@ public class C3 ...@@ -315,7 +316,7 @@ public class C3
using (var testState = ChangeSignatureTestState.Create(XElement.Parse(workspaceXml))) using (var testState = ChangeSignatureTestState.Create(XElement.Parse(workspaceXml)))
{ {
testState.TestChangeSignatureOptionsService.IsCancelled = false; testState.TestChangeSignatureOptionsService.IsCancelled = false;
testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature; testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature.Select(i => new AddedParameterOrExistingIndex(i)).ToArray();
var result = testState.ChangeSignature(); var result = testState.ChangeSignature();
Assert.True(result.Succeeded); Assert.True(result.Succeeded);
......
...@@ -43,10 +43,10 @@ public void Goo(int x, string y) ...@@ -43,10 +43,10 @@ public void Goo(int x, string y)
} }
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)] [WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task ReorderMethodParameters_InsufficientParameters_None() public async Task ReorderMethodParameters_CanBeStartedEvenWithNoParameters()
{ {
var markup = @"class C { void $$M() { } }"; var markup = @"class C { void $$M() { } }";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: false, expectedErrorText: FeaturesResources.This_signature_does_not_contain_parameters_that_can_be_changed); await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, expectedSuccess: true);
} }
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)] [WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
......
...@@ -15,28 +15,29 @@ ...@@ -15,28 +15,29 @@
namespace Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature namespace Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature
{ {
internal abstract class AbstractChangeSignatureTests : AbstractCodeActionTest public abstract class AbstractChangeSignatureTests : AbstractCodeActionTest
{ {
protected override ParseOptions GetScriptOptions() protected override ParseOptions GetScriptOptions()
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
public async Task TestChangeSignatureViaCodeActionAsync( internal async Task TestChangeSignatureViaCodeActionAsync(
string markup, string markup,
bool expectedCodeAction = true, bool expectedCodeAction = true,
bool isCancelled = false, bool isCancelled = false,
int[] updatedSignature = null, int[] updatedSignature = null,
string expectedCode = null, string expectedCode = null,
int index = 0) int index = 0)
=> await TestChangeSignatureViaCodeActionAsync(markup, expectedCodeAction, isCancelled, => await TestChangeSignatureViaCodeActionAsync(
updatedSignature.Select(i => new AddedParameterOrExistingIndex(i)).ToArray(), expectedCode, index).ConfigureAwait(false); markup, updatedSignature?.Select(i => new AddedParameterOrExistingIndex(i)).ToArray(),
expectedCodeAction, isCancelled, expectedCode, index).ConfigureAwait(false);
public async Task TestChangeSignatureViaCodeActionAsync( internal async Task TestChangeSignatureViaCodeActionAsync(
string markup, string markup,
AddedParameterOrExistingIndex[] updatedSignature,
bool expectedCodeAction = true, bool expectedCodeAction = true,
bool isCancelled = false, bool isCancelled = false,
AddedParameterOrExistingIndex[] updatedSignature = null,
string expectedCode = null, string expectedCode = null,
int index = 0) int index = 0)
{ {
...@@ -64,7 +65,7 @@ protected override ParseOptions GetScriptOptions() ...@@ -64,7 +65,7 @@ protected override ParseOptions GetScriptOptions()
} }
} }
public async Task TestChangeSignatureViaCommandAsync( internal async Task TestChangeSignatureViaCommandAsync(
string languageName, string languageName,
string markup, string markup,
bool expectedSuccess = true, bool expectedSuccess = true,
...@@ -75,20 +76,20 @@ protected override ParseOptions GetScriptOptions() ...@@ -75,20 +76,20 @@ protected override ParseOptions GetScriptOptions()
bool verifyNoDiagnostics = false, bool verifyNoDiagnostics = false,
ParseOptions parseOptions = null, ParseOptions parseOptions = null,
int expectedSelectedIndex = -1) int expectedSelectedIndex = -1)
=> await TestChangeSignatureViaCommandAsync(languageName, markup, expectedSuccess, => await TestChangeSignatureViaCommandAsync(languageName, markup,
updatedSignature.Select(i => new AddedParameterOrExistingIndex(i)).ToArray(), updatedSignature?.Select(i => new AddedParameterOrExistingIndex(i)).ToArray(),
expectedUpdatedInvocationDocumentCode, expectedSuccess, expectedUpdatedInvocationDocumentCode,
expectedErrorText, expectedErrorText,
totalParameters, totalParameters,
verifyNoDiagnostics, verifyNoDiagnostics,
parseOptions, parseOptions,
expectedSelectedIndex); expectedSelectedIndex);
public async Task TestChangeSignatureViaCommandAsync( internal async Task TestChangeSignatureViaCommandAsync(
string languageName, string languageName,
string markup, string markup,
AddedParameterOrExistingIndex[] updatedSignature,
bool expectedSuccess = true, bool expectedSuccess = true,
AddedParameterOrExistingIndex[] updatedSignature = null,
string expectedUpdatedInvocationDocumentCode = null, string expectedUpdatedInvocationDocumentCode = null,
string expectedErrorText = null, string expectedErrorText = null,
int? totalParameters = null, int? totalParameters = null,
......
...@@ -29,7 +29,7 @@ AddedParameterResult IChangeSignatureOptionsService.GetAddedParameter(Document d ...@@ -29,7 +29,7 @@ AddedParameterResult IChangeSignatureOptionsService.GetAddedParameter(Document d
Document document) Document document)
{ {
var list = parameters.ToListOfParameters(); var list = parameters.ToListOfParameters();
var updateParameters = UpdatedSignature.Select(item => item.IsExisting var updateParameters = UpdatedSignature?.Select(item => item.IsExisting
? list[item.OldIndex] ? list[item.OldIndex]
: item.AddedParameter).ToList(); : item.AddedParameter).ToList();
......
...@@ -390,11 +390,10 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode) ...@@ -390,11 +390,10 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
isReducedExtensionMethod = true; isReducedExtensionMethod = true;
} }
SignatureChange signaturePermutationWithoutAddedParameters = signaturePermutation.WithoutAddedParameters(); SignatureChange signaturePermutationWithoutAddedParameters = signaturePermutation.WithoutAddedParameters();
var newArguments = PermuteArgumentList(document, declarationSymbol, invocation.ArgumentList.Arguments, signaturePermutationWithoutAddedParameters, isReducedExtensionMethod); var newArguments = PermuteArgumentList(document, declarationSymbol, invocation.ArgumentList.Arguments, signaturePermutationWithoutAddedParameters, isReducedExtensionMethod);
newArguments = AddNewArgumentsToList(document, declarationSymbol, newArguments, signaturePermutation, isReducedExtensionMethod); newArguments = AddNewArgumentsToList(newArguments, signaturePermutation);
return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(newArguments).WithAdditionalAnnotations(changeSignatureFormattingAnnotation)); return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(newArguments).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
} }
...@@ -449,7 +448,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode) ...@@ -449,7 +448,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return null; return null;
} }
private SeparatedSyntaxList<ArgumentSyntax> AddNewArgumentsToList(Document document, ISymbol declarationSymbol, SeparatedSyntaxList<ArgumentSyntax> newArguments, SignatureChange signaturePermutation, bool isReducedExtensionMethod) private SeparatedSyntaxList<ArgumentSyntax> AddNewArgumentsToList(SeparatedSyntaxList<ArgumentSyntax> newArguments, SignatureChange signaturePermutation)
{ {
List<ArgumentSyntax> fullList = new List<ArgumentSyntax>(); List<ArgumentSyntax> fullList = new List<ArgumentSyntax>();
...@@ -473,12 +472,15 @@ private SeparatedSyntaxList<ArgumentSyntax> AddNewArgumentsToList(Document docum ...@@ -473,12 +472,15 @@ private SeparatedSyntaxList<ArgumentSyntax> AddNewArgumentsToList(Document docum
} }
else else
{ {
if (newArguments[indexInExistingList].NameColon != default) if (indexInExistingList < newArguments.Count)
{ {
seenNameEquals = true; if (newArguments[indexInExistingList].NameColon != default)
} {
seenNameEquals = true;
}
fullList.Add(newArguments[indexInExistingList++]); fullList.Add(newArguments[indexInExistingList++]);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册