Repository: dotnet/aspnetcore
File: src/ProjectTemplates/test/Templates.Tests/BaselineTest.cs (C#)

Code before:
    [MemberData(nameof(TemplateBaselines))]
    public async Task Template_Produces_The_Right_Set_Of_FilesAsync(string arguments, string[] expectedFiles)
    {
        Project = await ProjectFactory.CreateProject(Output);
        await Project.RunDotNetNewRawAsync(arguments);

        expectedFiles = expectedFiles.Select(f => f.Replace("{ProjectName}", Project.ProjectName)).ToArray();

        foreach (var file in expectedFiles)
        {
            AssertFileExists(Project.TemplateOutputDir, file, shouldExist: true);
        }

        var filesInFolder = Directory.EnumerateFiles(Project.TemplateOutputDir, "*", SearchOption.AllDirectories).ToArray();
        foreach (var file in filesInFolder)
        {
            var relativePath = file.Replace(Project.TemplateOutputDir, "").Replace("\\", "/").Trim('/');
            if (IsIgnoredPath(relativePath))
            {
                continue;
            }
            Assert.Contains(relativePath, expectedFiles);

            if (relativePath.EndsWith(".cs", StringComparison.Ordinal) && !relativePath.EndsWith("Extensions.cs", StringComparison.Ordinal))
            {
                var namespaceDeclarationPrefix = "namespace ";
                var namespaceDeclaration = File.ReadLines(file)
                    .SingleOrDefault(line => line.StartsWith(namespaceDeclarationPrefix, StringComparison.Ordinal))
                    ?.Substring(namespaceDeclarationPrefix.Length);

                // nullable because Program.cs with top-level statements doesn't have a namespace declaration
                if (namespaceDeclaration is not null)
                {
                    Assert.StartsWith(Project.ProjectName, namespaceDeclaration, StringComparison.Ordinal);
                }
            }
        }
    }

    private static bool IsIgnoredPath(string relativePath) =>
        relativePath.StartsWith("bin/", StringComparison.Ordinal) ||
        relativePath.StartsWith("obj/", StringComparison.Ordinal) ||
        relativePath.Contains("/bin/", StringComparison.Ordinal) ||
        relativePath.Contains("/obj/", StringComparison.Ordinal);

    private void AssertFileExists(string basePath, string path, bool shouldExist)
    {
        var fullPath = Path.Combine(basePath, path);
        var doesExist = File.Exists(fullPath);

        if (shouldExist)

Review comment (refactor):
The inline filtering logic duplicates the same pattern checking multiple times. Consider extracting this logic into a helper method like `IsIgnoredPath` for better maintainability and readability.
```suggestion
            if (IsIgnoredPath(relativePath))
```

Code after:
    [MemberData(nameof(TemplateBaselines))]
    public async Task Template_Produces_The_Right_Set_Of_FilesAsync(string arguments, string[] expectedFiles)
    {
        Project = await ProjectFactory.CreateProject(Output);
        await Project.RunDotNetNewRawAsync(arguments);

        expectedFiles = expectedFiles.Select(f => f.Replace("{ProjectName}", Project.ProjectName)).ToArray();

        foreach (var file in expectedFiles)
        {
            AssertFileExists(Project.TemplateOutputDir, file, shouldExist: true);
        }

        var filesInFolder = Directory.EnumerateFiles(Project.TemplateOutputDir, "*", SearchOption.AllDirectories).ToArray();
        foreach (var file in filesInFolder)
        {
            var relativePath = file.Replace(Project.TemplateOutputDir, "").Replace("\\", "/").Trim('/');
            if (relativePath.EndsWith(".csproj", StringComparison.Ordinal) ||
                relativePath.EndsWith(".fsproj", StringComparison.Ordinal) ||
                relativePath.EndsWith(".props", StringComparison.Ordinal) ||
                relativePath.EndsWith(".sln", StringComparison.Ordinal) ||
                relativePath.EndsWith(".targets", StringComparison.Ordinal) ||
                relativePath.StartsWith("bin/", StringComparison.Ordinal) ||
                relativePath.StartsWith("obj/", StringComparison.Ordinal) ||
                relativePath.Contains("/bin/", StringComparison.Ordinal) ||
                relativePath.Contains("/obj/", StringComparison.Ordinal))
            {
                continue;
            }
            Assert.Contains(relativePath, expectedFiles);

            if (relativePath.EndsWith(".cs", StringComparison.Ordinal) && !relativePath.EndsWith("Extensions.cs", StringComparison.Ordinal))
            {
                var namespaceDeclarationPrefix = "namespace ";
                var namespaceDeclaration = File.ReadLines(file)
                    .SingleOrDefault(line => line.StartsWith(namespaceDeclarationPrefix, StringComparison.Ordinal))
                    ?.Substring(namespaceDeclarationPrefix.Length);

                // nullable because Program.cs with top-level statements doesn't have a namespace declaration
                if (namespaceDeclaration is not null)
                {
                    Assert.StartsWith(Project.ProjectName, namespaceDeclaration, StringComparison.Ordinal);
                }
            }
        }
    }

    private void AssertFileExists(string basePath, string path, bool shouldExist)
    {
        var fullPath = Path.Combine(basePath, path);
        var doesExist = File.Exists(fullPath);