Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Adds comprehensive test coverage for the ValidateProjectPath private method in AppProvisioningTool.cs.

Changes

  • 4 new test cases covering testable code paths:

    • Null/empty ProjectFilePath handling (early return)
    • Valid file path updates ProjectPath to file's directory
    • Valid file path matching existing ProjectPath (no-op)
  • Helper method GetValidateProjectPathMethod() extracts reflection boilerplate and adds null assertion

Implementation

Tests use reflection to invoke the private method directly, creating temporary files where filesystem validation is required:

[Fact]
public void ValidateProjectPath_ValidProjectFilePath_UpdatesProjectPath()
{
    var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
    Directory.CreateDirectory(tempDir);
    var tempFile = Path.Combine(tempDir, "test.csproj");
    File.WriteAllText(tempFile, "<Project></Project>");
    
    try
    {
        var options = new ProvisioningToolOptions
        {
            ProjectPath = "/some/other/path",
            ProjectFilePath = tempFile
        };
        
        var tool = new AppProvisioningTool("test-command", options, silent: true);
        GetValidateProjectPathMethod().Invoke(tool, null);
        
        Assert.Equal(tempDir, options.ProjectPath);
    }
    finally
    {
        if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
    }
}

Note on Test Coverage

The error path where an invalid ProjectFilePath triggers LogFailureAndExit cannot be unit tested because LogFailureAndExit calls Environment.Exit(1), which would terminate the test runner process. This scenario is better suited for integration tests.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Unit Test for ValidateProjectFilePath method in AppProvisioningTool.cs</issue_title>
<issue_description>

</issue_description>

<agent_instructions>Add unit tests for ValidateProjectFilePath in AppProvisioningTool.cs</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add unit test for ValidateProjectFilePath method Add unit tests for ValidateProjectPath method in AppProvisioningTool Dec 18, 2025
Copilot AI requested a review from haileymck December 18, 2025 19:24
@haileymck
Copy link
Member

@copilot fix the failing tests

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot fix the failing tests

Fixed in commit a04d1c7. The failing test ValidateProjectPath_InvalidProjectFilePath_CallsLogFailureAndExit was calling Environment.Exit(1) which terminated the test runner process. Removed this test as the error path (invalid file) cannot be safely unit tested when it calls Environment.Exit - this scenario is better suited for integration tests.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/Scaffolding/Scaffolding/.dotnet/dotnet /home/REDACTED/work/Scaffolding/Scaffolding/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/Scaffolding/Scaffolding/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/Scaffolding/Scaffolding/artifacts/toolset/11.0.0-beta.25609.1.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Test for ValidateProjectFilePath method in AppProvisioningTool.cs

2 participants