#Import the psd1 $ModuleName = 'PoshCore' $ModuleManifestName = "$ModuleName.psd1" $ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName" Import-Module $ModuleManifestPath -Force -ErrorAction Stop <# Integration/Acceptance Testing for PoshCore-Contact.ps1 Invoke-Pester –Script @{'Path' = 'C:\Githubdata\poshcore\Tests\PoshCore-Contact.Tests.ps1';} Description: Run through all variations of attribute groups and confirm data from core is as expected #> #################### Data to Compare with Output - BEGIN #################### #region <# This data should be updated by pulling the data from core using a known good version of poshcore Using the code found in Tools\PSOGenerationForPesterTests.ps1 This only needs to be done if the data has changed in core or you want to change the users used for the tests. #> #First Test Device (mark4808) $ComputerPSO1 = New-Object PSObject -Property @{ employee_number = '9646' employee_userid = 'mark4808' first_name = 'Mark' id = '802884' is_employee = 'True' last_active = '2017-02-28 05:23:30' last_name = 'Wichall' login_time = '2017-02-28 03:32:55' name = 'Mark Wichall' reverse_name = 'Wichall, Mark' primary_email = 'Mark.Wichall@rackspace.co.uk' } #Second Test Device (mart6141) $ComputerPSO2 = New-Object PSObject -Property @{ employee_number = '11567' employee_userid = 'mart6141' first_name = 'Martin' id = '1057184' is_employee = 'True' last_active = '2017-02-28 05:23:35' last_name = 'Howlett' login_time = '2017-02-28 03:55:40' name = 'Martin Howlett' reverse_name = 'Howlett, Martin' primary_email = 'Martin.Howlett@rackspace.co.uk' } #endregion ##################### Data to Compare with Output - END ##################### #################### Pester Tests - BEGIN #################### #region #Device numbers and account numbers from PSO's $Username1 = "$($ComputerPSO1.employee_userid)" $Username2 = "$($ComputerPSO2.employee_userid)" Describe "Find-CoreContact" { It 'Return a single contact from core, compares employee_userid' { $Test1 = Find-CoreContact -Ssos @($Username1) $($Test1.employee_userid) | should be $($ComputerPSO1.employee_userid) } It 'Return 2 contacts from core, compares employee_userid' { $Test2 = Find-CoreContact -Ssos @("$Username1","$Username2") $($Test2[0].employee_userid) | should be $($ComputerPSO1.employee_userid) $($Test2[1].employee_userid) | should be $($ComputerPSO2.employee_userid) } It 'Return a single contact from core and param CustomAttribute = reverse_name, compares reverse_name' { $Test3 = Find-CoreContact -Ssos @($Username1) -CustomAttribute @{"reverse_name"="reverse_name"} $($Test3.reverse_name) | should be $($ComputerPSO1.reverse_name) } It 'Return a single contact from core and IsEmployee param, compares is_employee' { $Test3 = Find-CoreContact -Ssos @($Username1) -IsEmployee $($Test3.is_employee) | should be $($ComputerPSO1.is_employee) } It 'Return a single contact from core by Id param, compares is_employee' { $Test4 = Find-CoreContact -Id $ComputerPSO1.id $($Test4.employee_userid) | should be $($ComputerPSO1.employee_userid) } It 'Return contacts from core by FirstName and LastName, checks that return contains user' { $Test5 = Find-CoreContact -FirstNames $ComputerPSO1.first_name -LastNames $ComputerPSO1.last_name $Test5 | where {$_.employee_userid -eq $ComputerPSO1.employee_userid} | Measure-Object | select -ExpandProperty Count | Should Be 1 } It 'Returns a single contact from core, checks email address' { $Test6 = Find-CoreContact -Ssos @($Username1) $($Test6.primary_email) | should be $($ComputerPSO1.primary_email) } It 'Return full object from core, checks all root level data e.g. load_arg, QueryTime, class, etc' { $Test4 = Find-CoreContact -Ssos @($Username1) -FullObject $Test4.count | should be 1 $Test4.load_arg | should Not Be $null $test4.result.employee_userid | should be $($ComputerPSO1.employee_userid) $Test4.class | should match "Contact.Contact" $Test4.QueryTime | should BeGreaterThan 0 $Test4.offset | should be "0" $Test4.limit | should be "100" } } #endregion ##################### Pester Tests - END ##################### #Log to appstats Try { Set-LogtoAppstats -FunctionID "PoshCore-Contact-Tests" -AppID "PoshCore" } Catch { Write-Warning "Failed to Log to Appstats, Error message: $($_.exception.message))" }