@@ -401,5 +401,158 @@ public void MethodName((string Name, string Value) obj)
401
401
402
402
await VerifyCSharpDiagnosticAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
403
403
}
404
+
405
+ [ Theory ]
406
+ [ InlineData ( "(int I, string foo)" ) ]
407
+ [ InlineData ( "(int I, (bool foo, string S))" ) ]
408
+ [ InlineData ( "(int foo, string S)[]" ) ]
409
+ [ InlineData ( "System.Collections.Generic.List<(string foo, bool B)>" ) ]
410
+ [ WorkItem ( 3781 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3781" ) ]
411
+ public async Task TestImproperTupleElementNameInOverriddenMethodsParameterTypeAsync ( string paramType )
412
+ {
413
+ var testCode = $@ "
414
+ public class BaseType
415
+ {{
416
+ public virtual void TestMethod({ paramType . Replace ( "foo" , "[|foo|]" ) } p)
417
+ {{
418
+ }}
419
+ }}
420
+
421
+ public class TestType : BaseType
422
+ {{
423
+ public override void TestMethod({ paramType } p)
424
+ {{
425
+ }}
426
+ }}
427
+ " ;
428
+
429
+ await VerifyCSharpDiagnosticAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
430
+ }
431
+
432
+ [ Theory ]
433
+ [ InlineData ( "(int I, string foo)" ) ]
434
+ [ InlineData ( "(int I, (bool foo, string S))" ) ]
435
+ [ InlineData ( "(int foo, string S)[]" ) ]
436
+ [ InlineData ( "List<(string foo, bool B)>" ) ]
437
+ [ WorkItem ( 3781 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3781" ) ]
438
+ public async Task TestImproperTupleElementNameInOverriddenMethodsReturnTypeAsync ( string returnType )
439
+ {
440
+ var testCode = $@ "
441
+ using System.Collections.Generic;
442
+
443
+ public class BaseType
444
+ {{
445
+ public virtual { returnType . Replace ( "foo" , "[|foo|]" ) } TestMethod()
446
+ {{
447
+ throw new System.Exception();
448
+ }}
449
+ }}
450
+
451
+ public class TestType : BaseType
452
+ {{
453
+ public override { returnType } TestMethod()
454
+ {{
455
+ throw new System.Exception();
456
+ }}
457
+ }}
458
+ " ;
459
+
460
+ await VerifyCSharpDiagnosticAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
461
+ }
462
+
463
+ [ Theory ]
464
+ [ InlineData ( "(int I, string foo)" ) ]
465
+ [ InlineData ( "(int I, (bool foo, string S))" ) ]
466
+ [ InlineData ( "(int foo, string S)[]" ) ]
467
+ [ InlineData ( "List<(string foo, bool B)>" ) ]
468
+ [ WorkItem ( 3781 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3781" ) ]
469
+ public async Task TestImproperTupleElementNameInOverriddenPropertysTypeAsync ( string type )
470
+ {
471
+ var testCode = $@ "
472
+ using System.Collections.Generic;
473
+
474
+ public class BaseType
475
+ {{
476
+ public virtual { type . Replace ( "foo" , "[|foo|]" ) } TestProperty {{ get; set; }}
477
+ }}
478
+
479
+ public class TestType : BaseType
480
+ {{
481
+ public override { type } TestProperty {{ get; set; }}
482
+ }}
483
+ " ;
484
+
485
+ await VerifyCSharpDiagnosticAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
486
+ }
487
+
488
+ [ Theory ]
489
+ [ InlineData ( "(int I, string foo)" ) ]
490
+ [ InlineData ( "(int I, (bool foo, string S))" ) ]
491
+ [ InlineData ( "(int foo, string S)[]" ) ]
492
+ [ InlineData ( "List<(string foo, bool B)>" ) ]
493
+ [ WorkItem ( 3781 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3781" ) ]
494
+ public async Task TestImproperTupleElementNameInOverriddenIndexersReturnTypeAsync ( string type )
495
+ {
496
+ var testCode = $@ "
497
+ using System.Collections.Generic;
498
+
499
+ public abstract class BaseType
500
+ {{
501
+ public abstract { type . Replace ( "foo" , "[|foo|]" ) } this[int i] {{ get; }}
502
+ }}
503
+
504
+ public class TestType : BaseType
505
+ {{
506
+ public override { type } this[int i] => throw new System.Exception();
507
+ }}
508
+ " ;
509
+
510
+ await VerifyCSharpDiagnosticAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
511
+ }
512
+
513
+ [ Fact ]
514
+ [ WorkItem ( 3781 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3781" ) ]
515
+ public async Task TestImproperVariableTupleElementNameInsideOverriddenMethodAsync ( )
516
+ {
517
+ var testCode = @"
518
+ using System.Collections.Generic;
519
+
520
+ public abstract class BaseType
521
+ {
522
+ public virtual void TestMethod()
523
+ {
524
+ }
525
+ }
526
+
527
+ public class TestType : BaseType
528
+ {
529
+ public override void TestMethod()
530
+ {
531
+ (int I, bool [|b|]) x;
532
+ }
533
+ }
534
+ " ;
535
+
536
+ var fixedCode = @"
537
+ using System.Collections.Generic;
538
+
539
+ public abstract class BaseType
540
+ {
541
+ public virtual void TestMethod()
542
+ {
543
+ }
544
+ }
545
+
546
+ public class TestType : BaseType
547
+ {
548
+ public override void TestMethod()
549
+ {
550
+ (int I, bool B) x;
551
+ }
552
+ }
553
+ " ;
554
+
555
+ await VerifyCSharpFixAsync ( testCode , DefaultTestSettings , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
556
+ }
404
557
}
405
558
}
0 commit comments