Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(core): classify C# files in test projects as test material (#3233) (#3586)

Rishabh Mishraf410901a8890
diff --git a/packages/core/src/repowise/core/dotnet_test_projects.py b/packages/core/src/repowise/core/dotnet_test_projects.py
new file mode 100644
index 000000000..518a93c37
--- /dev/null
+++ b/packages/core/src/repowise/core/dotnet_test_projects.py
@@ -0,0 +1,96 @@
+"""Where .NET test projects live, read from .csproj files.
+
+A C# test project sets `<IsTestProject>true</IsTestProject>` or references
+`Microsoft.NET.Test.Sdk`. Files inside such a project (step definitions, fakes,
+helpers) are test material even if their filename or directory does not say Test.
+"""
+
+from __future__ import annotations
+
+import xml.etree.ElementTree as ET
+from collections.abc import Iterable, Mapping
+from dataclasses import dataclass, field
+from pathlib import PurePosixPath
+
+_TEST_SDK_PACKAGE = "microsoft.net.test.sdk"
+
+
+@dataclass(frozen=True, slots=True)
+class DotnetTestProjects:
+ """Directory-level verdict on whether .csproj files mark a project as a test project."""
+
+ by_dir: Mapping[str, bool | None] = field(default_factory=dict)
+
+ def collects(self, path: str) -> bool | None:
+ """Whether the nearest .csproj governing *path* is a test project.
+
+ Returns:
+ True: nearest project is a test project.
+ False: nearest project is not a test project.
+ None: no project governs *path*, or nearest project is unreadable.
+ """
+ p = PurePosixPath(path.replace("\\", "/"))
+ for parent in p.parents:
+ key = "" if str(parent) == "." else str(parent)
+ if key in self.by_dir:
+ return self.by_dir[key]
+ return None
+
+
+def is_test_project_csproj(text: str) -> bool | None:
+ """Whether a .csproj XML string describes a test project.
+
+ Returns:
+ True: is a test project.
+ False: is not a test project.
+ None: XML parse error (unknown).
+ """
+ try:
+ root = ET.fromstring(text)
+ except (ET.ParseError, ValueError):
+ return None
+
+ explicit_is_test: bool | None = None
+ has_test_sdk = False
+
+ for elem in root.iter():
+ local_tag = elem.tag.split("}")[-1].lower()
+ if local_tag == "istestproject":
+ val = (elem.text or "").strip().lower()
+ if val == "true":
+ explicit_is_test = True
+ elif val == "false":
+ explicit_is_test = False
+ elif local_tag in ("packagereference", "packageversion"):
+ for attr_name, attr_val in elem.attrib.items():
+ if (
+ attr_name.split("}")[-1].lower() in ("include", "update")
+ and attr_val.strip().lower() == _TEST_SDK_PACKAGE
+ ):
+ has_test_sdk = True
+
+ if explicit_is_test is False:
+ return False
+ if explicit_is_test is True:
+ return True
+ return has_test_sdk
+
+
+def read_dotnet_test_projects(files: Iterable[tuple[str, str]]) -> DotnetTestProjects:
+ """Build DotnetTestProjects from iterable of (rel_path, text) pairs."""
+ by_dir: dict[str, bool | None] = {}
+ for path, text in files:
+ p = PurePosixPath(path.replace("\\", "/"))
+ key = "" if str(p.parent) == "." else str(p.parent)
+ verdict = is_test_project_csproj(text)
+ if key not in by_dir:
+ by_dir[key] = verdict
+ else:
+ existing = by_dir[key]
+ if verdict is True or existing is True:
+ by_dir[key] = True
+ elif verdict is False or existing is False:
+ by_dir[key] = False
+ else:
+ by_dir[key] = None
+ return DotnetTestProjects(by_dir)
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py b/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
index c656c613f..265af6155 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
@@ -13,6 +13,7 @@ SPEC = LanguageSpec(
# singular Foo.UnitTest (#2662). Case-sensitive whole-suffix matches, so a
# shipped Foo.Testing/ library stays production code.
test_camel_suffixes=("Test", "Tests", "Spec", "Specs"),
+ fixture_camel_suffixes=("Fixture", "Fixtures"),
test_dir_suffixes=(
".Tests",
".Specs",
diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.py
index b1bc1974b..41b530b1a 100644
--- a/packages/core/src/repowise/core/ingestion/traverser.py
+++ b/packages/core/src/repowise/core/ingestion/traverser.py
@@ -30,6 +30,7 @@ import structlog
from pathspec.patterns.gitwildmatch import GitWildMatchPattern, GitWildMatchPatternError
from ..code_origin import is_generated_header
+from ..dotnet_test_projects import DotnetTestProjects, read_dotnet_test_projects
from ..entry_candidacy import conventional_entry_stems, not_an_execution_start
from ..pytest_roots import (
PYTEST_CONFIG_NAMES,
@@ -472,6 +473,11 @@ class FileTraverser:
"""Where pytest collects, from the configs the console-script pass read."""
return self._console_script_tables().pytest_roots
+ @property
+ def dotnet_test_projects(self) -> DotnetTestProjects:
+ """The .NET test projects, from the .csproj files the config pass read."""
+ return self._console_script_tables().dotnet_test_projects
+
@property
def _console_script_names(self) -> frozenset[str]:
return self._console_script_tables().names
@@ -826,8 +832,12 @@ class FileTraverser:
_is_console_script_target(rel_str, self._console_script_modules)
or rel_str in self._distribution_inits
)
+ scripts = self._console_script_tables()
is_test = is_test_related_path(
- rel_str, language, self._console_script_tables().pytest_roots
+ rel_str,
+ language,
+ roots=scripts.pytest_roots,
+ dotnet_projects=scripts.dotnet_test_projects,
)
entry = _is_entry_point(rel_str, abs_path, language) or manifest_entry
return FileInfo(
@@ -1163,7 +1173,7 @@ def _is_entry_point(rel_str: str, abs_path: Path, language: str) -> bool:
class ConsoleScriptTables(NamedTuple):
- """What one pass over the repo's Python project configs yields."""
+ """What one pass over the repo's Python and .NET project configs yields."""
names: frozenset[str]
"""Launcher names an installer drops in the environment's script dir."""
@@ -1175,6 +1185,8 @@ class ConsoleScriptTables(NamedTuple):
"""Repo-relative ``__init__.py`` of each distribution's own import package."""
pytest_roots: PytestRoots = PytestRoots()
"""Where a bare pytest run collects tests, which decides a test-named module."""
+ dotnet_test_projects: DotnetTestProjects = DotnetTestProjects()
+ """.NET test projects, which govern .cs files beneath them."""
def _collect_console_scripts(
@@ -1198,13 +1210,23 @@ def _collect_console_scripts(
inits: set[str] = set()
pytest_configs: list[tuple[str, dict]] = []
unreadable: list[str] = []
+ csproj_files: list[tuple[str, str]] = []
+ manifest_patterns = (*PYTEST_CONFIG_NAMES, "*.csproj")
try:
config_files = list(
- iter_glob(repo_root, tuple(PYTEST_CONFIG_NAMES), prune_nested_git=prune_nested_git)
+ iter_glob(repo_root, manifest_patterns, prune_nested_git=prune_nested_git)
)
except OSError:
return ConsoleScriptTables(frozenset(), frozenset(), frozenset(), frozenset())
for config_file in config_files:
+ if config_file.name.endswith(".csproj"):
+ rel = config_file.relative_to(repo_root).as_posix()
+ try:
+ text = config_file.read_text(encoding="utf-8", errors="replace")
+ csproj_files.append((rel, text))
+ except Exception:
+ csproj_files.append((rel, ""))
+ continue
project, options, parsed = _read_python_config(config_file)
rel = config_file.relative_to(repo_root).as_posix()
if options is not None:
@@ -1225,6 +1247,7 @@ def _collect_console_scripts(
frozenset(distributions),
frozenset(inits),
pytest_roots(pytest_configs, unreadable),
+ read_dotnet_test_projects(csproj_files),
)
diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.py
index d6ae01ed7..783e9a6f3 100644
--- a/packages/core/src/repowise/core/test_paths.py
+++ b/packages/core/src/repowise/core/test_paths.py
@@ -65,6 +65,7 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Collection
+ from .dotnet_test_projects import DotnetTestProjects
from .pytest_roots import PytestRoots
# Directory segments that mark every file beneath them as test material,
@@ -417,7 +418,12 @@ def _has_wildcard_pair(
)
-def _classify(path: str, language: str | None, roots: PytestRoots | None = None) -> str:
+def _classify(
+ path: str,
+ language: str | None,
+ roots: PytestRoots | None = None,
+ dotnet_projects: DotnetTestProjects | None = None,
+) -> str:
"""``"test"``, ``"support"``, or ``""`` for production code.
One traversal, so the two public predicates cannot disagree with each other
@@ -451,7 +457,11 @@ def _classify(path: str, language: str | None, roots: PytestRoots | None = None)
# A test name outside a test directory still needs pytest to collect it.
needs_test_dir = not named_test or _pytest_skips(path, filename, roots)
- if needs_test_dir and not _is_test_dir(segments, original_segments, filename, language):
+ if (
+ needs_test_dir
+ and not _is_test_dir(segments, original_segments, filename, language)
+ and not _dotnet_project_collects(path, filename, dotnet_projects)
+ ):
return ""
# Inside test material. A test-shaped filename wins; otherwise a
@@ -461,6 +471,17 @@ def _classify(path: str, language: str | None, roots: PytestRoots | None = None)
return "test"
+def _dotnet_project_collects(
+ path: str, filename: str, dotnet_projects: DotnetTestProjects | None
+) -> bool:
+ """Whether a .cs file is governed by a .NET test project."""
+ return (
+ dotnet_projects is not None
+ and filename.lower().endswith(".cs")
+ and dotnet_projects.collects(path) is True
+ )
+
+
def _pytest_skips(path: str, filename: str, roots: PytestRoots | None) -> bool:
"""Whether pytest's config keeps a test-named Python file out of collection."""
return (
@@ -471,7 +492,10 @@ def _pytest_skips(path: str, filename: str, roots: PytestRoots | None) -> bool:
def is_test_path(
- path: str, language: str | None = None, roots: PytestRoots | None = None
+ path: str,
+ language: str | None = None,
+ roots: PytestRoots | None = None,
+ dotnet_projects: DotnetTestProjects | None = None,
) -> bool:
"""Whether *path* is a test.
@@ -480,13 +504,17 @@ def is_test_path(
*language* when it is known: it decides the ambiguous ``spec/``/``t/``
cases, which are RSpec for Ruby and a Perl-style test tree for Python,
and specification or miscellaneous folders for everything else. Pass
- *roots* to let pytest's config overrule a test-shaped Python name.
+ *roots* to let pytest's config overrule a test-shaped Python name. Pass
+ *dotnet_projects* to recognize C# files governed by a test project.
"""
- return _classify(path, language, roots) == "test"
+ return _classify(path, language, roots, dotnet_projects) == "test"
def is_test_support_path(
- path: str, language: str | None = None, roots: PytestRoots | None = None
+ path: str,
+ language: str | None = None,
+ roots: PytestRoots | None = None,
+ dotnet_projects: DotnetTestProjects | None = None,
) -> bool:
"""Whether *path* is test infrastructure rather than a test.
@@ -494,11 +522,14 @@ def is_test_support_path(
scaffolding directories inside a test tree (``tests/factories/user.py``).
Never true at the same time as :func:`is_test_path`.
"""
- return _classify(path, language, roots) == "support"
+ return _classify(path, language, roots, dotnet_projects) == "support"
def is_test_related_path(
- path: str, language: str | None = None, roots: PytestRoots | None = None
+ path: str,
+ language: str | None = None,
+ roots: PytestRoots | None = None,
+ dotnet_projects: DotnetTestProjects | None = None,
) -> bool:
"""Whether *path* is a test **or** test support.
@@ -507,7 +538,8 @@ def is_test_related_path(
skipping files, a health biomarker exempting them. Callers that rank or
search should prefer :func:`is_test_path`, so fixtures stay findable.
"""
- return _classify(path, language, roots) != ""
+ return _classify(path, language, roots, dotnet_projects) != ""
+
def in_test_tree(path: str, language: str | None = None) -> bool:
diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.py
index d80d8235b..06c0fda1a 100644
--- a/tests/unit/ingestion/test_traverser.py
+++ b/tests/unit/ingestion/test_traverser.py
@@ -438,6 +438,30 @@ class TestFileTraverser:
assert files["tests/test_demo.py"] is True
assert files["tools/test_cli.py"] is True
+ def test_csharp_test_project_classifies_files_as_tests(self, tmp_path: Path) -> None:
+ (tmp_path / "acceptance" / "Acme.Acceptance.csproj").parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / "acceptance" / "Acme.Acceptance.csproj").write_text(
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup>\n"
+ " <ItemGroup>\n"
+ ' <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />\n'
+ ' <PackageReference Include="xunit" Version="2.9.0" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n"
+ )
+ (tmp_path / "acceptance" / "Authentication" / "AuthSteps.cs").parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / "acceptance" / "Authentication" / "AuthSteps.cs").write_text("public class AuthSteps {}\n")
+ (tmp_path / "acceptance" / "Authentication" / "AuthenticationTests.cs").write_text(
+ "public class AuthenticationTests {}\n"
+ )
+ (tmp_path / "src" / "App" / "Program.cs").parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / "src" / "App" / "Program.cs").write_text("public class Program {}\n")
+
+ files = {f.path: f.is_test for f in FileTraverser(tmp_path).traverse()}
+ assert files["acceptance/Authentication/AuthSteps.cs"] is True
+ assert files["acceptance/Authentication/AuthenticationTests.cs"] is True
+ assert files["src/App/Program.cs"] is False
+
def test_file_info_fields(self, tmp_path: Path) -> None:
(tmp_path / "calc.py").write_text("class Calc: pass")
traverser = FileTraverser(tmp_path)
diff --git a/tests/unit/test_dotnet_test_projects.py b/tests/unit/test_dotnet_test_projects.py
new file mode 100644
index 000000000..fb66df143
--- /dev/null
+++ b/tests/unit/test_dotnet_test_projects.py
@@ -0,0 +1,214 @@
+"""Unit tests for .NET test project detection."""
+
+from __future__ import annotations
+
+import pytest
+
+from repowise.core.dotnet_test_projects import (
+ is_test_project_csproj,
+ read_dotnet_test_projects,
+)
+
+
+ ("xml", "expected"),
+ [
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup>\n"
+ " <TargetFramework>net8.0</TargetFramework>\n"
+ " <IsTestProject>true</IsTestProject>\n"
+ " </PropertyGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup>\n"
+ " <istestproject>True</istestproject>\n"
+ " </PropertyGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup>\n"
+ " <IsTestProject>false</IsTestProject>\n"
+ " </PropertyGroup>\n"
+ "</Project>\n",
+ False,
+ ),
+ # Microsoft.NET.Test.Sdk via PackageReference Include
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />\n'
+ ' <PackageReference Include="xunit" Version="2.9.0" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Microsoft.NET.Test.Sdk via PackageReference Update
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <PackageReference Update="Microsoft.NET.Test.Sdk" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Microsoft.NET.Test.Sdk via PackageVersion Include
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Microsoft.NET.Test.Sdk via PackageVersion Update
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <PackageVersion Update="Microsoft.NET.Test.Sdk" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Case-insensitivity in attribute name and package name
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <packagereference include="microsoft.net.test.sdk" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Explicit IsTestProject=false overrides Microsoft.NET.Test.Sdk
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup>\n"
+ " <IsTestProject>false</IsTestProject>\n"
+ " </PropertyGroup>\n"
+ " <ItemGroup>\n"
+ ' <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ False,
+ ),
+ # Framework-only references without SDK are NOT test projects
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <ItemGroup>\n"
+ ' <PackageReference Include="MSTest.TestFramework" Version="3.0.0" />\n'
+ ' <PackageReference Include="xunit" Version="2.9.0" />\n'
+ ' <PackageReference Include="NUnit" Version="4.0.0" />\n'
+ " </ItemGroup>\n"
+ "</Project>\n",
+ False,
+ ),
+ # Classic MSBuild XML with xmlns
+ (
+ '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\n'
+ " <PropertyGroup>\n"
+ " <IsTestProject>true</IsTestProject>\n"
+ " </PropertyGroup>\n"
+ "</Project>\n",
+ True,
+ ),
+ # Regular non-test project
+ (
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup>\n"
+ " <TargetFramework>net8.0</TargetFramework>\n"
+ " </PropertyGroup>\n"
+ "</Project>\n",
+ False,
+ ),
+ # Malformed XML yields None (unknown)
+ ("<Project><Unclosed>", None),
+ ("", None),
+ ],
+)
+def test_is_test_project_csproj(xml: str, expected: bool | None) -> None:
+ assert is_test_project_csproj(xml) is expected
+
+
+def test_nearest_project_wins_for_nested_directories() -> None:
+ projects = read_dotnet_test_projects(
+ [
+ (
+ "src/App/App.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><TargetFramework>net8.0</TargetFramework></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ (
+ "acceptance/Acme.Acceptance.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ (
+ "tests/Tests.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ (
+ "tests/fixtures/sample_app/Sample.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>false</IsTestProject></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ ]
+ )
+ # File in acceptance test project
+ assert projects.collects("acceptance/Authentication/AuthSteps.cs") is True
+ # File under src/App/App.csproj
+ assert projects.collects("src/App/Program.cs") is False
+ # File directly under tests/ test project
+ assert projects.collects("tests/UnitTest.cs") is True
+ # Nested sample app inside tests/ has its own non-test project: nearest project wins
+ assert projects.collects("tests/fixtures/sample_app/Program.cs") is False
+ assert projects.collects("tests/fixtures/sample_app/Sub/Util.cs") is False
+ # File outside any project
+ assert projects.collects("other/External.cs") is None
+
+
+def test_root_project_governs_repository_descendants() -> None:
+ projects = read_dotnet_test_projects(
+ [
+ (
+ "Root.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><TargetFramework>net8.0</TargetFramework></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ (
+ "tests/Tests.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ ]
+ )
+ assert projects.collects("other/External.cs") is False
+ assert projects.collects("tests/MyTest.cs") is True
+
+
+
+def test_unreadable_project_yields_unknown() -> None:
+ projects = read_dotnet_test_projects(
+ [
+ ("malformed/Bad.csproj", "<Project><"),
+ (
+ "outer/Outer.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup></Project>',
+ ),
+ ("outer/inner/Inner.csproj", "<Project><broken"),
+ ]
+ )
+ assert projects.collects("malformed/File.cs") is None
+ assert projects.collects("outer/Valid.cs") is True
+ assert projects.collects("outer/inner/File.cs") is None
diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.py
index f32afe249..c0685d25a 100644
--- a/tests/unit/test_test_paths.py
+++ b/tests/unit/test_test_paths.py
@@ -10,6 +10,7 @@ from __future__ import annotations
import pytest
+from repowise.core.dotnet_test_projects import read_dotnet_test_projects
from repowise.core.pytest_roots import read_pytest_roots
from repowise.core.test_paths import (
is_skippable_test_path,
@@ -462,3 +463,46 @@ def test_pytest_config_overrules_a_test_shaped_python_name(path: str, expected:
)
def test_a_test_named_for_a_file_may_carry_a_qualifier(test_path, source, siblings, named):
assert names_test_for(test_path, source, siblings) is named
+
+
+_DOTNET_PROJECTS = read_dotnet_test_projects(
+ [
+ (
+ "acceptance/Acme.Acceptance.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><IsTestProject>true</IsTestProject></PropertyGroup>\n"
+ " <ItemGroup><PackageReference Include=\"Microsoft.NET.Test.Sdk\" Version=\"17.11.0\" /></ItemGroup>\n"
+ "</Project>\n",
+ ),
+ (
+ "src/App/App.csproj",
+ '<Project Sdk="Microsoft.NET.Sdk">\n'
+ " <PropertyGroup><TargetFramework>net8.0</TargetFramework></PropertyGroup>\n"
+ "</Project>\n",
+ ),
+ ]
+)
+
+
+ ("path", "expected_with", "expected_without"),
+ [
+ ("acceptance/Authentication/AuthSteps.cs", "test", ""),
+ ("acceptance/Authentication/AuthenticationTests.cs", "test", "test"),
+ ("acceptance/Helpers/AuthHelper.cs", "support", ""),
+ ("acceptance/Authentication/AuthFixtures.cs", "support", "support"),
+ ("src/App/Program.cs", "", ""),
+ ("src/App/Program.py", "", ""),
+ ],
+)
+def test_dotnet_test_project_classifies_csharp_files(
+ path: str, expected_with: str, expected_without: str
+) -> None:
+ got_with = "test" if is_test_path(path, dotnet_projects=_DOTNET_PROJECTS) else ""
+ got_with = "support" if is_test_support_path(path, dotnet_projects=_DOTNET_PROJECTS) else got_with
+ assert got_with == expected_with
+
+ got_without = "test" if is_test_path(path) else ""
+ got_without = "support" if is_test_support_path(path) else got_without
+ assert got_without == expected_without
+