public void ChangeSignature_Formatting_KeepCountsPerLine() { var markup = @" class C { void $$Method(int a, int b, int c, int d, int e, int f) { Method(1, 2, 3, 4, 5, 6); } }"; var updatedSignature = new[] { 5, 4, 3, 2, 1, 0 }; var expectedUpdatedCode = @" class C { void Method(int f, int e, int d, int c, int b, int a) { Method(6, 5, 4, 3, 2, 1); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderParameters_Cascade_ToOverriddenMethod() { var markup = @" class B { public virtual void M(int x, string y) { } } class D : B { $$public override void M(int x, string y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class B { public virtual void M(string y, int x) { } } class D : B { public override void M(string y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_Method() { var markup = @" class C { void $$Method(int a, int b) { Method(1, 2); } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class C { void Method(int b, int a) { Method(2, 1); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderParameters_Cascade_ToImplementingMethod() { var markup = @" interface I { $$void M(int x, string y); } class C : I { public void M(int x, string y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" interface I { void M(string y, int x); } class C : I { public void M(string y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_Constructor() { var markup = @" class SomeClass { $$SomeClass(int a, int b) { new SomeClass(1, 2); } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class SomeClass { SomeClass(int b, int a) { new SomeClass(2, 1); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderMethodParameters_InvokeAfterParameterList() { var markup = @" using System; class MyClass { public void Foo(int x, string y)$$ { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" using System; class MyClass { public void Foo(string y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_ConstructorInitializers() { var markup = @" class B { public $$B(int x, int y) { } public B() : this(1, 2) { } } class D : B { public D() : base(1, 2) { } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class B { public B(int y, int x) { } public B() : this(2, 1) { } } class D : B { public D() : base(2, 1) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ChangeSignature_Formatting_AnonymousMethod() { var markup = @" class SomeClass { delegate void $$MyDelegate(int a, int b); void M() { MyDelegate myDel = delegate (int x, int y) { // Nothing }; } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class SomeClass { delegate void MyDelegate(int b, int a); void M() { MyDelegate myDel = delegate (int y, int x) { // Nothing }; } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderMethodParameters_InvokeOnReference_OnlyHasCandidateSymbols() { var markup = @" class Test { void M(int x, string y) { } void M(int x, double y) { } void M2() { $$M(""s"", 1); } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class Test { void M(string y, int x) { } void M(int x, double y) { } void M2() { M(1, ""s""); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderParameters_Cascade_ToMethods_Complex() { //// B I I2 //// \ / \ / //// D (I3) //// / \ \ //// $$D2 D3 C var markup = @" class B { public virtual void M(int x, string y) { } } class D : B, I { public override void M(int x, string y) { } } class D2 : D { public override void $$M(int x, string y) { } } class D3 : D { public override void M(int x, string y) { } } interface I { void M(int x, string y); } interface I2 { void M(int x, string y); } interface I3 : I, I2 { } class C : I3 { public void M(int x, string y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class B { public virtual void M(string y, int x) { } } class D : B, I { public override void M(string y, int x) { } } class D2 : D { public override void M(string y, int x) { } } class D3 : D { public override void M(string y, int x) { } } interface I { void M(string y, int x); } interface I2 { void M(string y, int x); } interface I3 : I, I2 { } class C : I3 { public void M(string y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_Indexer() { var markup = @" class SomeClass { public int $$this[int a, int b] { get { return new SomeClass()[1, 2]; } } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class SomeClass { public int this[int b, int a] { get { return new SomeClass()[2, 1]; } } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderDelegateParameters_ObjectCreation2() { var markup = @" public class CD<T> { public delegate void D(T t, T u); } class Test { public void M() { var dele = new CD<int>.$$D((int x, int y) => { }); } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" public class CD<T> { public delegate void D(T u, T t); } class Test { public void M() { var dele = new CD<int>.D((int y, int x) => { }); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderDelegateParameters_ObjectCreation1() { var markup = @" public class C { void T() { var d = new $$D((x, y) => { }); } public delegate void D(int x, int y); }"; var permutation = new[] { 1, 0 }; var updatedCode = @" public class C { void T() { var d = new D((y, x) => { }); } public delegate void D(int y, int x); }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderIndexerParameters_InvokeOnReference_InArgumentList() { var markup = @" class Program { void M(Program p) { var t = p[5, ""test""$$]; } int this[int x, string y] { get { return 5; } set { } } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class Program { void M(Program p) { var t = p[""test"", 5]; } int this[string y, int x] { get { return 5; } set { } } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderIndexerParameters_InvokeInAccessor() { var markup = @" class Program { int this[int x, string y] { get { return $$5; } set { } } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class Program { int this[string y, int x] { get { return 5; } set { } } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderMethodParameters_InvokeOnReference_CallToBaseConstructor() { var markup = @" class B { public B(int a, int b) { } } class D : B { public D(int x, int y) : base(1, 2)$$ { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class B { public B(int b, int a) { } } class D : B { public D(int x, int y) : base(2, 1) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderMethodParameters_InvokeOnReference_CallToOtherConstructor() { var markup = @" class Program { public Program(int x, int y) : this(1, 2, 3)$$ { } public Program(int x, int y, int z) { } }"; var permutation = new[] { 2, 1, 0 }; var updatedCode = @" class Program { public Program(int x, int y) : this(3, 2, 1) { } public Program(int z, int y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_Attribute() { var markup = @" [Custom(1, 2)] class CustomAttribute : System.Attribute { public $$CustomAttribute(int x, int y) { } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" [Custom(2, 1)] class CustomAttribute : System.Attribute { public CustomAttribute(int y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ChangeSignature_Formatting_LambdaAsArgument() { var markup = @"class C { void M(System.Action<int, int> f, int z$$) { M((x, y) => System.Console.WriteLine(x + y), 5); } }"; var updatedSignature = new[] { 0 }; var expectedUpdatedCode = @"class C { void M(System.Action<int, int> f) { M((x, y) => System.Console.WriteLine(x + y)); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderMethodParameters_CodeRefactoring_InvokeBeforeMethodName() { var markup = @" using System; class MyClass { public void [||]Foo(int x, string y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" using System; class MyClass { public void Foo(string y, int x) { } }"; TestChangeSignatureViaCodeAction(markup, expectedCodeAction: true, updatedSignature: permutation, expectedCode: updatedCode); }
public void ReorderMethodParameters_CodeRefactoring_InLambda() { var markup = @" class Program { void M(int x) { System.Func<int, int, int> f = (a, b)[||] => { return a; }; } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class Program { void M(int x) { System.Func<int, int, int> f = (b, a) => { return a; }; } }"; TestChangeSignatureViaCodeAction(markup, expectedCodeAction: true, updatedSignature: permutation, expectedCode: updatedCode); }
public void ReorderMethodParameters_CodeRefactoring_AtCallSite() { var markup = @" class Program { void M(int x, int y) { M([|5|], 6); } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" class Program { void M(int y, int x) { M(6, 5); } }"; TestChangeSignatureViaCodeAction(markup, expectedCodeAction: true, updatedSignature: permutation, expectedCode: updatedCode); }
public void RemoveParameters1() { var markup = @" static class Ext { /// <summary> /// This is a summary of <see cref=""M(object, int, string, bool, int, string, int[])""/> /// </summary> /// <param name=""o""></param> /// <param name=""a""></param> /// <param name=""b""></param> /// <param name=""c""></param> /// <param name=""x""></param> /// <param name=""y""></param> /// <param name=""p""></param> static void $$M(this object o, int a, string b, bool c, int x = 0, string y = ""Zero"", params int[] p) { object t = new object(); M(t, 1, ""two"", true, 3, ""four"", new[] { 5, 6 }); M(t, 1, ""two"", true, 3, ""four"", 5, 6); t.M(1, ""two"", true, 3, ""four"", new[] { 5, 6 }); t.M(1, ""two"", true, 3, ""four"", 5, 6); M(t, 1, ""two"", true, 3, ""four""); M(t, 1, ""two"", true, 3); M(t, 1, ""two"", true); M(t, 1, ""two"", c: true); M(t, 1, ""two"", true, 3, y: ""four""); M(t, 1, ""two"", true, 3, p: new[] { 5 }); M(t, 1, ""two"", true, p: new[] { 5 }); M(t, 1, ""two"", true, y: ""four""); M(t, 1, ""two"", true, x: 3); M(t, 1, ""two"", true, y: ""four"", x: 3); M(t, 1, y: ""four"", x: 3, b: ""two"", c: true); M(t, y: ""four"", x: 3, c: true, b: ""two"", a: 1); M(t, p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1); M(p: new[] { 5 }, y: ""four"", x: 3, c: true, b: ""two"", a: 1, o: t); } }"; var updatedSignature = new[] { 0, 2, 5 }; var updatedCode = @" static class Ext { /// <summary> /// This is a summary of <see cref=""M(object, string, string)""/> /// </summary> /// <param name=""o""></param> /// <param name=""b""></param> /// <param name=""y""></param> /// /// /// /// static void M(this object o, string b, string y = ""Zero"") { object t = new object(); M(t, ""two"", ""four""); M(t, ""two"", ""four""); t.M(""two"", ""four""); t.M(""two"", ""four""); M(t, ""two"", ""four""); M(t, ""two""); M(t, ""two""); M(t, ""two""); M(t, ""two"", y: ""four""); M(t, ""two""); M(t, ""two""); M(t, ""two"", y: ""four""); M(t, ""two""); M(t, ""two"", y: ""four""); M(t, y: ""four"", b: ""two""); M(t, y: ""four"", b: ""two""); M(t, y: ""four"", b: ""two""); M(y: ""four"", b: ""two"", o: t); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderMethodParameters_InvokeOnReference_NestedCalls3() { var markup = @" using System; class MyClass { public void Foo(int x, string y) { Bar(Baz(x, y), $$y); } public void Bar(int x, string y) { } public int Baz(int x, string y) { return 1; } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" using System; class MyClass { public void Foo(int x, string y) { Bar(y, Baz(x, y)); } public void Bar(string y, int x) { } public int Baz(int x, string y) { return 1; } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderParameters_Cascade_ToMethods_WithDifferentParameterNames() { var markup = @" public class B { /// <param name=""x""></param> /// <param name=""y""></param> public virtual int M(int x, string y) { return 1; } } public class D : B { /// <param name=""a""></param> /// <param name=""b""></param> public override int M(int a, string b) { return 1; } } public class D2 : D { /// <param name=""y""></param> /// <param name=""x""></param> public override int $$M(int y, string x) { M(1, ""Two""); ((D)this).M(1, ""Two""); ((B)this).M(1, ""Two""); M(1, x: ""Two""); ((D)this).M(1, b: ""Two""); ((B)this).M(1, y: ""Two""); return 1; } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" public class B { /// <param name=""y""></param> /// <param name=""x""></param> public virtual int M(string y, int x) { return 1; } } public class D : B { /// <param name=""b""></param> /// <param name=""a""></param> public override int M(string b, int a) { return 1; } } public class D2 : D { /// <param name=""x""></param> /// <param name=""y""></param> public override int M(string x, int y) { M(""Two"", 1); ((D)this).M(""Two"", 1); ((B)this).M(""Two"", 1); M(x: ""Two"", y: 1); ((D)this).M(b: ""Two"", a: 1); ((B)this).M(y: ""Two"", x: 1); return 1; } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ChangeSignature_Formatting_Delegate() { var markup = @" class SomeClass { delegate void $$MyDelegate(int a, int b); void M(int a, int b) { var myDel = new MyDelegate(M); myDel(1, 2); } }"; var updatedSignature = new[] { 1, 0 }; var expectedUpdatedCode = @" class SomeClass { delegate void MyDelegate(int b, int a); void M(int b, int a) { var myDel = new MyDelegate(M); myDel(2, 1); } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode); }
public void ReorderMethodParameters_InvokeOnReference_BeginningOfIdentifier() { var markup = @" using System; class MyClass { public void Foo(int x, string y) { $$Bar(x, y); } public void Bar(int x, string y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" using System; class MyClass { public void Foo(int x, string y) { Bar(y, x); } public void Bar(string y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }
public void ReorderMethodParameters_InvokeOnReference_Attribute() { var markup = @" using System; [$$My(1, 2)] class MyAttribute : Attribute { public MyAttribute(int x, int y) { } }"; var permutation = new[] { 1, 0 }; var updatedCode = @" using System; [My(2, 1)] class MyAttribute : Attribute { public MyAttribute(int y, int x) { } }"; TestChangeSignatureViaCommand(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode); }