$currentScriptLocation = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module -Force (Join-Path $currentScriptLocation '..\..\modules\FnmsEnvironment.psm1')


Describe "Server type checks" {
	Context "When a single component is installed" {

		Mock -ModuleName FnmsEnvironment Get-InstalledComponents { return @('PresentationServer') }


		It "Returns true for the installed component" {
			Test-InstalledComponent 'PresentationServer' | Should Be $true
		}

		It "Passes assertions for the installed component" {
			{ Assert-InstalledComponent 'PresentationServer' } | Should Not Throw
		}

		It "Returns false for other components" {
			Test-InstalledComponent 'BatchServer' | Should Be $false
			Test-InstalledComponent 'InventoryServer' | Should Be $false
		}

		It "Fails assertions when the component is not installed" {
			{ Assert-InstalledComponent 'BatchServer' } | Should Throw
			{ Assert-InstalledComponent 'InventoryServer' } | Should Throw
		}
	}

	Context "When the server type is has multiple values" {

		Mock -ModuleName FnmsEnvironment Get-InstalledComponents { return @('PresentationServer', 'BatchServer') }

		It "Returns true if the component is installed" {
			Test-InstalledComponent 'PresentationServer' | Should Be $true
			Test-InstalledComponent 'BatchServer' | Should Be $true
		}

		It "Passes assertions for the installed components" {
			{ Assert-InstalledComponent 'PresentationServer' } | Should Not Throw
			{ Assert-InstalledComponent 'BatchServer' } | Should Not Throw
		}

		It "Returns false when it is not" {
			Test-InstalledComponent 'InventoryServer' | Should Be $false
		}

		It "Fails assertions when the component is not installed" {
			{ Assert-InstalledComponent 'InventoryServer' } | Should Throw
		}
	}
}