Skip to content

Commit 25322e8

Browse files
CopilotMalcolmnixon
andcommitted
Address code review feedback - remove unused using and refactor tests
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent 047a07e commit 25322e8

File tree

2 files changed

+27
-103
lines changed

2 files changed

+27
-103
lines changed

test/DemaConsulting.BuildMark.Tests/GitHubRepoConnectorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// SOFTWARE.
2020

2121
using DemaConsulting.BuildMark.RepoConnectors;
22-
using NSubstitute;
2322
using Octokit;
2423

2524
namespace DemaConsulting.BuildMark.Tests;

test/DemaConsulting.BuildMark.Tests/PathHelpersTests.cs

Lines changed: 27 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -53,124 +53,49 @@ public void PathHelpers_SafePathCombine_PathTraversalWithDoubleDots_ThrowsArgume
5353
var basePath = "/home/user/project";
5454
var relativePath = "../etc/passwd";
5555

56-
ArgumentException? caughtException = null;
57-
58-
try
59-
{
60-
// Act
61-
PathHelpers.SafePathCombine(basePath, relativePath);
62-
63-
// Assert - Fail if no exception is thrown
64-
Assert.Fail("Expected ArgumentException to be thrown");
65-
}
66-
catch (ArgumentException ex)
67-
{
68-
// Store exception for verification
69-
caughtException = ex;
70-
}
71-
72-
// Assert - Verify exception
73-
Assert.IsNotNull(caughtException);
74-
Assert.Contains("Invalid path component", caughtException.Message);
56+
// Act & Assert
57+
var exception = Assert.Throws<ArgumentException>(() =>
58+
PathHelpers.SafePathCombine(basePath, relativePath));
59+
Assert.Contains("Invalid path component", exception.Message);
7560
}
7661

7762
/// <summary>
78-
/// Test that SafePathCombine throws ArgumentException for rooted path.
63+
/// Test that SafePathCombine throws ArgumentException for path with double dots in middle.
7964
/// </summary>
8065
[TestMethod]
81-
public void PathHelpers_SafePathCombine_RootedPath_ThrowsArgumentException()
66+
public void PathHelpers_SafePathCombine_DoubleDotsInMiddle_ThrowsArgumentException()
8267
{
8368
// Arrange
8469
var basePath = "/home/user/project";
85-
var relativePath = "/etc/passwd";
86-
87-
ArgumentException? caughtException = null;
88-
89-
try
90-
{
91-
// Act
92-
PathHelpers.SafePathCombine(basePath, relativePath);
93-
94-
// Assert - Fail if no exception is thrown
95-
Assert.Fail("Expected ArgumentException to be thrown");
96-
}
97-
catch (ArgumentException ex)
98-
{
99-
// Store exception for verification
100-
caughtException = ex;
101-
}
102-
103-
// Assert - Verify exception
104-
Assert.IsNotNull(caughtException);
105-
Assert.Contains("Invalid path component", caughtException.Message);
106-
}
107-
108-
/// <summary>
109-
/// Test that SafePathCombine throws ArgumentException for Windows rooted path.
110-
/// </summary>
111-
[TestMethod]
112-
public void PathHelpers_SafePathCombine_WindowsRootedPath_ThrowsArgumentException()
113-
{
114-
// Skip test on non-Windows platforms where Windows paths are not considered rooted
115-
if (!OperatingSystem.IsWindows())
116-
{
117-
Assert.Inconclusive("Test only applies on Windows");
118-
return;
119-
}
120-
121-
// Arrange
122-
var basePath = "C:\\Users\\project";
123-
var relativePath = "C:\\Windows\\System32\\file.txt";
124-
125-
ArgumentException? caughtException = null;
126-
127-
try
128-
{
129-
// Act
130-
PathHelpers.SafePathCombine(basePath, relativePath);
131-
132-
// Assert - Fail if no exception is thrown
133-
Assert.Fail("Expected ArgumentException to be thrown");
134-
}
135-
catch (ArgumentException ex)
136-
{
137-
// Store exception for verification
138-
caughtException = ex;
139-
}
70+
var relativePath = "subfolder/../../../etc/passwd";
14071

141-
// Assert - Verify exception
142-
Assert.IsNotNull(caughtException);
143-
Assert.Contains("Invalid path component", caughtException.Message);
72+
// Act & Assert
73+
var exception = Assert.Throws<ArgumentException>(() =>
74+
PathHelpers.SafePathCombine(basePath, relativePath));
75+
Assert.Contains("Invalid path component", exception.Message);
14476
}
14577

14678
/// <summary>
147-
/// Test that SafePathCombine throws ArgumentException for path with double dots in middle.
79+
/// Test that SafePathCombine throws ArgumentException for absolute paths.
14880
/// </summary>
14981
[TestMethod]
150-
public void PathHelpers_SafePathCombine_DoubleDotsInMiddle_ThrowsArgumentException()
82+
public void PathHelpers_SafePathCombine_AbsolutePath_ThrowsArgumentException()
15183
{
152-
// Arrange
153-
var basePath = "/home/user/project";
154-
var relativePath = "subfolder/../../../etc/passwd";
155-
156-
ArgumentException? caughtException = null;
157-
158-
try
84+
// Test Unix absolute path
85+
var unixBasePath = "/home/user/project";
86+
var unixRelativePath = "/etc/passwd";
87+
var unixException = Assert.Throws<ArgumentException>(() =>
88+
PathHelpers.SafePathCombine(unixBasePath, unixRelativePath));
89+
Assert.Contains("Invalid path component", unixException.Message);
90+
91+
// Test Windows absolute path (only on Windows since Windows paths may not be rooted on Unix)
92+
if (OperatingSystem.IsWindows())
15993
{
160-
// Act
161-
PathHelpers.SafePathCombine(basePath, relativePath);
162-
163-
// Assert - Fail if no exception is thrown
164-
Assert.Fail("Expected ArgumentException to be thrown");
94+
var windowsBasePath = "C:\\Users\\project";
95+
var windowsRelativePath = "C:\\Windows\\System32\\file.txt";
96+
var windowsException = Assert.Throws<ArgumentException>(() =>
97+
PathHelpers.SafePathCombine(windowsBasePath, windowsRelativePath));
98+
Assert.Contains("Invalid path component", windowsException.Message);
16599
}
166-
catch (ArgumentException ex)
167-
{
168-
// Store exception for verification
169-
caughtException = ex;
170-
}
171-
172-
// Assert - Verify exception
173-
Assert.IsNotNull(caughtException);
174-
Assert.Contains("Invalid path component", caughtException.Message);
175100
}
176101
}

0 commit comments

Comments
 (0)