/src/EditorFeatures/CSharpTest/GenerateFromMembers/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersTests.cs

https://github.com/dotnet/roslyn · C# · 1905 lines · 1825 code · 75 blank · 5 comment · 0 complexity · 2bd2bac1a05fe38d42f3f3c95eee5920 MD5 · raw file

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Immutable;
  5. using System.Threading.Tasks;
  6. using Microsoft.CodeAnalysis.AddConstructorParametersFromMembers;
  7. using Microsoft.CodeAnalysis.CodeActions;
  8. using Microsoft.CodeAnalysis.CodeRefactorings;
  9. using Microsoft.CodeAnalysis.CSharp;
  10. using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
  11. using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
  12. using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles;
  13. using Microsoft.CodeAnalysis.Test.Utilities;
  14. using Roslyn.Test.Utilities;
  15. using Xunit;
  16. namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.GenerateFromMembers.AddConstructorParameters
  17. {
  18. public class AddConstructorParametersFromMembersTests : AbstractCSharpCodeActionTest
  19. {
  20. protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
  21. => new AddConstructorParametersFromMembersCodeRefactoringProvider();
  22. private readonly NamingStylesTestOptionSets options = new NamingStylesTestOptionSets(LanguageNames.CSharp);
  23. protected override ImmutableArray<CodeAction> MassageActions(ImmutableArray<CodeAction> actions)
  24. => FlattenActions(actions);
  25. [WorkItem(308077, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/308077")]
  26. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  27. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  28. public async Task TestAdd1()
  29. {
  30. await TestInRegularAndScriptAsync(
  31. @"using System.Collections.Generic;
  32. class Program
  33. {
  34. [|int i;
  35. string s;|]
  36. public Program(int i)
  37. {
  38. this.i = i;
  39. }
  40. }",
  41. @"using System.Collections.Generic;
  42. class Program
  43. {
  44. int i;
  45. string s;
  46. public Program(int i, string s)
  47. {
  48. this.i = i;
  49. this.s = s;
  50. }
  51. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  52. }
  53. [WorkItem(308077, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/308077")]
  54. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  55. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  56. public async Task TestAddOptional1()
  57. {
  58. await TestInRegularAndScriptAsync(
  59. @"using System.Collections.Generic;
  60. class Program
  61. {
  62. [|int i;
  63. string s;|]
  64. public Program(int i)
  65. {
  66. this.i = i;
  67. }
  68. }",
  69. @"using System.Collections.Generic;
  70. class Program
  71. {
  72. int i;
  73. string s;
  74. public Program(int i, string s = null)
  75. {
  76. this.i = i;
  77. this.s = s;
  78. }
  79. }", index: 1, title: string.Format(FeaturesResources.Add_optional_parameters_to_0, "Program(int)"));
  80. }
  81. [WorkItem(308077, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/308077")]
  82. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  83. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  84. public async Task TestAddToConstructorWithMostMatchingParameters1()
  85. {
  86. // behavior change with 33603, now all constructors offered
  87. await TestInRegularAndScriptAsync(
  88. @"using System.Collections.Generic;
  89. class Program
  90. {
  91. [|int i;
  92. string s;
  93. bool b;|]
  94. public Program(int i)
  95. {
  96. this.i = i;
  97. }
  98. public Program(int i, string s) : this(i)
  99. {
  100. this.s = s;
  101. }
  102. }",
  103. @"using System.Collections.Generic;
  104. class Program
  105. {
  106. int i;
  107. string s;
  108. bool b;
  109. public Program(int i)
  110. {
  111. this.i = i;
  112. }
  113. public Program(int i, string s, bool b) : this(i)
  114. {
  115. this.s = s;
  116. this.b = b;
  117. }
  118. }", index: 1, title: string.Format(FeaturesResources.Add_to_0, "Program(int, string)"));
  119. }
  120. [WorkItem(308077, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/308077")]
  121. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  122. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  123. public async Task TestAddOptionalToConstructorWithMostMatchingParameters1()
  124. {
  125. // Behavior change with #33603, now all constructors are offered
  126. await TestInRegularAndScriptAsync(
  127. @"using System.Collections.Generic;
  128. class Program
  129. {
  130. [|int i;
  131. string s;
  132. bool b;|]
  133. public Program(int i)
  134. {
  135. this.i = i;
  136. }
  137. public Program(int i, string s) : this(i)
  138. {
  139. this.s = s;
  140. }
  141. }",
  142. @"using System.Collections.Generic;
  143. class Program
  144. {
  145. int i;
  146. string s;
  147. bool b;
  148. public Program(int i)
  149. {
  150. this.i = i;
  151. }
  152. public Program(int i, string s, bool b = false) : this(i)
  153. {
  154. this.s = s;
  155. this.b = b;
  156. }
  157. }", index: 3, title: string.Format(FeaturesResources.Add_to_0, "Program(int, string)"));
  158. }
  159. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  160. public async Task TestSmartTagDisplayText1()
  161. {
  162. await TestSmartTagTextAsync(
  163. @"using System.Collections.Generic;
  164. class Program
  165. {
  166. [|bool b;
  167. HashSet<string> s;|]
  168. public Program(bool b)
  169. {
  170. this.b = b;
  171. }
  172. }",
  173. string.Format(FeaturesResources.Add_parameters_to_0, "Program(bool)"));
  174. }
  175. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  176. public async Task TestSmartTagDisplayText2()
  177. {
  178. await TestSmartTagTextAsync(
  179. @"using System.Collections.Generic;
  180. class Program
  181. {
  182. [|bool b;
  183. HashSet<string> s;|]
  184. public Program(bool b)
  185. {
  186. this.b = b;
  187. }
  188. }",
  189. string.Format(FeaturesResources.Add_optional_parameters_to_0, "Program(bool)"),
  190. index: 1);
  191. }
  192. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  193. public async Task TestTuple()
  194. {
  195. await TestInRegularAndScriptAsync(
  196. @"class Program
  197. {
  198. [|(int, string) i;
  199. (string, int) s;|]
  200. public Program((int, string) i)
  201. {
  202. this.i = i;
  203. }
  204. }",
  205. @"class Program
  206. {
  207. (int, string) i;
  208. (string, int) s;
  209. public Program((int, string) i, (string, int) s)
  210. {
  211. this.i = i;
  212. this.s = s;
  213. }
  214. }");
  215. }
  216. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  217. public async Task TestTupleWithNames()
  218. {
  219. await TestInRegularAndScriptAsync(
  220. @"class Program
  221. {
  222. [|(int a, string b) i;
  223. (string c, int d) s;|]
  224. public Program((int a, string b) i)
  225. {
  226. this.i = i;
  227. }
  228. }",
  229. @"class Program
  230. {
  231. (int a, string b) i;
  232. (string c, int d) s;
  233. public Program((int a, string b) i, (string c, int d) s)
  234. {
  235. this.i = i;
  236. this.s = s;
  237. }
  238. }");
  239. }
  240. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  241. public async Task TestTupleWithDifferentNames()
  242. {
  243. await TestInRegularAndScriptAsync(
  244. @"class Program
  245. {
  246. [|(int a, string b) i;
  247. (string c, int d) s;|]
  248. public Program((int e, string f) i)
  249. {
  250. this.i = i;
  251. }
  252. }",
  253. @"class Program
  254. {
  255. [|(int a, string b) i;
  256. (string c, int d) s;|]
  257. public Program((int e, string f) i, (string c, int d) s)
  258. {
  259. this.i = i;
  260. this.s = s;
  261. }
  262. }");
  263. }
  264. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  265. public async Task TestTupleOptionalCSharp7()
  266. {
  267. await TestAsync(
  268. @"class Program
  269. {
  270. [|(int, string) i;
  271. (string, int) s;|]
  272. public Program((int, string) i)
  273. {
  274. this.i = i;
  275. }
  276. }",
  277. @"class Program
  278. {
  279. (int, string) i;
  280. (string, int) s;
  281. public Program((int, string) i, (string, int) s = default((string, int)))
  282. {
  283. this.i = i;
  284. this.s = s;
  285. }
  286. }",
  287. index: 1, parseOptions: new CSharpParseOptions(LanguageVersion.CSharp7));
  288. }
  289. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  290. public async Task TestTupleOptional()
  291. {
  292. await TestInRegularAndScriptAsync(
  293. @"class Program
  294. {
  295. [|(int, string) i;
  296. (string, int) s;|]
  297. public Program((int, string) i)
  298. {
  299. this.i = i;
  300. }
  301. }",
  302. @"class Program
  303. {
  304. (int, string) i;
  305. (string, int) s;
  306. public Program((int, string) i, (string, int) s = default)
  307. {
  308. this.i = i;
  309. this.s = s;
  310. }
  311. }",
  312. index: 1);
  313. }
  314. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  315. public async Task TestTupleOptionalWithNames_CSharp7()
  316. {
  317. await TestInRegularAndScriptAsync(
  318. @"class Program
  319. {
  320. [|(int a, string b) i;
  321. (string c, int d) s;|]
  322. public Program((int a, string b) i)
  323. {
  324. this.i = i;
  325. }
  326. }",
  327. @"class Program
  328. {
  329. (int a, string b) i;
  330. (string c, int d) s;
  331. public Program((int a, string b) i, (string c, int d) s = default((string c, int d)))
  332. {
  333. this.i = i;
  334. this.s = s;
  335. }
  336. }",
  337. parseOptions: TestOptions.Regular7,
  338. index: 1);
  339. }
  340. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  341. public async Task TestTupleOptionalWithNamesCSharp7()
  342. {
  343. await TestAsync(
  344. @"class Program
  345. {
  346. [|(int a, string b) i;
  347. (string c, int d) s;|]
  348. public Program((int a, string b) i)
  349. {
  350. this.i = i;
  351. }
  352. }",
  353. @"class Program
  354. {
  355. (int a, string b) i;
  356. (string c, int d) s;
  357. public Program((int a, string b) i, (string c, int d) s = default((string c, int d)))
  358. {
  359. this.i = i;
  360. this.s = s;
  361. }
  362. }",
  363. index: 1, parseOptions: new CSharpParseOptions(LanguageVersion.CSharp7));
  364. }
  365. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  366. public async Task TestTupleOptionalWithNames()
  367. {
  368. await TestInRegularAndScriptAsync(
  369. @"class Program
  370. {
  371. [|(int a, string b) i;
  372. (string c, int d) s;|]
  373. public Program((int a, string b) i)
  374. {
  375. this.i = i;
  376. }
  377. }",
  378. @"class Program
  379. {
  380. (int a, string b) i;
  381. (string c, int d) s;
  382. public Program((int a, string b) i, (string c, int d) s = default)
  383. {
  384. this.i = i;
  385. this.s = s;
  386. }
  387. }",
  388. index: 1);
  389. }
  390. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  391. public async Task TestTupleOptionalWithDifferentNames()
  392. {
  393. await TestInRegularAndScriptAsync(
  394. @"class Program
  395. {
  396. [|(int a, string b) i;
  397. (string c, int d) s;|]
  398. public Program((int e, string f) i)
  399. {
  400. this.i = i;
  401. }
  402. }",
  403. @"class Program
  404. {
  405. [|(int a, string b) i;
  406. (string c, int d) s;|]
  407. public Program((int e, string f) i, (string c, int d) s = default)
  408. {
  409. this.i = i;
  410. this.s = s;
  411. }
  412. }", index: 1);
  413. }
  414. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  415. public async Task TestTupleWithNullable()
  416. {
  417. await TestInRegularAndScriptAsync(
  418. @"class Program
  419. {
  420. [|(int?, bool?) i;
  421. (byte?, long?) s;|]
  422. public Program((int?, bool?) i)
  423. {
  424. this.i = i;
  425. }
  426. }",
  427. @"class Program
  428. {
  429. (int?, bool?) i;
  430. (byte?, long?) s;
  431. public Program((int?, bool?) i, (byte?, long?) s)
  432. {
  433. this.i = i;
  434. this.s = s;
  435. }
  436. }");
  437. }
  438. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  439. public async Task TestTupleWithGenericss()
  440. {
  441. await TestInRegularAndScriptAsync(
  442. @"class Program
  443. {
  444. [|(List<int>, List<bool>) i;
  445. (List<byte>, List<long>) s;|]
  446. public Program((List<int>, List<bool>) i)
  447. {
  448. this.i = i;
  449. }
  450. }",
  451. @"class Program
  452. {
  453. (List<int>, List<bool>) i;
  454. (List<byte>, List<long>) s;
  455. public Program((List<int>, List<bool>) i, (List<byte>, List<long>) s)
  456. {
  457. this.i = i;
  458. this.s = s;
  459. }
  460. }");
  461. }
  462. [WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")]
  463. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  464. public async Task TestAddParamtersToConstructorBySelectOneMember()
  465. {
  466. await TestInRegularAndScriptAsync(
  467. @"
  468. class C
  469. {
  470. int i;
  471. [|(List<byte>, List<long>) s;|]
  472. int j;
  473. public C(int i, int j)
  474. {
  475. this.i = i;
  476. this.j = j;
  477. }
  478. }",
  479. @"
  480. class C
  481. {
  482. int i;
  483. (List<byte>, List<long>) s;
  484. int j;
  485. public C(int i, int j, (List<byte>, List<long>) s)
  486. {
  487. this.i = i;
  488. this.j = j;
  489. this.s = s;
  490. }
  491. }");
  492. }
  493. [WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")]
  494. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  495. public async Task TestParametersAreStillRightIfMembersAreOutOfOrder()
  496. {
  497. await TestInRegularAndScriptAsync(
  498. @"
  499. class C
  500. {
  501. [|int i;
  502. int k;
  503. int j;|]
  504. public C(int i, int j)
  505. {
  506. this.i = i;
  507. this.j = j;
  508. }
  509. }",
  510. @"
  511. class C
  512. {
  513. int i;
  514. int k;
  515. int j;
  516. public C(int i, int j, int k)
  517. {
  518. this.i = i;
  519. this.j = j;
  520. this.k = k;
  521. }
  522. }");
  523. }
  524. [WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")]
  525. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  526. public async Task TestMissingIfFieldsAlreadyExistingInConstructor()
  527. {
  528. await TestMissingAsync(
  529. @"
  530. class C
  531. {
  532. [|string _barBar;
  533. int fooFoo;|]
  534. public C(string barBar, int fooFoo)
  535. {
  536. }
  537. }"
  538. );
  539. }
  540. [WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")]
  541. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  542. public async Task TestMissingIfPropertyAlreadyExistingInConstructor()
  543. {
  544. await TestMissingAsync(
  545. @"
  546. class C
  547. {
  548. [|string bar;
  549. int HelloWorld { get; set; }|]
  550. public C(string bar, int helloWorld)
  551. {
  552. }
  553. }"
  554. );
  555. }
  556. [WorkItem(28775, "https://github.com/dotnet/roslyn/issues/28775")]
  557. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  558. public async Task TestNormalProperty()
  559. {
  560. await TestInRegularAndScriptAsync(
  561. @"
  562. class C
  563. {
  564. [|int i;
  565. int Hello { get; set; }|]
  566. public C(int i)
  567. {
  568. }
  569. }",
  570. @"
  571. class C
  572. {
  573. int i;
  574. int Hello { get; set; }
  575. public C(int i, int hello)
  576. {
  577. Hello = hello;
  578. }
  579. }"
  580. );
  581. }
  582. [WorkItem(33602, "https://github.com/dotnet/roslyn/issues/33602")]
  583. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  584. public async Task TestConstructorWithNoParameters()
  585. {
  586. await TestInRegularAndScriptAsync(
  587. @"
  588. class C
  589. {
  590. [|int i;
  591. int Hello { get; set; }|]
  592. public C()
  593. {
  594. }
  595. }",
  596. @"
  597. class C
  598. {
  599. int i;
  600. int Hello { get; set; }
  601. public C(int i, int hello)
  602. {
  603. this.i = i;
  604. Hello = hello;
  605. }
  606. }"
  607. );
  608. }
  609. [WorkItem(33602, "https://github.com/dotnet/roslyn/issues/33602")]
  610. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  611. public async Task TestDefaultConstructor()
  612. {
  613. await TestMissingAsync(
  614. @"
  615. class C
  616. {
  617. [|int i;|]
  618. int Hello { get; set; }
  619. }");
  620. }
  621. [WorkItem(33601, "https://github.com/dotnet/roslyn/issues/33601")]
  622. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  623. public async Task TestPartialSelected()
  624. {
  625. await TestInRegularAndScriptAsync(
  626. @"
  627. class C
  628. {
  629. int i;
  630. int [|j|];
  631. public C(int i)
  632. {
  633. }
  634. }",
  635. @"
  636. class C
  637. {
  638. int i;
  639. int j;
  640. public C(int i, int j)
  641. {
  642. this.j = j;
  643. }
  644. }"
  645. );
  646. }
  647. [WorkItem(33601, "https://github.com/dotnet/roslyn/issues/33601")]
  648. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  649. public async Task TestPartialMultipleSelected()
  650. {
  651. await TestInRegularAndScriptAsync(
  652. @"
  653. class C
  654. {
  655. int i;
  656. int [|j;
  657. int k|];
  658. public C(int i)
  659. {
  660. }
  661. }",
  662. @"
  663. class C
  664. {
  665. int i;
  666. int j;
  667. int k;
  668. public C(int i, int j, int k)
  669. {
  670. this.j = j;
  671. this.k = k;
  672. }
  673. }"
  674. );
  675. }
  676. [WorkItem(33601, "https://github.com/dotnet/roslyn/issues/33601")]
  677. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  678. public async Task TestPartialMultipleSelected2()
  679. {
  680. await TestInRegularAndScriptAsync(
  681. @"
  682. class C
  683. {
  684. int i;
  685. int [|j;
  686. int |]k;
  687. public C(int i)
  688. {
  689. }
  690. }",
  691. @"
  692. class C
  693. {
  694. int i;
  695. int j;
  696. int k;
  697. public C(int i, int j)
  698. {
  699. this.j = j;
  700. }
  701. }"
  702. );
  703. }
  704. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  705. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  706. public async Task TestMultipleConstructors_FirstofThree()
  707. {
  708. var source =
  709. @"
  710. class C
  711. {
  712. int [|l|];
  713. public C(int i)
  714. {
  715. }
  716. public C(int i, int j)
  717. {
  718. }
  719. public C(int i, int j, int k)
  720. {
  721. }
  722. }";
  723. var expected =
  724. @"
  725. class C
  726. {
  727. int l;
  728. public C(int i, int l)
  729. {
  730. this.l = l;
  731. }
  732. public C(int i, int j)
  733. {
  734. }
  735. public C(int i, int j, int k)
  736. {
  737. }
  738. }";
  739. await TestInRegularAndScriptAsync(source, expected, index: 0, title: string.Format(FeaturesResources.Add_to_0, "C(int)"));
  740. }
  741. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  742. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  743. public async Task TestMultipleConstructors_SecondOfThree()
  744. {
  745. var source =
  746. @"
  747. class C
  748. {
  749. int [|l|];
  750. public C(int i)
  751. {
  752. }
  753. public C(int i, int j)
  754. {
  755. }
  756. public C(int i, int j, int k)
  757. {
  758. }
  759. }";
  760. var expected =
  761. @"
  762. class C
  763. {
  764. int l;
  765. public C(int i)
  766. {
  767. }
  768. public C(int i, int j, int l)
  769. {
  770. this.l = l;
  771. }
  772. public C(int i, int j, int k)
  773. {
  774. }
  775. }";
  776. await TestInRegularAndScriptAsync(source, expected, index: 1, title: string.Format(FeaturesResources.Add_to_0, "C(int, int)"));
  777. }
  778. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  779. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  780. public async Task TestMultipleConstructors_ThirdOfThree()
  781. {
  782. var source =
  783. @"
  784. class C
  785. {
  786. int [|l|];
  787. public C(int i)
  788. {
  789. }
  790. public C(int i, int j)
  791. {
  792. }
  793. public C(int i, int j, int k)
  794. {
  795. }
  796. }";
  797. var expected =
  798. @"
  799. class C
  800. {
  801. int l;
  802. public C(int i)
  803. {
  804. }
  805. public C(int i, int j)
  806. {
  807. }
  808. public C(int i, int j, int k, int l)
  809. {
  810. this.l = l;
  811. }
  812. }";
  813. await TestInRegularAndScriptAsync(source, expected, index: 2, title: string.Format(FeaturesResources.Add_to_0, "C(int, int, int)"));
  814. }
  815. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  816. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  817. public async Task TestMultipleConstructors_FirstOptionalOfThree()
  818. {
  819. var source =
  820. @"
  821. class C
  822. {
  823. int [|l|];
  824. public C(int i)
  825. {
  826. }
  827. public C(int i, int j)
  828. {
  829. }
  830. public C(int i, int j, int k)
  831. {
  832. }
  833. }";
  834. var expected =
  835. @"
  836. class C
  837. {
  838. int l;
  839. public C(int i, int l = 0)
  840. {
  841. this.l = l;
  842. }
  843. public C(int i, int j)
  844. {
  845. }
  846. public C(int i, int j, int k)
  847. {
  848. }
  849. }";
  850. await TestInRegularAndScriptAsync(source, expected, index: 3, title: string.Format(FeaturesResources.Add_to_0, "C(int)"));
  851. }
  852. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  853. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  854. public async Task TestMultipleConstructors_SecondOptionalOfThree()
  855. {
  856. var source =
  857. @"
  858. class C
  859. {
  860. int [|l|];
  861. public C(int i)
  862. {
  863. }
  864. public C(int i, int j)
  865. {
  866. }
  867. public C(int i, int j, int k)
  868. {
  869. }
  870. }";
  871. var expected =
  872. @"
  873. class C
  874. {
  875. int [|l|];
  876. public C(int i)
  877. {
  878. }
  879. public C(int i, int j, int l = 0)
  880. {
  881. this.l = l;
  882. }
  883. public C(int i, int j, int k)
  884. {
  885. }
  886. }";
  887. await TestInRegularAndScriptAsync(source, expected, index: 4, title: string.Format(FeaturesResources.Add_to_0, "C(int, int)"));
  888. }
  889. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  890. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  891. public async Task TestMultipleConstructors_ThirdOptionalOfThree()
  892. {
  893. var source =
  894. @"
  895. class C
  896. {
  897. int [|l|];
  898. public C(int i)
  899. {
  900. }
  901. public C(int i, int j)
  902. {
  903. }
  904. public C(int i, int j, int k)
  905. {
  906. }
  907. }";
  908. var expected =
  909. @"
  910. class C
  911. {
  912. int [|l|];
  913. public C(int i)
  914. {
  915. }
  916. public C(int i, int j)
  917. {
  918. }
  919. public C(int i, int j, int k, int l = 0)
  920. {
  921. this.l = l;
  922. }
  923. }";
  924. await TestInRegularAndScriptAsync(source, expected, index: 5, title: string.Format(FeaturesResources.Add_to_0, "C(int, int, int)"));
  925. }
  926. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  927. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  928. public async Task TestMultipleConstructors_OneMustBeOptional()
  929. {
  930. var source =
  931. @"
  932. class C
  933. {
  934. int [|l|];
  935. // index 0 as required
  936. // index 2 as optional
  937. public C(int i)
  938. {
  939. }
  940. // index 3 as optional
  941. public C(int i, double j = 0)
  942. {
  943. }
  944. // index 1 as required
  945. // index 4 as optional
  946. public C(int i, double j, int k)
  947. {
  948. }
  949. }";
  950. var expected =
  951. @"
  952. class C
  953. {
  954. int [|l|];
  955. // index 0 as required
  956. // index 2 as optional
  957. public C(int i)
  958. {
  959. }
  960. // index 3 as optional
  961. public C(int i, double j = 0)
  962. {
  963. }
  964. // index 1 as required
  965. // index 4 as optional
  966. public C(int i, double j, int k, int l)
  967. {
  968. this.l = l;
  969. }
  970. }";
  971. await TestInRegularAndScriptAsync(source, expected, index: 1, title: string.Format(FeaturesResources.Add_to_0, "C(int, double, int)"));
  972. }
  973. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  974. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  975. public async Task TestMultipleConstructors_OneMustBeOptional2()
  976. {
  977. var source =
  978. @"
  979. class C
  980. {
  981. int [|l|];
  982. // index 0, and 2 as optional
  983. public C(int i)
  984. {
  985. }
  986. // index 3 as optional
  987. public C(int i, double j = 0)
  988. {
  989. }
  990. // index 1, and 4 as optional
  991. public C(int i, double j, int k)
  992. {
  993. }
  994. }";
  995. var expected =
  996. @"
  997. class C
  998. {
  999. int [|l|];
  1000. // index 0, and 2 as optional
  1001. public C(int i)
  1002. {
  1003. }
  1004. // index 3 as optional
  1005. public C(int i, double j = 0, int l = 0)
  1006. {
  1007. this.l = l;
  1008. }
  1009. // index 1, and 4 as optional
  1010. public C(int i, double j, int k)
  1011. {
  1012. }
  1013. }";
  1014. await TestInRegularAndScriptAsync(source, expected, index: 3, title: string.Format(FeaturesResources.Add_to_0, "C(int, double)"));
  1015. }
  1016. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  1017. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1018. public async Task TestMultipleConstructors_AllMustBeOptional()
  1019. {
  1020. var source =
  1021. @"
  1022. class C
  1023. {
  1024. int [|p|];
  1025. public C(int i = 0)
  1026. {
  1027. }
  1028. public C(double j, int k = 0)
  1029. {
  1030. }
  1031. public C(int l, double m, int n = 0)
  1032. {
  1033. }
  1034. }";
  1035. var expected =
  1036. @"
  1037. class C
  1038. {
  1039. int [|p|];
  1040. public C(int i = 0, int p = 0)
  1041. {
  1042. this.p = p;
  1043. }
  1044. public C(double j, int k = 0)
  1045. {
  1046. }
  1047. public C(int l, double m, int n = 0)
  1048. {
  1049. }
  1050. }";
  1051. await TestInRegularAndScriptAsync(source, expected, index: 0, title: string.Format(FeaturesResources.Add_to_0, "C(int)"));
  1052. }
  1053. [WorkItem(33603, "https://github.com/dotnet/roslyn/issues/33603")]
  1054. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1055. public async Task TestMultipleConstructors_AllMustBeOptional2()
  1056. {
  1057. var source =
  1058. @"
  1059. class C
  1060. {
  1061. int [|p|];
  1062. public C(int i = 0)
  1063. {
  1064. }
  1065. public C(double j, int k = 0)
  1066. {
  1067. }
  1068. public C(int l, double m, int n = 0)
  1069. {
  1070. }
  1071. }";
  1072. var expected =
  1073. @"
  1074. class C
  1075. {
  1076. int [|p|];
  1077. public C(int i = 0)
  1078. {
  1079. }
  1080. public C(double j, int k = 0)
  1081. {
  1082. }
  1083. public C(int l, double m, int n = 0, int p = 0)
  1084. {
  1085. this.p = p;
  1086. }
  1087. }";
  1088. await TestInRegularAndScriptAsync(source, expected, index: 2, title: string.Format(FeaturesResources.Add_to_0, "C(int, double, int)"));
  1089. }
  1090. [WorkItem(33623, "https://github.com/dotnet/roslyn/issues/33623")]
  1091. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1092. public async Task TestDeserializationConstructor()
  1093. {
  1094. await TestMissingAsync(
  1095. @"
  1096. using System;
  1097. using System.Runtime.Serialization;
  1098. class C : ISerializable
  1099. {
  1100. int [|i|];
  1101. private C(SerializationInfo info, StreamingContext context)
  1102. {
  1103. }
  1104. }
  1105. ");
  1106. }
  1107. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1108. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1109. public async Task TestNoFieldNamingStyle_ParameterPrefixAndSuffix()
  1110. {
  1111. var source =
  1112. @"
  1113. class C
  1114. {
  1115. private int [|v|];
  1116. public C()
  1117. {
  1118. }
  1119. }
  1120. ";
  1121. var expected =
  1122. @"
  1123. class C
  1124. {
  1125. private int v;
  1126. public C(int p_v_End)
  1127. {
  1128. v = p_v_End;
  1129. }
  1130. }
  1131. ";
  1132. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.ParameterNamesAreCamelCaseWithPUnderscorePrefixAndUnderscoreEndSuffix);
  1133. }
  1134. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1135. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1136. public async Task TestCommonFieldNamingStyle()
  1137. {
  1138. var source =
  1139. @"
  1140. class C
  1141. {
  1142. private int [|t_v|];
  1143. public C()
  1144. {
  1145. }
  1146. }
  1147. ";
  1148. var expected =
  1149. @"
  1150. class C
  1151. {
  1152. private int t_v;
  1153. public C(int p_v)
  1154. {
  1155. t_v = p_v;
  1156. }
  1157. }
  1158. ";
  1159. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.ParameterNamesAreCamelCaseWithPUnderscorePrefix);
  1160. }
  1161. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1162. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1163. public async Task TestSpecifiedFieldNamingStyle()
  1164. {
  1165. var source =
  1166. @"
  1167. class C
  1168. {
  1169. private int [|field_v|];
  1170. public C()
  1171. {
  1172. }
  1173. }
  1174. ";
  1175. var expected =
  1176. @"
  1177. class C
  1178. {
  1179. private int field_v;
  1180. public C(int p_v)
  1181. {
  1182. field_v = p_v;
  1183. }
  1184. }
  1185. ";
  1186. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.MergeStyles(
  1187. options.FieldNamesAreCamelCaseWithFieldUnderscorePrefix, options.ParameterNamesAreCamelCaseWithPUnderscorePrefix));
  1188. }
  1189. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1190. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1191. public async Task TestSpecifiedAndCommonFieldNamingStyle()
  1192. {
  1193. var source =
  1194. @"
  1195. class C
  1196. {
  1197. private int [|field_s_v|];
  1198. public C()
  1199. {
  1200. }
  1201. }
  1202. ";
  1203. var expected =
  1204. @"
  1205. class C
  1206. {
  1207. private int field_s_v;
  1208. public C(int p_v)
  1209. {
  1210. field_s_v = p_v;
  1211. }
  1212. }
  1213. ";
  1214. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.MergeStyles(
  1215. options.FieldNamesAreCamelCaseWithFieldUnderscorePrefix, options.ParameterNamesAreCamelCaseWithPUnderscorePrefix));
  1216. }
  1217. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1218. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1219. public async Task TestSpecifiedAndCommonFieldNamingStyle2()
  1220. {
  1221. var source =
  1222. @"
  1223. class C
  1224. {
  1225. private int [|s_field_v|];
  1226. public C()
  1227. {
  1228. }
  1229. }
  1230. ";
  1231. var expected =
  1232. @"
  1233. class C
  1234. {
  1235. private int s_field_v;
  1236. public C(int p_v)
  1237. {
  1238. s_field_v = p_v;
  1239. }
  1240. }
  1241. ";
  1242. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.MergeStyles(
  1243. options.FieldNamesAreCamelCaseWithFieldUnderscorePrefix, options.ParameterNamesAreCamelCaseWithPUnderscorePrefix));
  1244. }
  1245. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1246. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1247. public async Task TestBaseNameEmpty()
  1248. {
  1249. var source =
  1250. @"
  1251. class C
  1252. {
  1253. private int [|field__End|];
  1254. public C()
  1255. {
  1256. }
  1257. }
  1258. ";
  1259. await TestMissingAsync(source, parameters: new TestParameters(options: options.FieldNamesAreCamelCaseWithFieldUnderscorePrefixAndUnderscoreEndSuffix));
  1260. }
  1261. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1262. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1263. public async Task TestSomeBaseNamesAreEmpty()
  1264. {
  1265. var source =
  1266. @"
  1267. class C
  1268. {
  1269. private int [|field_test_End;
  1270. private int field__End|];
  1271. public C()
  1272. {
  1273. }
  1274. }
  1275. ";
  1276. var expected =
  1277. @"
  1278. class C
  1279. {
  1280. private int field_test_End;
  1281. private int field__End;
  1282. public C(int p_test)
  1283. {
  1284. field_test_End = p_test;
  1285. }
  1286. }
  1287. ";
  1288. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.MergeStyles(
  1289. options.FieldNamesAreCamelCaseWithFieldUnderscorePrefixAndUnderscoreEndSuffix, options.ParameterNamesAreCamelCaseWithPUnderscorePrefix));
  1290. }
  1291. [WorkItem(35775, "https://github.com/dotnet/roslyn/issues/35775")]
  1292. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1293. public async Task TestManyCommonPrefixes()
  1294. {
  1295. var source =
  1296. @"
  1297. class C
  1298. {
  1299. private int [|______test|];
  1300. public C()
  1301. {
  1302. }
  1303. }
  1304. ";
  1305. var expected =
  1306. @"
  1307. class C
  1308. {
  1309. private int ______test;
  1310. public C(int p_test)
  1311. {
  1312. ______test = p_test;
  1313. }
  1314. }
  1315. ";
  1316. await TestInRegularAndScriptAsync(source, expected, index: 0, options: options.ParameterNamesAreCamelCaseWithPUnderscorePrefix);
  1317. }
  1318. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1319. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1320. public async Task TestNonSelection1()
  1321. {
  1322. await TestInRegularAndScriptAsync(
  1323. @"using System.Collections.Generic;
  1324. class Program
  1325. {
  1326. int i;
  1327. [||] string s;
  1328. public Program(int i)
  1329. {
  1330. this.i = i;
  1331. }
  1332. }",
  1333. @"using System.Collections.Generic;
  1334. class Program
  1335. {
  1336. int i;
  1337. string s;
  1338. public Program(int i, string s)
  1339. {
  1340. this.i = i;
  1341. this.s = s;
  1342. }
  1343. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1344. }
  1345. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1346. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1347. public async Task TestNonSelection2()
  1348. {
  1349. await TestInRegularAndScriptAsync(
  1350. @"using System.Collections.Generic;
  1351. class Program
  1352. {
  1353. int i;
  1354. [||]string s;
  1355. public Program(int i)
  1356. {
  1357. this.i = i;
  1358. }
  1359. }",
  1360. @"using System.Collections.Generic;
  1361. class Program
  1362. {
  1363. int i;
  1364. string s;
  1365. public Program(int i, string s)
  1366. {
  1367. this.i = i;
  1368. this.s = s;
  1369. }
  1370. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1371. }
  1372. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1373. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1374. public async Task TestNonSelection3()
  1375. {
  1376. await TestInRegularAndScriptAsync(
  1377. @"using System.Collections.Generic;
  1378. class Program
  1379. {
  1380. int i;
  1381. string [||]s;
  1382. public Program(int i)
  1383. {
  1384. this.i = i;
  1385. }
  1386. }",
  1387. @"using System.Collections.Generic;
  1388. class Program
  1389. {
  1390. int i;
  1391. string s;
  1392. public Program(int i, string s)
  1393. {
  1394. this.i = i;
  1395. this.s = s;
  1396. }
  1397. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1398. }
  1399. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1400. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1401. public async Task TestNonSelection4()
  1402. {
  1403. await TestInRegularAndScriptAsync(
  1404. @"using System.Collections.Generic;
  1405. class Program
  1406. {
  1407. int i;
  1408. string s[||];
  1409. public Program(int i)
  1410. {
  1411. this.i = i;
  1412. }
  1413. }",
  1414. @"using System.Collections.Generic;
  1415. class Program
  1416. {
  1417. int i;
  1418. string s;
  1419. public Program(int i, string s)
  1420. {
  1421. this.i = i;
  1422. this.s = s;
  1423. }
  1424. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1425. }
  1426. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1427. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1428. public async Task TestNonSelection5()
  1429. {
  1430. await TestInRegularAndScriptAsync(
  1431. @"using System.Collections.Generic;
  1432. class Program
  1433. {
  1434. int i;
  1435. string s;[||]
  1436. public Program(int i)
  1437. {
  1438. this.i = i;
  1439. }
  1440. }",
  1441. @"using System.Collections.Generic;
  1442. class Program
  1443. {
  1444. int i;
  1445. string s;
  1446. public Program(int i, string s)
  1447. {
  1448. this.i = i;
  1449. this.s = s;
  1450. }
  1451. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1452. }
  1453. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1454. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1455. public async Task TestNonSelection6()
  1456. {
  1457. await TestInRegularAndScriptAsync(
  1458. @"using System.Collections.Generic;
  1459. class Program
  1460. {
  1461. int i;
  1462. string s; [||]
  1463. public Program(int i)
  1464. {
  1465. this.i = i;
  1466. }
  1467. }",
  1468. @"using System.Collections.Generic;
  1469. class Program
  1470. {
  1471. int i;
  1472. string s;
  1473. public Program(int i, string s)
  1474. {
  1475. this.i = i;
  1476. this.s = s;
  1477. }
  1478. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1479. }
  1480. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1481. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1482. public async Task TestNonSelectionMultiVar1()
  1483. {
  1484. await TestInRegularAndScriptAsync(
  1485. @"using System.Collections.Generic;
  1486. class Program
  1487. {
  1488. int i;
  1489. [||]string s, t;
  1490. public Program(int i)
  1491. {
  1492. this.i = i;
  1493. }
  1494. }",
  1495. @"using System.Collections.Generic;
  1496. class Program
  1497. {
  1498. int i;
  1499. string s, t;
  1500. public Program(int i, string s, string t)
  1501. {
  1502. this.i = i;
  1503. this.s = s;
  1504. this.t = t;
  1505. }
  1506. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1507. }
  1508. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1509. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1510. public async Task TestNonSelectionMultiVar2()
  1511. {
  1512. await TestInRegularAndScriptAsync(
  1513. @"using System.Collections.Generic;
  1514. class Program
  1515. {
  1516. int i;
  1517. string s, t;[||]
  1518. public Program(int i)
  1519. {
  1520. this.i = i;
  1521. }
  1522. }",
  1523. @"using System.Collections.Generic;
  1524. class Program
  1525. {
  1526. int i;
  1527. string s, t;
  1528. public Program(int i, string s, string t)
  1529. {
  1530. this.i = i;
  1531. this.s = s;
  1532. this.t = t;
  1533. }
  1534. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1535. }
  1536. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1537. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1538. public async Task TestNonSelectionMultiVar3()
  1539. {
  1540. await TestInRegularAndScriptAsync(
  1541. @"using System.Collections.Generic;
  1542. class Program
  1543. {
  1544. int i;
  1545. string [||]s, t;
  1546. public Program(int i)
  1547. {
  1548. this.i = i;
  1549. }
  1550. }",
  1551. @"using System.Collections.Generic;
  1552. class Program
  1553. {
  1554. int i;
  1555. string s, t;
  1556. public Program(int i, string s)
  1557. {
  1558. this.i = i;
  1559. this.s = s;
  1560. }
  1561. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1562. }
  1563. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1564. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1565. public async Task TestNonSelectionMultiVar4()
  1566. {
  1567. await TestInRegularAndScriptAsync(
  1568. @"using System.Collections.Generic;
  1569. class Program
  1570. {
  1571. int i;
  1572. string s[||], t;
  1573. public Program(int i)
  1574. {
  1575. this.i = i;
  1576. }
  1577. }",
  1578. @"using System.Collections.Generic;
  1579. class Program
  1580. {
  1581. int i;
  1582. string s, t;
  1583. public Program(int i, string s)
  1584. {
  1585. this.i = i;
  1586. this.s = s;
  1587. }
  1588. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1589. }
  1590. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1591. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1592. public async Task TestNonSelectionMultiVar5()
  1593. {
  1594. await TestInRegularAndScriptAsync(
  1595. @"using System.Collections.Generic;
  1596. class Program
  1597. {
  1598. int i;
  1599. string s, [||]t;
  1600. public Program(int i)
  1601. {
  1602. this.i = i;
  1603. }
  1604. }",
  1605. @"using System.Collections.Generic;
  1606. class Program
  1607. {
  1608. int i;
  1609. string s, t;
  1610. public Program(int i, string t)
  1611. {
  1612. this.i = i;
  1613. this.t = t;
  1614. }
  1615. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1616. }
  1617. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1618. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1619. public async Task TestNonSelectionMultiVar6()
  1620. {
  1621. await TestInRegularAndScriptAsync(
  1622. @"using System.Collections.Generic;
  1623. class Program
  1624. {
  1625. int i;
  1626. string s, t[||];
  1627. public Program(int i)
  1628. {
  1629. this.i = i;
  1630. }
  1631. }",
  1632. @"using System.Collections.Generic;
  1633. class Program
  1634. {
  1635. int i;
  1636. string s, t;
  1637. public Program(int i, string t)
  1638. {
  1639. this.i = i;
  1640. this.t = t;
  1641. }
  1642. }", title: string.Format(FeaturesResources.Add_parameters_to_0, "Program(int)"));
  1643. }
  1644. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1645. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1646. public async Task TestNonSelectionMissing1()
  1647. {
  1648. await TestMissingInRegularAndScriptAsync(
  1649. @"using System.Collections.Generic;
  1650. class Program
  1651. {
  1652. int i;
  1653. [||]
  1654. string s, t;
  1655. public Program(int i)
  1656. {
  1657. this.i = i;
  1658. }
  1659. }");
  1660. }
  1661. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1662. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1663. public async Task TestNonSelectionMissing2()
  1664. {
  1665. await TestMissingInRegularAndScriptAsync(
  1666. @"using System.Collections.Generic;
  1667. class Program
  1668. {
  1669. int i;
  1670. s[||]tring s, t;
  1671. public Program(int i)
  1672. {
  1673. this.i = i;
  1674. }
  1675. }");
  1676. }
  1677. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1678. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1679. public async Task TestNonSelectionMissing3()
  1680. {
  1681. await TestMissingInRegularAndScriptAsync(
  1682. @"using System.Collections.Generic;
  1683. class Program
  1684. {
  1685. int i;
  1686. string[||] s, t;
  1687. public Program(int i)
  1688. {
  1689. this.i = i;
  1690. }
  1691. }");
  1692. }
  1693. [WorkItem(23271, "https://github.com/dotnet/roslyn/issues/23271")]
  1694. [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddConstructorParametersFromMembers)]
  1695. public async Task TestNonSelectionMissing4()
  1696. {
  1697. await TestMissingInRegularAndScriptAsync(
  1698. @"using System.Collections.Generic;
  1699. class Program
  1700. {
  1701. int i;
  1702. string s,[||] t;
  1703. public Program(int i)
  1704. {
  1705. this.i = i;
  1706. }
  1707. }");
  1708. }
  1709. }
  1710. }