Skip to content

Commit

Permalink
fix issues after rebase - fix test that fails only in debug mode + tr…
Browse files Browse the repository at this point in the history
…y to increase coverage
  • Loading branch information
mary-georgiou-sonarsource committed May 2, 2024
1 parent b679709 commit 738eb0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public static Accessibility GetEffectiveAccessibility(this ISymbol symbol)
public static bool IsConstructor(this ISymbol symbol) =>
symbol.Kind == SymbolKind.Method && symbol.Name == ".ctor";

public static bool IsStaticConstructor(this ISymbol symbol) =>
symbol.Kind == SymbolKind.Method && ((IMethodSymbol)symbol).MethodKind == MethodKind.StaticConstructor;

public static IEnumerable<AttributeData> GetAttributes(this ISymbol symbol, KnownType attributeType) =>
symbol?.GetAttributes().Where(x => x.AttributeClass.Is(attributeType)) ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ArrowExpressionBody_WithNotExpectedNode_ReturnsNull()
[TestMethod]
public void GetDeclarationTypeName_UnknownType() =>
#if DEBUG
Assert.ThrowsException<System.ArgumentException>(() => SyntaxNodeExtensionsCSharp.GetDeclarationTypeName(SyntaxFactory.Block()), "Unexpected type Block\r\nParameter name: kind");
Assert.ThrowsException<UnexpectedValueException>(() => SyntaxNodeExtensionsCSharp.GetDeclarationTypeName(SyntaxFactory.Block()), "Unexpected type Block\r\nParameter name: kind");
#else
SyntaxNodeExtensionsCSharp.GetDeclarationTypeName(SyntaxFactory.Block()).Should().Be("type");
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public class DoesNotInheritDirectlyFromControllerBase(IS1 s1, IS2 s2) : ApiContr
public IActionResult A2() { s2.Use(); return Ok(); }
}

public class InheritsFromController(IS1 s1, IS2 s2) : ControllerBase // Compliant, we report only in classes that inherit directly from ControllerBase
public class InheritsFromController(IS1 s1, IS2 s2) : Controller // Compliant, we report only in classes that inherit directly from ControllerBase
{
public IActionResult A1() { s1.Use(); return Ok(); }
public IActionResult A2() { s2.Use(); return Ok(); }
Expand Down Expand Up @@ -1143,3 +1143,9 @@ public class WithDestructor : ControllerBase // Noncompliant
public void A1() { s1.Use(); } // Secondary {{May belong to responsibility #1.}}
public void A2() { s2.Use(); } // Secondary {{May belong to responsibility #2.}}
}

public class NotAControllerForCoverage
{
private readonly IS1 s1;
private readonly IS2 s2;
}

0 comments on commit 738eb0b

Please sign in to comment.