|
1 | | -using System.Threading.Tasks; |
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
2 | 4 | using Microsoft.CodeAnalysis; |
3 | 5 | using Microsoft.CodeAnalysis.CodeFixes; |
4 | 6 | using Microsoft.CodeAnalysis.Diagnostics; |
@@ -442,6 +444,100 @@ void IInterface.foo() { } |
442 | 444 | VerifyCSharpDiagnostic(test, expected1, expected2); |
443 | 445 | } |
444 | 446 |
|
| 447 | + public static IEnumerable<object[]> TestFrameworks => |
| 448 | + TestFrameworkReferences.All.Select(f => new object[] { f.Name, f.TestAttribute, f.UsingDirective }); |
| 449 | + |
| 450 | + [TestMethod] |
| 451 | + [DynamicData(nameof(TestFrameworks))] |
| 452 | + [Description("Issue 371 - Test method with underscores should not trigger INTL0003 for any supported framework")] |
| 453 | + public void TestMethodWithUnderscores_TestFrameworkAttribute_NoDiagnosticInformationReturned( |
| 454 | + string frameworkName, string testAttribute, string usingDirective) |
| 455 | + { |
| 456 | + _ = frameworkName; // parameter used for test identification in output |
| 457 | + string test = $@" |
| 458 | + using System; |
| 459 | + {usingDirective} |
| 460 | +
|
| 461 | + namespace ConsoleApplication1 |
| 462 | + {{ |
| 463 | + public class TypeName |
| 464 | + {{ |
| 465 | + {testAttribute} |
| 466 | + public void FooThing_IsFooThing_HasFooThing() {{ }} |
| 467 | + }} |
| 468 | + }}"; |
| 469 | + |
| 470 | + VerifyCSharpDiagnostic(test); |
| 471 | + } |
| 472 | + |
| 473 | + [TestMethod] |
| 474 | + [Description("Issue 371 - Non-test method with underscores in a test class should still trigger INTL0003")] |
| 475 | + public void NonTestMethodWithUnderscores_InTestClass_DiagnosticReturned() |
| 476 | + { |
| 477 | + string test = @" |
| 478 | + using System; |
| 479 | + using Xunit; |
| 480 | +
|
| 481 | + namespace ConsoleApplication1 |
| 482 | + { |
| 483 | + public class TypeName |
| 484 | + { |
| 485 | + [Fact] |
| 486 | + public void FooThing_IsFooThing_HasFooThing() { } |
| 487 | +
|
| 488 | + public void helper_setup() { } |
| 489 | + } |
| 490 | + }"; |
| 491 | + |
| 492 | + var expected = new DiagnosticResult |
| 493 | + { |
| 494 | + Id = "INTL0003", |
| 495 | + Message = "Method 'helper_setup' should be PascalCase", |
| 496 | + Severity = DiagnosticSeverity.Warning, |
| 497 | + Locations = |
| 498 | + [ |
| 499 | + new DiagnosticResultLocation("Test0.cs", 12, 25) |
| 500 | + ] |
| 501 | + }; |
| 502 | + |
| 503 | + VerifyCSharpDiagnostic(test, expected); |
| 504 | + } |
| 505 | + |
| 506 | + [TestMethod] |
| 507 | + [Description("Issue 371 - User-defined attribute named 'Test' in a non-framework namespace must not suppress INTL0003")] |
| 508 | + public void MethodWithUnderscores_UserDefinedTestAttribute_DiagnosticReturned() |
| 509 | + { |
| 510 | + string test = @" |
| 511 | + using System; |
| 512 | +
|
| 513 | + namespace MyApp |
| 514 | + { |
| 515 | + public class TestAttribute : System.Attribute { } |
| 516 | + } |
| 517 | +
|
| 518 | + namespace ConsoleApplication1 |
| 519 | + { |
| 520 | + public class TypeName |
| 521 | + { |
| 522 | + [MyApp.Test] |
| 523 | + public void FooThing_IsFooThing_HasFooThing() { } |
| 524 | + } |
| 525 | + }"; |
| 526 | + |
| 527 | + var expected = new DiagnosticResult |
| 528 | + { |
| 529 | + Id = "INTL0003", |
| 530 | + Message = "Method 'FooThing_IsFooThing_HasFooThing' should be PascalCase", |
| 531 | + Severity = DiagnosticSeverity.Warning, |
| 532 | + Locations = |
| 533 | + [ |
| 534 | + new DiagnosticResultLocation("Test0.cs", 14, 25) |
| 535 | + ] |
| 536 | + }; |
| 537 | + |
| 538 | + VerifyCSharpDiagnostic(test, expected); |
| 539 | + } |
| 540 | + |
445 | 541 |
|
446 | 542 | protected override CodeFixProvider GetCSharpCodeFixProvider() |
447 | 543 | { |
|
0 commit comments