@@ -17,6 +17,9 @@ namespace StyleCop.Analyzers.Test.LayoutRules
1717 /// </summary>
1818 public class SA1503UnitTests : CodeFixVerifier
1919 {
20+ private bool suppressSA1519 ;
21+ private string consecutiveUsingsSettings ;
22+
2023 /// <summary>
2124 /// Gets the statements that will be used in the theory test cases.
2225 /// </summary>
@@ -392,6 +395,101 @@ public void Bar(int i)
392395 await this . VerifyCSharpFixAsync ( testCode , testCode ) . ConfigureAwait ( false ) ;
393396 }
394397
398+ [ Theory ]
399+ [ InlineData ( true ) ]
400+ [ InlineData ( false ) ]
401+ [ WorkItem ( 2623 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2623" ) ]
402+ public async Task TestMultipleUsingStatementsWithDefaultSettingsAsync ( bool suppressSA1519 )
403+ {
404+ this . suppressSA1519 = suppressSA1519 ;
405+ var testCode = @"using System;
406+ public class Foo
407+ {
408+ public void Bar(int i)
409+ {
410+ using (default(IDisposable))
411+ using (default(IDisposable))
412+ {
413+ }
414+ }
415+ }" ;
416+
417+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
418+ }
419+
420+ [ Theory ]
421+ [ InlineData ( true , true , false ) ]
422+ [ InlineData ( true , false , false ) ]
423+ [ InlineData ( false , true , true ) ]
424+ [ InlineData ( false , false , false ) ]
425+ [ WorkItem ( 2623 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2623" ) ]
426+ public async Task TestMultipleUsingStatementsWithExplicitSettingAsync ( bool allowConsecutiveUsings , bool suppressSA1519 , bool expectDiagnostic )
427+ {
428+ this . consecutiveUsingsSettings = $@ "
429+ {{
430+ ""settings"": {{
431+ ""layoutRules"": {{
432+ ""allowConsecutiveUsings"": { ( allowConsecutiveUsings ? "true" : "false" ) }
433+ }}
434+ }}
435+ }}
436+ " ;
437+ this . suppressSA1519 = suppressSA1519 ;
438+
439+ var testCode = @"using System;
440+ public class Foo
441+ {
442+ public void Bar(int i)
443+ {
444+ using (default(IDisposable))
445+ using (default(IDisposable))
446+ {
447+ }
448+ }
449+ }" ;
450+ var fixedCode = @"using System;
451+ public class Foo
452+ {
453+ public void Bar(int i)
454+ {
455+ using (default(IDisposable))
456+ {
457+ using (default(IDisposable))
458+ {
459+ }
460+ }
461+ }
462+ }" ;
463+
464+ if ( expectDiagnostic )
465+ {
466+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 7 , 9 ) ;
467+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
468+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
469+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
470+ }
471+ else
472+ {
473+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
474+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
475+ }
476+ }
477+
478+ /// <inheritdoc/>
479+ protected override string GetSettings ( )
480+ {
481+ return this . consecutiveUsingsSettings ?? base . GetSettings ( ) ;
482+ }
483+
484+ /// <inheritdoc/>
485+ protected override IEnumerable < string > GetDisabledDiagnostics ( )
486+ {
487+ if ( this . suppressSA1519 )
488+ {
489+ yield return SA1519BracesMustNotBeOmittedFromMultiLineChildStatement . DiagnosticId ;
490+ }
491+ }
492+
395493 /// <inheritdoc/>
396494 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
397495 {
0 commit comments