Skip to content

Commit 33e67a0

Browse files
committed
//
1 parent 0f7f1b7 commit 33e67a0

File tree

72 files changed

+934
-26914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+934
-26914
lines changed

.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1+
Dev/Build/*.clixml
12

2-
Tests/Azurecred\.xml
3-
4-
PesterTests/Core/AzureCred\.xml
5-
6-
MSGraph\.Posh\.Alpha/Config\.json
3+
WithGraph.Alpha\.Posh\.Alpha/Config\.json

Dev/Build/Build.log

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
10/22/2017 4:48:16 PM INFORMATION ## Starting Build 2017/10/22 04:48. Module WithGraph.Alpha ##
2+
10/22/2017 4:48:16 PM INFORMATION ## Testphase ##
3+
10/22/2017 4:48:25 PM INFORMATION 12 tests failed:
4+
10/22/2017 4:49:19 PM INFORMATION ## Starting Build 2017/10/22 04:49. Module WithGraph.Alpha ##
5+
10/22/2017 4:49:19 PM INFORMATION ## Testphase ##
6+
10/22/2017 4:49:26 PM INFORMATION 18 tests failed
7+
10/22/2017 4:49:47 PM INFORMATION ## Starting Build 2017/10/22 04:49. Module WithGraph.Alpha ##
8+
10/22/2017 4:49:47 PM INFORMATION ## Testphase ##
9+
10/22/2017 4:49:52 PM INFORMATION 18 tests failed
10+
10/22/2017 5:27:23 PM INFORMATION ## Starting Build 2017/10/22 05:27. Module WithGraph.Alpha ##
11+
10/22/2017 5:27:23 PM INFORMATION ## Testphase ##
12+
10/22/2017 5:27:25 PM INFORMATION 12 tests failed
13+
10/22/2017 5:47:10 PM INFORMATION ## Starting Build 2017/10/22 05:47. Module WithGraph.Alpha ##
14+
10/22/2017 5:47:10 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
15+
10/22/2017 5:47:10 PM INFORMATION ## Testphase ##
16+
10/22/2017 5:47:16 PM INFORMATION 18 tests failed
17+
10/22/2017 5:50:04 PM INFORMATION ## Starting Build 2017/10/22 05:50. Module WithGraph.Alpha ##
18+
10/22/2017 5:50:04 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
19+
10/22/2017 5:50:04 PM INFORMATION ## Testphase ##
20+
10/22/2017 5:50:09 PM INFORMATION 17 tests failed
21+
10/22/2017 5:50:48 PM INFORMATION ## Starting Build 2017/10/22 05:50. Module WithGraph.Alpha ##
22+
10/22/2017 5:50:48 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
23+
10/22/2017 5:50:48 PM INFORMATION ## Testphase ##
24+
10/22/2017 5:50:53 PM INFORMATION 17 tests failed
25+
10/22/2017 5:59:59 PM INFORMATION ## Starting Build 2017/10/22 05:59. Module WithGraph.Alpha ##
26+
10/22/2017 5:59:59 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
27+
10/22/2017 5:59:59 PM INFORMATION ## Testphase ##
28+
10/22/2017 6:00:05 PM INFORMATION 11 tests failed
29+
10/22/2017 6:06:43 PM INFORMATION ## Starting Build 2017/10/22 06:06. Module WithGraph.Alpha ##
30+
10/22/2017 6:06:43 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
31+
10/22/2017 6:06:43 PM INFORMATION ## Testphase ##
32+
10/22/2017 6:06:49 PM INFORMATION 6 tests failed
33+
10/22/2017 6:07:47 PM INFORMATION ## Starting Build 2017/10/22 06:07. Module WithGraph.Alpha ##
34+
10/22/2017 6:07:47 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
35+
10/22/2017 6:07:47 PM INFORMATION ## Testphase ##
36+
10/22/2017 6:07:52 PM INFORMATION 6 tests failed
37+
10/24/2017 9:24:26 PM INFORMATION ## Starting Build 2017/10/24 09:24. Module WithGraph.Alpha ##
38+
10/24/2017 9:24:26 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
39+
10/24/2017 9:24:26 PM INFORMATION ## Testphase ##
40+
10/24/2017 9:25:25 PM INFORMATION ## Starting Build 2017/10/24 09:25. Module WithGraph.Alpha ##
41+
10/24/2017 9:25:25 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
42+
10/24/2017 9:25:25 PM INFORMATION ## Testphase ##
43+
10/26/2017 9:59:06 PM INFORMATION ## Starting Build 2017/10/26 09:59. Module: WithGraph.Alpha ##
44+
10/26/2017 9:59:06 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
45+
10/26/2017 9:59:06 PM INFORMATION ## Testphase ##
46+
10/26/2017 9:59:11 PM INFORMATION 8 tests failed
47+
10/26/2017 9:59:52 PM INFORMATION ## Starting Build 2017/10/26 09:59. Module: WithGraph.Alpha ##
48+
10/26/2017 9:59:52 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
49+
10/26/2017 9:59:52 PM INFORMATION ## Testphase ##
50+
10/26/2017 9:59:54 PM INFORMATION 8 tests failed
51+
10/26/2017 10:00:34 PM INFORMATION ## Starting Build 2017/10/26 10:00. Module: WithGraph.Alpha ##
52+
10/26/2017 10:00:34 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
53+
10/26/2017 10:00:34 PM INFORMATION ## Testphase ##
54+
10/26/2017 10:01:18 PM INFORMATION 5 tests failed
55+
10/26/2017 10:03:14 PM INFORMATION ## Starting Build 2017/10/26 10:03. Module: WithGraph.Alpha ##
56+
10/26/2017 10:03:14 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
57+
10/26/2017 10:03:14 PM INFORMATION ## Testphase ##
58+
10/26/2017 10:04:09 PM INFORMATION ## Starting Build 2017/10/26 10:04. Module: WithGraph.Alpha ##
59+
10/26/2017 10:04:09 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
60+
10/26/2017 10:04:09 PM INFORMATION ## Testphase ##
61+
10/26/2017 10:04:43 PM INFORMATION 5 tests failed
62+
10/26/2017 10:18:51 PM INFORMATION ## Starting Build 2017/10/26 10:18. Module: WithGraph.Alpha ##
63+
10/26/2017 10:18:51 PM INFORMATION ## C:\git\MSGraph.Posh.Alpha\Dev\WithGraph.Alpha ##
64+
10/26/2017 10:18:51 PM INFORMATION ## Testphase ##

Dev/Build/Build.ps1

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Function Invoke-Credential
2+
{
3+
param(
4+
[parameter(mandatory=$true)]
5+
$name
6+
)
7+
8+
$credpath = (join-path $PSScriptRoot "$name.clixml")
9+
if(test-path $credpath)
10+
{
11+
Import-Clixml -Path $credpath
12+
}
13+
else
14+
{
15+
$Cred = get-credential -Message "GraphAPI Credentials"
16+
if($Cred -ne $null)
17+
{
18+
$cred | Export-Clixml -Path $credpath
19+
Invoke-Credential $path
20+
}
21+
}
22+
}
23+
24+
25+
26+
##Start
27+
try {
28+
#$VerbosePreference = "continue"
29+
gci $PSScriptRoot\logging -Filter "*.ps1"|%{. $_.FullName}
30+
New-Log ".\Build.log" -Append
31+
32+
$Global:PesterTestCred = Invoke-Credential -name "GraphAPI"
33+
$Global:ModuleRootFolder = (Gci (split-path $PSScriptRoot) -Directory|?{(gci $_.FullName -Filter "*psm1") -ne $null}|select -First 1).FullName
34+
$Global:modulename = split-path $Global:ModuleRootFolder -Leaf
35+
$Testpath = join-path (Split-Path $PSScriptRoot) "Tests"
36+
write-log "## Starting Build $(get-date -f "yyyy/MM/dd hh:mm"). Module: $Global:modulename ##" -PassThru
37+
Write-Log "## $Global:ModuleRootFolder ##" -PassThru
38+
Write-Log "## Testphase ##" -PassThru
39+
import-module $Global:ModuleRootFolder -Force
40+
$tests = @()
41+
$tests += invoke-pester -path $Testpath -PassThru
42+
if($tests.totalcount -eq $tests.passedcount)
43+
{
44+
Write-Log "All tests ($($tests.count)) passed!" -PassThru
45+
}
46+
else
47+
{
48+
Write-Log "$($tests.failedcount) tests failed" -PassThru
49+
# $tests.TestResult.where{
50+
# $_.passed -eq $false
51+
# }|select describe,Context,FailureMessage,name|fl
52+
}
53+
}
54+
catch {
55+
throw $_
56+
}
57+
finally{
58+
#Get-Module $Global:modulename | Remove-Module
59+
$VerbosePreference = "Silentlycontinue"
60+
}
61+
62+
63+
#$Global:ModuleRootFolder = "$(split-path $PSScriptRoot)\$modulename"
64+
65+
# get-module $global:modulename | Remove-Module -Force
66+
# import-module (join-path $ModuleRootFolder "$global:modulename.psd1") -Force
File renamed without changes.
File renamed without changes.

Dev/Build/Logging/lib_Write-Log.ps1

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
function Write-Log {
2+
<#
3+
.SYNOPSIS
4+
Write to the log.
5+
.DESCRIPTION
6+
The Write-Log function is used to write to the log. It is using the log object created by New-Log
7+
to determine if it's going to write to a log file or to a Windows Event log.
8+
.EXAMPLE
9+
Write-Log 'Finished running WMI query'
10+
Get the log object from $global:PSLOG and write to the log.
11+
.EXAMPLE
12+
$myLog | Write-Log 'Finished running WMI query'
13+
Use the log object saved in $myLog and write to the log.
14+
.EXAMPLE
15+
Write-Log 'WMI query failed - Access denied!' -LogType Error -PassThru | Write-Warning
16+
Will write an error to the event log, and then pass the log entry to the Write-Warning cmdlet.
17+
.NOTES
18+
Author: Øyvind Kallstad
19+
Date: 21.11.2014
20+
Version: 1.0
21+
Dependencies: Invoke-LogRotation
22+
#>
23+
[CmdletBinding()]
24+
param (
25+
# The text you want to write to the log.
26+
[Parameter(Position = 0)]
27+
[string] $LogEntry,
28+
29+
# The type of log entry. Valid choices are 'Error', 'FailureAudit','Information','SuccessAudit' and 'Warning'.
30+
# Note that the CMTrace format only supports 3 log types (1-3), so 'Error' and 'FailureAudit' are translated to CMTrace log type 3, 'Information' and 'SuccessAudit'
31+
# are translated to 1, while 'Warning' is translated to 2. 'FailureAudit' and 'SuccessAudit' are only really included since they are valid log types when
32+
# writing to the Windows Event Log.
33+
[Parameter()]
34+
[ValidateSet('Error','FailureAudit','Information','SuccessAudit','Warning')]
35+
[string] $LogType = 'Information',
36+
37+
# Event ID. Only applicable when writing to the Windows Event Log.
38+
[Parameter()]
39+
[string] $EventID,
40+
41+
# The log object created using the New-Log function. Defaults to reading the global PSLOG variable.
42+
[Parameter(ValueFromPipeline)]
43+
[ValidateNotNullorEmpty()]
44+
[object] $Log = $global:PSLOG,
45+
46+
# PassThru passes the log entry to the pipeline for further processing.
47+
[Parameter()]
48+
[switch] $PassThru
49+
)
50+
51+
try {
52+
53+
# get information from log object
54+
$logObject = $Log
55+
56+
# translate event types to CMTrace format
57+
if ($logObject.LogFormat -eq 'CMTrace') {
58+
switch ($LogType) {
59+
'Error' {$cmType = '3';break}
60+
'FailureAudit' {$cmType = '3';break}
61+
'Information' {$cmType = '1';break}
62+
'SuccessAudit' {$cmType = '1';break}
63+
'Warning' {$cmType = '2';break}
64+
DEFAULT {$cmType = '1'}
65+
}
66+
}
67+
68+
# get invocation information
69+
$thisInvocation = (Get-Variable -Name 'MyInvocation' -Scope 1).Value
70+
71+
# get calling script info
72+
if(-not ($thisInvocation.ScriptName)){
73+
$scriptName = $thisInvocation.MyCommand
74+
$file = "$($scriptName)"
75+
}
76+
else{
77+
$scriptName = Split-Path -Leaf ($thisInvocation.ScriptName)
78+
$file = "$($scriptName):$($thisInvocation.ScriptLineNumber)"
79+
}
80+
81+
# get calling command info
82+
$component = "$($thisInvocation.MyCommand)"
83+
84+
if ($logObject.LogType -eq 'EventLog') {
85+
if($logObject.Elevated) {
86+
87+
# if EventID is not specified use default event id from the log object
88+
if([system.string]::IsNullOrEmpty($EventID)) {
89+
$EventID = $logObject.DefaultEventID
90+
}
91+
92+
Write-EventLog -LogName $logObject.EventLogName -Source $logObject.EventLogSource -EntryType $LogType -EventId $EventID -Message $LogEntry
93+
}
94+
95+
else {
96+
Write-Warning 'When writing to the Windows Event Log you need to run as a user with elevated rights!'
97+
}
98+
}
99+
100+
else {
101+
# create a mutex, so we can lock the file while writing to it
102+
$mutex = New-Object System.Threading.Mutex($false, 'LogMutex')
103+
104+
# handle the different log file formats
105+
switch ($logObject.LogFormat) {
106+
107+
'Minimal' { $logEntryString = $LogEntry; break }
108+
109+
'PlainText' {
110+
$logEntryString = "$((Get-Date).ToString()) $($LogType.ToUpper()) $($LogEntry)"
111+
# when component and file are equal
112+
#if($component -eq $file){
113+
#$logEntryString = "$((Get-Date).ToString()) $($LogType.ToUpper()) [$($file)] $($LogEntry)"
114+
#Write-Verbose $logEntryString ####
115+
#}
116+
117+
# log entry when component and file are not equal
118+
#else{
119+
#$logEntryString = "$((Get-Date).ToString()) $($LogType.ToUpper()) [$($component) - $($file)] $($LogEntry)"
120+
#}
121+
break
122+
}
123+
124+
'CMTrace' {
125+
$date = Get-Date -Format 'MM-dd-yyyy'
126+
$time = Get-Date -Format 'HH:mm:ss.ffffff'
127+
#$logEntryString = "<![LOG[$LogEntry]LOG]!><time=""$time"" date=""$date"" component=""$component"" context="""" type=""$cmType"" thread=""$pid"" file=""$file"">"
128+
$logEntryString = "<![LOG[$LogEntry]LOG]!><time=""$time"" date=""$date"" component="""" context="""" type=""$cmType"" thread=""$pid"" file="""">"
129+
break
130+
}
131+
}
132+
133+
# write to the log file
134+
[void]$mutex.WaitOne()
135+
Add-Content -Path $logObject.Path -Value $logEntryString
136+
$mutex.ReleaseMutex()
137+
138+
# invoke log rotation if log is file
139+
if ($logObject.LogType -eq 'LogFile') {
140+
Invoke-LogRotation
141+
}
142+
143+
# handle PassThru
144+
if ($PassThru) {
145+
Write-host $LogEntry
146+
}
147+
}
148+
}
149+
150+
catch {
151+
Write-Warning $_.Exception.Message
152+
}
153+
}

PesterTests/Core/Connect-GraphAPI.Tests.ps1 Dev/Tests/Core/Connect-GraphAPI.Tests.ps1

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
InModuleScope $Global:modulename{
22
Describe "Connect-GraphAPI. Always using pscredentials" -Tag "Core"{
3-
$CredPath = (join-path $PSScriptRoot 'AzureCred.xml')
4-
if(!(test-path $CredPath))
5-
{
6-
$cred = Get-Credential -Message "Azure AD Admin User"
7-
$cred | export-clixml -Path $CredPath
8-
}
9-
$cred = import-clixml $CredPath
10-
3+
$cred = $Global:PesterTestCred
114
Context "-Credentials"{
125
it "Should not throw"{
136
{Connect-GraphAPI -Credentials $cred}|should not throw
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
InModuleScope $Global:modulename{
2+
Describe "Get-GraphVersion" -Tag "Core"{
3+
Context "Without Switches"{
4+
it "returns psobject"{
5+
get-graphversion|should beoftype [pscustomobject]
6+
}
7+
8+
it "Returns active correctly"{
9+
(get-graphversion).active|should be $Script:GraphVersion
10+
}
11+
12+
it "Returns persistent correctly"{
13+
(get-graphversion).persistent|should be (Get-GraphAPIConfigFile).graphversion.Selected
14+
}
15+
16+
it "Returns avalible correctly"{
17+
(get-graphversion).persistent|should be (Get-GraphAPIConfigFile).graphversion.Avalible
18+
}
19+
}
20+
}
21+
}

PesterTests/Core/Invoke-GraphCall.Tests.ps1 Dev/Tests/Core/Invoke-GraphCall.Tests.ps1

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ InModuleScope $Global:modulename{
1010
{invoke-graphcall -Call "test" -Method "get" -ErrorAction Stop}|should throw
1111
}
1212

13-
it "Standard call should return pscustomobject"{
13+
14+
it "Standard call should return pscustomobject when classes is not enabled"{
15+
#Set-GraphClassUsage -enabled false
16+
Mock get-GraphAPIConfigFile {
17+
$config = (get-content $Script:GraphAPIConfigFile -raw | convertfrom-json)
18+
$config.Odata.UseClasses = $false
19+
return $config
20+
}
1421
invoke-graphcall -Call "me" -Method "get"|should beoftype [PsCustomObject]
1522
}
1623

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
InModuleScope $global:modulename{
2+
Describe "Module Startup"{
3+
Context "First time"{
4+
#Remove config file for test
5+
$configfile = $script:GraphAPIConfigFile
6+
get-item $configfile -ErrorAction SilentlyContinue| remove-item -force -ErrorAction SilentlyContinue
7+
8+
it "Test that Config.json is gone before we start test"{
9+
{get-item $configfile -ErrorAction Stop}|should throw
10+
}
11+
12+
it "Creates new config.json"{
13+
import-module "$ModuleRootFolder\$modulename.psd1" -Force
14+
{get-item $configfile -ErrorAction Stop}|should not throw
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)