Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S2187: Rule should not raise an issue when class is abstract #930

Merged
merged 2 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SonarAnalyzer for .NET
* Copyright (C) 2015-2017 SonarSource SA
* mailto: contact AT sonarsource DOT com
Expand Down Expand Up @@ -61,8 +61,10 @@ protected override void Initialize(SonarAnalysisContext context)
}

var classDeclaration = (ClassDeclarationSyntax)c.Node;
var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration);
var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration);

if (classSymbol == null ||
classSymbol.IsAbstract ||
!classSymbol.GetAttributes().Any(a => a.AttributeClass.IsAny(HandledTestClassAttributes)))
{
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -58,4 +58,32 @@ class ClassTest9
[TestMethod]
public void Foo() { }
}

[TestClass]
public abstract class MyCommonCode1
{
}

[TestClass]
public class MySubCommonCode1 : MyCommonCode1 // Noncompliant
{
}

public class MySubCommonCode11 : MyCommonCode1 // Compliant
{
}

[TestFixture]
public abstract class MyCommonCode2
{
}

[TestFixture]
public class MySubCommonCode2 : MyCommonCode2 // Noncompliant
{
}

public class MySubCommonCode22 : MyCommonCode2 // Compliant
{
}
}