/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="before">The code to analyze with <paramref name="refactoring"/>. Position is provided by <paramref name="span"/>.</param> /// <param name="span">A <see cref="TextSpan"/> indicating the position.</param> /// <param name="after">The expected code produced by <paramref name="refactoring"/>.</param> public static void Refactoring(CodeRefactoringProvider refactoring, string before, TextSpan span, string after) { #pragma warning disable CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() var refactored = Refactor.Apply(refactoring, before, span, MetadataReferences); #pragma warning restore CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() CodeAssert.AreEqual(after, refactored); }
/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="codeWithPositionIndicated">The code to refactor with position indicated with ↓.</param> /// <param name="title">The title of the refactoring to apply.</param> /// <param name="fixedCode">The expected code produced by the refactoring.</param> public static void Refactoring(CodeRefactoringProvider refactoring, string codeWithPositionIndicated, string title, string fixedCode) { var position = GetPosition(codeWithPositionIndicated, out var testCode); var refactored = Refactor.Apply(refactoring, testCode, position, title, MetadataReferences); CodeAssert.AreEqual(refactored, fixedCode); }
/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="before">The code to analyze with <paramref name="refactoring"/>. Indicate position with ↓ (alt + 25).</param> /// <param name="after">The expected code produced by <paramref name="refactoring"/>.</param> public static void Refactoring(CodeRefactoringProvider refactoring, string before, string after) { var position = GetPosition(before, out var testCode); #pragma warning disable CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() var refactored = Refactor.Apply(refactoring, testCode, position, MetadataReferences); #pragma warning restore CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() CodeAssert.AreEqual(after, refactored); }
/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="code">The code to analyze with <paramref name="refactoring"/>. Position is provided by <paramref name="span"/>.</param> /// <param name="span">A <see cref="TextSpan"/> indicating the position.</param> /// <param name="title">The title of the refactoring to apply.</param> public static void NoRefactoring(CodeRefactoringProvider refactoring, string code, TextSpan span, string title) { #pragma warning disable CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() var actions = Refactor.CodeActions(refactoring, code, span, MetadataReferences); #pragma warning restore CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() if (actions.Any(x => x.Title == title)) { throw new AssertException("Expected the refactoring to not register any code actions."); } }
/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="code">The code to analyze with <paramref name="refactoring"/>. Indicate position with ↓ (alt + 25).</param> public static void NoRefactoring(CodeRefactoringProvider refactoring, string code) { var position = GetPosition(code, out var testCode); #pragma warning disable CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() var actions = Refactor.CodeActions(refactoring, testCode, position, MetadataReferences); #pragma warning restore CS0618 // Suppress until removed. Will be replaced with Metadatareferences.FromAttributes() if (actions.Any()) { throw new AssertException("Expected the refactoring to not register any code actions."); } }
/// <summary> /// For testing a <see cref="CodeRefactoringProvider"/>. /// </summary> /// <param name="refactoring">The <see cref="CodeRefactoringProvider"/>.</param> /// <param name="code">The code to refactor.</param> /// <param name="span">The position.</param> /// <param name="title">The title of the refactoring to apply.</param> /// <param name="fixedCode">The expected code produced by the refactoring.</param> public static void Refactoring(CodeRefactoringProvider refactoring, string code, TextSpan span, string title, string fixedCode) { var refactored = Refactor.Apply(refactoring, code, span, title, MetadataReferences); CodeAssert.AreEqual(refactored, fixedCode); }