Skip to content

Commit 4179268

Browse files
authored
Merge pull request #35 from jongalloway/copilot/extend-dotnet-tool-with-parameters
Add CI/CD and advanced testing parameters to dotnet_project_test tool
2 parents 3a19096 + 89fde00 commit 4179268

File tree

3 files changed

+164
-1
lines changed

3 files changed

+164
-1
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using DotNetMcp;
2+
using FluentAssertions;
3+
using Microsoft.Extensions.Logging;
4+
using Moq;
5+
using Xunit;
6+
7+
namespace DotNetMcp.Tests;
8+
9+
public class DotNetCliToolsTests
10+
{
11+
private readonly DotNetCliTools _tools;
12+
private readonly Mock<ILogger<DotNetCliTools>> _loggerMock;
13+
14+
public DotNetCliToolsTests()
15+
{
16+
_loggerMock = new Mock<ILogger<DotNetCliTools>>();
17+
_tools = new DotNetCliTools(_loggerMock.Object);
18+
}
19+
20+
[Fact]
21+
public async Task DotnetProjectTest_WithBasicParameters_BuildsCorrectCommand()
22+
{
23+
// This test validates that the method exists and can be called with basic parameters
24+
// The actual command execution would require the dotnet CLI to be available
25+
var result = await _tools.DotnetProjectTest(
26+
project: "test.csproj",
27+
configuration: "Debug",
28+
filter: "FullyQualifiedName~MyTest");
29+
30+
// The result should contain output (even if it's an error about missing project)
31+
result.Should().NotBeNull();
32+
}
33+
34+
[Fact]
35+
public async Task DotnetProjectTest_WithCollectParameter_BuildsCorrectCommand()
36+
{
37+
// Validates that the collect parameter is accepted
38+
var result = await _tools.DotnetProjectTest(
39+
collect: "XPlat Code Coverage");
40+
41+
result.Should().NotBeNull();
42+
}
43+
44+
[Fact]
45+
public async Task DotnetProjectTest_WithResultsDirectory_BuildsCorrectCommand()
46+
{
47+
// Validates that the resultsDirectory parameter is accepted
48+
var result = await _tools.DotnetProjectTest(
49+
resultsDirectory: "/tmp/test-results");
50+
51+
result.Should().NotBeNull();
52+
}
53+
54+
[Fact]
55+
public async Task DotnetProjectTest_WithLogger_BuildsCorrectCommand()
56+
{
57+
// Validates that the logger parameter is accepted
58+
var result = await _tools.DotnetProjectTest(
59+
logger: "trx");
60+
61+
result.Should().NotBeNull();
62+
}
63+
64+
[Fact]
65+
public async Task DotnetProjectTest_WithNoBuild_BuildsCorrectCommand()
66+
{
67+
// Validates that the noBuild parameter is accepted
68+
var result = await _tools.DotnetProjectTest(
69+
noBuild: true);
70+
71+
result.Should().NotBeNull();
72+
}
73+
74+
[Fact]
75+
public async Task DotnetProjectTest_WithNoRestore_BuildsCorrectCommand()
76+
{
77+
// Validates that the noRestore parameter is accepted
78+
var result = await _tools.DotnetProjectTest(
79+
noRestore: true);
80+
81+
result.Should().NotBeNull();
82+
}
83+
84+
[Fact]
85+
public async Task DotnetProjectTest_WithVerbosity_BuildsCorrectCommand()
86+
{
87+
// Validates that the verbosity parameter is accepted
88+
var result = await _tools.DotnetProjectTest(
89+
verbosity: "detailed");
90+
91+
result.Should().NotBeNull();
92+
}
93+
94+
[Fact]
95+
public async Task DotnetProjectTest_WithFramework_BuildsCorrectCommand()
96+
{
97+
// Validates that the framework parameter is accepted
98+
var result = await _tools.DotnetProjectTest(
99+
framework: "net8.0");
100+
101+
result.Should().NotBeNull();
102+
}
103+
104+
[Fact]
105+
public async Task DotnetProjectTest_WithBlame_BuildsCorrectCommand()
106+
{
107+
// Validates that the blame parameter is accepted
108+
var result = await _tools.DotnetProjectTest(
109+
blame: true);
110+
111+
result.Should().NotBeNull();
112+
}
113+
114+
[Fact]
115+
public async Task DotnetProjectTest_WithListTests_BuildsCorrectCommand()
116+
{
117+
// Validates that the listTests parameter is accepted
118+
var result = await _tools.DotnetProjectTest(
119+
listTests: true);
120+
121+
result.Should().NotBeNull();
122+
}
123+
124+
[Fact]
125+
public async Task DotnetProjectTest_WithAllNewParameters_BuildsCorrectCommand()
126+
{
127+
// Validates that all new parameters can be used together
128+
var result = await _tools.DotnetProjectTest(
129+
project: "test.csproj",
130+
configuration: "Release",
131+
filter: "Category=Unit",
132+
collect: "XPlat Code Coverage",
133+
resultsDirectory: "/tmp/results",
134+
logger: "trx;LogFileName=test-results.trx",
135+
noBuild: true,
136+
noRestore: true,
137+
verbosity: "minimal",
138+
framework: "net9.0",
139+
blame: true,
140+
listTests: false);
141+
142+
result.Should().NotBeNull();
143+
}
144+
}

DotNetMcp.Tests/DotNetMcp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="FluentAssertions" Version="8.8.0" />
1313
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.10" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
15+
<PackageReference Include="Moq" Version="4.20.72" />
1516
<PackageReference Include="xunit" Version="2.9.2" />
1617
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
1718
</ItemGroup>

DotNetMcp/DotNetCliTools.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,30 @@ public async Task<string> DotnetProjectRun(
144144
public async Task<string> DotnetProjectTest(
145145
[Description("The project file or solution file to test")] string? project = null,
146146
[Description("The configuration to test (Debug or Release)")] string? configuration = null,
147-
[Description("Filter to run specific tests")] string? filter = null)
147+
[Description("Filter to run specific tests")] string? filter = null,
148+
[Description("The friendly name of the data collector (e.g., 'XPlat Code Coverage')")] string? collect = null,
149+
[Description("The directory where test results will be placed")] string? resultsDirectory = null,
150+
[Description("The logger to use for test results (e.g., 'trx', 'console;verbosity=detailed')")] string? logger = null,
151+
[Description("Do not build the project before testing")] bool noBuild = false,
152+
[Description("Do not restore the project before building")] bool noRestore = false,
153+
[Description("Set the MSBuild verbosity level (quiet, minimal, normal, detailed, diagnostic)")] string? verbosity = null,
154+
[Description("The target framework to test for")] string? framework = null,
155+
[Description("Run tests in blame mode to isolate problematic tests")] bool blame = false,
156+
[Description("List discovered tests without running them")] bool listTests = false)
148157
{
149158
var args = new StringBuilder("test");
150159
if (!string.IsNullOrEmpty(project)) args.Append($" \"{project}\"");
151160
if (!string.IsNullOrEmpty(configuration)) args.Append($" -c {configuration}");
152161
if (!string.IsNullOrEmpty(filter)) args.Append($" --filter \"{filter}\"");
162+
if (!string.IsNullOrEmpty(collect)) args.Append($" --collect \"{collect}\"");
163+
if (!string.IsNullOrEmpty(resultsDirectory)) args.Append($" --results-directory \"{resultsDirectory}\"");
164+
if (!string.IsNullOrEmpty(logger)) args.Append($" --logger \"{logger}\"");
165+
if (noBuild) args.Append(" --no-build");
166+
if (noRestore) args.Append(" --no-restore");
167+
if (!string.IsNullOrEmpty(verbosity)) args.Append($" --verbosity {verbosity}");
168+
if (!string.IsNullOrEmpty(framework)) args.Append($" --framework {framework}");
169+
if (blame) args.Append(" --blame");
170+
if (listTests) args.Append(" --list-tests");
153171
return await ExecuteDotNetCommand(args.ToString());
154172
}
155173

0 commit comments

Comments
 (0)