You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TestMethod][ExpectedException(typeof(InvalidOperationException))]publicvoidTestMethod(){try// This is one statement{
Console.ForegroundColor = ConsoleColor.Black;usingvar_=new ConsoleAlert();
Assert.AreEqual(ConsoleColor.Red, Console.ForegroundColor);thrownew InvalidOperationException();}finally{
Assert.AreEqual(ConsoleColor.Black, Console.ForegroundColor);}}publicsealedclassConsoleAlert:IDisposable{privatereadonlyConsoleColorprevious;publicConsoleAlert(){previous= Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;}publicvoidDispose()=>
Console.ForegroundColor =previous;}
The method body has only one statement which is the try statement, discarding the lines within the try statement.
This applies to some other statements as well (non-exhaustive):
Block
CatchClause
CheckedStatement
DoStatement
FinallyClause
FixedStatement
ForEachStatement
ForEachVariableStatement
ForStatement
IfStatement
LockStatement
SwitchStatement
TryStatement
UncheckedStatement
UnsafeStatement
UsingStatement
WhileStatement
This does not seem to be an issue in VB.NET, might need more investigation.
The text was updated successfully, but these errors were encountered:
S3431 has an exception for single-line tests.
To check this, we count the number of statements in the method body
sonar-dotnet/analyzers/src/SonarAnalyzer.CSharp/Rules/ExpectedExceptionAttributeShouldNotBeUsed.cs
Lines 28 to 33 in b26c926
However, this will be count has one:
The method body has only one statement which is the
try
statement, discarding the lines within thetry
statement.This applies to some other statements as well (non-exhaustive):
This does not seem to be an issue in VB.NET, might need more investigation.
The text was updated successfully, but these errors were encountered: