$current_directory = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$current_directory\..\..\lib\Create-Site.ps1"
Describe "Create-Site New-item" {
$script:site_name = $null
$script:applicationPool = $null
$script:forced = $false
$website_name = "HelloWorld"
$app_pool = "HelloWorld"
$bindings_string = "http:*:80:helloworld.authoring"
Mock Get-Item -MockWith {
return $null
}
Mock Set-ItemProperty {}
Mock New-Website -MockWith {
Set-Variable -Name site_name -Value $Name -Scope script
Set-Variable -Name applicationPool -Value $ApplicationPool -Scope script
Set-Variable -Name forced -Value $force -Scope script
}
Create-Site $website_name $app_pool $app_path $bindings_string
It "Should Create A New Site when the Site does not exist" {
$site_name | Should Be "$website_name"
}
It "Should Create A New Site with the correct application pool" {
$applicationPool | Should Be "$app_pool"
}
It "Should Force the Website Creation without a physical path" {
$forced | Should Be $true
}
}
$current_directory = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$current_directory\..\..\lib\Create-Site.ps1"
Describe "Create-Site New-item" {
$website_name = "HelloWorld"
$app_pool = "HelloWorld"
$bindings_string = "http:*:80:helloworld.authoring"
Mock Get-Item -MockWith {
return $null
}
Mock Set-ItemProperty {}
It "Should Create A New Site when the Site does not exist" {
$script:site_name = $null
Mock New-Website -MockWith {
Set-Variable -Name site_name -Value $Name -Scope script
}
Create-Site $website_name $app_pool $app_path $bindings_string
$site_name | Should Be "$website_name"
}
It "Should Create A New Site with the correct application pool" {
$script:applicationPool = $null
Mock New-Website -MockWith {
Set-Variable -Name applicationPool -Value $ApplicationPool -Scope script
}
Create-Site $website_name $app_pool $app_path $bindings_string
$applicationPool | Should Be "$app_pool"
}
It "Should Force the Website Creation without a physical path" {
$script:forced = $false
Mock New-Website -MockWith {
Set-Variable -Name forced -Value $force -Scope script
}
Create-Site $website_name $app_pool $app_path $bindings_string
$forced | Should Be $true
}
}
$current_directory = Split-Path $script:MyInvocation.MyCommand.Path
$binding_builder_path = "$current_directory\Bindings-Builder.ps1"
function Create-Site($name,$applicationPool,$physicalPath, $bindings_string){
Import-Module WebAdministration
$site_path = "IIS:\Sites\$name"
$bindings_builder = Import-Module $binding_builder_path
$bindings = $bindings_builder.build($bindings_string)
$site = Get-Item $site_path -ErrorAction SilentlyContinue
if(!$site){
New-Website $name -applicationPool $applicationPool -force
}
Set-ItemProperty $site_path -name bindings -value $bindings
if($physicalPath){
Set-ItemProperty $site_path -name physicalPath -value $physicalPath
}
}