Commits

Aaron Jensen committed 0a45350

Improving ParentProcessID dynamic property.

  • Participants
  • Parent commits f3a4e75

Comments (0)

Files changed (2)

Carbon/Carbon.types.ps1xml

             <ScriptProperty>
                 <Name>ParentProcessID</Name>
                 <GetScriptBlock>
-                    (Get-WmiObject Win32_Process -f "ProcessID='$($_.Id)'").ParentProcessID
+                    $filter = "ProcessID='{0}'" -f $this.Id
+                    $process = Get-WmiObject Win32_Process -Filter $filter
+                    $process.ParentProcessID
                 </GetScriptBlock>
             </ScriptProperty>
         </Members>

Test/Test-ParentProcessID.ps1

 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
-function SetUp()
+function Start-Test()
 {
-    Import-Module (Join-Path $TestDir ..\Carbon -Resolve)
+    & (Join-Path -Path $TestDir -ChildPath ..\Carbon\Import-Carbon.ps1 -Resolve)
 }
 
-function TearDown()
+function Stop-Test()
 {
-    Remove-Module Carbon
 }
 
 function Test-ProcessesHaveParentProcessID
 {
-    Get-Process | % {
-        Assert-IsNotNull $_.ParentProcessID "Process $($_.Name) does not have a parent."
-    }
+    $parents = @{}
+    Get-WmiObject Win32_Process |
+        ForEach-Object { $parents[$_.ProcessID] = $_.ParentProcessID }
+
+    Get-Process | 
+        Where-Object { $parents.ContainsKey( [UInt32]$_.Id ) } |
+        ForEach-Object {
+            #Assert-IsNotNull $_.ParentProcessID 
+            Assert-Equal $parents[ [UInt32]$_.Id ] $_.ParentProcessID "Process $($_.Name) [$($_.ID)] does not have parent process ID '$($_.ParentPRocessID)'."
+        }
 }