Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ public class NewTemporaryFileCommand : Cmdlet
protected override void EndProcessing()
{
string filePath = null;
string tempPath = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath = Path.GetTempPath();
if (ShouldProcess(tempPath))
{
try
{
filePath = Path.GetTempFileName();
}
catch (Exception e)
catch (IOException ioException)
{
WriteError(
ThrowTerminatingError(
new ErrorRecord(
e,
ioException,
"NewTemporaryFileWriteError",
ErrorCategory.WriteError,
tempPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
A FileInfo object for the temporary file is returned.
#>

Describe "NewTemporaryFile" -Tags "CI" {
Describe "New-TemporaryFile" -Tags "CI" {

It "creates a new temporary file" {
$tempFile = New-TemporaryFile

Test-Path $tempFile | Should be $true
$tempFile | Should Exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a black box testing point of view, it seems that we should check that the $tempFile path starts with the path returned from GetTempPath()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could... Would you be ok with this one:

$tempFile | Should BeLikeExactly "$([System.IO.Path]::GetTempPath())*"

$tempFile | Should BeOfType System.IO.FileInfo
$tempFile | Should BeLikeExactly "$([System.IO.Path]::GetTempPath())*"

if(Test-Path $tempFile)
{
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction SilentlyContinue -Force
}
}
Expand Down