<commit_before>﻿#Thank you Warren http://ramblingcookiemonster.github.io/Testing-DSC-with-Pester-and-AppVeyor/

if (-not $PSScriptRoot) {
	$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
$Verbose = @{ }
if ($env:APPVEYOR_REPO_BRANCH -and $env:APPVEYOR_REPO_BRANCH -notlike "master") {
	$Verbose.add("Verbose", $True)
}

$scriptname = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.', '.')
$Name = $scriptname.Split('.')[0]

Describe 'Script Analyzer Tests' -Tags @('ScriptAnalyzer') {
	Context "Testing $Name for Standard Processing" {
		foreach ($rule in $ScriptAnalyzerRules) {
			$i = $ScriptAnalyzerRules.IndexOf($rule)
			It "passes the PSScriptAnalyzer Rule number $i - $rule  " {
				(Invoke-ScriptAnalyzer -Path "$PSScriptRoot\..\internal\$scriptname" -IncludeRule $rule.RuleName).Count | Should Be 0
			}
		}
	}
}

# Test functionality

Describe "Restore-DbaDatabase Integration Tests" -Tags "Integrationtests" {
	Context "Properly restores a database on the local drive using Path" {
		$results = Restore-DbaDatabase -SqlServer localhost -Path C:\github\appveyor-lab\singlerestore\singlerestore.bak
		It "Should Return the proper backup file location" {
			$results.BackupFile | Should Be "C:\github\appveyor-lab\singlerestore\singlerestore.bak"
		}
		It "Should return successful restore" {
			$results.RestoreComplete | Should Be $true
		}
	}

Context "Ensuring warning is thrown if database already exists" {
		$results = Restore-DbaDatabase -SqlServer localhost -Path C:\github\appveyor-lab\singlerestore\singlerestore.bak -WarningVariable warning
		It "Should warn" {
			$warning | Should Match "exists and will not be overwritten"
		}
		It "Should not return object" {
			$results | Should Be $null
		}
	}
	
	Context "Database is properly removed for next test" {
		$results = Remove-DbaDatabase -SqlInstance localhost -Database singlerestore
		It "Should say the status was dropped" {
			$results.Status | Should Be "Dropped"
		}
	}
	
	Context "Properly restores a database on the local drive using piped Get-ChildItem results" {
		$results = Get-ChildItem C:\github\appveyor-lab\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlServer localhost
		It "Should Return the proper backup file location" {
			$results.BackupFile | Should Be "C:\github\appveyor-lab\singlerestore\singlerestore.bak"
		}
		It "Should return successful restore" {
			$results.RestoreComplete | Should Be $true
		}
	}
	
	Context "Database is properly removed again" {
		$results = Remove-DbaDatabase -SqlInstance localhost -Database singlerestore
		It "Should say the status was dropped" {
			$results.Status | Should Be "Dropped"
		}
	}
}<commit_msg>added ola tests<commit_after>﻿#Thank you Warren http://ramblingcookiemonster.github.io/Testing-DSC-with-Pester-and-AppVeyor/

if (-not $PSScriptRoot) {
	$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
$Verbose = @{ }
if ($env:APPVEYOR_REPO_BRANCH -and $env:APPVEYOR_REPO_BRANCH -notlike "master") {
	$Verbose.add("Verbose", $True)
}

$scriptname = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.', '.')
$Name = $scriptname.Split('.')[0]

Describe 'Script Analyzer Tests' -Tags @('ScriptAnalyzer') {
	Context "Testing $Name for Standard Processing" {
		foreach ($rule in $ScriptAnalyzerRules) {
			$i = $ScriptAnalyzerRules.IndexOf($rule)
			It "passes the PSScriptAnalyzer Rule number $i - $rule  " {
				(Invoke-ScriptAnalyzer -Path "$PSScriptRoot\..\internal\$scriptname" -IncludeRule $rule.RuleName).Count | Should Be 0
			}
		}
	}
}

# Test functionality

Describe "Restore-DbaDatabase Integration Tests" -Tags "Integrationtests" {
	Context "Properly restores a database on the local drive using Path" {
		$results = Restore-DbaDatabase -SqlServer localhost -Path C:\github\appveyor-lab\singlerestore\singlerestore.bak
		It "Should Return the proper backup file location" {
			$results.BackupFile | Should Be "C:\github\appveyor-lab\singlerestore\singlerestore.bak"
		}
		It "Should return successful restore" {
			$results.RestoreComplete | Should Be $true
		}
	}

Context "Ensuring warning is thrown if database already exists" {
		$results = Restore-DbaDatabase -SqlServer localhost -Path C:\github\appveyor-lab\singlerestore\singlerestore.bak -WarningVariable warning
		It "Should warn" {
			$warning | Should Match "exists and will not be overwritten"
		}
		It "Should not return object" {
			$results | Should Be $null
		}
	}
	
	Context "Database is properly removed for next test" {
		$results = Remove-DbaDatabase -SqlInstance localhost -Database singlerestore
		It "Should say the status was dropped" {
			$results.Status | Should Be "Dropped"
		}
	}
	
	Context "Properly restores a database on the local drive using piped Get-ChildItem results" {
		$results = Get-ChildItem C:\github\appveyor-lab\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlServer localhost
		It "Should Return the proper backup file location" {
			$results.BackupFile | Should Be "C:\github\appveyor-lab\singlerestore\singlerestore.bak"
		}
		It "Should return successful restore" {
			$results.RestoreComplete | Should Be $true
		}
	}
	
	Context "Database is properly removed again" {
		$results = Remove-DbaDatabase -SqlInstance localhost -Database singlerestore
		It "Should say the status was dropped" {
			$results.Status | Should Be "Dropped"
		}
	}
	
	Context "Properly restores an instance using ola backups" {
		$results = Get-ChildItem C:\github\appveyor-lab\sql2008-backups | Restore-DbaDatabase -SqlServer localhost
		It "Restored files count should be right" {
			$results.databasename.count | Should Be 31
		}
		It "Should return successful restore" {
			$results.RestoreComplete | Should Be $true
		}
	}
	
	Context "All user databases are removed" {
		$results = Get-DbaDatabase -SqlInstance localhost -NoSystemDb | Remove-DbaDatabase
		It "Should say the status was dropped" {
			$results.Status | Should Be "Dropped"
		}
	}
}
{'fraction_non_alphanumeric': 0.10874307769760026, 'fraction_numerical': 0.0016781339150864238, 'mean_word_length': 4.265017667844523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2746593', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1873, 'n_words': 523}