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

Code before:
    }

    // This test should generally not be quarantined as it only is checking that the expected files are on disk
    // and that the namespace declarations in the generated .cs files start with the project name
    [Theory]
    [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.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);

Review comment (refactor):
[nitpick] The condition could be simplified by combining the bin and obj directory checks into a more concise pattern. Consider using a helper method or array to check against multiple patterns to improve readability.
```suggestion
            if (IsIgnoredPath(relativePath))
```

Code after:
    }

    // This test should generally not be quarantined as it only is checking that the expected files are on disk
    // and that the namespace declarations in the generated .cs files start with the project name
    [Theory]
    [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)