· 8 years ago · Feb 09, 2018, 01:54 PM
1#------------------------------------------------------------------------------------------------#
2# Script: PowerBuild.Tests.ps1 #
3# Author: Roy Kooiman, Gijs Reijn #
4# Keywords: Unit Testing, Powerbuild, Enza Zaden #
5# Comments: Pester module 4.0.0 or higher is necessary #
6# Contact: roytie67@hotmail.com #
7#------------------------------------------------------------------------------------------------#
8 Set-StrictMode -Version Latest
9 Import-Module Pester -Force
10
11 if(!(Get-Module Pester))
12 {
13 Write-Host "You don't have Pester installed, first run this Powershell environment in Adminstrator mode. Then run this script again" -ErrorAction Stop
14 }
15
16 if (!(Get-module Pester | Select {$_.Version -match "4" -or "5" -or "6" -or "7" -or "8" -or "9"})) #These high digits for making it future proof
17 {
18 Write-host "You have the Pester module but you don't have the correct version, you need to update the Pester module to continue. Updating..."
19 try
20 {
21 Install-Module pester -Force -Scope CurrentUser -SkipPublisherCheck
22 Write-Host "Updated Pester as you need Pester module version 4 or higher for some tests to pass"
23 }
24 catch
25 {
26 Write-Host "Couldn't update. It needs Admistrator rights" -ErrorAction Stop
27 }
28 }
29 else
30 {
31 Write-Host "You already have the right version of the Pester, continuing test"
32 }
33
34
35 #Setting files and folders
36
37 if (!(Test-Path "$env:HOMEDRIVE\Temp"))
38 {
39 Write-Host "Going to set the appropriate folder and/or files, either this test can't run"
40 Write-Host 'First we need to create the "Temp" folder'
41 try{
42 New-Item "$env:HOMEDRIVE\Temp" -ItemType Directory
43 }catch{
44 Write-Host "Stopping script... Couldn't set the appropriate files/folder(s):" $_.exception.message -ErrorAction Stop
45 }
46 Write-Host ""
47 Write-Host "Finished. Location is: $env:HOMEDRIVE\Temp" -ForegroundColor Green
48 }
49 else
50 {
51 Write-Host "The 'Temp' folder is already set on this computer, continuing test"
52 }
53
54
55 if (!(Test-Path "$env:HOMEDRIVE\Temp\UnitTestDir"))
56 {
57 Write-Host "U don't have the right folder structure and files to run this unit test, downloading..."
58 $URL = "www.dropbox.com/s/vjyex8vhzu8dm9e/UnitTestDir.zip?dl=1"
59 $Output = "$env:HOMEDRIVE\Temp\UnitTestDir.zip"
60 Invoke-WebRequest -Uri $URL -OutFile $Output
61 Write-Host "Finished downloading the appropriate file" -ForegroundColor Green
62 Write-Host "Unpacking zip and setting it at the right location..."
63
64 $ZipFile = "$env:HOMEDRIVE\Temp\UnitTestDir.zip"
65 $OutPath = "$env:HOMEDRIVE\Temp\"
66
67 try{
68 Expand-Archive $ZipFile -DestinationPath $OutPath
69 }catch{
70 Write-Host "Stopping script... Couldn't unpack the zip:" $_.exception.message -ErrorAction Stop
71 }
72
73 if(Test-Path "$env:HOMEDRIVE\Temp\UnitTestDir")
74 {
75 Write-Host "The right folder structure is set, starting Test..."
76 }
77 else
78 {
79 Write-Host "The right foldur structure isn't set. Stopping..." -ErrorAction Stop
80 }
81
82 if(Test-Path "$env:HOMEDRIVE\Temp\UnitTestDir.zip")
83 {
84 Remove-Item -Path "$env:HOMEDRIVE\Temp\UnitTestDir.zip"
85 }
86 else
87 {
88 Write-Host "Couldn't remove the 'UnitTestDir.zip'" $_.exception.message
89 }
90 }
91 else{
92 Write-Host "The appropriate files and/or folders are already set, starting Test..."
93 }
94#-----------------------------------------------------------------------------------------------------------------------------------------------#
95
96Describe "Execute-PowerBuild" {
97 It "Cannot test this one because I would need System Center Configuration Manager`
98 and most of the parameters won't work because I have no access to it.`
99 I also can't execute some of the cmdlets in this function because I would need some programs to run it.`
100 So that makes it pretty hard to test and reproduce."{
101 }
102}
103
104Describe "Get-ReleaseNotes" {
105 Context "Checks if the release notes are outputted to the temporary directory" {
106
107 It "Checks if the releasenote file exists and if its of type: .txt" {
108 $Item = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-ReleaseNotes\releasenotesfile.txt"
109 if (Test-Path $Item)
110 {
111 Remove-Item $Item
112 }
113 $Item = New-Item "$env:HOMEDRIVE\Temp\UnitTestDir\Get-ReleaseNotes\releasenotesfile.txt" -Type File
114 $Item | Should Exist
115 [IO.Path]::GetExtension($Item) | Should -MatchExactly '.txt'
116 }
117
118 It "Handles a comment" {
119 $script:OutputFile = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-ReleaseNotes\releasenotesfile.txt"
120 $Path = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-ReleaseNotes\UnitTest-Comment.xml"
121 [xml]$Script:Content = (Get-Content -Path $Path)
122 }
123
124 It "Checks if the property for Variable 'comment' are available" {
125 $Script:Comment = $Content.xml.PropertyGroup.Content.changes.change.comment
126 $Comment | Should -Not -BeNullOrEmpty
127 }
128
129 if ($Content.xml.PropertyGroup.Content.count -ge 1){
130 It "Checks if there is any comment found. If it is: it outputs it to the $OutputFile" {
131 if ([string]::IsNullOrEmpty($Comment))
132 {
133 $ReleaseNotesText = "" | Should -be $null
134 }
135 else
136 {
137 $Comment | Out-File $OutputFile -Append
138 $Outputfile | Should -FileContentMatch "Unit"
139 }
140 }
141
142 It "Searches for a pattern" {
143 #Couldn't use the full pattern: "^#\d+" here as it would give no result
144 $ReleaseNotesText = Get-Content -path $OutputFile -Raw | Select-String -Pattern "d"
145 $ReleaseNotesText | Should -Match "d"
146
147 if([string]::IsNullOrEmpty($ReleaseNotesText))
148 {
149 $ReleaseNotesText = "" | Should -BeNullOrEmpty
150 }
151 }
152 }
153 }
154}
155
156Describe "Get-ApplicationInfo" {
157 Context "Returns the build file location for a single project or a multi project based on the arguments which are provided by the parameters"{
158 param(
159 # [string][parameter(Mandatory=$true,HelpMessage='$env:HOMEDRIVE\Temp\UnitTestDir\Get-ApplicationInfo\App.Android')]$CheckOutDirectory,
160 # [string][parameter(Mandatory=$true)][ValidateSet("csproj","sln")]$SolutionOrProject,
161 # [string][parameter(Mandatory=$true,HelpMessage="iOS, Android or Windows")]$Flavor #Setting the 'Mandatory' True here either I couldn't test it. As normally you would run this function as a line. Also: maybe adding a validateset as flavors are mainly iOS,Android,Windows?
162 )
163
164 $CheckOutDirectory = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-ApplicationInfo\App.Android'
165 $SolutionOrProject = "sln" #or Project
166 $Flavor = "Android" #or iOS/Windows
167
168 It "Fetches the project extensions from the CheckOutDirectory" {
169 $Script:ProjectExtensions = Get-ChildItem ($CheckOutDirectory + '\*') -Include *.csproj, *.sln
170 $Script:ProjectExtensions | Should -Not -BeNullOrEmpty
171 $Script:ProjectExtensions.Extension | Should -Not -BeNullOrEmpty
172 }
173
174 It "Checks if count equals 2" {
175 #with the count of 2 it expects that it is a single application
176 if ($ProjectExtensions -eq 2)
177 {
178 $Script:CheckOutDirectory = $CheckOutDirectory
179 }
180 }
181
182 if ($ProjectExtensions -eq 2) {
183 It "Determines the Project File Location and the Solution File Location, Then it needs the build file location" {
184 #I've researched if its better to use Select-Object instead of Where-object, but Where-Object does the job best
185 $ProjectFileLocation = ($ProjectExtensions | Where-Object {$_.Name -like '*.csproj'}).FullName
186 $ProjectFileLocation | Should -Not -BeNullOrEmpty
187 $SolutionFileLocation = ($ProjectExtensions | Where-Object {$_.Name -like '*.sln'}).FullName
188 $SolutionFileLocation | Should -Not -BeNullOrEmpty
189
190 if ($SolutionOrProject -eq 'csproj') #Then the project file will be used as a build location
191 {
192 $BuildFileLocation = $ProjectFileLocation
193 $ProjectFileLocation | Should -Not -BeNullOrEmpty
194 }
195 elseif ($SolutionOrProject -eq 'sln') #The solution file will be used as a build location
196 {
197 $BuildFileLocation = $SolutionFileLocation
198 $SolutionFileLocation | Should -Not -BeNullOrEmpty
199 }
200 else #If it doesn't find anything
201 {
202 Throw "Validateset did not work"
203 }
204
205 Return $BuildFileLocation | Should -Not -BeNullOrEmpty
206 Return $Script:CheckOutDirectory | Should -Not -BeNullOrEmpty
207 }
208 }
209 else
210 {
211 It "Expects that the solution file is in the CheckOutDirectory, and checks if '`$Flavor' is empty"{
212 if (!($ProjectExtensions.Extension -eq '.sln'))
213 {
214 Throw "Solution file not found, but project file was. Was this a valid project?"
215 }
216 }
217
218 It "Sets the variables as sln file is found" {
219 $Script:DirectoryApplicationName = $ProjectExtensions[0].Name.Replace($ProjectExtensions[0].Extension,"")
220 $DirectoryApplicationName | Should -Not -BeNullOrEmpty
221 $Script:SolutionFileLocation = ($ProjectExtensions | Where-Object {$_.Name -like "*.sln"}) | Select-Object -ExpandProperty FullName
222 $SolutionFileLocation | Should -match ".sln"
223 }
224
225 It "It Creates a temporary directory variable to see if the folder structure is ok, because flavor is provided" {
226 #Can't use the $CheckOutDirectory here as I don't have the same folder structure as the Desktop where this function has been made on
227 #I will use a different variable to reproduce it at its best
228 if ([string]::IsNullOrEmpty($Flavor))
229 {
230 Throw "Parameter Flavor has not been set, It cannot determine from which project to get properties from"
231 }
232 $Script:TMPdir = Get-ChildItem "$CheckOutDirectory\$($DirectoryApplicationName + "." + $Flavor)"
233 }
234
235 It "Checks if the directory path is valid" {
236 if ($TMPdir.Count -eq 0 | Should -Not -BeNullOrEmpty)
237 {
238 Throw "Directory is invalid. Please review the folder structure"
239 }
240 }
241
242 It "It executes this block if the folder structure is ok" {
243 if ([string]::IsNullOrEmpty($Flavor))
244 {
245 Throw "Parameter Flavor has not been set, so can't continue script as it needs the Flavor."
246 }
247 $Script:CheckOutDirectory = "$CheckOutDirectory\$($DirectoryApplicationName + "." + $Flavor)"
248 $Script:FlavorConcat = "-" + " $Flavor"
249 $SolutionOrProjectFileLocation = (Get-ChildItem $Script:CheckOutDirectory | Where-Object {$_.Name -match ".$SolutionOrProject"}) | Select-Object -ExpandProperty FullName
250 $SolutionOrProjectFileLocation, $Script:CheckOutDirectory,$FlavorConcat | Should -Not -BeNullOrEmpty
251 }
252 }
253 }
254}
255
256
257Describe "Check-Environment" {
258 It "Checks if production is parsed through the main params"{
259
260 $Environment = "Production"
261 if ($Environment -eq "Production"){
262 [string]$Environment=""
263 Write-Host "Production was passed. Environment set to an empty string"
264 $Environment | Should -BeNullOrEmpty
265 }
266 }
267}
268
269Describe "Get-iOSCertificateInfo" {
270
271 It "Gets the certificate info for a iOS application and if changes are neccessary it sets the information" {
272 param(
273 #[string][parameter(Mandatory=$true,HelpMessage='$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSCertificateInfo_Put-iOSCertificateInfo\test.csproj')][ValidateNotNullOrEmpty()]$Path,
274 #[string][parameter(Mandatory=$true,HelpMessage='"iPhone" can be used here')]$Architecture,
275 #[string][parameter(Mandatory=$true,HelpMessage='"Release" or "Test" can be used here')]$Configuration
276 )
277
278 $Path = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-iOSCertificateInfo_Put-iOSCertificateInfo\test.csproj'
279 $Architecture = "iPhone"
280 $Configuration = "Release" #Or 'Test'
281
282 if((Get-ChildItem $Path).Extension -ne ".csproj")
283 {
284 Throw "Project file not provided"
285 }
286 $FirstConditionPart = '''($Configuration)|$(Platform)'''
287 $SecondConditionPart = ' == '
288 $LastConditionPart = "$Configuration|$Architecture"
289 $Condition = " $FirstConditionPart" + $SecondConditionPart + '''' + $LastConditionPart + '''' + " "
290 $Condition | Should -Not -BeNullOrEmpty
291
292 [xml]$ProjectFile = Get-Content $Path -Force
293 $ProjectFile | Should -Not -BeNullOrEmpty
294 }
295 #Can't test it further, as I can't fill in the appropriate parameters to continue this script
296}
297
298
299Describe "Put-iOSCertificateInfo" {
300
301 $Path = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-iOSCertificateInfo_Put-iOSCertificateInfo\xml.xml'
302 It "Saves a project file" {
303 [xml]$ProjectFile = ([xml](Get-content -path "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSCertificateInfo_Put-iOSCertificateInfo\Test.csproj"))
304 $ProjectFile.Save($Path)
305 $ProjectFile | Should -Not -BeNullOrEmpty
306 $Path | Should -Exist
307
308 }
309}
310
311
312Describe "Get-AndroidManifestInfo" {
313
314 It "Stores manifest info in a variable, and displays the current Android manifest values" {
315 [xml]$AndroidManifestXML = Get-content "$env:HOMEDRIVE\Temp\UnitTestDir\Get-AndroidManifestInfo_Set-AndroidManifestInfo\Package.appxmanifest" -ErrorAction Stop
316 $AndroidManifestXML | Should -Not -BeNullOrEmpty
317 $Return = $AndroidManifestXML.instrumentationManifest.instrumentation.events.provider.guid
318 $Return | should -Not -BeNullOrEmpty
319 }
320}
321
322Describe "Get-iOSManifestInfo" {
323
324 It "Stores iOS manifest info in a variable, and saves it" {
325 $XMLPath = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSManifestInfo_Set-iOSManifestInfo\log.plist"
326 $XMLPath | Should -Not -BeNullOrEmpty
327 $Path = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSManifestInfo_Set-iOSManifestInfo\log.xml"
328 $Path | Should -Not -BeNullOrEmpty
329 $iOSManifest = New-Object xml
330 $iOSManifest.PreserveWhitespace = $true
331 $iOSManifest.Load($XMLPath)
332 $iOSManifest.Save($Path)
333 $iOSManifest | should -Not -BeNullOrEmpty
334 }
335}
336
337Describe "Get-WindowsManifestInfo" {
338
339 It "Stores manifest info in a variable" {
340
341 $Path = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-WindowsManifestInfo_Set-WindowsManifestInfo\package.appxmanifest'
342
343 [xml]$WindowsManifestXML = Get-content $Path -ErrorAction Stop
344 $WindowsManifestXML | Should -Not -Be $null
345 }
346
347 It "Retrieves the current info in manifest"{
348
349 $Path = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-WindowsManifestInfo_Set-WindowsManifestInfo\package.appxmanifest'
350 [xml]$WindowsManifestXML = Get-content $Path -ErrorAction Stop
351 $Name = $WindowsManifestXML.instrumentationManifest.instrumentation.events.provider.name
352 $Name | Should -Not -BeNullOrEmpty
353 $Guid = $WindowsManifestXML.instrumentationManifest.instrumentation.events.provider.guid
354 $Guid | Should -Not -BeNullOrEmpty
355 $WindowsManifestXML | Should -Not -BeNullOrEmpty
356 }
357}
358
359Describe "Set-AndroidManifestInfo" {
360
361 It "Sets the current info in manifest" {
362
363 $Androidmanifest = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-AndroidManifestInfo_Set-AndroidManifestInfo\package.xml'
364 $Outpath = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-AndroidManifestInfo_Set-AndroidManifestInfo\Manifest.txt'
365 $ApplicationName = "String"
366 $Environment = "Production"
367
368 [xml]$AndroidManifestXML = Get-Content $AndroidManifest
369 [string]$AndroidManifestXML.instrumentationManifest.manifest.versionCode = ([int]$AndroidManifestXML.instrumentationManifest.manifest.versionCode) +1
370 [string]$BuildManifestNumber = $AndroidManifestXML.instrumentationManifest.manifest.versionName
371 $BuildManifestNumber | Should -Not -BeNullOrEmpty
372 $AndroidManifestXML | Should -Not -BeNullOrEmpty
373 if([string]::IsNullOrEmpty($Environment))
374 {
375 Write-Host "'$Environment' not set, Setting manifest package statically with value"
376 $AndroidManifestXML.instrumentationManifest.manifest.package = "com.$ApplicationName" + "." + "Production"
377 }
378 else
379 {
380 $Environment | Should -BeExactly "Production"
381 Write-Host "Setting manifest with values: $($ApplicationName + "." + $Environment)"
382 }
383 try{
384 $AndroidManifestXML.Save($Outpath)
385 }catch{
386 Write-Host "Saving manifest info failed"
387 }
388 }
389}
390
391Describe "Set-iOSManifestInfo" {
392
393 It "Sets the current manifest info in a specifed plist file" {
394
395 $iOSPlistXml = 'System.XmlDocument.XmlDocument'
396 [xml]$iOSPlistXml = Get-content -Path "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSManifestInfo_Set-iOSManifestInfo\log.xml"
397 $XMLPath = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSManifestInfo_Set-iOSManifestInfo\log.plist"
398 $iOSPlistXML.Save($XMLPath)
399 $iOSPlistXML | Should -Not -BeNullOrEmpty
400 }
401
402}
403
404Describe "Set-WindowsManifestInfo" {
405
406 It "Sets the current info in manifest" {
407
408 $ManifestXML = [xml](Get-Content "$env:HOMEDRIVE\Temp\UnitTestDir\Get-WindowsManifestInfo_Set-WindowsManifestInfo\Package.appxmanifest")
409 $CheckOutDirectory = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-WindowsManifestInfo_Set-WindowsManifestInfo\package.xml"
410 [string]$ApplicationName = "Test"
411 [string]$Environment = "Production"
412 [string]$BuildManifestNumber = "1"
413
414 $ManifestXML | Should -Not -BeNullOrEmpty
415 $ManifestXML.instrumentationManifest.manifest.label = $Environment # | Should -Not -BeNullOrEmpty
416 $Environment # | Should -Not -BeNullOrEmpty
417 $ManifestXML.instrumentationManifest.manifest.versionName = $ApplicationName # | Should -Not -BeNullOrEmpty
418 $ApplicationName # | Should -Not -BeNullOrEmpty
419 $ManifestXML.instrumentationManifest.manifest.versionCode = $BuildManifestNumber #| Should -Not -BeNullOrEmpty
420 $BuildManifestNumber #| Should -Not -BeNullOrEmpty
421
422 Try{
423 $ManifestXML.Save($CheckOutDirectory)
424 }Catch{
425 Throw $_.Exception.message
426 }
427 }
428}
429
430Describe "Get-OldApplications/Put-OldApplications/Get-SCCMApplication/Get-BuildInformation/Get-BuildResult" {
431
432 Context "Get-OldApplication"{
433 It "Does nothing: because this one can't be unit tested because I would need System Center Configuration Manager"{
434 }
435 }
436
437 Context "Put-OldApplication"{
438 It "Does nothing: because this one can't be unit tested because I would need System Center Configuration Manager" {
439 }
440 }
441
442 Context "Get-SCCMApplication"{
443 It "Does nothing: because this one can't be unit tested because I would need System Center Configuration Manager" {
444 }
445 }
446
447 Context "Get-BuildInformation"{
448 It "Does nothing: because I dont have a valid MSBuild to test against" {
449 }
450 }
451
452 Context "Get-BuildResult"{
453 It "Does nothing: because I dont have a valid MSBuild to test against, so there won't be a build result." {
454 }
455 }
456}
457
458Describe "Get-AndroidBuildOutput" {
459
460 It "Find a pattern of a log file" {
461 $BuildlogFileContent = Get-Content -Path "$env:HOMEDRIVE\Temp\UnitTestDir\Get-AndroidBuildOutput\build.log"
462 $Pattern = "Configuration:"
463 $Pattern | Should -MatchExactly "Configuration:"
464 $Buildlog = $BuildlogFileContent | Select-String -pattern $Pattern
465 $Buildlog | Should -Match $Pattern
466 }
467}
468
469Describe "Get-iOSBuildOutput" {
470
471 It "Checks if path and file exist" {
472 $Path = Test-Path "$env:HOMEDRIVE\Temp\UnitTestDir\Get-iOSBuildOutput\package.log"
473 $Path | Should -Be $true
474 }
475}
476
477Describe "BuildOutput and Dependencies" {
478
479 #the if statement is needed for It block #3 to run succesfully
480 try {
481 if (Test-Path "$env:HOMEDRIVE\Temp\UnitTestDir\Dependencies") {
482 Move-Item -Path "$env:HOMEDRIVE\Temp\UnitTestDir\Dependencies" -Destination "$env:HOMEDRIVE\Temp\UnitTestDir\Get-WindowsBuildOutput_Get-WindowsDependency_Put-WindowsDependency\"
483 }
484 }catch{
485 $_.exception.message
486 }
487
488 #I combined these 3 function in 1 describe block because of the scope
489 It "Function: Get-WindowsBuildOutput, Retrieves appx package from log and returns it" {
490
491 $Path = $env:HOMEDRIVE + '\Temp\UnitTestDir\Get-WindowsBuildOutput_Get-WindowsDependency_Put-WindowsDependency\build.log'
492
493 $BuildLogFileContent = Get-Content -Path $Path
494 [string]$MakeAppxBundleTargetString = $BuildLogFileContent | Select-String -Pattern "MakeAppx.exe pack".ToString().TrimStart("")
495 $SubstringAppx = $MakeAppxBundleTargetString.Substring($MakeAppxBundleTargetString.IndexOf("/p")+2).trimstart("")
496 $TaskIdString = $SubstringAppx.Substring($SubstringAppx.IndexOf(" "))
497 $script:AppxFileLocation = $SubstringAppx.trimend($TaskIdString)
498 $AppxFileLocation | Should -Not -BeNullOrEmpty
499 }
500
501 #I think this a weird function
502 It "Function: Get-WindowsDependency, Gets the dependencies folder and returns it" {
503 [array]$AppxSplit = $AppxFileLocation.Split("\")
504 [string]$AppxName = $AppxSplit -match ".appx"
505 [string]$DependenciesFolder = $AppxFileLocation.TrimEnd("$AppxName") + 'Dependencies\Test'
506 $DependenciesFolder | Should -Not -BeNullOrEmpty
507 }
508
509 #Changed the $DependenciesFolder variable either I couldn't test it properly
510 It "Function: Put-WindowsDependency, Moves the dependencies to the right location" {
511 $DependenciesFolder = "$env:HOMEDRIVE\Temp\UnitTestDir\Get-WindowsBuildOutput_Get-WindowsDependency_Put-WindowsDependency\Dependencies\"
512 $SCCMFileShareDestination = "$env:HOMEDRIVE\Temp\UnitTestDir\Dependencies"
513 $Move = Move-Item -Path $DependenciesFolder -Destination $SCCMFileShareDestination -PassThru -ErrorAction Stop
514 $Move | Should -Not -Be $Null
515 }
516}
517
518Describe "Set-AndroidBuildOutput/Set-WindowsBuildOutput" {
519
520 Context "Set-AndroidBuildOutput"{
521 It "Does nothing: I cannot unit test this one because I can't 'Sign' and/or 'ZipAlign' an application" {
522 }
523 }
524
525 Context "Set-WindowsBuildOutput"{
526 It "Does nothing: I cannot unit test this one because I can't 'Sign' an application" {
527 }
528 }
529}
530
531Describe "Put-BuildOutput" {
532
533 It "Creates a new folder" {
534 $SCCMFileShareDestination = "$env:HOMEDRIVE\Temp\UnitTestDir\SCCMFileShareDestination"
535 $Name = 'Put-BuildOutput'
536 $Script:FileDestination = New-Item -path $SCCMFileShareDestination -Name $Name -ItemType 'directory' -ErrorAction Stop
537 $Script:FileDestination | Should -Be $true
538 }
539
540 if (Test-Path -path "$env:HOMEDRIVE\Temp\UnitTestDir\Put-BuildOutput\test.test")
541 {
542 }
543 else{
544 New-Item -Path "$env:HOMEDRIVE\Temp\UnitTestDir\Put-BuildOutput\" -Name 'Test.Test'
545 }
546
547 It "Moves the item and clean the packagelocation instead of copying it"{
548 $SCCMFileShareDestination = "$env:HOMEDRIVE\Temp\UnitTestDir\SCCMFileShareDestination"
549 $Path = "$env:HOMEDRIVE\Temp\UnitTestDir\Put-BuildOutput\test.test"
550 $Move = Move-Item -Path $Path -Destination $SCCMFileShareDestination -PassThru -ErrorAction Stop
551 $Move | Should -Not -Be $Null
552 if (Test-Path -path "$env:HOMEDRIVE\Temp\UnitTestDir\SCCMFileShareDestination") {
553 Remove-Item -Path "$env:HOMEDRIVE\Temp\UnitTestDir\SCCMFileShareDestination" -Recurse
554 }
555 }
556}
557
558Describe "Get-ApplicationTypeInfo" {
559
560 It "Puts the application type info in a hash table" {
561
562 $ApplicationName = "String"
563 $LocalizedDisplayName = "String"
564 [int]$Version = "1"
565 $PublisherDisplayName = "String"
566
567 [array]$ApplicationPropHash = @{Name = $ApplicationName;LocalizedDisplayname = $LocalizedDisplayName;Version = $Version;Publisher = $PublisherDisplayName}
568 $ApplicationPropHash | Should -Not -BeNullOrEmpty
569 }
570}
571
572Describe "Get-DeploymentTypeInfo" {
573
574 #Removed the 'Test-path -Pathtype Leaf $_' line as it was giving weird results.
575 It "Puts the deployment type info in a hash table" {
576
577 $Contentlocation = $env:HOMEDRIVE
578 $ApplicationName = "String"
579 $DeploymentTypeName = "String"
580
581 [array]$DeploymentTypePropHash = @{ContentLocation = $ContentLocation;DeploymentTypeName = ($ApplicationName + " - $DeploymentTypeName");}
582 $DeploymentTypePropHash | Should -Not -BeNullOrEmpty
583 }
584}
585
586Describe "Put-CMApplication/Put-CMDeploymentType/Put-CMMoveApplication/Auto-DeployCMApplication" {
587
588 Context "Put-CMApplication"{
589 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
590 }
591 }
592
593 Context "Put-CMDeploymentType"{
594 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
595 }
596 }
597
598 Context "Put-CMMoveApplication"{
599 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
600 }
601 }
602
603 Context "Auto-DeployCMApplication"{
604 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
605 }
606 }
607}
608
609Describe "Get-WindowsUnitTestProject" {
610
611 It "Retrieves the unit test project file in the current sources"{
612
613 $CheckoutDirectory = $env:HOMEDRIVE + '\Temp\UnitTestDir'
614 $UnitTestFolderName = 'Get-WindowsUnitTestProject_Get-SCCMIconFile'
615
616 $ProjectFileLocation = (Get-ChildItem ("$CheckOutDirectory\"+ "$UnitTestFolderName\") | Where-Object {$_.Extension -eq '.csproj'}).FullName
617 $ProjectFileLocation[0] | Should -MatchExactly "unittest.csproj"
618 [xml]$ProjectFile = Get-Content $ProjectFileLocation -ErrorAction Stop
619 $ProjectFile.Project.ToolsVersion | Should -Be "14.0"
620 }
621}
622
623Describe "Put-WindowsUnitTestProject" {
624
625 Context "Put-WindowsUnitTestProject"{
626 It "Does nothing: Because I can't call the 'VSConsole.exe'." {
627 }
628 }
629
630 Context "Get-JarSignLocation"{
631 It "Does nothing: As I don't have a jarsigner I also can't retrieve it." {
632 }
633 }
634
635 Context "Get-ZipAlignLocation"{
636 It "Does nothing: As I don't have a ZipAlign location I also can't retrieve it." {
637 }
638 }
639
640 Context "Get-WinSDKSignTool"{
641 It "Does nothing: As I don't have access to Windows SDK Tool" {
642 }
643 }
644
645 Context "Check-CMObject"{
646 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
647 }
648 }
649
650 Context "Create-WindowsRequirementRule"{
651 It "Does nothing: this one can't be unit tested because I would need System Center 2012 R2" {
652 }
653 }
654
655 Context "Determine-VSTestConsole"{
656 It "Does nothing: I can't access the VSTest.Console.exe" {
657 }
658 }
659}
660
661Describe "Get-SCCMIconFile" {
662
663 #Although this one needs the SCCM I can still reproduce its code
664
665 It "Retrieves the icon file location and loops through the PNG pictures looking for 50x50 pictures" {
666 $CheckoutDirectory = $env:HOMEDRIVE + '\Temp\UnitTestDir'
667 $AssetFolderLocation = 'Get-WindowsUnitTestProject_Get-SCCMIconFile'
668
669 Add-Type -AssemblyName System.Drawing -ErrorAction Stop
670 $PNGPictures = (Get-ChildItem "$CheckoutDirectory\$AssetFolderLocation" -Filter *.png -ErrorAction Stop).FullName
671 $PNGPictures | Should not BeNullOrEmpty
672
673 $PNGPictures | ForEach-Object{
674 $Img = [System.Drawing.Image]::FromFile($_)
675 $Img | Should Not BeNullOrEmpty
676 $Dimensions = "$($Img.Width) x $($Img.Height)"
677 $50x50Picture = $_
678 $Dimensions | Should -Match "50 x 50"
679 return $50x50Picture;
680 }
681 }
682}