Repository: PowerShell/PowerShell
File: test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 (PowerShell)

Code before:
        BeforeEach {
            #remove every file so that New-Item can be validated
            Remove-Item -Path * -Recurse -Force -ErrorAction SilentlyContinue
        }

        It "Verify Directory + Whatif" {
            New-Item -Path . -ItemType Directory -Name $testDir -WhatIf > $null
            { Get-Item -Path $testDir -ErrorAction Stop } |
                Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand"
        }

        It "Verify Directory + Confirm bypass" {
            $result = New-Item -Path . -ItemType Directory -Name $testDir -Confirm:$false
            $result.Name | Should -BeExactly $testDir
        }

        It "Verify Directory + Force" {
            New-Item -Path . -ItemType Directory -Name $testDir > $null
            $result = New-Item -Path . -ItemType Directory -Name $testDir -Force #would normally fail without force
            $result.Name | Should -BeExactly $testDir
        }

        It "Verify Directory creation when path relative to current PSDrive is empty" {
            try {
                New-Item "NewDirectory" -ItemType Directory -Force
                $newPSDrive = New-PSDrive -Name "NewPSDrive" -PSProvider FileSystem -Root "NewDirectory"

                $result = New-Item -Path "NewPSDrive:\" -ItemType Directory -Force
                $result.FullName.TrimEnd("/\") | Should -BeExactly $newPSDrive.Root
            }
            finally {
                Remove-PSDrive -Name "NewPSDrive" -Force -ErrorAction SilentlyContinue
            }
        }

        It "Verify File + Value" {
            $result = New-Item -Path . -ItemType File -Name $testFile -Value "Some String"
            $content = Get-Content -Path $testFile
            $result.Name | Should -BeExactly $testFile
            $content | Should -BeExactly "Some String"
        }
    }

    Context "Valdiate Get-Item parameters" {
        It "Verify Force" {
            $result = Get-Item -Path $testFile -Force
            $result.Name | Should -BeExactly $testFile
        }

        It "Verify Path Wildcard" {
            $result = Get-Item -Path "*2.txt"

Review comment (suggestion):
Here we create PSDrive with relative root path - this leads to unpredictable results (the psdrive base path is taken as OS cwd!). Please use absolute path like:
```suggestion
                $rootDir = New-Item "NewDirectory" -ItemType Directory -Force
                $rootPath = $rootDir.FullName
                $newPSDrive = New-PSDrive -Name "NewPSDrive" -PSProvider FileSystem -Root $rootPath
```

Code after:
        BeforeEach {
            #remove every file so that New-Item can be validated
            Remove-Item -Path * -Recurse -Force -ErrorAction SilentlyContinue
        }

        It "Verify Directory + Whatif" {
            New-Item -Path . -ItemType Directory -Name $testDir -WhatIf > $null
            { Get-Item -Path $testDir -ErrorAction Stop } |
                Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand"
        }

        It "Verify Directory + Confirm bypass" {
            $result = New-Item -Path . -ItemType Directory -Name $testDir -Confirm:$false
            $result.Name | Should -BeExactly $testDir
        }

        It "Verify Directory + Force" {
            New-Item -Path . -ItemType Directory -Name $testDir > $null
            $result = New-Item -Path . -ItemType Directory -Name $testDir -Force #would normally fail without force
            $result.Name | Should -BeExactly $testDir
        }

        It "Verify Directory creation when path relative to current PSDrive is empty" {
            try {
                $rootDir = New-Item "NewDirectory" -ItemType Directory -Force
                $rootPath = $rootDir.FullName
                $newPSDrive = New-PSDrive -Name "NewPSDrive" -PSProvider FileSystem -Root $rootPath

                $result = New-Item -Path "NewPSDrive:\" -ItemType Directory -Force
                $result.FullName.TrimEnd("/\") | Should -BeExactly $newPSDrive.Root
            }
            finally {
                Remove-PSDrive -Name "NewPSDrive" -Force -ErrorAction SilentlyContinue
            }
        }

        It "Verify File + Value" {
            $result = New-Item -Path . -ItemType File -Name $testFile -Value "Some String"
            $content = Get-Content -Path $testFile
            $result.Name | Should -BeExactly $testFile
            $content | Should -BeExactly "Some String"
        }
    }

    Context "Valdiate Get-Item parameters" {
        It "Verify Force" {
            $result = Get-Item -Path $testFile -Force
            $result.Name | Should -BeExactly $testFile
        }

        It "Verify Path Wildcard" {