Skip to content

Commit 3da4eb4

Browse files
vweijstersdlemstra
authored andcommitted
Added SA1516 unit tests
1 parent e50ebd3 commit 3da4eb4

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1516UnitTests.cs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,189 @@ public class TestClass
543543
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
544544
}
545545

546+
/// <summary>
547+
/// Verifies that setters with an accessibility restriction will report a warning.
548+
/// This is a regression for #2269
549+
/// </summary>
550+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
551+
[Fact]
552+
public async Task TestSetterWithAccessibilityRestrictionAsync()
553+
{
554+
var testCode = @"
555+
public class TestClass
556+
{
557+
public int TestProtected
558+
{
559+
get
560+
{
561+
return 1;
562+
}
563+
protected set
564+
{
565+
}
566+
}
567+
568+
public int TestInternal
569+
{
570+
get
571+
{
572+
return 1;
573+
}
574+
internal set
575+
{
576+
}
577+
}
578+
579+
public int TestPrivate
580+
{
581+
get
582+
{
583+
return 1;
584+
}
585+
private set
586+
{
587+
}
588+
}
589+
590+
public int this[int i]
591+
{
592+
get
593+
{
594+
return 1;
595+
}
596+
protected set
597+
{
598+
}
599+
}
600+
}
601+
602+
public class TestClass2
603+
{
604+
public int this[int i]
605+
{
606+
get
607+
{
608+
return 1;
609+
}
610+
internal set
611+
{
612+
}
613+
}
614+
}
615+
616+
public class TestClass3
617+
{
618+
public int this[int i]
619+
{
620+
get
621+
{
622+
return 1;
623+
}
624+
private set
625+
{
626+
}
627+
}
628+
}
629+
";
630+
631+
var fixedTestCode = @"
632+
public class TestClass
633+
{
634+
public int TestProtected
635+
{
636+
get
637+
{
638+
return 1;
639+
}
640+
641+
protected set
642+
{
643+
}
644+
}
645+
646+
public int TestInternal
647+
{
648+
get
649+
{
650+
return 1;
651+
}
652+
653+
internal set
654+
{
655+
}
656+
}
657+
658+
public int TestPrivate
659+
{
660+
get
661+
{
662+
return 1;
663+
}
664+
665+
private set
666+
{
667+
}
668+
}
669+
670+
public int this[int i]
671+
{
672+
get
673+
{
674+
return 1;
675+
}
676+
677+
protected set
678+
{
679+
}
680+
}
681+
}
682+
683+
public class TestClass2
684+
{
685+
public int this[int i]
686+
{
687+
get
688+
{
689+
return 1;
690+
}
691+
692+
internal set
693+
{
694+
}
695+
}
696+
}
697+
698+
public class TestClass3
699+
{
700+
public int this[int i]
701+
{
702+
get
703+
{
704+
return 1;
705+
}
706+
707+
private set
708+
{
709+
}
710+
}
711+
}
712+
";
713+
714+
var expected = new[]
715+
{
716+
this.CSharpDiagnostic().WithLocation(10, 1),
717+
this.CSharpDiagnostic().WithLocation(21, 1),
718+
this.CSharpDiagnostic().WithLocation(32, 1),
719+
this.CSharpDiagnostic().WithLocation(43, 1),
720+
this.CSharpDiagnostic().WithLocation(57, 1),
721+
this.CSharpDiagnostic().WithLocation(71, 1),
722+
};
723+
724+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
725+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
726+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
727+
}
728+
546729
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
547730
{
548731
yield return new SA1516ElementsMustBeSeparatedByBlankLine();

0 commit comments

Comments
 (0)