|
| 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 | +} |
0 commit comments