internal static async Task TestChangeSignatureViaCommandAsync( string languageName, string markup, AddedParameterOrExistingIndex[] updatedSignature, bool expectedSuccess = true, string expectedUpdatedInvocationDocumentCode = null, string expectedErrorText = null, int?totalParameters = null, bool verifyNoDiagnostics = false, ParseOptions parseOptions = null, OptionsCollection options = null, int expectedSelectedIndex = -1) { using (var testState = ChangeSignatureTestState.Create(markup, languageName, parseOptions, options)) { testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature; var result = testState.ChangeSignature(); if (expectedSuccess) { Assert.True(result.Succeeded); Assert.Null(testState.ErrorMessage); } else { Assert.False(result.Succeeded); if (expectedErrorText != null) { Assert.Equal(expectedErrorText, testState.ErrorMessage); Assert.Equal(NotificationSeverity.Error, testState.ErrorSeverity); } } // Allow testing of invocation document regardless of success/failure if (expectedUpdatedInvocationDocumentCode != null) { var updatedInvocationDocument = result.UpdatedSolution.GetDocument(testState.InvocationDocument.Id); var updatedCode = (await updatedInvocationDocument.GetTextAsync()).ToString(); Assert.Equal(expectedUpdatedInvocationDocumentCode, updatedCode); } if (verifyNoDiagnostics) { var diagnostics = (await testState.InvocationDocument.GetSemanticModelAsync()).GetDiagnostics(); if (diagnostics.Length > 0) { Assert.True(false, CreateDiagnosticsString(diagnostics, updatedSignature, testState.InvocationDocument, totalParameters, (await testState.InvocationDocument.GetTextAsync()).ToString())); } } if (expectedSelectedIndex != -1) { var parameterConfiguration = await testState.GetParameterConfigurationAsync(); Assert.Equal(expectedSelectedIndex, parameterConfiguration.SelectedIndex); } } }
public void TestChangeSignatureViaCommand( string languageName, string markup, bool expectedSuccess = true, int[] updatedSignature = null, string expectedUpdatedInvocationDocumentCode = null, string expectedErrorText = null, int? totalParameters = null, bool verifyNoDiagnostics = false, ParseOptions parseOptions = null) { using (var testState = new ChangeSignatureTestState(markup, languageName, parseOptions)) { testState.TestChangeSignatureOptionsService.IsCancelled = false; testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature; var result = testState.ChangeSignature(); if (expectedSuccess) { Assert.True(result.Succeeded); Assert.Null(testState.ErrorMessage); } else { Assert.False(result.Succeeded); if (expectedErrorText != null) { Assert.Equal(expectedErrorText, testState.ErrorMessage); Assert.Equal(NotificationSeverity.Error, testState.ErrorSeverity); } } // Allow testing of invocation document regardless of success/failure if (expectedUpdatedInvocationDocumentCode != null) { var updatedInvocationDocument = result.UpdatedSolution.GetDocument(testState.InvocationDocument.Id); var updatedCode = updatedInvocationDocument.GetTextAsync(CancellationToken.None).Result.ToString(); Assert.Equal(expectedUpdatedInvocationDocumentCode, updatedCode); } if (verifyNoDiagnostics) { var diagnostics = testState.InvocationDocument.GetSemanticModelAsync().Result.GetDiagnostics(); if (diagnostics.Length > 0) { Assert.True(false, CreateDiagnosticsString(diagnostics, updatedSignature, totalParameters, testState.InvocationDocument.GetTextAsync().Result.ToString())); } } } }
public void TestChangeSignatureViaCommand( string languageName, string markup, bool expectedSuccess = true, int[] updatedSignature = null, string expectedUpdatedInvocationDocumentCode = null, string expectedErrorText = null, int?totalParameters = null, bool verifyNoDiagnostics = false, ParseOptions parseOptions = null) { using (var testState = new ChangeSignatureTestState(markup, languageName, parseOptions)) { testState.TestChangeSignatureOptionsService.IsCancelled = false; testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature; var result = testState.ChangeSignature(); if (expectedSuccess) { Assert.True(result.Succeeded); Assert.Null(testState.ErrorMessage); } else { Assert.False(result.Succeeded); if (expectedErrorText != null) { Assert.Equal(expectedErrorText, testState.ErrorMessage); Assert.Equal(NotificationSeverity.Error, testState.ErrorSeverity); } } // Allow testing of invocation document regardless of success/failure if (expectedUpdatedInvocationDocumentCode != null) { var updatedInvocationDocument = result.UpdatedSolution.GetDocument(testState.InvocationDocument.Id); var updatedCode = updatedInvocationDocument.GetTextAsync(CancellationToken.None).Result.ToString(); Assert.Equal(expectedUpdatedInvocationDocumentCode, updatedCode); } if (verifyNoDiagnostics) { var diagnostics = testState.InvocationDocument.GetSemanticModelAsync().Result.GetDiagnostics(); if (diagnostics.Length > 0) { Assert.True(false, CreateDiagnosticsString(diagnostics, updatedSignature, totalParameters, testState.InvocationDocument.GetTextAsync().Result.ToString())); } } } }
public void RemoveParameters_ExtensionMethodInAnotherFile() { var workspaceXml = @" <Workspace> <Project Language=""C#"" AssemblyName=""CSharpAssembly"" CommonReferences=""true"">"; for (int i = 0; i <= 4; i++) { workspaceXml += $@" <Document FilePath = ""C{i}.cs""> class C{i} {{ void M() {{ C5 c = new C5(); c.Ext(1, ""two""); }} }} </Document>"; } workspaceXml += @" <Document FilePath = ""C5.cs""> public class C5 { } public static class C5Ext { public void $$Ext(this C5 c, int i, string s) { } } </Document>"; for (int i = 6; i <= 9; i++) { workspaceXml += $@" <Document FilePath = ""C{i}.cs""> class C{i} {{ void M() {{ C5 c = new C5(); c.Ext(1, ""two""); }} }} </Document>"; } workspaceXml += @" </Project> </Workspace>"; // Ext(this F f, int i, string s) --> Ext(this F f, string s) // If a reference does not bind correctly, it will believe Ext is not an extension // method and remove the string argument instead of the int argument. var updatedSignature = new[] { 0, 2 }; using (var testState = new ChangeSignatureTestState(XElement.Parse(workspaceXml))) { testState.TestChangeSignatureOptionsService.IsCancelled = false; testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature; var result = testState.ChangeSignature(); Assert.True(result.Succeeded); Assert.Null(testState.ErrorMessage); foreach (var updatedDocument in testState.Workspace.Documents.Select(d => result.UpdatedSolution.GetDocument(d.Id))) { if (updatedDocument.Name == "C5.cs") { Assert.Contains("void Ext(this C5 c, string s)", updatedDocument.GetTextAsync(CancellationToken.None).Result.ToString()); } else { Assert.Contains(@"c.Ext(""two"");", updatedDocument.GetTextAsync(CancellationToken.None).Result.ToString()); } } } }