From fca3e164e113dd94bf855619736dea5c6e862825 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Thu, 17 Oct 2024 13:33:58 +0200 Subject: [PATCH] global var required by new scopes --- tests/Add-DbaAgDatabase.Tests.ps1 | 14 +- tests/Add-DbaAgListener.Tests.ps1 | 8 +- tests/Add-DbaAgReplica.Tests.ps1 | 18 +- tests/Add-DbaComputerCertificate.Tests.ps1 | 4 +- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 16 +- tests/Add-DbaDbRoleMember.Tests.ps1 | 30 +-- tests/Add-DbaExtendedProperty.Tests.ps1 | 4 +- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 4 +- tests/Add-DbaRegServer.Tests.ps1 | 10 +- tests/Add-DbaRegServerGroup.Tests.ps1 | 20 +- tests/Add-DbaReplArticle.Tests.ps1 | 2 +- tests/Add-DbaServerRoleMember.Tests.ps1 | 20 +- tests/Backup-DbaComputerCertificate.Tests.ps1 | 6 +- tests/Backup-DbaDatabase.Tests.ps1 | 192 +++++++++--------- tests/Backup-DbaDbCertificate.Tests.ps1 | 24 +-- tests/Backup-DbaDbMasterKey.Tests.ps1 | 2 +- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 2 +- tests/Clear-DbaLatchStatistics.Tests.ps1 | 12 +- tests/Clear-DbaPlanCache.Tests.ps1 | 4 +- tests/Clear-DbaWaitStatistics.Tests.ps1 | 12 +- tests/Connect-DbaInstance.Tests.ps1 | 56 ++--- tests/ConvertTo-DbaXESession.Tests.ps1 | 16 +- tests/Copy-DbaAgentAlert.Tests.ps1 | 20 +- tests/Copy-DbaAgentJob.Tests.ps1 | 24 +-- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 12 +- tests/Copy-DbaAgentOperator.Tests.ps1 | 14 +- tests/Copy-DbaAgentProxy.Tests.ps1 | 21 +- tests/Copy-DbaAgentSchedule.Tests.ps1 | 10 +- tests/Copy-DbaBackupDevice.Tests.ps1 | 16 +- tests/Copy-DbaCredential.Tests.ps1 | 18 +- tests/Copy-DbaCustomError.Tests.ps1 | 16 +- tests/Copy-DbaDatabase.Tests.ps1 | 126 ++++++------ tests/Copy-DbaDbAssembly.Tests.ps1 | 28 +-- tests/Copy-DbaDbCertificate.Tests.ps1 | 22 +- tests/Copy-DbaDbMail.Tests.ps1 | 42 ++-- tests/Copy-DbaDbQueryStoreOption.Tests.ps1 | 6 +- tests/Copy-DbaDbTableData.Tests.ps1 | 26 +-- tests/Copy-DbaDbViewData.Tests.ps1 | 58 +++--- tests/Copy-DbaEndpoint.Tests.ps1 | 22 +- tests/Copy-DbaInstanceAudit.Tests.ps1 | 4 +- tests/Copy-DbaInstanceTrigger.Tests.ps1 | 6 +- tests/Copy-DbaLinkedServer.Tests.ps1 | 14 +- tests/Copy-DbaLogin.Tests.ps1 | 72 +++---- tests/Copy-DbaPolicyManagement.Tests.ps1 | 4 +- tests/Copy-DbaRegServer.Tests.ps1 | 6 +- tests/Copy-DbaResourceGovernor.Tests.ps1 | 14 +- tests/Copy-DbaSpConfigure.Tests.ps1 | 22 +- tests/Copy-DbaStartupProcedure.Tests.ps1 | 10 +- tests/Copy-DbaSystemDbUserObject.Tests.ps1 | 18 +- tests/Copy-DbaXESession.Tests.ps1 | 4 +- tests/Disable-DbaAgHadr.Tests.ps1 | 6 +- tests/Disable-DbaDbEncryption.Tests.ps1 | 16 +- tests/Disable-DbaFilestream.Tests.ps1 | 10 +- ...isable-DbaForceNetworkEncryption.Tests.ps1 | 4 +- tests/Disable-DbaHideInstance.Tests.ps1 | 4 +- tests/Disable-DbaReplDistributor.Tests.ps1 | 4 +- tests/Disable-DbaReplPublishing.Tests.ps1 | 4 +- tests/Disable-DbaStartupProcedure.Tests.ps1 | 12 +- tests/Disable-DbaTraceFlag.Tests.ps1 | 4 +- tests/Disconnect-DbaInstance.Tests.ps1 | 2 +- tests/Dismount-DbaDatabase.Tests.ps1 | 50 ++--- tests/Enable-DbaAgHadr.Tests.ps1 | 8 +- tests/Enable-DbaDbEncryption.Tests.ps1 | 22 +- tests/Enable-DbaFilestream.Tests.ps1 | 10 +- ...Enable-DbaForceNetworkEncryption.Tests.ps1 | 4 +- tests/Enable-DbaHideInstance.Tests.ps1 | 4 +- tests/Enable-DbaReplPublishing.Tests.ps1 | 10 +- tests/Enable-DbaStartupProcedure.Tests.ps1 | 12 +- tests/Enable-DbaTraceFlag.Tests.ps1 | 6 +- tests/Expand-DbaDbLogFile.Tests.ps1 | 12 +- tests/Export-DbaBinaryFile.Tests.ps1 | 12 +- tests/Export-DbaCredential.Tests.ps1 | 14 +- tests/Export-DbaDacPackage.Tests.ps1 | 40 ++-- tests/Export-DbaDbRole.Tests.ps1 | 38 ++-- tests/Export-DbaDbTableData.Tests.ps1 | 8 +- tests/Export-DbaDiagnosticQuery.Tests.ps1 | 2 +- tests/Export-DbaExecutionPlan.Tests.ps1 | 2 +- tests/Export-DbaInstance.Tests.ps1 | 14 +- tests/Export-DbaLogin.Tests.ps1 | 56 ++--- ...rt-DbaPfDataCollectorSetTemplate.Tests.ps1 | 4 +- tests/Export-DbaRegServer.Tests.ps1 | 44 ++-- tests/Export-DbaScript.Tests.ps1 | 16 +- tests/Export-DbaServerRole.Tests.ps1 | 40 ++-- tests/Export-DbaSpConfigure.Tests.ps1 | 2 +- tests/Export-DbaSysDbUserObject.Tests.ps1 | 18 +- tests/Export-DbaUser.Tests.ps1 | 48 ++--- tests/Export-DbaXECsv.Tests.ps1 | 2 +- tests/Export-DbaXESession.Tests.ps1 | 16 +- tests/Export-DbaXESessionTemplate.Tests.ps1 | 6 +- tests/Export-DbatoolsConfig.Tests.ps1 | 8 +- tests/Find-DbaAgentJob.Tests.ps1 | 46 ++--- tests/Find-DbaCommand.Tests.ps1 | 8 +- tests/Find-DbaDatabase.Tests.ps1 | 18 +- tests/Find-DbaDbDisabledIndex.Tests.ps1 | 14 +- tests/Find-DbaDbDuplicateIndex.Tests.ps1 | 10 +- tests/Find-DbaDbGrowthEvent.Tests.ps1 | 6 +- tests/Find-DbaDbUnusedIndex.Tests.ps1 | 14 +- tests/Find-DbaInstance.Tests.ps1 | 4 +- tests/Find-DbaLoginInGroup.Tests.ps1 | 8 +- tests/Find-DbaOrphanedFile.Tests.ps1 | 32 +-- tests/Find-DbaSimilarTable.Tests.ps1 | 4 +- tests/Find-DbaStoredProcedure.Tests.ps1 | 22 +- tests/Find-DbaTrigger.Tests.ps1 | 30 +-- tests/Find-DbaUserObject.Tests.ps1 | 12 +- tests/Find-DbaView.Tests.ps1 | 24 +-- tests/Get-DbaAgDatabase.Tests.ps1 | 16 +- tests/Get-DbaAgHadr.Tests.ps1 | 6 +- tests/Get-DbaAgListener.Tests.ps1 | 10 +- tests/Get-DbaAgReplica.Tests.ps1 | 12 +- tests/Get-DbaAgentAlert.Tests.ps1 | 10 +- tests/Get-DbaAgentAlertCategory.Tests.ps1 | 10 +- tests/Get-DbaAgentJob.Tests.ps1 | 72 +++---- tests/Get-DbaAgentJobCategory.Tests.ps1 | 12 +- tests/Get-DbaAgentJobHistory.Tests.ps1 | 6 +- tests/Get-DbaAgentJobOutputFile.Tests.ps1 | 2 +- tests/Get-DbaAgentJobStep.Tests.ps1 | 16 +- tests/Get-DbaAgentLog.Tests.ps1 | 6 +- tests/Get-DbaAgentOperator.Tests.ps1 | 8 +- tests/Get-DbaAgentProxy.Tests.ps1 | 18 +- tests/Get-DbaAgentSchedule.Tests.ps1 | 84 ++++---- tests/Get-DbaAgentServer.Tests.ps1 | 8 +- tests/Get-DbaAvailabilityGroup.Tests.ps1 | 14 +- tests/Get-DbaAvailableCollation.Tests.ps1 | 4 +- tests/Get-DbaBackupDevice.Tests.ps1 | 6 +- tests/Get-DbaBackupInformation.Tests.ps1 | 58 +++--- tests/Get-DbaBinaryFileTable.Tests.ps1 | 12 +- tests/Get-DbaBuild.Tests.ps1 | 12 +- tests/Get-DbaClientProtocol.Tests.ps1 | 2 +- tests/Get-DbaCmObject.Tests.ps1 | 12 +- tests/Get-DbaComputerCertificate.Tests.ps1 | 2 +- tests/Get-DbaComputerSystem.Tests.ps1 | 2 +- tests/Get-DbaConnectedInstance.Tests.ps1 | 2 +- tests/Get-DbaConnection.Tests.ps1 | 2 +- tests/Get-DbaCpuRingBuffer.Tests.ps1 | 4 +- tests/Get-DbaCpuUsage.Tests.ps1 | 4 +- tests/Get-DbaCredential.Tests.ps1 | 20 +- tests/Get-DbaCustomError.Tests.ps1 | 6 +- tests/Get-DbaDBFileGroup.Tests.ps1 | 16 +- tests/Get-DbaDatabase.Tests.ps1 | 16 +- tests/Get-DbaDbAssembly.Tests.ps1 | 6 +- tests/Get-DbaDbAsymmetricKey.Tests.ps1 | 20 +- tests/Get-DbaDbBackupHistory.Tests.ps1 | 42 ++-- tests/Get-DbaDbCertificate.Tests.ps1 | 22 +- tests/Get-DbaDbCheckConstraint.Tests.ps1 | 18 +- tests/Get-DbaDbCompatibility.Tests.ps1 | 12 +- tests/Get-DbaDbCompression.Tests.ps1 | 14 +- tests/Get-DbaDbDbccOpenTran.Tests.ps1 | 8 +- tests/Get-DbaDbDetachedFileInfo.Tests.ps1 | 20 +- tests/Get-DbaDbEncryption.Tests.ps1 | 6 +- tests/Get-DbaDbEncryptionKey.Tests.ps1 | 14 +- tests/Get-DbaDbExtentDiff.Tests.ps1 | 10 +- tests/Get-DbaDbFeatureUsage.Tests.ps1 | 10 +- tests/Get-DbaDbFile.Tests.ps1 | 16 +- tests/Get-DbaDbFileGrowth.Tests.ps1 | 4 +- tests/Get-DbaDbFileMapping.Tests.ps1 | 12 +- tests/Get-DbaDbForeignKey.Tests.ps1 | 18 +- tests/Get-DbaDbIdentity.Tests.ps1 | 6 +- tests/Get-DbaDbLogShipError.Tests.ps1 | 8 +- tests/Get-DbaDbLogSpace.Tests.ps1 | 14 +- tests/Get-DbaDbMail.Tests.ps1 | 4 +- tests/Get-DbaDbMailAccount.Tests.ps1 | 10 +- tests/Get-DbaDbMailConfig.Tests.ps1 | 6 +- tests/Get-DbaDbMailHistory.Tests.ps1 | 10 +- tests/Get-DbaDbMailLog.Tests.ps1 | 10 +- tests/Get-DbaDbMailProfile.Tests.ps1 | 20 +- tests/Get-DbaDbMailServer.Tests.ps1 | 14 +- tests/Get-DbaDbMasterKey.Tests.ps1 | 16 +- tests/Get-DbaDbMemoryUsage.Tests.ps1 | 6 +- tests/Get-DbaDbMirror.Tests.ps1 | 22 +- tests/Get-DbaDbMirrorMonitor.Tests.ps1 | 4 +- tests/Get-DbaDbObjectTrigger.Tests.ps1 | 30 +-- tests/Get-DbaDbOrphanUser.Tests.ps1 | 10 +- tests/Get-DbaDbPageInfo.Tests.ps1 | 8 +- tests/Get-DbaDbPartitionFunction.Tests.ps1 | 16 +- tests/Get-DbaDbPartitionScheme.Tests.ps1 | 20 +- tests/Get-DbaDbQueryStoreOption.Tests.ps1 | 14 +- tests/Get-DbaDbRecoveryModel.Tests.ps1 | 14 +- tests/Get-DbaDbRestoreHistory.Tests.ps1 | 36 ++-- tests/Get-DbaDbRole.Tests.ps1 | 6 +- tests/Get-DbaDbRoleMember.Tests.ps1 | 2 +- tests/Get-DbaDbSchema.Tests.ps1 | 4 +- tests/Get-DbaDbSequence.Tests.ps1 | 4 +- tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 | 8 +- tests/Get-DbaDbServiceBrokerService.Tests.ps1 | 8 +- tests/Get-DbaDbSharePoint.Tests.ps1 | 14 +- tests/Get-DbaDbSnapshot.Tests.ps1 | 36 ++-- tests/Get-DbaDbSpace.Tests.ps1 | 10 +- tests/Get-DbaDbState.Tests.ps1 | 62 +++--- tests/Get-DbaDbStoredProcedure.Tests.ps1 | 26 +-- tests/Get-DbaDbSynonym.Tests.ps1 | 36 ++-- tests/Get-DbaDbTable.Tests.ps1 | 18 +- tests/Get-DbaDbTrigger.Tests.ps1 | 12 +- tests/Get-DbaDbUdf.Tests.ps1 | 10 +- tests/Get-DbaDbUser.Tests.ps1 | 22 +- tests/Get-DbaDbUserDefinedTableType.Tests.ps1 | 8 +- tests/Get-DbaDbView.Tests.ps1 | 20 +- tests/Get-DbaDbVirtualLogFile.Tests.ps1 | 8 +- tests/Get-DbaDbccHelp.Tests.ps1 | 6 +- tests/Get-DbaDbccMemoryStatus.Tests.ps1 | 4 +- tests/Get-DbaDbccProcCache.Tests.ps1 | 8 +- tests/Get-DbaDbccSessionBuffer.Tests.ps1 | 14 +- tests/Get-DbaDbccStatistic.Tests.ps1 | 20 +- tests/Get-DbaDbccUserOption.Tests.ps1 | 4 +- tests/Get-DbaDefaultPath.Tests.ps1 | 4 +- tests/Get-DbaDependency.Tests.ps1 | 18 +- tests/Get-DbaDeprecatedFeature.Tests.ps1 | 2 +- tests/Get-DbaDump.Tests.ps1 | 6 +- tests/Get-DbaEndpoint.Tests.ps1 | 8 +- tests/Get-DbaErrorLog.Tests.ps1 | 36 ++-- tests/Get-DbaErrorLogConfig.Tests.ps1 | 8 +- .../Get-DbaEstimatedCompletionTime.Tests.ps1 | 14 +- tests/Get-DbaExecutionPlan.Tests.ps1 | 18 +- tests/Get-DbaExtendedProperty.Tests.ps1 | 4 +- tests/Get-DbaExtendedProtection.Tests.ps1 | 12 +- tests/Get-DbaExternalProcess.Tests.ps1 | 6 +- tests/Get-DbaFeature.Tests.ps1 | 2 +- tests/Get-DbaFile.Tests.ps1 | 12 +- tests/Get-DbaFilestream.Tests.ps1 | 2 +- tests/Get-DbaFirewallRule.Tests.ps1 | 6 +- tests/Get-DbaForceNetworkEncryption.Tests.ps1 | 4 +- tests/Get-DbaHelpIndex.Tests.ps1 | 16 +- tests/Get-DbaHideInstance.Tests.ps1 | 8 +- tests/Get-DbaInstalledPatch.Tests.ps1 | 2 +- tests/Get-DbaInstanceAudit.Tests.ps1 | 8 +- ...et-DbaInstanceAuditSpecification.Tests.ps1 | 6 +- tests/Get-DbaInstanceInstallDate.Tests.ps1 | 8 +- tests/Get-DbaInstanceProperty.Tests.ps1 | 10 +- tests/Get-DbaInstanceProtocol.Tests.ps1 | 2 +- tests/Get-DbaInstanceTrigger.Tests.ps1 | 10 +- tests/Get-DbaInstanceUserOption.Tests.ps1 | 4 +- tests/Get-DbaIoLatency.Tests.ps1 | 8 +- tests/Get-DbaKbUpdate.Tests.ps1 | 8 +- tests/Get-DbaLastBackup.Tests.ps1 | 34 ++-- tests/Get-DbaLastGoodCheckDb.Tests.ps1 | 28 +-- tests/Get-DbaLatchStatistic.Tests.ps1 | 4 +- tests/Get-DbaLinkedServer.Tests.ps1 | 20 +- tests/Get-DbaLinkedServerLogin.Tests.ps1 | 6 +- tests/Get-DbaLogin.Tests.ps1 | 54 ++--- tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 | 6 +- tests/Get-DbaManagementObject.Tests.ps1 | 2 +- tests/Get-DbaMaxMemory.Tests.ps1 | 6 +- tests/Get-DbaMemoryCondition.Tests.ps1 | 8 +- tests/Get-DbaMemoryUsage.Tests.ps1 | 6 +- tests/Get-DbaModule.Tests.ps1 | 12 +- tests/Get-DbaMsdtc.Tests.ps1 | 2 +- tests/Get-DbaNetworkCertificate.Tests.ps1 | 6 +- tests/Get-DbaNetworkConfiguration.Tests.ps1 | 6 +- tests/Get-DbaOleDbProvider.Tests.ps1 | 2 +- tests/Get-DbaOpenTransaction.Tests.ps1 | 8 +- tests/Get-DbaOperatingSystem.Tests.ps1 | 4 +- tests/Get-DbaPbmCategory.Tests.ps1 | 10 +- tests/Get-DbaPbmCondition.Tests.ps1 | 10 +- tests/Get-DbaPbmObjectSet.Tests.ps1 | 2 +- tests/Get-DbaPbmPolicy.Tests.ps1 | 12 +- tests/Get-DbaPbmStore.Tests.ps1 | 6 +- tests/Get-DbaPermission.Tests.ps1 | 2 +- tests/Get-DbaPfAvailableCounter.Tests.ps1 | 2 +- tests/Get-DbaPfDataCollector.Tests.ps1 | 2 +- tests/Get-DbaPfDataCollectorCounter.Tests.ps1 | 2 +- ...-DbaPfDataCollectorCounterSample.Tests.ps1 | 6 +- ...et-DbaPfDataCollectorSetTemplate.Tests.ps1 | 4 +- tests/Get-DbaPlanCache.Tests.ps1 | 10 +- tests/Get-DbaPowerPlan.Tests.ps1 | 4 +- tests/Get-DbaProcess.Tests.ps1 | 6 +- tests/Get-DbaQueryExecutionTime.Tests.ps1 | 2 +- tests/Get-DbaRandomizedDataset.Tests.ps1 | 2 +- tests/Get-DbaRandomizedValue.Tests.ps1 | 4 +- tests/Get-DbaRegServer.Tests.ps1 | 14 +- tests/Get-DbaRegServerGroup.Tests.ps1 | 18 +- tests/Get-DbaRegServerStore.Tests.ps1 | 4 +- tests/Get-DbaReplDistributor.Tests.ps1 | 8 +- tests/Get-DbaReplPublication.Tests.ps1 | 2 +- tests/Get-DbaReplPublisher.Tests.ps1 | 6 +- tests/Get-DbaReplServer.Tests.ps1 | 6 +- tests/Get-DbaReplSubscription.Tests.ps1 | 2 +- tests/Get-DbaResourceGovernor.Tests.ps1 | 6 +- tests/Get-DbaRgClassifierFunction.Tests.ps1 | 12 +- tests/Get-DbaRgResourcePool.Tests.ps1 | 6 +- tests/Get-DbaRgWorkloadGroup.Tests.ps1 | 4 +- tests/Get-DbaRunningJob.Tests.ps1 | 2 +- tests/Get-DbaSchemaChangeHistory.Tests.ps1 | 4 +- tests/Get-DbaServerRole.Tests.ps1 | 12 +- tests/Get-DbaServerRoleMember.Tests.ps1 | 4 +- tests/Get-DbaService.Tests.ps1 | 18 +- tests/Get-DbaSpConfigure.Tests.ps1 | 12 +- tests/Get-DbaSpinLockStatistic.Tests.ps1 | 8 +- tests/Get-DbaSpn.Tests.ps1 | 10 +- .../Get-DbaSsisEnvironmentVariable.Tests.ps1 | 2 +- tests/Get-DbaSsisExecutionHistory.Tests.ps1 | 2 +- tests/Get-DbaStartupParameter.Tests.ps1 | 14 +- tests/Get-DbaStartupProcedure.Tests.ps1 | 10 +- tests/Get-DbaSuspectPage.Tests.ps1 | 8 +- tests/Get-DbaTcpPort.Tests.ps1 | 12 +- tests/Get-DbaTempdbUsage.Tests.ps1 | 6 +- tests/Get-DbaTrace.Tests.ps1 | 6 +- tests/Get-DbaTraceFlag.Tests.ps1 | 8 +- tests/Get-DbaUpTime.Tests.ps1 | 8 +- tests/Get-DbaUserPermission.Tests.ps1 | 14 +- tests/Get-DbaWaitResource.Tests.ps1 | 20 +- tests/Get-DbaWaitStatistic.Tests.ps1 | 8 +- tests/Get-DbaWaitingTask.Tests.ps1 | 2 +- tests/Get-DbaWindowsLog.Tests.ps1 | 4 +- tests/Get-DbaWsfcCluster.Tests.ps1 | 6 +- tests/Get-DbaWsfcNetwork.Tests.ps1 | 6 +- tests/Get-DbaWsfcNetworkInterface.Tests.ps1 | 6 +- tests/Get-DbaWsfcResourceType.Tests.ps1 | 6 +- tests/Get-DbaWsfcRole.Tests.ps1 | 6 +- tests/Get-DbaWsfcSharedVolume.Tests.ps1 | 6 +- tests/Get-DbaXEObject.Tests.ps1 | 8 +- tests/Get-DbaXESession.Tests.ps1 | 4 +- tests/Get-DbaXESessionTarget.Tests.ps1 | 4 +- tests/Get-DbaXESessionTargetFile.Tests.ps1 | 2 +- tests/Get-DbaXESessionTemplate.Tests.ps1 | 4 +- tests/Get-DbaXESmartTarget.Tests.ps1 | 6 +- tests/Get-DbaXEStore.Tests.ps1 | 6 +- tests/Get-DbatoolsChangeLog.Tests.ps1 | 8 +- tests/Get-DbatoolsConfig.Tests.ps1 | 4 +- tests/Get-DbatoolsError.Tests.ps1 | 2 +- tests/Get-DbatoolsLog.Tests.ps1 | 12 +- tests/Get-DbatoolsPath.Tests.ps1 | 4 +- tests/Get-DirectoryRestoreFile.Tests.ps1 | 4 +- tests/Get-XpDirTreeRestoreFile.Tests.ps1 | 8 +- tests/Grant-DbaAgPermission.Tests.ps1 | 12 +- tests/Import-DbaBinaryFile.Tests.ps1 | 8 +- tests/Import-DbaCsv.Tests.ps1 | 76 +++---- tests/Import-DbaRegServer.Tests.ps1 | 30 +-- tests/Import-DbaSpConfigure.Tests.ps1 | 4 +- tests/Import-DbaXESessionTemplate.Tests.ps1 | 8 +- tests/Import-DbatoolsConfig.Tests.ps1 | 8 +- tests/Install-DbaAgentAdminAlert.Tests.ps1 | 14 +- tests/Install-DbaDarlingData.Tests.ps1 | 16 +- tests/Install-DbaFirstResponderKit.Tests.ps1 | 24 +-- tests/Install-DbaInstance.Tests.ps1 | 8 +- .../Install-DbaMaintenanceSolution.Tests.ps1 | 22 +- tests/Install-DbaMultiTool.Tests.ps1 | 24 +-- tests/Install-DbaSqlWatch.Tests.ps1 | 24 +-- tests/Install-DbaWhoIsActive.Tests.ps1 | 18 +- tests/Invoke-DbaAdvancedInstall.Tests.ps1 | 8 +- tests/Invoke-DbaAdvancedRestore.Tests.ps1 | 18 +- tests/Invoke-DbaAdvancedUpdate.Tests.ps1 | 8 +- tests/Invoke-DbaAgFailover.Tests.ps1 | 16 +- tests/Invoke-DbaAzSqlDbTip.Tests.ps1 | 14 +- tests/Invoke-DbaBalanceDataFiles.Tests.ps1 | 8 +- tests/Invoke-DbaCycleErrorLog.Tests.ps1 | 12 +- tests/Invoke-DbaDbClone.Tests.ps1 | 18 +- tests/Invoke-DbaDbCorruption.Tests.ps1 | 18 +- tests/Invoke-DbaDbDataGenerator.Tests.ps1 | 18 +- tests/Invoke-DbaDbDataMasking.Tests.ps1 | 24 +-- .../Invoke-DbaDbDbccCheckConstraint.Tests.ps1 | 14 +- tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 | 12 +- tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 | 12 +- tests/Invoke-DbaDbDecryptObject.Tests.ps1 | 60 +++--- tests/Invoke-DbaDbLogShipping.Tests.ps1 | 32 +-- tests/Invoke-DbaDbMirroring.Tests.ps1 | 30 +-- tests/Invoke-DbaDbPiiScan.Tests.ps1 | 48 ++--- tests/Invoke-DbaDbShrink.Tests.ps1 | 10 +- tests/Invoke-DbaDbTransfer.Tests.ps1 | 38 ++-- tests/Invoke-DbaDbUpgrade.Tests.ps1 | 14 +- tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 | 6 +- tests/Invoke-DbaDbccFreeCache.Tests.ps1 | 14 +- tests/Invoke-DbaDiagnosticQuery.Tests.ps1 | 42 ++-- tests/Invoke-DbaPfRelog.Tests.ps1 | 28 +-- tests/Invoke-DbaQuery.Tests.ps1 | 96 ++++----- tests/Invoke-DbaWhoisActive.Tests.ps1 | 22 +- tests/Invoke-DbaXEReplay.Tests.ps1 | 4 +- tests/Join-DbaAvailabilityGroup.Tests.ps1 | 2 +- tests/Join-DbaPath.Tests.ps1 | 8 +- tests/Measure-DbaBackupThroughput.Tests.ps1 | 12 +- tests/Measure-DbaDbVirtualLogFile.Tests.ps1 | 12 +- .../Measure-DbaDiskSpaceRequirement.Tests.ps1 | 14 +- tests/Mount-DbaDatabase.Tests.ps1 | 16 +- tests/Move-DbaDbFile.Tests.ps1 | 36 ++-- tests/Move-DbaRegServer.Tests.ps1 | 28 +-- tests/Move-DbaRegServerGroup.Tests.ps1 | 16 +- tests/New-DbaAgentAlert.Tests.ps1 | 16 +- tests/New-DbaAgentAlertCategory.Tests.ps1 | 12 +- tests/New-DbaAgentJob.Tests.ps1 | 14 +- tests/New-DbaAgentJobCategory.Tests.ps1 | 16 +- tests/New-DbaAgentJobStep.Tests.ps1 | 44 ++-- tests/New-DbaAgentOperator.Tests.ps1 | 10 +- tests/New-DbaAgentProxy.Tests.ps1 | 2 +- tests/New-DbaAgentSchedule.Tests.ps1 | 36 ++-- tests/New-DbaAvailabilityGroup.Tests.ps1 | 14 +- tests/New-DbaAzAccessToken.Tests.ps1 | 2 +- tests/New-DbaClientAlias.Tests.ps1 | 2 +- tests/New-DbaComputerCertificate.Tests.ps1 | 14 +- tests/New-DbaConnectionString.Tests.ps1 | 16 +- .../New-DbaConnectionStringBuilder.Tests.ps1 | 16 +- tests/New-DbaCredential.Tests.ps1 | 22 +- tests/New-DbaCustomError.Tests.ps1 | 4 +- tests/New-DbaDacOption.Tests.ps1 | 6 +- tests/New-DbaDacProfile.Tests.ps1 | 8 +- tests/New-DbaDatabase.Tests.ps1 | 6 +- tests/New-DbaDbAsymmetricKey.Tests.ps1 | 58 +++--- tests/New-DbaDbCertificate.Tests.ps1 | 16 +- tests/New-DbaDbDataGeneratorConfig.Tests.ps1 | 6 +- tests/New-DbaDbEncryptionKey.Tests.ps1 | 28 +-- tests/New-DbaDbFileGroup.Tests.ps1 | 26 +-- tests/New-DbaDbMailAccount.Tests.ps1 | 6 +- tests/New-DbaDbMailProfile.Tests.ps1 | 10 +- tests/New-DbaDbMaskingConfig.Tests.ps1 | 8 +- tests/New-DbaDbMasterKey.Tests.ps1 | 16 +- tests/New-DbaDbRole.Tests.ps1 | 4 +- tests/New-DbaDbSchema.Tests.ps1 | 6 +- tests/New-DbaDbSequence.Tests.ps1 | 6 +- tests/New-DbaDbSnapshot.Tests.ps1 | 32 +-- tests/New-DbaDbSynonym.Tests.ps1 | 38 ++-- tests/New-DbaDbTable.Tests.ps1 | 28 +-- tests/New-DbaDbTransfer.Tests.ps1 | 62 +++--- tests/New-DbaDbUser.Tests.ps1 | 52 ++--- tests/New-DbaEndpoint.Tests.ps1 | 16 +- tests/New-DbaFirewallRule.Tests.ps1 | 26 +-- tests/New-DbaLinkedServer.Tests.ps1 | 6 +- tests/New-DbaLinkedServerLogin.Tests.ps1 | 8 +- tests/New-DbaLogin.Tests.ps1 | 40 ++-- tests/New-DbaReplPublication.Tests.ps1 | 2 +- tests/New-DbaReplSubscription.Tests.ps1 | 10 +- tests/New-DbaRgResourcePool.Tests.ps1 | 34 ++-- tests/New-DbaRgWorkloadGroup.Tests.ps1 | 36 ++-- tests/New-DbaServerRole.Tests.ps1 | 4 +- tests/New-DbaServiceMasterKey.Tests.ps1 | 10 +- tests/New-DbaSqlParameter.Tests.ps1 | 22 +- tests/New-DbaSsisCatalog.Tests.ps1 | 2 +- tests/New-DbaXESmartCsvWriter.Tests.ps1 | 4 +- tests/New-DbaXESmartEmail.Tests.ps1 | 2 +- tests/New-DbaXESmartQueryExec.Tests.ps1 | 6 +- tests/New-DbaXESmartReplay.Tests.ps1 | 10 +- tests/New-DbaXESmartTableWriter.Tests.ps1 | 4 +- tests/New-DbatoolsSupportPackage.Tests.ps1 | 24 +-- tests/Publish-DbaDacPackage.Tests.ps1 | 56 ++--- tests/Read-DbaAuditFile.Tests.ps1 | 14 +- tests/Read-DbaBackupHeader.Tests.ps1 | 8 +- tests/Read-DbaTraceFile.Tests.ps1 | 14 +- tests/Read-DbaTransactionLog.Tests.ps1 | 4 +- tests/Read-DbaXEFile.Tests.ps1 | 6 +- tests/Register-DbatoolsConfig.Tests.ps1 | 2 +- tests/Remove-DbaAgDatabase.Tests.ps1 | 18 +- tests/Remove-DbaAgListener.Tests.ps1 | 10 +- tests/Remove-DbaAgReplica.Tests.ps1 | 10 +- tests/Remove-DbaAgentAlert.Tests.ps1 | 6 +- tests/Remove-DbaAgentAlertCategory.Tests.ps1 | 14 +- tests/Remove-DbaAgentJob.Tests.ps1 | 50 ++--- tests/Remove-DbaAgentJobCategory.Tests.ps1 | 10 +- tests/Remove-DbaAgentJobStep.Tests.ps1 | 10 +- tests/Remove-DbaAgentOperator.Tests.ps1 | 12 +- tests/Remove-DbaAgentProxy.Tests.ps1 | 6 +- tests/Remove-DbaAgentSchedule.Tests.ps1 | 16 +- tests/Remove-DbaAvailabilityGroup.Tests.ps1 | 12 +- tests/Remove-DbaClientAlias.Tests.ps1 | 2 +- tests/Remove-DbaComputerCertificate.Tests.ps1 | 4 +- tests/Remove-DbaCredential.Tests.ps1 | 4 +- tests/Remove-DbaCustomError.Tests.ps1 | 12 +- tests/Remove-DbaDatabase.Tests.ps1 | 38 ++-- tests/Remove-DbaDatabaseSafely.Tests.ps1 | 20 +- tests/Remove-DbaDbAsymmetricKey.Tests.ps1 | 34 ++-- ...Remove-DbaDbBackupRestoreHistory.Tests.ps1 | 4 +- tests/Remove-DbaDbCertificate.Tests.ps1 | 8 +- tests/Remove-DbaDbCheckConstraint.Tests.ps1 | 6 +- tests/Remove-DbaDbData.Tests.ps1 | 46 ++--- tests/Remove-DbaDbEncryptionKey.Tests.ps1 | 14 +- tests/Remove-DbaDbFileGroup.Tests.ps1 | 36 ++-- tests/Remove-DbaDbLogShipping.Tests.ps1 | 42 ++-- tests/Remove-DbaDbMailAccount.Tests.ps1 | 4 +- tests/Remove-DbaDbMailProfile.Tests.ps1 | 4 +- tests/Remove-DbaDbMasterKey.Tests.ps1 | 12 +- tests/Remove-DbaDbMirrorMonitor.Tests.ps1 | 14 +- tests/Remove-DbaDbOrphanUser.Tests.ps1 | 86 ++++---- tests/Remove-DbaDbPartitionFunction.Tests.ps1 | 4 +- tests/Remove-DbaDbPartitionScheme.Tests.ps1 | 12 +- tests/Remove-DbaDbRole.Tests.ps1 | 38 ++-- tests/Remove-DbaDbRoleMember.Tests.ps1 | 30 +-- tests/Remove-DbaDbSchema.Tests.ps1 | 6 +- tests/Remove-DbaDbSequence.Tests.ps1 | 4 +- tests/Remove-DbaDbSnapshot.Tests.ps1 | 44 ++-- tests/Remove-DbaDbSynonym.Tests.ps1 | 94 ++++----- tests/Remove-DbaDbTable.Tests.ps1 | 2 +- tests/Remove-DbaDbTableData.Tests.ps1 | 12 +- tests/Remove-DbaDbUdf.Tests.ps1 | 2 +- tests/Remove-DbaDbUser.Tests.ps1 | 8 +- tests/Remove-DbaDbView.Tests.ps1 | 4 +- tests/Remove-DbaEndpoint.Tests.ps1 | 12 +- tests/Remove-DbaExtendedProperty.Tests.ps1 | 12 +- tests/Remove-DbaFirewallRule.Tests.ps1 | 6 +- tests/Remove-DbaLinkedServer.Tests.ps1 | 16 +- tests/Remove-DbaLinkedServerLogin.Tests.ps1 | 6 +- tests/Remove-DbaLogin.Tests.ps1 | 10 +- tests/Remove-DbaNetworkCertificate.Tests.ps1 | 10 +- ...Remove-DbaPfDataCollectorCounter.Tests.ps1 | 2 +- tests/Remove-DbaPfDataCollectorSet.Tests.ps1 | 2 +- tests/Remove-DbaRegServer.Tests.ps1 | 10 +- tests/Remove-DbaRegServerGroup.Tests.ps1 | 22 +- tests/Remove-DbaReplSubscription.Tests.ps1 | 10 +- tests/Remove-DbaRgResourcePool.Tests.ps1 | 50 ++--- tests/Remove-DbaRgWorkloadGroup.Tests.ps1 | 40 ++-- tests/Remove-DbaServerRole.Tests.ps1 | 4 +- tests/Remove-DbaServerRoleMember.Tests.ps1 | 20 +- tests/Remove-DbaTrace.Tests.ps1 | 8 +- tests/Remove-DbaXESession.Tests.ps1 | 10 +- tests/Rename-DbaDatabase.Tests.ps1 | 32 +-- tests/Rename-DbaLogin.Tests.ps1 | 14 +- tests/Repair-DbaDbOrphanUser.Tests.ps1 | 16 +- tests/Repair-DbaInstanceName.Tests.ps1 | 6 +- tests/Reset-DbaAdmin.Tests.ps1 | 10 +- tests/Restart-DbaService.Tests.ps1 | 14 +- tests/Restore-DbaDatabase.Tests.ps1 | 64 +++--- tests/Restore-DbaDbCertificate.Tests.ps1 | 16 +- tests/Restore-DbaDbSnapshot.Tests.ps1 | 42 ++-- tests/Resume-DbaAgDbDataMovement.Tests.ps1 | 18 +- tests/Revoke-DbaAgPermission.Tests.ps1 | 12 +- tests/Save-DbaCommunitySoftware.Tests.ps1 | 2 +- tests/Save-DbaKbUpdate.Tests.ps1 | 4 +- tests/Select-DbaDbSequenceNextValue.Tests.ps1 | 4 +- tests/Set-DbaAgListener.Tests.ps1 | 10 +- tests/Set-DbaAgReplica.Tests.ps1 | 16 +- tests/Set-DbaAgentAlert.Tests.ps1 | 16 +- tests/Set-DbaAgentJob.Tests.ps1 | 2 +- tests/Set-DbaAgentJobCategory.Tests.ps1 | 10 +- tests/Set-DbaAgentJobOutputFile.Tests.ps1 | 2 +- tests/Set-DbaAgentJobOwner.Tests.ps1 | 2 +- tests/Set-DbaAgentJobStep.Tests.ps1 | 4 +- tests/Set-DbaAgentOperator.Tests.ps1 | 6 +- tests/Set-DbaAgentSchedule.Tests.ps1 | 64 +++--- tests/Set-DbaAgentServer.Tests.ps1 | 4 +- tests/Set-DbaAvailabilityGroup.Tests.ps1 | 10 +- tests/Set-DbaCmConnection.Tests.ps1 | 28 +-- tests/Set-DbaDbCompatibility.Tests.ps1 | 8 +- tests/Set-DbaDbCompression.Tests.ps1 | 36 ++-- tests/Set-DbaDbFileGroup.Tests.ps1 | 32 +-- tests/Set-DbaDbFileGrowth.Tests.ps1 | 8 +- tests/Set-DbaDbIdentity.Tests.ps1 | 10 +- tests/Set-DbaDbMirror.Tests.ps1 | 2 +- tests/Set-DbaDbOwner.Tests.ps1 | 26 +-- tests/Set-DbaDbQueryStoreOption.Tests.ps1 | 22 +- tests/Set-DbaDbRecoveryModel.Tests.ps1 | 14 +- tests/Set-DbaDbSchema.Tests.ps1 | 6 +- tests/Set-DbaDbSequence.Tests.ps1 | 6 +- tests/Set-DbaDbState.Tests.ps1 | 74 +++---- tests/Set-DbaDefaultPath.Tests.ps1 | 2 +- tests/Set-DbaEndpoint.Tests.ps1 | 4 +- tests/Set-DbaErrorLogConfig.Tests.ps1 | 14 +- tests/Set-DbaExtendedProperty.Tests.ps1 | 12 +- tests/Set-DbaExtendedProtection.Tests.ps1 | 18 +- tests/Set-DbaLogin.Tests.ps1 | 118 +++++------ tests/Set-DbaMaxDop.Tests.ps1 | 20 +- tests/Set-DbaMaxMemory.Tests.ps1 | 12 +- tests/Set-DbaNetworkCertificate.Tests.ps1 | 8 +- tests/Set-DbaNetworkConfiguration.Tests.ps1 | 14 +- tests/Set-DbaPowerPlan.Tests.ps1 | 2 +- tests/Set-DbaPrivilege.Tests.ps1 | 2 +- tests/Set-DbaResourceGovernor.Tests.ps1 | 14 +- tests/Set-DbaRgResourcePool.Tests.ps1 | 32 +-- tests/Set-DbaRgWorkloadGroup.Tests.ps1 | 42 ++-- tests/Set-DbaSpConfigure.Tests.ps1 | 10 +- tests/Set-DbaStartupParameter.Tests.ps1 | 4 +- tests/Set-DbaTcpPort.Tests.ps1 | 16 +- tests/Set-DbaTempDbConfig.Tests.ps1 | 16 +- tests/Set-DbatoolsConfig.Tests.ps1 | 40 ++-- .../Set-DbatoolsInsecureConnection.Tests.ps1 | 8 +- tests/Set-DbatoolsPath.Tests.ps1 | 12 +- tests/Show-DbaDbList.Tests.ps1 | 4 +- tests/Show-DbaInstanceFileSystem.Tests.ps1 | 6 +- tests/Start-DbaAgentJob.Tests.ps1 | 30 +-- tests/Start-DbaDbEncryption.Tests.ps1 | 12 +- tests/Start-DbaEndpoint.Tests.ps1 | 6 +- tests/Start-DbaMigration.Tests.ps1 | 20 +- tests/Start-DbaPfDataCollectorSet.Tests.ps1 | 8 +- tests/Start-DbaService.Tests.ps1 | 10 +- tests/Start-DbaTrace.Tests.ps1 | 12 +- tests/Start-DbaXESession.Tests.ps1 | 16 +- tests/Start-DbaXESmartTarget.Tests.ps1 | 6 +- tests/Stop-DbaAgentJob.Tests.ps1 | 6 +- tests/Stop-DbaDbEncryption.Tests.ps1 | 14 +- tests/Stop-DbaEndpoint.Tests.ps1 | 6 +- tests/Stop-DbaExternalProcess.Tests.ps1 | 8 +- tests/Stop-DbaPfDataCollectorSet.Tests.ps1 | 8 +- tests/Stop-DbaProcess.Tests.ps1 | 10 +- tests/Stop-DbaService.Tests.ps1 | 14 +- tests/Stop-DbaTrace.Tests.ps1 | 20 +- tests/Stop-DbaXESession.Tests.ps1 | 12 +- tests/Stop-Function.Tests.ps1 | 12 +- tests/Suspend-DbaAgDbDataMovement.Tests.ps1 | 18 +- tests/Sync-DbaLoginPermission.Tests.ps1 | 14 +- tests/Test-DbaAgSpn.Tests.ps1 | 6 +- tests/Test-DbaAgentJobOwner.Tests.ps1 | 14 +- tests/Test-DbaAvailabilityGroup.Tests.ps1 | 4 +- tests/Test-DbaBackupEncrypted.Tests.ps1 | 20 +- tests/Test-DbaBuild.Tests.ps1 | 12 +- ...DbaComputerCertificateExpiration.Tests.ps1 | 2 +- tests/Test-DbaConnection.Tests.ps1 | 2 +- tests/Test-DbaConnectionAuthScheme.Tests.ps1 | 2 +- tests/Test-DbaDbCollation.Tests.ps1 | 6 +- tests/Test-DbaDbCompatibility.Tests.ps1 | 8 +- tests/Test-DbaDbCompression.Tests.ps1 | 24 +-- tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 | 10 +- tests/Test-DbaDbDataMaskingConfig.Tests.ps1 | 8 +- tests/Test-DbaDbLogShipStatus.Tests.ps1 | 26 +-- tests/Test-DbaDbOwner.Tests.ps1 | 10 +- tests/Test-DbaDbQueryStore.Tests.ps1 | 20 +- tests/Test-DbaDbRecoveryModel.Tests.ps1 | 38 ++-- tests/Test-DbaDeprecatedFeature.Tests.ps1 | 6 +- tests/Test-DbaDiskAlignment.Tests.ps1 | 6 +- tests/Test-DbaDiskAllocation.Tests.ps1 | 6 +- tests/Test-DbaDiskSpeed.Tests.ps1 | 48 ++--- tests/Test-DbaEndpoint.Tests.ps1 | 4 +- tests/Test-DbaIdentityUsage.Tests.ps1 | 30 +-- tests/Test-DbaInstanceName.Tests.ps1 | 6 +- tests/Test-DbaLastBackup.Tests.ps1 | 68 +++---- .../Test-DbaLinkedServerConnection.Tests.ps1 | 18 +- tests/Test-DbaLoginPassword.Tests.ps1 | 12 +- tests/Test-DbaManagementObject.Tests.ps1 | 8 +- tests/Test-DbaMaxDop.Tests.ps1 | 12 +- tests/Test-DbaMaxMemory.Tests.ps1 | 2 +- tests/Test-DbaMigrationConstraint.Tests.ps1 | 14 +- tests/Test-DbaNetworkLatency.Tests.ps1 | 2 +- tests/Test-DbaOptimizeForAdHoc.Tests.ps1 | 4 +- tests/Test-DbaPath.Tests.ps1 | 16 +- tests/Test-DbaPowerPlan.Tests.ps1 | 8 +- tests/Test-DbaReplLatency.Tests.ps1 | 6 +- tests/Test-DbaTempDbConfig.Tests.ps1 | 4 +- tests/Test-DbaWindowsLogin.Tests.ps1 | 16 +- tests/Test-PSRemoting.Tests.ps1 | 2 +- tests/Uninstall-DbaSqlWatch.Tests.ps1 | 18 +- tests/Update-DbaInstance.Tests.ps1 | 4 +- tests/Update-DbaMaintenanceSolution.Tests.ps1 | 14 +- tests/Update-DbaServiceAccount.Tests.ps1 | 10 +- tests/Update-dbatools.Tests.ps1 | 14 +- tests/Watch-DbaDbLogin.Tests.ps1 | 28 +-- tests/Watch-DbaXESession.Tests.ps1 | 8 +- tests/Write-DbaDbTableData.Tests.ps1 | 22 +- tests/constants.ps1 | 86 ++++---- tests/dbatools.Tests.ps1 | 24 +-- tests/pester.groups.ps1 | 6 +- 632 files changed, 4823 insertions(+), 4808 deletions(-) diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 4d8e132c36..146c6d1065 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -51,14 +51,14 @@ Describe "Add-DbaAgDatabase" { Context "Command usage" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance3 $agname = "dbatoolsci_addagdb_agroup" $dbname = "dbatoolsci_addagdb_agroupdb" $newdbname = "dbatoolsci_addag_agroupdb_2" $server.Query("create database $dbname") - $backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert + $backup = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Backup-DbaDatabase + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { @@ -68,11 +68,11 @@ Describe "Add-DbaAgDatabase" { It "adds ag db and returns proper results" { $server.Query("create database $newdbname") - $backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $newdbname | Backup-DbaDatabase - $results = Add-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false + $backup = Get-DbaDatabase -SqlInstance $global:instance3 -Database $newdbname | Backup-DbaDatabase + $results = Add-DbaAgDatabase -SqlInstance $global:instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $newdbname $results.IsJoined | Should -Be $true } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index c23cc1eb3c..6b01467773 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -53,17 +53,17 @@ Describe "Add-DbaAgListener" { BeforeAll { $agname = "dbatoolsci_ag_newlistener" $listenerName = 'dbatoolsci_listener' - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterEach { - $null = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAgListener -SqlInstance $global:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false } It "creates a listener and returns results with proper data" { $results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false $results.PortNumber | Should -Be 14330 } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index e850d13cbb..4818cc39e8 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -47,7 +47,7 @@ Describe "Add-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter EndpointUrl -Type String[] } It "Should have Passthru parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch } It "Should have ReadOnlyRoutingList parameter" { $CommandUnderTest | Should -HaveParameter ReadOnlyRoutingList -Type String[] @@ -59,7 +59,7 @@ Describe "Add-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter Certificate -Type String } It "Should have ConfigureXESession parameter" { - $CommandUnderTest | Should -HaveParameter ConfigureXESession -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ConfigureXESession -Type Switch } It "Should have SessionTimeout parameter" { $CommandUnderTest | Should -HaveParameter SessionTimeout -Type Int32 @@ -68,32 +68,32 @@ Describe "Add-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { $agname = "dbatoolsci_agroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false } It "gets ag replicas" { $agname = "dbatoolsci_add_replicagroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica - $results = Get-DbaAgReplica -SqlInstance $script:instance3 + $results = Get-DbaAgReplica -SqlInstance $global:instance3 $results.AvailabilityGroup | Should -Contain $agname $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' $results.FailoverMode | Should -Contain 'Manual' } It "returns just one result" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $global:instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' @@ -102,4 +102,4 @@ Describe "Add-DbaAgReplica" { } } -#$script:instance2 for appveyor +#$global:instance2 for appveyor diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index b75278508d..a9dc1e90f6 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -36,13 +36,13 @@ Describe "Add-DbaComputerCertificate" { $CommandUnderTest | Should -HaveParameter Flag -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Certificate is added properly" { BeforeAll { - $results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $results = Add-DbaComputerCertificate -Path $global:appveyorlabrepo\certificates\localhost.crt -Confirm:$false } It "Should show the proper thumbprint has been added" { diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 725e67fdda..4350dd7ed5 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Add-DbaDbMirrorMonitor" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -57,23 +57,23 @@ Describe "Add-DbaDbMirrorMonitor" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } Context "Command usage" { BeforeAll { - $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Remove-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue } AfterAll { - $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Remove-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue } It "adds the mirror monitor" { - $results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Add-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue $results.MonitorStatus | Should -Be 'Added' } } diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 5bb099e6d3..7ddbe1cba9 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -24,36 +24,36 @@ Describe "Add-DbaDbRoleMember" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $user1 = "dbatoolssci_user1_$(Get-Random)" $user2 = "dbatoolssci_user2_$(Get-Random)" $role = "dbatoolssci_role_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $global:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $global:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname -Owner sa - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user1 -Username $user1 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user2 -Username $user2 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name $dbname -Owner sa + $null = New-DbaDbUser -SqlInstance $global:instance2 -Database $dbname -Login $user1 -Username $user1 + $null = New-DbaDbUser -SqlInstance $global:instance2 -Database $dbname -Login $user2 -Username $user2 + $null = New-DbaDbUser -SqlInstance $global:instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem + $null = New-DbaDbUser -SqlInstance $global:instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem $null = $server.Query("CREATE ROLE $role", $dbname) } AfterAll { $null = $server.Query("DROP USER $user1", 'msdb') $null = $server.Query("DROP USER $user2", 'msdb') - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $user1, $user2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $global:instance2 -Login $user1, $user2 -Confirm:$false } It 'Adds User to Role' { - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false + Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role $roleDBAfter.Role | Should -Be $role @@ -63,7 +63,7 @@ Describe "Add-DbaDbRoleMember" { It 'Adds User to Multiple Roles' { $roleDB = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -Confirm:$false + Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole $roleDBAfter.Count | Should -BeGreaterThan $roleDB.Count @@ -82,14 +82,14 @@ Describe "Add-DbaDbRoleMember" { } It 'Skip adding user to role if already a member' { - $messages = Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false -Verbose 4>&1 + $messages = Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false -Verbose 4>&1 $messageCount = ($messages -match 'Adding user').Count $messageCount | Should -Be 0 } It 'Adds Role to Role' { - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datawriter -Member $role -Database $dbname -Confirm:$false + Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role db_datawriter -Member $role -Database $dbname -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role db_datawriter $roleDBAfter.MemberRole | Should -Contain $role diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index e79618afdb..281778cee0 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -24,14 +24,14 @@ Describe "Add-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 6c6e008224..9a329ffa83 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -23,8 +23,8 @@ Describe "Add-DbaPfDataCollectorCounter" { It "Should have InputObject as a non-mandatory Object[] parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index f71d33c986..6def95f445 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -57,23 +57,23 @@ Describe "Add-DbaRegServer" { $group = "dbatoolsci-group1" $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $groupobject = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $groupobject = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $global:instance1, $global:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $global:instance1, $global:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "adds a registered server" { - $results1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName + $results1 = Add-DbaRegServer -SqlInstance $global:instance1 -ServerName $srvName $results1.Name | Should -Be $srvName $results1.ServerName | Should -Be $srvName $results1.SqlInstance | Should -Not -BeNullOrEmpty } It "adds a registered server with extended properties" { - $results2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc + $results2 = Add-DbaRegServer -SqlInstance $global:instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc $results2.ServerName | Should -Be $regSrvName $results2.Description | Should -Be $regSrvDesc $results2.Name | Should -Be $srvName diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index bb3948ee00..f2f1a81852 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Add-DbaRegServerGroup" { $CommandUnderTest | Should -HaveParameter InputObject -Type ServerGroup[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -41,35 +41,35 @@ Describe "Add-DbaRegServerGroup" { $descriptionUpdated = "group description updated" } AfterAll { - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $global:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "adds a registered server group" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group $results.Name | Should -Be $group $results.SqlInstance | Should -Not -BeNullOrEmpty } It "adds a registered server group with extended properties" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 -Description $description + $results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group2 -Description $description $results.Name | Should -Be $group2 $results.Description | Should -Be $description $results.SqlInstance | Should -Not -BeNullOrEmpty } It "supports hella pipe" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | - Add-DbaRegServerGroup -Name dbatoolsci-first | - Add-DbaRegServerGroup -Name dbatoolsci-second | - Add-DbaRegServerGroup -Name dbatoolsci-third | + $results = Get-DbaRegServerGroup -SqlInstance $global:instance1 -Id 1 | + Add-DbaRegServerGroup -Name dbatoolsci-first | + Add-DbaRegServerGroup -Name dbatoolsci-second | + Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous $results.Group | Should -Be 'dbatoolsci-first\dbatoolsci-second\dbatoolsci-third' } It "adds a registered server group and sub-group when not exists" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $description + $results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name "$group\$group2" -Description $description $results.Name | Should -Be $group2 $results.SqlInstance | Should -Not -BeNullOrEmpty } It "updates description of sub-group when it already exists" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $descriptionUpdated + $results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name "$group\$group2" -Description $descriptionUpdated $results.Name | Should -Be $group2 $results.Description | Should -Be $descriptionUpdated $results.SqlInstance | Should -Not -BeNullOrEmpty diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 6e413ebc39..6c787c7bfb 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Add-DbaReplArticle" { $CommandUnderTest | Should -HaveParameter CreationScriptOptions -Type PSObject } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index edf77bc559..6367ff3fdd 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -24,30 +24,30 @@ Describe "Add-DbaServerRoleMember" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $login1 = "dbatoolsci_login1_$(Get-Random)" $login2 = "dbatoolsci_login2_$(Get-Random)" $customServerRole = "dbatoolsci_customrole_$(Get-Random)" $fixedServerRoles = 'dbcreator','processadmin' - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa + $null = New-DbaLogin -SqlInstance $global:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $global:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaServerRole -SqlInstance $global:instance2 -ServerRole $customServerRole -Owner sa } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $global:instance2 + $null = Remove-DbaLogin -SqlInstance $global:instance2 -Login $login1, $login2 -Confirm:$false } It 'Adds Login to Role' { - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $global:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] $roleAfter.Role | Should -Be $fixedServerRoles[0] @@ -56,7 +56,7 @@ Describe "Add-DbaServerRoleMember" { It 'Adds Login to Multiple Roles' { $serverRoles = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $global:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false $roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles $roleDBAfter.Count | Should -Be $serverRoles.Count @@ -64,7 +64,7 @@ Describe "Add-DbaServerRoleMember" { } It 'Adds Customer Server-Level Role Membership' { - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $global:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[-1] $roleAfter.Role | Should -Be $fixedServerRoles[-1] diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 1c959184e8..08cf432673 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -25,14 +25,14 @@ Describe "Backup-DbaComputerCertificate" { It "Should have Type as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Type -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Certificate is added properly" { BeforeAll { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path $global:appveyorlabrepo\certificates\localhost.crt -Confirm:$false } AfterAll { diff --git a/tests/Backup-DbaDatabase.Tests.ps1 b/tests/Backup-DbaDatabase.Tests.ps1 index fa2c2ccb33..138c6986a7 100644 --- a/tests/Backup-DbaDatabase.Tests.ps1 +++ b/tests/Backup-DbaDatabase.Tests.ps1 @@ -37,19 +37,19 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have IncrementPrefix parameter" { - $command | Should -HaveParameter IncrementPrefix -Type SwitchParameter + $command | Should -HaveParameter IncrementPrefix -Type Switch } It "Should have ReplaceInName parameter" { - $command | Should -HaveParameter ReplaceInName -Type SwitchParameter + $command | Should -HaveParameter ReplaceInName -Type Switch } It "Should have NoAppendDbNameInPath parameter" { - $command | Should -HaveParameter NoAppendDbNameInPath -Type SwitchParameter + $command | Should -HaveParameter NoAppendDbNameInPath -Type Switch } It "Should have CopyOnly parameter" { - $command | Should -HaveParameter CopyOnly -Type SwitchParameter + $command | Should -HaveParameter CopyOnly -Type Switch } It "Should have Type parameter" { @@ -61,7 +61,7 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have CreateFolder parameter" { - $command | Should -HaveParameter CreateFolder -Type SwitchParameter + $command | Should -HaveParameter CreateFolder -Type Switch } It "Should have FileCount parameter" { @@ -69,15 +69,15 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have CompressBackup parameter" { - $command | Should -HaveParameter CompressBackup -Type SwitchParameter + $command | Should -HaveParameter CompressBackup -Type Switch } It "Should have Checksum parameter" { - $command | Should -HaveParameter Checksum -Type SwitchParameter + $command | Should -HaveParameter Checksum -Type Switch } It "Should have Verify parameter" { - $command | Should -HaveParameter Verify -Type SwitchParameter + $command | Should -HaveParameter Verify -Type Switch } It "Should have MaxTransferSize parameter" { @@ -101,23 +101,23 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have NoRecovery parameter" { - $command | Should -HaveParameter NoRecovery -Type SwitchParameter + $command | Should -HaveParameter NoRecovery -Type Switch } It "Should have BuildPath parameter" { - $command | Should -HaveParameter BuildPath -Type SwitchParameter + $command | Should -HaveParameter BuildPath -Type Switch } It "Should have WithFormat parameter" { - $command | Should -HaveParameter WithFormat -Type SwitchParameter + $command | Should -HaveParameter WithFormat -Type Switch } It "Should have Initialize parameter" { - $command | Should -HaveParameter Initialize -Type SwitchParameter + $command | Should -HaveParameter Initialize -Type Switch } It "Should have SkipTapeHeader parameter" { - $command | Should -HaveParameter SkipTapeHeader -Type SwitchParameter + $command | Should -HaveParameter SkipTapeHeader -Type Switch } It "Should have TimeStampFormat parameter" { @@ -125,11 +125,11 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have IgnoreFileChecks parameter" { - $command | Should -HaveParameter IgnoreFileChecks -Type SwitchParameter + $command | Should -HaveParameter IgnoreFileChecks -Type Switch } It "Should have OutputScriptOnly parameter" { - $command | Should -HaveParameter OutputScriptOnly -Type SwitchParameter + $command | Should -HaveParameter OutputScriptOnly -Type Switch } It "Should have EncryptionAlgorithm parameter" { @@ -145,61 +145,61 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' { } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter + $command | Should -HaveParameter EnableException -Type Switch } } } Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance1 = "localhost" - $script:instance2 = "localhost\SQL2019" - $script:appveyorlabrepo = "C:\github\appveyor-lab" - $script:DestBackupDir = 'C:\Temp\backups' - $script:random = Get-Random - $script:DestDbRandom = "dbatools_ci_backupdbadatabase$script:random" + $global:instance1 = "localhost" + $global:instance2 = "localhost\SQL2019" + $global:appveyorlabrepo = "C:\github\appveyor-lab" + $global:DestBackupDir = 'C:\Temp\backups' + $global:random = Get-Random + $global:DestDbRandom = "dbatools_ci_backupdbadatabase$global:random" # Create backup directory if it doesn't exist - if (-not (Test-Path $script:DestBackupDir)) { - New-Item -Type Container -Path $script:DestBackupDir + if (-not (Test-Path $global:DestBackupDir)) { + New-Item -Type Container -Path $global:DestBackupDir } # Remove test databases if they exist - Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $script:DestDbRandom | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $global:DestDbRandom | Remove-DbaDatabase -Confirm:$false } AfterAll { # Clean up test databases and backup files - Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $script:DestDbRandom | Remove-DbaDatabase -Confirm:$false - if (Test-Path $script:DestBackupDir) { - Remove-Item "$script:DestBackupDir\*" -Force -Recurse + Get-DbaDatabase -SqlInstance $global:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $global:DestDbRandom | Remove-DbaDatabase -Confirm:$false + if (Test-Path $global:DestBackupDir) { + Remove-Item "$global:DestBackupDir\*" -Force -Recurse } } Context "Properly restores a database on the local drive using Path" { It "Should return a database name, specifically master" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir $results.DatabaseName | Should -Contain 'master' } It "Should return successful restore" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir $results | ForEach-Object { $_.BackupComplete | Should -Be $true } } } Context "Should not backup if database and exclude match" { It "Should not return object" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master -Exclude master + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master -Exclude master $results | Should -BeNullOrEmpty } } Context "No database found to backup should raise warning and null output" { It "Should not return object and should return a warning" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar -WarningAction SilentlyContinue + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar -WarningAction SilentlyContinue $results | Should -BeNullOrEmpty $warnvar | Should -BeLike "*No databases match the request for backups*" } @@ -207,21 +207,21 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Database should backup 1 database" { It "Database backup object count Should Be 1" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master $results.DatabaseName.Count | Should -Be 1 $results.BackupComplete | Should -Be $true } It "Database ID should be returned" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master - $masterDb = Get-DbaDatabase -SqlInstance $script:instance1 -Database master + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master + $masterDb = Get-DbaDatabase -SqlInstance $global:instance1 -Database master $results.DatabaseID | Should -Be $masterDb.ID } } Context "Database should backup 2 databases" { It "Database backup object count Should Be 2" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master, msdb + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master, msdb $results.DatabaseName.Count | Should -Be 2 $results.BackupComplete | Should -Be @($true, $true) } @@ -229,31 +229,31 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Should take path and filename" { It "Should report it has backed up to the path with the correct name" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master -BackupFileName 'PesterTest.bak' - $results.Fullname | Should -BeLike "$script:DestBackupDir*PesterTest.bak" + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master -BackupFileName 'PesterTest.bak' + $results.Fullname | Should -BeLike "$global:DestBackupDir*PesterTest.bak" } It "Should have backed up to the path with the correct name" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $script:DestBackupDir -Database master -BackupFileName 'PesterTest.bak' - Test-Path "$script:DestBackupDir\PesterTest.bak" | Should -Be $true + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $global:DestBackupDir -Database master -BackupFileName 'PesterTest.bak' + Test-Path "$global:DestBackupDir\PesterTest.bak" | Should -Be $true } } Context "Database parameter works when using pipes (fixes #5044)" { It "Should report it has backed up to the path with the correct name" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $script:DestBackupDir - $results.Fullname | Should -BeLike "$script:DestBackupDir*PesterTest.bak" + $results = Get-DbaDatabase -SqlInstance $global:instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $global:DestBackupDir + $results.Fullname | Should -BeLike "$global:DestBackupDir*PesterTest.bak" } It "Should have backed up to the path with the correct name" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $script:DestBackupDir - Test-Path "$script:DestBackupDir\PesterTest.bak" | Should -Be $true + $results = Get-DbaDatabase -SqlInstance $global:instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $global:DestBackupDir + Test-Path "$global:DestBackupDir\PesterTest.bak" | Should -Be $true } } Context "ExcludeDatabase parameter works when using pipes (fixes #5044)" { It "Should not contain excluded databases" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 | Backup-DbaDatabase -ExcludeDatabase master, tempdb, msdb, model + $results = Get-DbaDatabase -SqlInstance $global:instance1 | Backup-DbaDatabase -ExcludeDatabase master, tempdb, msdb, model $results.DatabaseName | Should -Not -Contain master $results.DatabaseName | Should -Not -Contain tempdb $results.DatabaseName | Should -Not -Contain msdb @@ -261,17 +261,17 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } } - + Context "Handling backup paths that don't exist" { $MissingPathTrailing = "$DestBackupDir\Missing1\Awol2\" $MissingPath = "$DestBackupDir\Missing1\Awol2" - $null = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPath -WarningVariable warnvar *>$null + $null = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $MissingPath -WarningVariable warnvar *>$null It "Should warn and fail if path doesn't exist and BuildPath not set" { $warnvar | Should -BeLike "*$MissingPath*" } # $MissingPathTrailing has a trailing slash but we normalize the path before doing the actual backup - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath It "Should have backed up to $MissingPath" { $results.BackupFolder | Should -Be "$MissingPath" $results.Path | Should -Not -BeLike '*\\*' @@ -279,7 +279,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } Context "CreateFolder switch should append the databasename to the backup path" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -CreateFolder + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $DestBackupDir -CreateFolder It "Should have appended master to the backup path" { $results.BackupFolder | Should -Be "$DestBackupDir\master" } @@ -287,7 +287,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "CreateFolder switch should append the databasename to the backup path even when striping" { $backupPaths = "$DestBackupDir\stripewithdb1", "$DestBackupDir\stripewithdb2" - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths -CreateFolder + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $backupPaths -CreateFolder It "Should have appended master to all backup paths" { foreach ($path in $results.BackupFolder) { ($results.BackupFolder | Sort-Object) | Should -Be ($backupPaths | Sort-Object | ForEach-Object { [IO.Path]::Combine($_, 'master') }) @@ -297,7 +297,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "A fully qualified path should override a backupfolder" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory c:\temp -BackupFileName "$DestBackupDir\PesterTest2.bak" + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory c:\temp -BackupFileName "$DestBackupDir\PesterTest2.bak" It "Should report backed up to $DestBackupDir" { $results.FullName | Should -BeLike "$DestBackupDir\PesterTest2.bak" $results.BackupFolder | Should Not Be 'c:\temp' @@ -312,7 +312,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { $null = New-Item -Path $backupPaths -ItemType Directory - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $backupPaths It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -327,14 +327,14 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } } # Assure that striping logic favours -BackupDirectory and not -Filecount - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths -FileCount 2 + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $backupPaths -FileCount 2 It "Should have created 3 backups, even when FileCount is different" { $results.BackupFilesCount | Should -Be 3 } } Context "Should stripe on filecount > 1" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount 3 + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount 3 It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -350,7 +350,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Should prefix the filenames when IncrementPrefix set" { $fileCount = 3 - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount $fileCount -IncrementPrefix + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount $fileCount -IncrementPrefix It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -362,8 +362,8 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } Context "Should Backup to default path if none specified" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName 'PesterTest.bak' - $DefaultPath = (Get-DbaDefaultPath -SqlInstance $script:instance1).Backup + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupFileName 'PesterTest.bak' + $DefaultPath = (Get-DbaDefaultPath -SqlInstance $global:instance1).Backup It "Should report it has backed up to the path with the corrrect name" { $results.Fullname | Should -BeLike "$DefaultPath*PesterTest.bak" } @@ -374,33 +374,33 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Test backup verification" { It "Should perform a full backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -Type full -Verify + $b = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -Type full -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True $b.count | Should -Be 1 } It -Skip "Should perform a diff backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database backuptest -Type diff -Verify + $b = Backup-DbaDatabase -SqlInstance $global:instance1 -Database backuptest -Type diff -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True } It -Skip "Should perform a log backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database backuptest -Type log -Verify + $b = Backup-DbaDatabase -SqlInstance $global:instance1 -Database backuptest -Type log -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True } } Context "Backup can pipe to restore" { - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName "dbatoolsci_singlerestore" - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database "dbatoolsci_singlerestore" | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName $DestDbRandom -TrustDbBackupHistory -ReplaceDbNameInFile + $null = Restore-DbaDatabase -SqlInstance $global:instance1 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName "dbatoolsci_singlerestore" + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -BackupDirectory $DestBackupDir -Database "dbatoolsci_singlerestore" | Restore-DbaDatabase -SqlInstance $global:instance2 -DatabaseName $DestDbRandom -TrustDbBackupHistory -ReplaceDbNameInFile It "Should return successful restore" { $results.RestoreComplete | Should -Be $true } } Context "Test Backup-DbaDatabase can take pipe input" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null It "Should not warn" { $warnvar | Should -BeNullOrEmpty } @@ -411,7 +411,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } Context "Should handle NUL as an input path" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName NUL + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupFileName NUL It "Should return succesful backup" { $results.BackupComplete | Should -Be $true } @@ -421,7 +421,7 @@ Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" { } Context "Should only output a T-SQL String if OutputScriptOnly specified" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName c:\notexists\file.bak -OutputScriptOnly + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupFileName c:\notexists\file.bak -OutputScriptOnly It "Should return a string" { $results.GetType().ToString() | Should -Be 'System.String' } @@ -440,7 +440,7 @@ go CREATE DATABASE encrypted go "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sqlencrypt -Database Master + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $sqlencrypt -Database Master $createdb = @" CREATE DATABASE ENCRYPTION KEY @@ -451,12 +451,12 @@ ALTER DATABASE encrypted SET ENCRYPTION ON; GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $createdb -Database encrypted + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $createdb -Database encrypted It "Should compress an encrypted db" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -Database encrypted -Compress + $results = Backup-DbaDatabase -SqlInstance $global:instance2 -Database encrypted -Compress $results.script | Should -BeLike '*D, COMPRESSION,*' } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database encrypted -confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database encrypted -confirm:$false $sqldrop = @" drop certificate MyServerCert @@ -464,82 +464,82 @@ go drop master key go "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sqldrop -Database Master + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $sqldrop -Database Master } Context "Custom TimeStamp" { # Test relies on DateFormat bobob returning bobob as the values aren't interpreted, check here in case .Net rules change - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -TimeStampFormat bobob + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master -BackupDirectory $DestBackupDir -TimeStampFormat bobob It "Should apply the corect custom Timestamp" { ($results | Where-Object { $_.BackupPath -like '*bobob*' }).count | Should -Be $results.count } } Context "Test Backup templating" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master, msdb -BackupDirectory $DestBackupDir\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath + $results = Backup-DbaDatabase -SqlInstance $global:instance1 -Database master, msdb -BackupDirectory $DestBackupDir\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath It "Should have replaced the markers" { - $results[0].BackupPath | Should -BeLike "$DestBackupDir\master\$(($script:instance1).split('\')[1])\Full\master-Full.bak" - $results[1].BackupPath | Should -BeLike "$DestBackupDir\msdb\$(($script:instance1).split('\')[1])\Full\msdb-Full.bak" + $results[0].BackupPath | Should -BeLike "$DestBackupDir\master\$(($global:instance1).split('\')[1])\Full\master-Full.bak" + $results[1].BackupPath | Should -BeLike "$DestBackupDir\msdb\$(($global:instance1).split('\')[1])\Full\msdb-Full.bak" } } Context "Test Backup templating when db object piped in issue 8100" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master,msdb | Backup-DbaDatabase -BackupDirectory $DestBackupDir\db2\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database master,msdb | Backup-DbaDatabase -BackupDirectory $DestBackupDir\db2\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath It "Should have replaced the markers" { - $results[0].BackupPath | Should -BeLike "$DestBackupDir\db2\master\$(($script:instance1).split('\')[1])\Full\master-Full.bak" - $results[1].BackupPath | Should -BeLike "$DestBackupDir\db2\msdb\$(($script:instance1).split('\')[1])\Full\msdb-Full.bak" + $results[0].BackupPath | Should -BeLike "$DestBackupDir\db2\master\$(($global:instance1).split('\')[1])\Full\master-Full.bak" + $results[1].BackupPath | Should -BeLike "$DestBackupDir\db2\msdb\$(($global:instance1).split('\')[1])\Full\msdb-Full.bak" } } Context "Test Backup Encryption with Certificate" { BeforeAll { $securePass = ConvertTo-SecureString "TestPassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -SecurePassword $securePass -Confirm:$false -ErrorAction SilentlyContinue - $cert = New-DbaDbCertificate -SqlInstance $script:instance2 -Database master -Name BackupCertt -Subject BackupCertt + New-DbaDbMasterKey -SqlInstance $global:instance2 -Database Master -SecurePassword $securePass -Confirm:$false -ErrorAction SilentlyContinue + $cert = New-DbaDbCertificate -SqlInstance $global:instance2 -Database master -Name BackupCertt -Subject BackupCertt } AfterAll { - Remove-DbaDbCertificate -SqlInstance $script:instance2 -Database master -Certificate BackupCertt -Confirm:$false - Remove-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -Confirm:$false + Remove-DbaDbCertificate -SqlInstance $global:instance2 -Database master -Certificate BackupCertt -Confirm:$false + Remove-DbaDbMasterKey -SqlInstance $global:instance2 -Database Master -Confirm:$false } It "Should encrypt the backup" { - $encBackupResults = Backup-DbaDatabase -SqlInstance $script:instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionCertificate BackupCertt -BackupFileName 'encryptiontest.bak' -Description "Encrypted backup" + $encBackupResults = Backup-DbaDatabase -SqlInstance $global:instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionCertificate BackupCertt -BackupFileName 'encryptiontest.bak' -Description "Encrypted backup" $encBackupResults.EncryptorType | Should -Be "CERTIFICATE" $encBackupResults.KeyAlgorithm | Should -Be "aes_128" - Invoke-Command2 -ComputerName $script:instance2 -ScriptBlock { Remove-Item -Path $args[0] } -ArgumentList $encBackupResults.FullName + Invoke-Command2 -ComputerName $global:instance2 -ScriptBlock { Remove-Item -Path $args[0] } -ArgumentList $encBackupResults.FullName } } Context "Azure works" -Skip:(-not $env:azurepasswd) { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance2 - if (Get-DbaCredential -SqlInstance $script:instance2 -Name "[$script:azureblob]" ) { - $server.Query("DROP CREDENTIAL [$script:azureblob]") + Get-DbaDatabase -SqlInstance $global:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $global:instance2 + if (Get-DbaCredential -SqlInstance $global:instance2 -Name "[$global:azureblob]" ) { + $server.Query("DROP CREDENTIAL [$global:azureblob]") } - $server.Query("CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'") + $server.Query("CREATE CREDENTIAL [$global:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'") $server.Query("CREATE DATABASE dbatoolsci_azure") - if (Get-DbaCredential -SqlInstance $script:instance2 -name dbatools_ci) { + if (Get-DbaCredential -SqlInstance $global:instance2 -name dbatools_ci) { $server.Query("DROP CREDENTIAL dbatools_ci") } - $server.Query("CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'") + $server.Query("CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$global:azureblobaccount', SECRET = N'$env:azurelegacypasswd'") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false - $server.Query("DROP CREDENTIAL [$script:azureblob]") + Get-DbaDatabase -SqlInstance $global:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server.Query("DROP CREDENTIAL [$global:azureblob]") } It "backs up to Azure properly using SHARED ACCESS SIGNATURE" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -AzureBaseUrl $script:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure.bak -WithFormat + $results = Backup-DbaDatabase -SqlInstance $global:instance2 -AzureBaseUrl $global:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure.bak -WithFormat $results.Database | Should -Be 'dbatoolsci_azure' $results.DeviceType | Should -Be 'URL' $results.BackupFile | Should -Be 'dbatoolsci_azure.bak' } It "backs up to Azure properly using legacy credential" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -AzureBaseUrl $script:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure2.bak -WithFormat -AzureCredential dbatools_ci + $results = Backup-DbaDatabase -SqlInstance $global:instance2 -AzureBaseUrl $global:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure2.bak -WithFormat -AzureCredential dbatools_ci $results.Database | Should -Be 'dbatoolsci_azure' $results.DeviceType | Should -Be 'URL' $results.BackupFile | Should -Be 'dbatoolsci_azure2.bak' diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index bac955e78d..2a89fb5d41 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Backup-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter InputObject -Type Certificate[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -45,45 +45,45 @@ Describe "Backup-DbaDbCertificate" { . "$PSScriptRoot\constants.ps1" $random = Get-Random $db1Name = "dbatoolscli_$random" - $db1 = New-DbaDatabase -SqlInstance $script:instance1 -Name $db1Name + $db1 = New-DbaDatabase -SqlInstance $global:instance1 -Name $db1Name $pw = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1Name)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1Name -Password $pw -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $global:instance1 -Database $db1Name)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $global:instance1 -Database $db1Name -Password $pw -Confirm:$false } - $cert = New-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert1_$random - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert2_$random + $cert = New-DbaDbCertificate -SqlInstance $global:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert1_$random + $cert2 = New-DbaDbCertificate -SqlInstance $global:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert2_$random } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance1 -Database $db1Name -Confirm:$false } It "backs up the db cert" { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $global:instance1 -Certificate $cert.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.Certificate | Should -Be $cert.Name $results.Status | Should -Match "Success" - $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $db1Name).ID + $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database $db1Name).ID } It "warns the caller if the cert cannot be found" { $invalidDBCertName = "dbatoolscli_invalidCertName" $invalidDBCertName2 = "dbatoolscli_invalidCertName2" - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null + $results = Backup-DbaDbCertificate -SqlInstance $global:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $warnVariable | Should -BeLike "*Database certificate(s) * not found*" } It "backs up all db certs for a database" -Skip { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $global:instance1 -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.length | Should -Be 2 $results.Certificate | Should -Be @($cert.Name, $cert2.Name) } It "backs up all db certs for an instance" -Skip { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -EncryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $global:instance1 -EncryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore } } diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index f422ecd60b..3ce9df8f29 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -41,7 +41,7 @@ Describe "Backup-DbaDbMasterKey" { BeforeAll { $password = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 if (-not (Get-DbaDbMasterKey -SqlInstance $server -Database tempdb)) { $null = New-DbaDbMasterKey -SqlInstance $server -Database tempdb -Password $password -Confirm:$false } diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 5156f649c0..b271931716 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -74,7 +74,7 @@ Describe "Backup-DbaServiceMasterKey" { Context "Can backup a service master key" { BeforeAll { $securePassword = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force - $results = Backup-DbaServiceMasterKey -SqlInstance $script:instance1 -Confirm:$false -SecurePassword $securePassword + $results = Backup-DbaServiceMasterKey -SqlInstance $global:instance1 -Confirm:$false -SecurePassword $securePassword } AfterAll { diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 72c375fbd9..2083bfd6ee 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Clear-DbaLatchStatistics" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -51,10 +51,10 @@ Describe "Clear-DbaLatchStatistics" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } @@ -63,7 +63,7 @@ Describe "Clear-DbaLatchStatistics" { . "$PSScriptRoot\constants.ps1" } BeforeAll { - $results = Clear-DbaLatchStatistics -SqlInstance $script:instance1 -Confirm:$false + $results = Clear-DbaLatchStatistics -SqlInstance $global:instance1 -Confirm:$false } It "returns success" { $results.Status | Should -Be 'Success' diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index fb53fa5a13..bd1e7347d6 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -28,13 +28,13 @@ Describe "Clear-DbaPlanCache" { Context "Functionality" { It "doesn't clear plan cache when threshold is high" { - $results = Clear-DbaPlanCache -SqlInstance $script:instance1 -Threshold 10240 + $results = Clear-DbaPlanCache -SqlInstance $global:instance1 -Threshold 10240 $results.Size | Should -BeOfType [dbasize] $results.Status | Should -Match 'below' } It "supports piping" { - $results = Get-DbaPlanCache -SqlInstance $script:instance1 | Clear-DbaPlanCache -Threshold 10240 + $results = Get-DbaPlanCache -SqlInstance $global:instance1 | Clear-DbaPlanCache -Threshold 10240 $results.Size | Should -BeOfType [dbasize] $results.Status | Should -Match 'below' } diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index 0dd090e18b..24421d4b3b 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Clear-DbaWaitStatistics" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -51,10 +51,10 @@ Describe "Clear-DbaWaitStatistics" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } @@ -64,7 +64,7 @@ Describe "Clear-DbaWaitStatistics" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $results = Clear-DbaWaitStatistics -SqlInstance $script:instance1 -Confirm:$false + $results = Clear-DbaWaitStatistics -SqlInstance $global:instance1 -Confirm:$false } It "returns success" { $results.Status | Should -Be 'Success' diff --git a/tests/Connect-DbaInstance.Tests.ps1 b/tests/Connect-DbaInstance.Tests.ps1 index da9a66d03e..3f5900dc2e 100644 --- a/tests/Connect-DbaInstance.Tests.ps1 +++ b/tests/Connect-DbaInstance.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Connect-DbaInstance" { $CommandUnderTest | Should -HaveParameter ApplicationIntent -Type String -Not -Mandatory } It "Should have AzureUnsupported as a parameter" { - $CommandUnderTest | Should -HaveParameter AzureUnsupported -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AzureUnsupported -Type Switch -Not -Mandatory } It "Should have BatchSeparator as a parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String -Not -Mandatory @@ -34,7 +34,7 @@ Describe "Connect-DbaInstance" { $CommandUnderTest | Should -HaveParameter ConnectTimeout -Type Int32 -Not -Mandatory } It "Should have EncryptConnection as a parameter" { - $CommandUnderTest | Should -HaveParameter EncryptConnection -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EncryptConnection -Type Switch -Not -Mandatory } It "Should have FailoverPartner as a parameter" { $CommandUnderTest | Should -HaveParameter FailoverPartner -Type String -Not -Mandatory @@ -52,16 +52,16 @@ Describe "Connect-DbaInstance" { $CommandUnderTest | Should -HaveParameter MinimumVersion -Type Int32 -Not -Mandatory } It "Should have MultipleActiveResultSets as a parameter" { - $CommandUnderTest | Should -HaveParameter MultipleActiveResultSets -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter MultipleActiveResultSets -Type Switch -Not -Mandatory } It "Should have MultiSubnetFailover as a parameter" { - $CommandUnderTest | Should -HaveParameter MultiSubnetFailover -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter MultiSubnetFailover -Type Switch -Not -Mandatory } It "Should have NetworkProtocol as a parameter" { $CommandUnderTest | Should -HaveParameter NetworkProtocol -Type String -Not -Mandatory } It "Should have NonPooledConnection as a parameter" { - $CommandUnderTest | Should -HaveParameter NonPooledConnection -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NonPooledConnection -Type Switch -Not -Mandatory } It "Should have PacketSize as a parameter" { $CommandUnderTest | Should -HaveParameter PacketSize -Type Int32 -Not -Mandatory @@ -76,19 +76,19 @@ Describe "Connect-DbaInstance" { $CommandUnderTest | Should -HaveParameter StatementTimeout -Type Int32 -Not -Mandatory } It "Should have TrustServerCertificate as a parameter" { - $CommandUnderTest | Should -HaveParameter TrustServerCertificate -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter TrustServerCertificate -Type Switch -Not -Mandatory } It "Should have WorkstationId as a parameter" { $CommandUnderTest | Should -HaveParameter WorkstationId -Type String -Not -Mandatory } It "Should have AlwaysEncrypted as a parameter" { - $CommandUnderTest | Should -HaveParameter AlwaysEncrypted -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AlwaysEncrypted -Type Switch -Not -Mandatory } It "Should have AppendConnectionString as a parameter" { $CommandUnderTest | Should -HaveParameter AppendConnectionString -Type String -Not -Mandatory } It "Should have SqlConnectionOnly as a parameter" { - $CommandUnderTest | Should -HaveParameter SqlConnectionOnly -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SqlConnectionOnly -Type Switch -Not -Mandatory } It "Should have AzureDomain as a parameter" { $CommandUnderTest | Should -HaveParameter AzureDomain -Type String -Not -Mandatory @@ -100,10 +100,10 @@ Describe "Connect-DbaInstance" { $CommandUnderTest | Should -HaveParameter AccessToken -Type PSObject -Not -Mandatory } It "Should have DedicatedAdminConnection as a parameter" { - $CommandUnderTest | Should -HaveParameter DedicatedAdminConnection -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DedicatedAdminConnection -Type Switch -Not -Mandatory } It "Should have DisableException as a parameter" { - $CommandUnderTest | Should -HaveParameter DisableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DisableException -Type Switch -Not -Mandatory } } @@ -116,7 +116,7 @@ Describe "Connect-DbaInstance" { Context "Connect to Azure" -Skip:($env:azuredbpasswd -ne "failstoooften") { BeforeAll { $securePassword = ConvertTo-SecureString $env:azuredbpasswd -AsPlainText -Force - $cred = New-Object System.Management.Automation.PSCredential ($script:azuresqldblogin, $securePassword) + $cred = New-Object System.Management.Automation.PSCredential ($global:azuresqldblogin, $securePassword) } It "Should login to Azure" { @@ -149,11 +149,11 @@ Describe "Connect-DbaInstance" { 'StatementTimeout' = 0 'ApplicationIntent' = 'ReadOnly' } - $server = Connect-DbaInstance -SqlInstance $script:instance1 @params + $server = Connect-DbaInstance -SqlInstance $global:instance1 @params } It "Returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $global:instance1 } It "Sets ConnectionContext parameters that are provided" { @@ -187,11 +187,11 @@ Describe "Connect-DbaInstance" { Context "Connection is properly made using a connection string" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance "Data Source=$script:instance1;Initial Catalog=tempdb;Integrated Security=True" + $server = Connect-DbaInstance -SqlInstance "Data Source=$global:instance1;Initial Catalog=tempdb;Integrated Security=True" } It "Returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $global:instance1 } It "Returns more than one database" { @@ -204,9 +204,9 @@ Describe "Connect-DbaInstance" { } } - Context "Connection is properly made using a dot" -Skip:($script:instance1 -notmatch 'localhost') { + Context "Connection is properly made using a dot" -Skip:($global:instance1 -notmatch 'localhost') { BeforeAll { - $newinstance = $script:instance1.Replace("localhost", ".") + $newinstance = $global:instance1.Replace("localhost", ".") $server = Connect-DbaInstance -SqlInstance $newinstance } @@ -226,13 +226,13 @@ Describe "Connect-DbaInstance" { Context "Connection is properly made using a connection object" { BeforeAll { Set-DbatoolsConfig -FullName commands.connect-dbainstance.smo.computername.source -Value 'instance.ComputerName' - [Microsoft.Data.SqlClient.SqlConnection]$sqlconnection = "Data Source=$script:instance1;Initial Catalog=tempdb;Integrated Security=True;Encrypt=False;Trust Server Certificate=True" + [Microsoft.Data.SqlClient.SqlConnection]$sqlconnection = "Data Source=$global:instance1;Initial Catalog=tempdb;Integrated Security=True;Encrypt=False;Trust Server Certificate=True" $server = Connect-DbaInstance -SqlInstance $sqlconnection Set-DbatoolsConfig -FullName commands.connect-dbainstance.smo.computername.source -Value $null } It "Returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $global:instance1 } It "Returns more than one database" { @@ -246,7 +246,7 @@ Describe "Connect-DbaInstance" { Context "Connection is properly cloned from an existing connection" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 } It "Clones when using parameter Database" { @@ -281,7 +281,7 @@ Describe "Connect-DbaInstance" { } It "Clones when using Backup-DbaDatabase" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance -SqlInstance $global:instance1 -Database tempdb $null = Backup-DbaDatabase -SqlInstance $server -Database msdb $null = Backup-DbaDatabase -SqlInstance $server -Database msdb -WarningVariable warn $warn | Should -BeNullOrEmpty @@ -290,20 +290,20 @@ Describe "Connect-DbaInstance" { Context "Multiple connections are properly made using strings" { It "Returns the proper names" { - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 - $server[0].Name | Should -Be $script:instance1 - $server[1].Name | Should -Be $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance1, $global:instance2 + $server[0].Name | Should -Be $global:instance1 + $server[1].Name | Should -Be $global:instance2 } } Context "Multiple dedicated admin connections are properly made using strings" { It "Opens and closes the connections" { - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 -DedicatedAdminConnection - $server[0].Name | Should -Be "ADMIN:$script:instance1" - $server[1].Name | Should -Be "ADMIN:$script:instance2" + $server = Connect-DbaInstance -SqlInstance $global:instance1, $global:instance2 -DedicatedAdminConnection + $server[0].Name | Should -Be "ADMIN:$global:instance1" + $server[1].Name | Should -Be "ADMIN:$global:instance2" $null = $server | Disconnect-DbaInstance Start-Sleep -Seconds 10 - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 -DedicatedAdminConnection + $server = Connect-DbaInstance -SqlInstance $global:instance1, $global:instance2 -DedicatedAdminConnection $server.Count | Should -Be 2 $null = $server | Disconnect-DbaInstance } diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index 29928d95d8..9cd8ecb02b 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -12,10 +12,10 @@ Describe "ConvertTo-DbaXESession" { $CommandUnderTest | Should -HaveParameter Name -Type String } It "Accepts OutputScriptOnly as a parameter" { - $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type Switch } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -102,20 +102,20 @@ exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references select TraceID=@TraceID "@ - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $traceid = ($server.Query($sql)).TraceID - $script:name = "dbatoolsci-session" + $global:name = "dbatoolsci-session" } AfterAll { - $null = Remove-DbaXESession -SqlInstance $script:instance2 -Session $script:name - $null = Remove-DbaTrace -SqlInstance $script:instance2 -Id $traceid + $null = Remove-DbaXESession -SqlInstance $global:instance2 -Session $global:name + $null = Remove-DbaTrace -SqlInstance $global:instance2 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue } It "returns the right results" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id $traceid | ConvertTo-DbaXESession -Name $script:name | Start-DbaXESession - $results.Name | Should -Be $script:name + $results = Get-DbaTrace -SqlInstance $global:instance2 -Id $traceid | ConvertTo-DbaXESession -Name $global:name | Start-DbaXESession + $results.Name | Should -Be $global:name $results.Status | Should -Be "Running" $results.Targets.Name | Should -Be "package0.event_file" } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 476d470b5f..9b5009dbdf 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Copy-DbaAgentAlert" { $CommandUnderTest | Should -HaveParameter ExcludeAlert -Type Object[] } It "Should have IncludeDefaults as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeDefaults -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeDefaults -Type Switch } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -42,7 +42,7 @@ Describe "Copy-DbaAgentAlert" { $alert2 = 'dbatoolsci test alert 2' $operatorName = 'Dan the man Levitan' $operatorEmail = 'levitan@dbatools.io' - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'$($alert1)', @message_id=0, @@ -71,34 +71,34 @@ Describe "Copy-DbaAgentAlert" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert2)'") $server.Query("EXEC msdb.dbo.sp_delete_operator @name = '$($operatorName)'") - $server = Connect-DbaInstance -SqlInstance $script:instance3 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance3 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") } It "Copies the sample alert" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert1 + $results = Copy-DbaAgentAlert -Source $global:instance2 -Destination $global:instance3 -Alert $alert1 $results.Name | Should -Be @('dbatoolsci test alert', 'dbatoolsci test alert') $results.Status | Should -Be @('Successful', 'Successful') } It "Skips alerts where destination is missing the operator" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningAction SilentlyContinue + $results = Copy-DbaAgentAlert -Source $global:instance2 -Destination $global:instance3 -Alert $alert2 -WarningAction SilentlyContinue $results.Status | Should -Be @('Skipped', 'Skipped') } It "Doesn't overwrite existing alerts" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert1 + $results = Copy-DbaAgentAlert -Source $global:instance2 -Destination $global:instance3 -Alert $alert1 $results.Name | Should -Be 'dbatoolsci test alert' $results.Status | Should -Be 'Skipped' } It "The newly copied alert exists" { - $results = Get-DbaAgentAlert -SqlInstance $script:instance2 + $results = Get-DbaAgentAlert -SqlInstance $global:instance2 $results.Name | Should -Contain 'dbatoolsci test alert' } } diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index 79642f265a..1112d4bef7 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -48,39 +48,39 @@ Describe "Copy-DbaAgentJob" { Context "Command copies jobs properly" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled - $sourcejobs = Get-DbaAgentJob -SqlInstance $script:instance2 - $destjobs = Get-DbaAgentJob -SqlInstance $script:instance3 + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_copyjob + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_copyjob_disabled + $sourcejobs = Get-DbaAgentJob -SqlInstance $global:instance2 + $destjobs = Get-DbaAgentJob -SqlInstance $global:instance3 } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false - $null = Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false } It "returns one success" { - $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob + $results = Copy-DbaAgentJob -Source $global:instance2 -Destination $global:instance3 -Job dbatoolsci_copyjob $results.Name | Should -Be "dbatoolsci_copyjob" $results.Status | Should -Be "Successful" } It "did not copy dbatoolsci_copyjob_disabled" { - $job = Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob_disabled + $job = Get-DbaAgentJob -SqlInstance $global:instance3 -Job dbatoolsci_copyjob_disabled $job | Should -BeNullOrEmpty } It "disables jobs when requested" { - $sourceJob = Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled + $sourceJob = Get-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_copyjob_disabled $sourceJob.Enabled | Should -BeTrue - $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force + $results = Copy-DbaAgentJob -Source $global:instance2 -Destination $global:instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force $results.Name | Should -Be "dbatoolsci_copyjob_disabled" $results.Status | Should -Be "Successful" - $sourceJobAfter = Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled + $sourceJobAfter = Get-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_copyjob_disabled $sourceJobAfter.Enabled | Should -BeFalse - $destJob = Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob_disabled + $destJob = Get-DbaAgentJob -SqlInstance $global:instance3 -Job dbatoolsci_copyjob_disabled $destJob.Enabled | Should -BeFalse } } diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 2eec1660cf..6d53e5208d 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -30,10 +30,10 @@ Describe "Copy-DbaAgentJobCategory" { $CommandUnderTest | Should -HaveParameter OperatorCategory -Type String[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -44,22 +44,22 @@ Describe "Copy-DbaAgentJobCategory Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category' + $null = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'dbatoolsci test category' } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category' -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'dbatoolsci test category' -Confirm:$false } Context "Command copies jobs properly" { It "returns one success" { - $results = Copy-DbaAgentJobCategory -Source $script:instance2 -Destination $script:instance3 -JobCategory 'dbatoolsci test category' + $results = Copy-DbaAgentJobCategory -Source $global:instance2 -Destination $global:instance3 -JobCategory 'dbatoolsci test category' $results.Name | Should -Be "dbatoolsci test category" $results.Status | Should -Be "Successful" } It "does not overwrite" { - $results = Copy-DbaAgentJobCategory -Source $script:instance2 -Destination $script:instance3 -JobCategory 'dbatoolsci test category' + $results = Copy-DbaAgentJobCategory -Source $global:instance2 -Destination $global:instance3 -JobCategory 'dbatoolsci test category' $results.Name | Should -Be "dbatoolsci test category" $results.Status | Should -Be "Skipped" } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 2832df4268..9112179e6a 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -24,17 +24,17 @@ Describe "Copy-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter ExcludeOperator -Type Object[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator', @enabled=1, @pager_days=0" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator2', @enabled=1, @pager_days=0" @@ -42,13 +42,13 @@ Describe "Copy-DbaAgentOperator" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator2'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance3 $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator2'" @@ -56,13 +56,13 @@ Describe "Copy-DbaAgentOperator" { } It "Copies operators" { - $results = Copy-DbaAgentOperator -Source $script:instance2 -Destination $script:instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 + $results = Copy-DbaAgentOperator -Source $global:instance2 -Destination $global:instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 $results.Count | Should -Be 2 $results.Status | Should -Be @("Successful", "Successful") } It "Returns one result that's skipped" { - $results = Copy-DbaAgentOperator -Source $script:instance2 -Destination $script:instance3 -Operator dbatoolsci_operator + $results = Copy-DbaAgentOperator -Source $global:instance2 -Destination $global:instance3 -Operator dbatoolsci_operator $results.Status | Should -Be "Skipped" } } diff --git a/tests/Copy-DbaAgentProxy.Tests.ps1 b/tests/Copy-DbaAgentProxy.Tests.ps1 index 80127b6b15..7d6c856a8e 100644 --- a/tests/Copy-DbaAgentProxy.Tests.ps1 +++ b/tests/Copy-DbaAgentProxy.Tests.ps1 @@ -1,5 +1,4 @@ param($ModuleName = 'dbatools') -. "$PSScriptRoot\constants.ps1" Describe "Copy-DbaAgentProxy" { Context "Validate parameters" { @@ -25,36 +24,40 @@ Describe "Copy-DbaAgentProxy" { $CommandUnderTest | Should -HaveParameter ExcludeProxyAccount -Type String[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } Describe "Copy-DbaAgentProxy Integration Tests" -Tag "IntegrationTests" { + BeforeDiscovery { + . "$PSScriptRoot\constants.ps1" + } + BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_proxy @proxy_name = 'dbatoolsci_agentproxy', @enabled = 1, @credential_name = 'dbatoolsci_credential'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'" $server.Query($sql) $sql = "DROP CREDENTIAL dbatoolsci_credential" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'" $server.Query($sql) $sql = "DROP CREDENTIAL dbatoolsci_credential" @@ -63,13 +66,13 @@ Describe "Copy-DbaAgentProxy Integration Tests" -Tag "IntegrationTests" { Context "Copies Agent Proxy" { It "returns one successful result" { - $results = Copy-DbaAgentProxy -Source $script:instance2 -Destination $script:instance3 -ProxyAccount dbatoolsci_agentproxy + $results = Copy-DbaAgentProxy -Source $env:instance2 -Destination $env:instance3 -ProxyAccount dbatoolsci_agentproxy $results.Count | Should -Be 1 $results.Status | Should -Be "Successful" } It "creates one proxy on the destination" { - $results = Get-DbaAgentProxy -SqlInstance $script:instance3 -Proxy dbatoolsci_agentproxy + $results = Get-DbaAgentProxy -SqlInstance $env:instance3 -Proxy dbatoolsci_agentproxy $results.Count | Should -Be 1 } } diff --git a/tests/Copy-DbaAgentSchedule.Tests.ps1 b/tests/Copy-DbaAgentSchedule.Tests.ps1 index c38cc0286a..1bb1fdcd5f 100644 --- a/tests/Copy-DbaAgentSchedule.Tests.ps1 +++ b/tests/Copy-DbaAgentSchedule.Tests.ps1 @@ -42,28 +42,28 @@ Describe "Copy-DbaAgentSchedule" { Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC msdb.dbo.sp_add_schedule @schedule_name = N'dbatoolsci_DailySchedule' , @freq_type = 4, @freq_interval = 1, @active_start_time = 010000" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance3 $sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'" $server.Query($sql) } It "Copies Agent Schedule" { - $results = Copy-DbaAgentSchedule -Source $script:instance2 -Destination $script:instance3 + $results = Copy-DbaAgentSchedule -Source $global:instance2 -Destination $global:instance3 $results.Count | Should -BeGreaterThan 1 ($results | Where-Object Status -eq "Successful") | Should -Not -BeNullOrEmpty } It "Returns one result of Start Time 1:00 AM" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_DailySchedule + $results = Get-DbaAgentSchedule -SqlInstance $global:instance3 -Schedule dbatoolsci_DailySchedule $results.ActiveStartTimeOfDay | Should -Be '01:00:00' } } diff --git a/tests/Copy-DbaBackupDevice.Tests.ps1 b/tests/Copy-DbaBackupDevice.Tests.ps1 index c09ef3fdba..b4e9592126 100644 --- a/tests/Copy-DbaBackupDevice.Tests.ps1 +++ b/tests/Copy-DbaBackupDevice.Tests.ps1 @@ -27,26 +27,26 @@ Describe "Copy-DbaBackupDevice" { $CommandUnderTest | Should -HaveParameter BackupDevice -Type Object[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" -Skip:($env:appveyor) { BeforeAll { $devicename = "dbatoolsci-backupdevice" - $backupdir = (Get-DbaDefaultPath -SqlInstance $script:instance1).Backup + $backupdir = (Get-DbaDefaultPath -SqlInstance $global:instance1).Backup $backupfilename = "$backupdir\$devicename.bak" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $server.Query("EXEC master.dbo.sp_addumpdevice @devtype = N'disk', @logicalname = N'$devicename',@physicalname = N'$backupfilename'") $server.Query("BACKUP DATABASE master TO DISK = '$backupfilename'") } AfterAll { $server.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'") - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $global:instance2 try { $server1.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'") } catch { @@ -56,17 +56,17 @@ Describe "Copy-DbaBackupDevice" { } It "Should copy the backup device with a warning" { - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue + $results = Copy-DbaBackupDevice -Source $global:instance1 -Destination $global:instance2 -WarningVariable warn -WarningAction SilentlyContinue $warn | Should -Match "backup device to destination" } It "Should report success when copying the backup device" { - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningAction SilentlyContinue + $results = Copy-DbaBackupDevice -Source $global:instance1 -Destination $global:instance2 -WarningAction SilentlyContinue $results.Status | Should -Be "Successful" } It "Should skip copying when the backup device already exists" { - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 + $results = Copy-DbaBackupDevice -Source $global:instance1 -Destination $global:instance2 $results.Status | Should -Not -Be "Successful" } } diff --git a/tests/Copy-DbaCredential.Tests.ps1 b/tests/Copy-DbaCredential.Tests.ps1 index fdb7c3bf0f..9a14d702f3 100644 --- a/tests/Copy-DbaCredential.Tests.ps1 +++ b/tests/Copy-DbaCredential.Tests.ps1 @@ -11,13 +11,13 @@ Describe "Copy-DbaCredential" { $plaintext = "BigOlPassword!" $password = ConvertTo-SecureString $plaintext -AsPlainText -Force - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 + $server3 = Connect-DbaInstance -SqlInstance $global:instance3 # Add user foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance3 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $global:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $global:instance3 } # check to see if a crypto provider is present on the instances @@ -32,8 +32,8 @@ Describe "Copy-DbaCredential" { (Get-DbaCredential -SqlInstance $server3 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance3 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $global:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $global:instance3 } } @@ -69,10 +69,10 @@ Describe "Copy-DbaCredential" { $CommandUnderTest | Should -HaveParameter ExcludeIdentity -Type String[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -120,7 +120,7 @@ Describe "Copy-DbaCredential" { Context "Crypto provider cred" { BeforeDiscovery { - $script:skipCryptoTests = -not $cryptoProvider + $global:skipCryptoTests = -not $cryptoProvider } It "ensure copied credential is using the same crypto provider" -Skip:$skipCryptoTests { diff --git a/tests/Copy-DbaCustomError.Tests.ps1 b/tests/Copy-DbaCustomError.Tests.ps1 index 918130662f..cd3fb0030c 100644 --- a/tests/Copy-DbaCustomError.Tests.ps1 +++ b/tests/Copy-DbaCustomError.Tests.ps1 @@ -24,41 +24,41 @@ Describe "Copy-DbaCustomError" { $CommandUnderTest | Should -HaveParameter ExcludeCustomError -Type Object[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC sp_addmessage @msgnum = 60000, @severity = 16,@msgtext = N'The item named %s already exists in %s.',@lang = 'us_english';") $server.Query("EXEC sp_addmessage @msgnum = 60000, @severity = 16, @msgtext = N'L''élément nommé %1! existe déjà dans %2!',@lang = 'French';") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC sp_dropmessage @msgnum = 60000, @lang = 'all';") - $server = Connect-DbaInstance -SqlInstance $script:instance3 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance3 -Database master $server.Query("EXEC sp_dropmessage @msgnum = 60000, @lang = 'all';") } It "copies the sample custom error" { - $results = Copy-DbaCustomError -Source $script:instance2 -Destination $script:instance3 -CustomError 60000 + $results = Copy-DbaCustomError -Source $global:instance2 -Destination $global:instance3 -CustomError 60000 $results.Name | Should -Be @("60000:'us_english'", "60000:'Français'") $results.Status | Should -Be @('Successful', 'Successful') } It "doesn't overwrite existing custom errors" { - $results = Copy-DbaCustomError -Source $script:instance2 -Destination $script:instance3 -CustomError 60000 + $results = Copy-DbaCustomError -Source $global:instance2 -Destination $global:instance3 -CustomError 60000 $results.Name | Should -Be @("60000:'us_english'", "60000:'Français'") $results.Status | Should -Be @('Skipped', 'Skipped') } It "the newly copied custom error exists" { - $results = Get-DbaCustomError -SqlInstance $script:instance2 + $results = Get-DbaCustomError -SqlInstance $global:instance2 $results.ID | Should -Contain 60000 } } diff --git a/tests/Copy-DbaDatabase.Tests.ps1 b/tests/Copy-DbaDatabase.Tests.ps1 index 4b4f2f0f17..992528daa2 100644 --- a/tests/Copy-DbaDatabase.Tests.ps1 +++ b/tests/Copy-DbaDatabase.Tests.ps1 @@ -12,24 +12,24 @@ Describe "Copy-DbaDatabase" { $backuprestoredb2 = "dbatoolsci_backuprestoreother$random" $detachattachdb = "dbatoolsci_detachattach$random" $supportDbs = @("ReportServer", "ReportServerTempDB", "distribution", "SSISDB") - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb, $detachattachdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2, $global:instance3 -Database $backuprestoredb, $detachattachdb - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance3 $server.Query("CREATE DATABASE $backuprestoredb2; ALTER DATABASE $backuprestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("CREATE DATABASE $backuprestoredb; ALTER DATABASE $backuprestoredb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $detachattachdb; ALTER DATABASE $detachattachdb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $backuprestoredb2; ALTER DATABASE $backuprestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") foreach ($db in $supportDbs) { $server.Query("CREATE DATABASE [$db]; ALTER DATABASE [$db] SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE;") } - $null = Set-DbaDbOwner -SqlInstance $script:instance2 -Database $backuprestoredb, $detachattachdb -TargetLogin sa + $null = Set-DbaDbOwner -SqlInstance $global:instance2 -Database $backuprestoredb, $detachattachdb -TargetLogin sa } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb, $detachattachdb, $backuprestoredb2 - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $supportDbs + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2, $global:instance3 -Database $backuprestoredb, $detachattachdb, $backuprestoredb2 + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $supportDbs } Context "Validate parameters" { @@ -97,7 +97,7 @@ Describe "Copy-DbaDatabase" { Context "Support databases are excluded when AllDatabase selected" { BeforeAll { $SupportDbs = "ReportServer", "ReportServerTempDB", "distribution", "SSISDB" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -AllDatabase -BackupRestore -UseLastBackup + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -AllDatabase -BackupRestore -UseLastBackup } It "Support databases should not be migrated" { @@ -107,20 +107,20 @@ Describe "Copy-DbaDatabase" { Context "Detach Attach" { It "Should be success" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $detachattachdb -DetachAttach -Reattach -Force + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $detachattachdb -DetachAttach -Reattach -Force $results.Status | Should -Be "Successful" } It "should not be null" { - $db1 = Get-DbaDatabase -SqlInstance $script:instance2 -Database $detachattachdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance3 -Database $detachattachdb + $db1 = Get-DbaDatabase -SqlInstance $global:instance2 -Database $detachattachdb + $db2 = Get-DbaDatabase -SqlInstance $global:instance3 -Database $detachattachdb $db1.Name | Should -Be $detachattachdb $db2.Name | Should -Be $detachattachdb } It "Name, recovery model, and status should match" { - $db1 = Get-DbaDatabase -SqlInstance $script:instance2 -Database $detachattachdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance3 -Database $detachattachdb + $db1 = Get-DbaDatabase -SqlInstance $global:instance2 -Database $detachattachdb + $db2 = Get-DbaDatabase -SqlInstance $global:instance3 -Database $detachattachdb $db1.Name | Should -Be $db2.Name $db1.RecoveryModel | Should -Be $db2.RecoveryModel $db1.Status | Should -Be $db2.Status @@ -128,7 +128,7 @@ Describe "Copy-DbaDatabase" { } It "Should say skipped" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $detachattachdb -DetachAttach -Reattach + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $detachattachdb -DetachAttach -Reattach $results.Status | Should -Be "Skipped" $results.Notes | Should -Be "Already exists on destination" } @@ -136,8 +136,8 @@ Describe "Copy-DbaDatabase" { Context "Backup restore" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath } It "copies a database successfully" { @@ -146,7 +146,7 @@ Describe "Copy-DbaDatabase" { } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database $backuprestoredb $dbs[0].Name | Should -Not -BeNullOrEmpty $dbs[0].Name | Should -Be $dbs[1].Name $dbs[0].RecoveryModel | Should -Be $dbs[1].RecoveryModel @@ -155,31 +155,31 @@ Describe "Copy-DbaDatabase" { } It "Should say skipped" { - $result = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath + $result = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath $result.Status | Should -Be "Skipped" $result.Notes | Should -Be "Already exists on destination" } It "Should overwrite when forced to" -Skip:$env:appveyor { - $result = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath -Force + $result = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath -Force $result.Status | Should -Be "Successful" } } Context "UseLastBackup - read backup history" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance3 -Database $backuprestoredb } It "copies a database successfully using backup history" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup $results.Name | Should -Be $backuprestoredb $results.Status | Should -Be "Successful" } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database $backuprestoredb $dbs[0].Name | Should -Not -BeNullOrEmpty $dbs[0].Name | Should -Be $dbs[1].Name $dbs[0].RecoveryModel | Should -Be $dbs[1].RecoveryModel @@ -190,20 +190,20 @@ Describe "Copy-DbaDatabase" { Context "UseLastBackup with -Continue" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb - $null = Get-DbaDbBackupHistory -SqlInstance $script:instance2 -Database $backuprestoredb -LastFull | Restore-DbaDatabase -SqlInstance $script:instance3 -DatabaseName $backuprestoredb -NoRecovery - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $backuprestoredb -BackupDirectory $NetworkPath -Type Diff + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance3 -Database $backuprestoredb + $null = Get-DbaDbBackupHistory -SqlInstance $global:instance2 -Database $backuprestoredb -LastFull | Restore-DbaDatabase -SqlInstance $global:instance3 -DatabaseName $backuprestoredb -NoRecovery + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $backuprestoredb -BackupDirectory $NetworkPath -Type Diff } It "continues the restore over existing database using backup history" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup -Continue + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup -Continue $results.Name | Should -Be $backuprestoredb $results.Status | Should -Be "Successful" } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database $backuprestoredb $dbs[0].Name | Should -Not -BeNullOrEmpty $dbs[0].Name | Should -Be $dbs[1].Name $dbs[0].RecoveryModel | Should -Be $dbs[1].RecoveryModel @@ -214,104 +214,104 @@ Describe "Copy-DbaDatabase" { Context "Copying with renames using backup/restore" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaDatabase -SqlInstance $script:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaDatabase -SqlInstance $global:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaDatabase -SqlInstance $script:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaDatabase -SqlInstance $global:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } It "Should have renamed a single db" { $newname = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname $results[0].DestinationDatabase | Should -Be $newname - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database $newname + $files = Get-DbaDbFile -Sqlinstance $global:instance3 -Database $newname ($files.PhysicalName -like "*$newname*").count | Should -Be $files.count } It "Should warn if trying to rename and prefix" { - $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar + $null = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar $warnvar | Should -BeLike "*NewName and Prefix are exclusive options, cannot specify both" } It "Should prefix databasename and files" { $prefix = "da$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -Prefix $prefix + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -Prefix $prefix $results[0].DestinationDatabase | Should -Be "$prefix$backuprestoredb" - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database "$prefix$backuprestoredb" + $files = Get-DbaDbFile -Sqlinstance $global:instance3 -Database "$prefix$backuprestoredb" ($files.PhysicalName -like "*$prefix$backuprestoredb*").count | Should -Be $files.count } } Context "Copying with renames using detachattach" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance3 -Database $backuprestoredb } It "Should have renamed a single db" { $newname = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -DetachAttach -NewName $newname -Reattach + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -DetachAttach -NewName $newname -Reattach $results[0].DestinationDatabase | Should -Be $newname - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database $newname + $files = Get-DbaDbFile -Sqlinstance $global:instance3 -Database $newname ($files.PhysicalName -like "*$newname*").count | Should -Be $files.count - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $newname + $null = Remove-DbaDatabase -SqlInstance $global:instance3 -Database $newname } It "Should prefix databasename and files" { $prefix = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -DetachAttach -Reattach -Prefix $prefix + $results = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -DetachAttach -Reattach -Prefix $prefix $results[0].DestinationDatabase | Should -Be "$prefix$backuprestoredb" - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database "$prefix$backuprestoredb" + $files = Get-DbaDbFile -Sqlinstance $global:instance3 -Database "$prefix$backuprestoredb" ($files.PhysicalName -like "*$prefix$backuprestoredb*").count | Should -Be $files.count - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database "$prefix$backuprestoredb" + $null = Remove-DbaDatabase -SqlInstance $global:instance3 -Database "$prefix$backuprestoredb" } It "Should warn and exit if newname and >1 db specified" { - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories - $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar + $null = Restore-DbaDatabase -SqlInstance $global:instance2 -path $global:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories + $null = Copy-DbaDatabase -Source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar $warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases" - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database RestoreTimeClean + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database RestoreTimeClean } } Context "Copying via Azure storage" -Skip:(-not $env:azurepasswd) { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance3 -Database $backuprestoredb + $server = Connect-DbaInstance -SqlInstance $global:instance2 + $sql = "CREATE CREDENTIAL [$global:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server.Query($sql) - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$global:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server.Query($sql) - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + $server3 = Connect-DbaInstance -SqlInstance $global:instance3 + $sql = "CREATE CREDENTIAL [$global:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server3.Query($sql) - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$global:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server3.Query($sql) } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance3 -Database $backuprestoredb | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $server.Query("DROP CREDENTIAL [$script:azureblob]") + Get-DbaDatabase -SqlInstance $global:instance3 -Database $backuprestoredb | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $global:instance2 + $server.Query("DROP CREDENTIAL [$global:azureblob]") $server.Query("DROP CREDENTIAL dbatools_ci") - $server = Connect-DbaInstance -SqlInstance $script:instance3 - $server.Query("DROP CREDENTIAL [$script:azureblob]") + $server = Connect-DbaInstance -SqlInstance $global:instance3 + $server.Query("DROP CREDENTIAL [$global:azureblob]") $server.Query("DROP CREDENTIAL dbatools_ci") } It "Should Copy $backuprestoredb via Azure legacy credentials" { - $results = Copy-DbaDatabase -source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $script:azureblob -AzureCredential dbatools_ci + $results = Copy-DbaDatabase -source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $global:azureblob -AzureCredential dbatools_ci $results[0].Name | Should -Be $backuprestoredb $results[0].Status | Should -BeLike 'Successful*' } It "Should Copy $backuprestoredb via Azure new credentials" { Start-Sleep -Seconds 60 - $results = Copy-DbaDatabase -source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -Newname djkhgfkjghfdjgd -BackupRestore -SharedPath $script:azureblob + $results = Copy-DbaDatabase -source $global:instance2 -Destination $global:instance3 -Database $backuprestoredb -Newname djkhgfkjghfdjgd -BackupRestore -SharedPath $global:azureblob $results[0].Name | Should -Be $backuprestoredb $results[0].DestinationDatabase | Should -Be 'djkhgfkjghfdjgd' $results[0].Status | Should -BeLike 'Successful*' diff --git a/tests/Copy-DbaDbAssembly.Tests.ps1 b/tests/Copy-DbaDbAssembly.Tests.ps1 index 4619a417eb..bcc42baf63 100644 --- a/tests/Copy-DbaDbAssembly.Tests.ps1 +++ b/tests/Copy-DbaDbAssembly.Tests.ps1 @@ -25,27 +25,27 @@ Describe "Copy-DbaDbAssembly Unit Tests" -Tag 'UnitTests' { $Command | Should -HaveParameter ExcludeAssembly -Type Object[] -Not -Mandatory } It "Should have Force parameter" { - $Command | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $Command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Copy-DbaDbAssembly Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server3 = Connect-DbaInstance -SqlInstance $global:instance3 $server3.Query("CREATE DATABASE dbclrassembly") $server3.Query("EXEC sp_configure 'CLR ENABLED' , '1'") $server3.Query("RECONFIGURE") - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 $server2.Query("CREATE DATABASE dbclrassembly") $server2.Query("EXEC sp_configure 'CLR ENABLED' , '1'") $server2.Query("RECONFIGURE") - $instance2DB = Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly + $instance2DB = Get-DbaDatabase -SqlInstance $global:instance2 -Database dbclrassembly $instance2DB.Query("CREATE ASSEMBLY [resolveDNS] AUTHORIZATION [dbo] FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300457830570000000000000000E00002210B010B000008000000060000000000002E260000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000E02500004B00000000400000B002000000000000000000000000000000000000006000000C000000A82400001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000034060000002000000008000000020000000000000000000000000000200000602E72737263000000B00200000040000000040000000A0000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000000E0000000000000000000000000000400000420000000000000000000000000000000010260000000000004800000002000500A42000000404000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B3001002F000000010000110000026F0500000A280600000A6F0700000A6F0800000A0A06730900000A0BDE0B260002730900000A0BDE0000072A0001100000000001002021000B010000011E02280A00000A2A42534A4201000100000000000C00000076322E302E35303732370000000005006C00000070010000237E0000DC010000A401000023537472696E67730000000080030000080000002355530088030000100000002347554944000000980300006C00000023426C6F620000000000000002000001471502000900000000FA253300160000010000000A0000000200000002000000010000000A0000000400000001000000010000000300000000000A0001000000000006003E0037000A006600510006009D008A000F00B10000000600E000C00006000001C0000A00440129010600590137000E00700165010E007401650100000000010000000000010001000100100019000000050001000100502000000000960070000A0001009C200000000086187D001000020000000100830019007D00140029007D001A0031007D00100039007D00100041006001240049008001280051008D01240009009A01240011007D002E0009007D001000200023001F002E000B0039002E00130042002E001B004B0033000480000000000000000000000000000000001E01000002000000000000000000000001002E00000000000200000000000000000000000100450000000000020000000000000000000000010037000000000000000000003C4D6F64756C653E007265736F6C7665444E532E646C6C0055736572446566696E656446756E6374696F6E73006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E67004950746F486F73744E616D65002E63746F72006970616464720053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465007265736F6C7665444E53004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E41747472696275746500537472696E67005472696D0053797374656D2E4E657400446E73004950486F7374456E74727900476574486F7374456E747279006765745F486F73744E616D6500546F537472696E6700000003200000000000BBBB2D2F51E12E4791398BFA79459ABA0008B77A5C561934E08905000111090E03200001052001011111042001010804010000000320000E05000112290E042001010E0507020E11090801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000000000004578305700000000020000001C010000C4240000C40600005253445357549849C5462E43AD588F97CA53634201000000633A5C74656D705C4461746162617365315C4461746162617365315C6F626A5C44656275675C7265736F6C7665444E532E706462000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000826000000000000000000001E260000002000000000000000000000000000000000000000000000102600000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000540200000000000000000000540234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000000000000000000000000000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B004B4010000010053007400720069006E006700460069006C00650049006E0066006F0000009001000001003000300030003000300034006200300000002C0002000100460069006C0065004400650073006300720069007000740069006F006E000000000020000000300008000100460069006C006500560065007200730069006F006E000000000030002E0030002E0030002E003000000040000F00010049006E007400650072006E0061006C004E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C00000000002800020001004C006500670061006C0043006F00700079007200690067006800740000002000000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C0000000000340008000100500072006F006400750063007400560065007200730069006F006E00000030002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000030002E0030002E0030002E003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000303600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") $hash = $instance2DB.Query("SELECT HASHBYTES('SHA2_512', content) AS SHA2_512 FROM sys.assembly_files WHERE name = 'resolveDNS'") @@ -61,7 +61,7 @@ Describe "Copy-DbaDbAssembly Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database dbclrassembly | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database dbclrassembly | Remove-DbaDatabase -Confirm:$false $server3.Query(" DECLARE @hash VARBINARY(64) = $hexStr @@ -75,30 +75,30 @@ Describe "Copy-DbaDbAssembly Integration Tests" -Tag "IntegrationTests" { Context "Copying database assemblies" { It "copies the sample database assembly" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $global:instance2 -Destination $global:instance3 -Assembly dbclrassembly.resolveDNS $results.Name | Should -Be resolveDns $results.Status | Should -Be Successful $results.Type | Should -Be "Database Assembly" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbclrassembly).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database dbclrassembly).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance3 -Database dbclrassembly).ID } It "excludes an assembly" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS -ExcludeAssembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $global:instance2 -Destination $global:instance3 -Assembly dbclrassembly.resolveDNS -ExcludeAssembly dbclrassembly.resolveDNS $results | Should -BeNullOrEmpty } It "forces a drop/create of the assembly in the target server" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $global:instance2 -Destination $global:instance3 -Assembly dbclrassembly.resolveDNS $results.Status | Should -Be Skipped $results.Notes | Should -Be "Already exists on destination" - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS -Force + $results = Copy-DbaDbAssembly -Source $global:instance2 -Destination $global:instance3 -Assembly dbclrassembly.resolveDNS -Force $results.Name | Should -Be resolveDns $results.Status | Should -Be Successful $results.Type | Should -Be "Database Assembly" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbclrassembly).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database dbclrassembly).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance3 -Database dbclrassembly).ID } } } diff --git a/tests/Copy-DbaDbCertificate.Tests.ps1 b/tests/Copy-DbaDbCertificate.Tests.ps1 index d910c63feb..042e4896f3 100644 --- a/tests/Copy-DbaDbCertificate.Tests.ps1 +++ b/tests/Copy-DbaDbCertificate.Tests.ps1 @@ -42,7 +42,7 @@ Describe "Copy-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter DecryptionPassword -Type SecureString } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -55,12 +55,12 @@ Describe "Copy-DbaDbCertificate Integration Tests" -Tag "IntegrationTests" { Context "Can create a database certificate" { BeforeAll { $passwd = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance2 -Database master -SecurePassword $passwd -Confirm:$false -ErrorAction SilentlyContinue + $masterkey = New-DbaDbMasterKey -SqlInstance $global:instance2 -Database master -SecurePassword $passwd -Confirm:$false -ErrorAction SilentlyContinue - $newdbs = New-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Name dbatoolscopycred - $null = New-DbaDbMasterKey -SqlInstance $script:instance2 -Database dbatoolscopycred -SecurePassword $passwd -Confirm:$false + $newdbs = New-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Name dbatoolscopycred + $null = New-DbaDbMasterKey -SqlInstance $global:instance2 -Database dbatoolscopycred -SecurePassword $passwd -Confirm:$false $certificateName2 = "Cert_$(Get-Random)" - $null = New-DbaDbCertificate -SqlInstance $script:instance2 -Name $certificateName2 -Database dbatoolscopycred -Confirm:$false + $null = New-DbaDbCertificate -SqlInstance $global:instance2 -Name $certificateName2 -Database dbatoolscopycred -Confirm:$false } AfterAll { @@ -73,20 +73,20 @@ Describe "Copy-DbaDbCertificate Integration Tests" -Tag "IntegrationTests" { It "Successfully copies a certificate" -Skip { $passwd = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force $paramscopydb = @{ - Source = $script:instance2 - Destination = $script:instance3 + Source = $global:instance2 + Destination = $global:instance3 EncryptionPassword = $passwd MasterKeyPassword = $passwd Database = "dbatoolscopycred" - SharedPath = $script:appveyorlabrepo + SharedPath = $global:appveyorlabrepo } $results = Copy-DbaDbCertificate @paramscopydb -Confirm:$false | Where-Object SourceDatabase -eq dbatoolscopycred | Select-Object -First 1 $results.Notes | Should -Be $null $results.Status | Should -Be "Successful" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolscopycred).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbatoolscopycred).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database dbatoolscopycred).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $global:instance3 -Database dbatoolscopycred).ID - Get-DbaDbCertificate -SqlInstance $script:instance3 -Database dbatoolscopycred -Certificate $certificateName2 | Should -Not -BeNullOrEmpty + Get-DbaDbCertificate -SqlInstance $global:instance3 -Database dbatoolscopycred -Certificate $certificateName2 | Should -Not -BeNullOrEmpty } } } diff --git a/tests/Copy-DbaDbMail.Tests.ps1 b/tests/Copy-DbaDbMail.Tests.ps1 index ca8a16bdc4..720e45153a 100644 --- a/tests/Copy-DbaDbMail.Tests.ps1 +++ b/tests/Copy-DbaDbMail.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Copy-DbaDbMail" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $servers = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $servers = Connect-DbaInstance -SqlInstance $global:instance2, $global:instance3 foreach ($s in $servers) { if ( (Get-DbaSpConfigure -SqlInstance $s -Name 'Database Mail XPs').RunningValue -ne 1 ) { Set-DbaSpConfigure -SqlInstance $s -Name 'Database Mail XPs' -Value 1 @@ -25,7 +25,7 @@ Describe "Copy-DbaDbMail" { $mailaccountpriority = 1 $splat1 = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Name = $accountName Description = $account_description EmailAddress = $email_address @@ -36,7 +36,7 @@ Describe "Copy-DbaDbMail" { $null = New-DbaDbMailAccount @splat1 -Force $splat2 = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Name = $profilename Description = $profile_description MailAccountName = $email_address @@ -46,7 +46,7 @@ Describe "Copy-DbaDbMail" { } AfterAll { - $servers = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $servers = Connect-DbaInstance -SqlInstance $global:instance2, $global:instance3 foreach ($s in $servers) { $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" @@ -76,60 +76,60 @@ Describe "Copy-DbaDbMail" { $CommandUnderTest | Should -HaveParameter DestinationSqlCredential -Type PSCredential } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } - Context "Copy DbMail to $script:instance3" { + Context "Copy DbMail to $global:instance3" { BeforeAll { - $results = Copy-DbaDbMail -Source $script:instance2 -Destination $script:instance3 + $results = Copy-DbaDbMail -Source $global:instance2 -Destination $global:instance3 } It "Should have copied database mailitems" { $results | Should -Not -BeNullOrEmpty } - It "Should have copied Mail Configuration from $script:instance2 to $script:instance3" { + It "Should have copied Mail Configuration from $global:instance2 to $global:instance3" { $results | Where-Object { $_.Type -eq 'Mail Configuration' } | Should -Not -BeNullOrEmpty $results | Where-Object { $_.Type -eq 'Mail Configuration' } | ForEach-Object { - $_.SourceServer | Should -Be "$script:instance2" - $_.DestinationServer | Should -Be "$script:instance3" + $_.SourceServer | Should -Be "$global:instance2" + $_.DestinationServer | Should -Be "$global:instance3" } } - It "Should have copied Mail Account from $script:instance2 to $script:instance3" { + It "Should have copied Mail Account from $global:instance2 to $global:instance3" { $results | Where-Object { $_.Type -eq 'Mail Account' } | Should -Not -BeNullOrEmpty $results | Where-Object { $_.Type -eq 'Mail Account' } | ForEach-Object { - $_.SourceServer | Should -Be "$script:instance2" - $_.DestinationServer | Should -Be "$script:instance3" + $_.SourceServer | Should -Be "$global:instance2" + $_.DestinationServer | Should -Be "$global:instance3" } } - It "Should have copied Mail Profile from $script:instance2 to $script:instance3" { + It "Should have copied Mail Profile from $global:instance2 to $global:instance3" { $results | Where-Object { $_.Type -eq 'Mail Profile' } | Should -Not -BeNullOrEmpty $results | Where-Object { $_.Type -eq 'Mail Profile' } | ForEach-Object { - $_.SourceServer | Should -Be "$script:instance2" - $_.DestinationServer | Should -Be "$script:instance3" + $_.SourceServer | Should -Be "$global:instance2" + $_.DestinationServer | Should -Be "$global:instance3" } } } Context "Copy MailServers specifically" { BeforeAll { - $results = Copy-DbaDbMail -Source $script:instance2 -Destination $script:instance3 -Type MailServers + $results = Copy-DbaDbMail -Source $global:instance2 -Destination $global:instance3 -Type MailServers } It "Should have copied database mailitems" { $results | Should -Not -BeNullOrEmpty } - It "Should have skipped MailServers from $script:instance2 to $script:instance3" { + It "Should have skipped MailServers from $global:instance2 to $global:instance3" { $results | ForEach-Object { - $_.SourceServer | Should -Be "$script:instance2" - $_.DestinationServer | Should -Be "$script:instance3" + $_.SourceServer | Should -Be "$global:instance2" + $_.DestinationServer | Should -Be "$global:instance3" $_.Status | Should -Be 'Skipped' } } diff --git a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 index d88e996b88..61b6d01d10 100644 --- a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 @@ -27,17 +27,17 @@ Describe "Copy-DbaDbQueryStoreOption" { $CommandUnderTest | Should -HaveParameter Exclude -Type Object[] } It "Should have AllDatabases as a parameter" { - $CommandUnderTest | Should -HaveParameter AllDatabases -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllDatabases -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } Describe "Copy-DbaDbQueryStoreOption Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 } Context "Verifying query store options are copied" { diff --git a/tests/Copy-DbaDbTableData.Tests.ps1 b/tests/Copy-DbaDbTableData.Tests.ps1 index 3ca79d3466..99c5e5f03e 100644 --- a/tests/Copy-DbaDbTableData.Tests.ps1 +++ b/tests/Copy-DbaDbTableData.Tests.ps1 @@ -6,8 +6,8 @@ Describe "Copy-DbaDbTableData" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb + $db2 = Get-DbaDatabase -SqlInstance $global:instance2 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example SELECT top 10 1 @@ -121,7 +121,7 @@ Describe "Copy-DbaDbTableData" { Context "Data movement" { It "copies the table data" { - $results = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_example2 + $results = Copy-DbaDbTableData -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_example2 $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count @@ -130,39 +130,39 @@ Describe "Copy-DbaDbTableData" { } It "copies the table data to another instance" { - $null = Copy-DbaDbTableData -SqlInstance $script:instance1 -Destination $script:instance2 -Database tempdb -Table tempdb.dbo.dbatoolsci_example -DestinationTable dbatoolsci_example3 + $null = Copy-DbaDbTableData -SqlInstance $global:instance1 -Destination $global:instance2 -Database tempdb -Table tempdb.dbo.dbatoolsci_example -DestinationTable dbatoolsci_example3 $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db2.Query("select id from dbo.dbatoolsci_example3") $table1count.Count | Should -Be $table2count.Count } It "Copy data using a query that relies on the default source database" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbTableData -SqlInstance $global:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } It "Copy data using a query that uses a 3 part query" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbTableData -SqlInstance $global:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } } Context "Functionality checks" { It "supports piping" { - $null = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example2 -Truncate + $null = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example2 -Truncate $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "supports piping more than one table" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example2, dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example3 + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example2, dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example3 $results.Count | Should -Be 2 $results.RowsCopied | Measure-Object -Sum | Select-Object -Expand Sum | Should -Be 20 } It "opens and closes connections properly" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example4' | Copy-DbaDbTableData -Destination $script:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example4' | Copy-DbaDbTableData -Destination $global:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate $results.Count | Should -Be 2 $table1DbCount = $db.Query("select id from dbo.dbatoolsci_example") $table4DbCount = $db2.Query("select id from dbo.dbatoolsci_example4") @@ -177,23 +177,23 @@ Describe "Copy-DbaDbTableData" { } It "Should return nothing if Source and Destination are same" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -Truncate + $result = Copy-DbaDbTableData -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example -Truncate $result | Should -BeNullOrEmpty } It "Should warn if the destinaton table doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbTableData -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -BeNullOrEmpty $tablewarning | Should -Match Auto } It "automatically creates the table" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_willexist -AutoCreateTable + $result = Copy-DbaDbTableData -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_willexist -AutoCreateTable $result.DestinationTable | Should -Be 'dbatoolsci_willexist' } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbTableData -SqlInstance $global:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -BeNullOrEmpty $tablewarning | Should -Match "cannot open database" } diff --git a/tests/Copy-DbaDbViewData.Tests.ps1 b/tests/Copy-DbaDbViewData.Tests.ps1 index 6a68667a4a..dbe78eb52f 100644 --- a/tests/Copy-DbaDbViewData.Tests.ps1 +++ b/tests/Copy-DbaDbViewData.Tests.ps1 @@ -33,8 +33,8 @@ Describe "Copy-DbaDbViewData" { } } - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb + $db2 = Get-DbaDatabase -SqlInstance $global:instance2 -Database tempdb Remove-TempObjects $db, $db2 $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example @@ -90,8 +90,8 @@ Describe "Copy-DbaDbViewData" { It "Should have Query as a String parameter" { $CommandUnderTest | Should -HaveParameter Query -Type String } - It "Should have AutoCreateTable as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type SwitchParameter + It "Should have AutoCreateTable as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type Switch } It "Should have BatchSize as an Int32 parameter" { $CommandUnderTest | Should -HaveParameter BatchSize -Type Int32 @@ -102,23 +102,23 @@ Describe "Copy-DbaDbViewData" { It "Should have DestinationTable as a String parameter" { $CommandUnderTest | Should -HaveParameter DestinationTable -Type String } - It "Should have NoTableLock as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter NoTableLock -Type SwitchParameter + It "Should have NoTableLock as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter NoTableLock -Type Switch } - It "Should have CheckConstraints as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter CheckConstraints -Type SwitchParameter + It "Should have CheckConstraints as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter CheckConstraints -Type Switch } - It "Should have FireTriggers as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter FireTriggers -Type SwitchParameter + It "Should have FireTriggers as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter FireTriggers -Type Switch } - It "Should have KeepIdentity as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter KeepIdentity -Type SwitchParameter + It "Should have KeepIdentity as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter KeepIdentity -Type Switch } - It "Should have KeepNulls as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter KeepNulls -Type SwitchParameter + It "Should have KeepNulls as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter KeepNulls -Type Switch } - It "Should have Truncate as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter Truncate -Type SwitchParameter + It "Should have Truncate as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter Truncate -Type Switch } It "Should have BulkCopyTimeOut as an Int32 parameter" { $CommandUnderTest | Should -HaveParameter BulkCopyTimeOut -Type Int32 @@ -126,41 +126,41 @@ Describe "Copy-DbaDbViewData" { It "Should have InputObject as a TableViewBase[] parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type TableViewBase[] } - It "Should have EnableException as a SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + It "Should have EnableException as a Switch parameter" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { It "copies the view data" { - $null = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_example2 + $null = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_example2 $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "copies the view data to another instance" { - $null = Copy-DbaDbViewData -SqlInstance $script:instance1 -Destination $script:instance2 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_example3 + $null = Copy-DbaDbViewData -SqlInstance $global:instance1 -Destination $global:instance2 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_example3 $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db2.Query("select id from dbo.dbatoolsci_view_example3") $table1count.Count | Should -Be $table2count.Count } It "supports piping" { - $null = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example2 -Truncate + $null = Get-DbaDbView -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example2 -Truncate $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "supports piping more than one view" { - $results = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example2, dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example3 + $results = Get-DbaDbView -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example2, dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example3 $results.Count | Should -Be 2 ($results.RowsCopied | Measure-Object -Sum).Sum | Should -Be 20 } It "opens and closes connections properly" { - $results = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View 'dbo.dbatoolsci_view_example', 'dbo.dbatoolsci_view_example4' | Copy-DbaDbViewData -Destination $script:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate + $results = Get-DbaDbView -SqlInstance $global:instance1 -Database tempdb -View 'dbo.dbatoolsci_view_example', 'dbo.dbatoolsci_view_example4' | Copy-DbaDbViewData -Destination $global:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate $results.Count | Should -Be 2 $table1dbcount = $db.Query("select id from dbo.dbatoolsci_view_example") $table4dbcount = $db2.Query("select id from dbo.dbatoolsci_view_example4") @@ -175,35 +175,35 @@ Describe "Copy-DbaDbViewData" { } It "Should warn and return nothing if Source and Destination are same" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null $result | Should -BeNullOrEmpty $tablewarning | Should -Match "Cannot copy dbatoolsci_view_example into itself" } It "Should warn if the destination table doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null $result | Should -BeNullOrEmpty $tablewarning | Should -Match Auto } It "automatically creates the table" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_will_exist -AutoCreateTable + $result = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_will_exist -AutoCreateTable $result.DestinationTable | Should -Be 'dbatoolsci_view_will_exist' } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $global:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -BeNullOrEmpty $tablewarning | Should -Match "Failure" } It "Copy data using a query that relies on the default source database" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } It "Copy data using a query that uses a 3 part query" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbViewData -SqlInstance $global:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } } diff --git a/tests/Copy-DbaEndpoint.Tests.ps1 b/tests/Copy-DbaEndpoint.Tests.ps1 index af639c0be8..5b4ae8bd6b 100644 --- a/tests/Copy-DbaEndpoint.Tests.ps1 +++ b/tests/Copy-DbaEndpoint.Tests.ps1 @@ -30,30 +30,30 @@ Describe "Copy-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter ExcludeEndpoint -Type Object[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } Describe "Copy-DbaEndpoint Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa - Get-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $global:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $global:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $global:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false } AfterAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa - Get-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa + Get-DbaEndpoint -SqlInstance $global:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $global:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $global:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $global:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa } It "copies an endpoint" { - $results = Copy-DbaEndpoint -Source $script:instance2 -Destination $script:instance3 -Endpoint dbatoolsci_MirroringEndpoint - $results.DestinationServer | Should -Be $script:instance3 + $results = Copy-DbaEndpoint -Source $global:instance2 -Destination $global:instance3 -Endpoint dbatoolsci_MirroringEndpoint + $results.DestinationServer | Should -Be $global:instance3 $results.Status | Should -Be 'Successful' $results.Name | Should -Be 'dbatoolsci_MirroringEndpoint' } diff --git a/tests/Copy-DbaInstanceAudit.Tests.ps1 b/tests/Copy-DbaInstanceAudit.Tests.ps1 index e6b14de207..87fda0474a 100644 --- a/tests/Copy-DbaInstanceAudit.Tests.ps1 +++ b/tests/Copy-DbaInstanceAudit.Tests.ps1 @@ -27,10 +27,10 @@ Describe "Copy-DbaInstanceAudit" { $CommandUnderTest | Should -HaveParameter Path -Type String } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Copy-DbaInstanceTrigger.Tests.ps1 b/tests/Copy-DbaInstanceTrigger.Tests.ps1 index 5e48d74cf8..3691908c65 100644 --- a/tests/Copy-DbaInstanceTrigger.Tests.ps1 +++ b/tests/Copy-DbaInstanceTrigger.Tests.ps1 @@ -42,7 +42,7 @@ Describe "Copy-DbaInstanceTrigger" { ON ALL SERVER FOR LOGON -- Tells you it's a logon trigger AS PRINT 'hello'" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $server.Query($sql) } @@ -50,7 +50,7 @@ Describe "Copy-DbaInstanceTrigger" { $server.Query("DROP TRIGGER [$triggername] ON ALL SERVER") try { - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $global:instance2 $server1.Query("DROP TRIGGER [$triggername] ON ALL SERVER") } catch { # don't care @@ -58,7 +58,7 @@ Describe "Copy-DbaInstanceTrigger" { } It "should report success" { - $results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningAction SilentlyContinue + $results = Copy-DbaInstanceTrigger -Source $global:instance1 -Destination $global:instance2 -WarningAction SilentlyContinue $results.Status | Should -Be "Successful" } } diff --git a/tests/Copy-DbaLinkedServer.Tests.ps1 b/tests/Copy-DbaLinkedServer.Tests.ps1 index d9c1ad9af6..1b7986be3f 100644 --- a/tests/Copy-DbaLinkedServer.Tests.ps1 +++ b/tests/Copy-DbaLinkedServer.Tests.ps1 @@ -11,8 +11,8 @@ Describe "Copy-DbaLinkedServer" { EXEC master.dbo.sp_addlinkedserver @server = N'dbatoolsci_localhost2', @srvproduct=N'', @provider=N'SQLNCLI10'; EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'dbatoolsci_localhost2',@useself=N'False',@locallogin=NULL,@rmtuser=N'testuser1',@rmtpassword='supfool';" - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + $server1 = Connect-DbaInstance -SqlInstance $global:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance3 $server1.Query($createsql) } @@ -64,7 +64,7 @@ Describe "Copy-DbaLinkedServer" { Context "Copy linked server with the same properties" { It "copies successfully" { - $result = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue + $result = Copy-DbaLinkedServer -Source $global:instance2 -Destination $global:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue $result | Select-Object -ExpandProperty Name -Unique | Should -Be "dbatoolsci_localhost" $result | Select-Object -ExpandProperty Status -Unique | Should -Be "Successful" } @@ -79,14 +79,14 @@ Describe "Copy-DbaLinkedServer" { } It "skips existing linked servers" { - $results = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue + $results = Copy-DbaLinkedServer -Source $global:instance2 -Destination $global:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue $results.Status | Should -Be "Skipped" } It "upgrades SQLNCLI provider based on what is registered" -Skip:($server1.VersionMajor -gt 14 -or $server2.VersionMajor -gt 14) { - $result = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost2 -UpgradeSqlClient - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + $result = Copy-DbaLinkedServer -Source $global:instance2 -Destination $global:instance3 -LinkedServer dbatoolsci_localhost2 -UpgradeSqlClient + $server1 = Connect-DbaInstance -SqlInstance $global:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance3 $server1.LinkedServers.Script() -match 'SQLNCLI10' | Should -Be $true $server2.LinkedServers.Script() -match 'SQLNCLI11' | Should -Be $true } diff --git a/tests/Copy-DbaLogin.Tests.ps1 b/tests/Copy-DbaLogin.Tests.ps1 index f71427e424..ea343ef019 100644 --- a/tests/Copy-DbaLogin.Tests.ps1 +++ b/tests/Copy-DbaLogin.Tests.ps1 @@ -30,17 +30,17 @@ Describe "Copy-DbaLogin" { } # create objects - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -InputFile $global:appveyorlabrepo\sql2008-scripts\logins.sql $tableQuery = @("CREATE TABLE tester_table (a int)", "CREATE USER tester FOR LOGIN tester", "GRANT INSERT ON tester_table TO tester;") - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query ($tableQuery -join '; ') - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $tableQuery[0] + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -Database tempdb -Query ($tableQuery -join '; ') + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database tempdb -Query $tableQuery[0] } BeforeEach { # cleanup targets - Initialize-TestLogin -Instance $script:instance2 -Login tester - Initialize-TestLogin -Instance $script:instance1 -Login tester_new + Initialize-TestLogin -Instance $global:instance2 -Login tester + Initialize-TestLogin -Instance $global:instance1 -Login tester_new } AfterAll { @@ -78,10 +78,10 @@ Describe "Copy-DbaLogin" { $CommandUnderTest | Should -HaveParameter ExcludeLogin -Type Object[] } It "Should have ExcludeSystemLogins parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemLogins -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemLogins -Type Switch } It "Should have SyncSaName parameter" { - $CommandUnderTest | Should -HaveParameter SyncSaName -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SyncSaName -Type Switch } It "Should have OutFile parameter" { $CommandUnderTest | Should -HaveParameter OutFile -Type String @@ -93,31 +93,31 @@ Describe "Copy-DbaLogin" { $CommandUnderTest | Should -HaveParameter LoginRenameHashtable -Type Hashtable } It "Should have KillActiveConnection parameter" { - $CommandUnderTest | Should -HaveParameter KillActiveConnection -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KillActiveConnection -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have ExcludePermissionSync parameter" { - $CommandUnderTest | Should -HaveParameter ExcludePermissionSync -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludePermissionSync -Type Switch } It "Should have NewSid parameter" { - $CommandUnderTest | Should -HaveParameter NewSid -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NewSid -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have ObjectLevel parameter" { - $CommandUnderTest | Should -HaveParameter ObjectLevel -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ObjectLevel -Type Switch } } Context "Copy login with the same properties" { It "Should copy successfully" { - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -Login Tester + $results = Copy-DbaLogin -Source $global:instance1 -Destination $global:instance2 -Login Tester $results.Status | Should -Be "Successful" - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login Tester - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login Tester + $login1 = Get-DbaLogin -SqlInstance $global:instance1 -login Tester + $login2 = Get-DbaLogin -SqlInstance $global:instance2 -login Tester $login2 | Should -Not -BeNullOrEmpty @@ -138,17 +138,17 @@ Describe "Copy-DbaLogin" { It "Should login with newly created Sql Login (also tests credential login) and gets name" { $password = ConvertTo-SecureString -Force -AsPlainText tester1 $cred = New-Object System.Management.Automation.PSCredential ("tester", $password) - $s = Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $cred - $s.Name | Should -Be $script:instance1 + $s = Connect-DbaInstance -SqlInstance $global:instance1 -SqlCredential $cred + $s.Name | Should -Be $global:instance1 } } Context "No overwrite" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -InputFile $global:appveyorlabrepo\sql2008-scripts\logins.sql } It "Should say skipped" { - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -Login tester + $results = Copy-DbaLogin -Source $global:instance1 -Destination $global:instance2 -Login tester $results.Status | Should -Be "Skipped" $results.Notes | Should -Be "Already exists on destination" } @@ -156,7 +156,7 @@ Describe "Copy-DbaLogin" { Context "ExcludeSystemLogins Parameter" { It "Should say skipped" { - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -ExcludeSystemLogins + $results = Copy-DbaLogin -Source $global:instance1 -Destination $global:instance2 -ExcludeSystemLogins $results.Status.Contains('Skipped') | Should -Be $true $results.Notes.Contains('System login') | Should -Be $true } @@ -164,7 +164,7 @@ Describe "Copy-DbaLogin" { Context "Supports pipe" { It "migrates the one tester login" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance2 -Force + $results = Get-DbaLogin -SqlInstance $global:instance1 -Login tester | Copy-DbaLogin -Destination $global:instance2 -Force $results.Name | Should -Be "tester" $results.Status | Should -Be "Successful" } @@ -172,25 +172,25 @@ Describe "Copy-DbaLogin" { Context "Supports cloning" { It "clones the one tester login" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid + $results = Copy-DbaLogin -Source $global:instance1 -Login tester -Destination $global:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - Get-DbaLogin -SqlInstance $script:instance1 -Login tester_new | Should -Not -BeNullOrEmpty + Get-DbaLogin -SqlInstance $global:instance1 -Login tester_new | Should -Not -BeNullOrEmpty } It "clones the one tester login using pipe" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid + $results = Get-DbaLogin -SqlInstance $global:instance1 -Login tester | Copy-DbaLogin -Destination $global:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - Get-DbaLogin -SqlInstance $script:instance1 -Login tester_new | Should -Not -BeNullOrEmpty + Get-DbaLogin -SqlInstance $global:instance1 -Login tester_new | Should -Not -BeNullOrEmpty } It "clones the one tester login to a different server with a new name" { 'tester', 'tester_new' | ForEach-Object { - Initialize-TestLogin -Instance $script:instance2 -Login $_ + Initialize-TestLogin -Instance $global:instance2 -Login $_ } - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } + $results = Get-DbaLogin -SqlInstance $global:instance1 -Login tester | Copy-DbaLogin -Destination $global:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $login = (Connect-DbaInstance -SqlInstance $script:instance2).Logins['tester_new'] + $login = (Connect-DbaInstance -SqlInstance $global:instance2).Logins['tester_new'] $login | Should -Not -BeNullOrEmpty $login | Remove-DbaLogin -Force } @@ -202,34 +202,34 @@ Describe "Copy-DbaLogin" { } BeforeEach { 'tester', 'tester_new' | ForEach-Object { - Initialize-TestLogin -Instance $script:instance2 -Login $_ + Initialize-TestLogin -Instance $global:instance2 -Login $_ } } AfterAll { Remove-Item -Path $tempExportFile -Force } It "clones the one tester login with sysadmin permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } + $results = Copy-DbaLogin -Source $global:instance1 -Login tester -Destination $global:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $i2 = Connect-DbaInstance -SqlInstance $script:instance2 + $i2 = Connect-DbaInstance -SqlInstance $global:instance2 $login = $i2.Logins['tester_new'] $login | Should -Not -BeNullOrEmpty $role = $i2.Roles['sysadmin'] $role.EnumMemberNames() | Should -Contain $results.Name } It "clones the one tester login with object permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } -ObjectLevel + $results = Copy-DbaLogin -Source $global:instance1 -Login tester -Destination $global:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } -ObjectLevel $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $i2 = Connect-DbaInstance -SqlInstance $script:instance2 + $i2 = Connect-DbaInstance -SqlInstance $global:instance2 $login = $i2.Logins['tester_new'] $login | Should -Not -BeNullOrEmpty - $permissions = Export-DbaUser -SqlInstance $script:instance2 -Database tempdb -User tester_new -Passthru + $permissions = Export-DbaUser -SqlInstance $global:instance2 -Database tempdb -User tester_new -Passthru $permissions | Should -BeLike '*GRANT INSERT ON OBJECT::`[dbo`].`[tester_table`] TO `[tester_new`]*' } It "scripts out two tester login with object permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester, port -OutFile $tempExportFile -ObjectLevel + $results = Copy-DbaLogin -Source $global:instance1 -Login tester, port -OutFile $tempExportFile -ObjectLevel $results | Should -Be $tempExportFile $permissions = Get-Content $tempExportFile -Raw $permissions | Should -BeLike '*CREATE LOGIN `[tester`]*' diff --git a/tests/Copy-DbaPolicyManagement.Tests.ps1 b/tests/Copy-DbaPolicyManagement.Tests.ps1 index dbd01cbf96..ef8a82beb3 100644 --- a/tests/Copy-DbaPolicyManagement.Tests.ps1 +++ b/tests/Copy-DbaPolicyManagement.Tests.ps1 @@ -30,10 +30,10 @@ Describe "Copy-DbaPolicyManagement" { $CommandUnderTest | Should -HaveParameter ExcludeCondition -Type Object[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Copy-DbaRegServer.Tests.ps1 b/tests/Copy-DbaRegServer.Tests.ps1 index b5705a70fc..6efa843d07 100644 --- a/tests/Copy-DbaRegServer.Tests.ps1 +++ b/tests/Copy-DbaRegServer.Tests.ps1 @@ -37,7 +37,7 @@ Describe "Copy-DbaRegServer" { Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance $script:instance2 + $server = Connect-DbaInstance $global:instance2 $regstore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbstore = $regstore.DatabaseEngineServerGroup @@ -59,7 +59,7 @@ Describe "Copy-DbaRegServer" { AfterAll { $newgroup.Drop() - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $global:instance1 $regstore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbstore = $regstore.DatabaseEngineServerGroup $groupstore = $dbstore.ServerGroups[$group] @@ -67,7 +67,7 @@ Describe "Copy-DbaRegServer" { } It "should copy registered servers successfully" { - $results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -Group $group -WarningAction SilentlyContinue + $results = Copy-DbaRegServer -Source $global:instance2 -Destination $global:instance1 -Group $group -WarningAction SilentlyContinue $results.Status | Should -Be @("Successful", "Successful") } } diff --git a/tests/Copy-DbaResourceGovernor.Tests.ps1 b/tests/Copy-DbaResourceGovernor.Tests.ps1 index 1aaf06bf03..559aea420b 100644 --- a/tests/Copy-DbaResourceGovernor.Tests.ps1 +++ b/tests/Copy-DbaResourceGovernor.Tests.ps1 @@ -39,7 +39,7 @@ END; ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE; "@ - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $global:instance2 -Query $sql } AfterAll { @@ -57,8 +57,8 @@ ALTER RESOURCE GOVERNOR RECONFIGURE; DROP RESOURCE POOL [dbatoolsci_prod]; ALTER RESOURCE GOVERNOR RECONFIGURE; "@ - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query $cleanup + Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $global:instance2, $global:instance3 -Query $cleanup } Context "Validate parameters" { @@ -84,22 +84,22 @@ ALTER RESOURCE GOVERNOR RECONFIGURE; $CommandUnderTest | Should -HaveParameter ExcludeResourcePool -Type Object[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command works" { It "copies the resource governor successfully" { - $results = Copy-DbaResourceGovernor -Source $script:instance2 -Destination $script:instance3 -Force -WarningAction SilentlyContinue + $results = Copy-DbaResourceGovernor -Source $global:instance2 -Destination $global:instance3 -Force -WarningAction SilentlyContinue $results.Status | Select-Object -Unique | Should -Be 'Successful' $results.Status.Count | Should -BeGreaterThan 3 $results.Name | Should -Contain 'dbatoolsci_prod' } It "returns the proper classifier function" { - $results = Get-DbaRgClassifierFunction -SqlInstance $script:instance3 + $results = Get-DbaRgClassifierFunction -SqlInstance $global:instance3 $results.Name | Should -Be 'dbatoolsci_fnRG' } } diff --git a/tests/Copy-DbaSpConfigure.Tests.ps1 b/tests/Copy-DbaSpConfigure.Tests.ps1 index a634c57bee..27726afbb1 100644 --- a/tests/Copy-DbaSpConfigure.Tests.ps1 +++ b/tests/Copy-DbaSpConfigure.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Copy-DbaSpConfigure" { $CommandUnderTest | Should -HaveParameter ExcludeConfigName -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -36,39 +36,39 @@ Describe "Copy-DbaSpConfigure Integration Tests" -Tag "IntegrationTests" { Context "Copy config with the same properties" { BeforeAll { - $sourceconfig = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue - $destconfig = (Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout).ConfiguredValue + $sourceconfig = (Get-DbaSpConfigure -SqlInstance $global:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $destconfig = (Get-DbaSpConfigure -SqlInstance $global:instance2 -ConfigName RemoteQueryTimeout).ConfiguredValue # Set it so they don't match if ($sourceconfig -and $destconfig) { $newvalue = $sourceconfig + $destconfig - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout -Value $newvalue + $null = Set-DbaSpConfigure -SqlInstance $global:instance2 -ConfigName RemoteQueryTimeout -Value $newvalue } } AfterAll { if ($destconfig -and $destconfig -ne $sourceconfig) { - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout -Value $destconfig + $null = Set-DbaSpConfigure -SqlInstance $global:instance2 -ConfigName RemoteQueryTimeout -Value $destconfig } } It "starts with different values" { - $config1 = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout - $config2 = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout + $config1 = Get-DbaSpConfigure -SqlInstance $global:instance1 -ConfigName RemoteQueryTimeout + $config2 = Get-DbaSpConfigure -SqlInstance $global:instance2 -ConfigName RemoteQueryTimeout $config1.ConfiguredValue | Should -Not -Be $config2.ConfiguredValue } It "copied successfully" { - $results = Copy-DbaSpConfigure -Source $script:instance1 -Destination $script:instance2 -ConfigName RemoteQueryTimeout + $results = Copy-DbaSpConfigure -Source $global:instance1 -Destination $global:instance2 -ConfigName RemoteQueryTimeout $results.Status | Should -Be "Successful" } It "retains the same properties" { - $config1 = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout - $config2 = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout + $config1 = Get-DbaSpConfigure -SqlInstance $global:instance1 -ConfigName RemoteQueryTimeout + $config2 = Get-DbaSpConfigure -SqlInstance $global:instance2 -ConfigName RemoteQueryTimeout $config1.ConfiguredValue | Should -Be $config2.ConfiguredValue } It "didn't modify the source" { - $newconfig = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $newconfig = (Get-DbaSpConfigure -SqlInstance $global:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue $newconfig | Should -Be $sourceconfig } } diff --git a/tests/Copy-DbaStartupProcedure.Tests.ps1 b/tests/Copy-DbaStartupProcedure.Tests.ps1 index 1898f77e79..6d217f37f3 100644 --- a/tests/Copy-DbaStartupProcedure.Tests.ps1 +++ b/tests/Copy-DbaStartupProcedure.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Copy-DbaStartupProcedure" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $procName = "dbatoolsci_test_startup" $server.Query("CREATE OR ALTER PROCEDURE $procName AS @@ -18,7 +18,7 @@ Describe "Copy-DbaStartupProcedure" { } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database "master" -Query "DROP PROCEDURE dbatoolsci_test_startup" + Invoke-DbaQuery -SqlInstance $global:instance2, $global:instance3 -Database "master" -Query "DROP PROCEDURE dbatoolsci_test_startup" } Context "Validate parameters" { @@ -44,16 +44,16 @@ Describe "Copy-DbaStartupProcedure" { $CommandUnderTest | Should -HaveParameter ExcludeProcedure -Type String[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Copy-DbaStartupProcedure -Source $script:instance2 -Destination $script:instance3 + $results = Copy-DbaStartupProcedure -Source $global:instance2 -Destination $global:instance3 } It "Should include test procedure: $procName" { ($results | Where-Object Name -eq $procName).Name | Should -Be $procName diff --git a/tests/Copy-DbaSystemDbUserObject.Tests.ps1 b/tests/Copy-DbaSystemDbUserObject.Tests.ps1 index f856ce7a86..4e1fc1c4ee 100644 --- a/tests/Copy-DbaSystemDbUserObject.Tests.ps1 +++ b/tests/Copy-DbaSystemDbUserObject.Tests.ps1 @@ -47,15 +47,15 @@ CREATE RULE dbo.dbatoolsci_range_rule AS @range>= $1000 AND @range <$20000; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $Function - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $TableFunction - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $Rule + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $Function + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $TableFunction + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $Rule } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION dbo.dbatoolscs_ISOweek;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION dbo.dbatoolsci_TableFunction;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP RULE dbo.dbatoolsci_range_rule;" + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query "DROP FUNCTION dbo.dbatoolscs_ISOweek;" + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query "DROP FUNCTION dbo.dbatoolsci_TableFunction;" + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query "DROP RULE dbo.dbatoolsci_range_rule;" } Context "Validate parameters" { @@ -87,17 +87,17 @@ AS Context "Should Copy Objects to the same instance" { It "Should execute with default parameters" { - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 + $results = Copy-DbaSystemDbUserObject -Source $global:instance2 -Destination $global:instance2 $results | Should -Not -BeNullOrEmpty } It "Should execute with -Classic parameter" { - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 -Classic + $results = Copy-DbaSystemDbUserObject -Source $global:instance2 -Destination $global:instance2 -Classic $results | Should -Not -BeNullOrEmpty } It "Should execute with -Force parameter" { - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 -Force + $results = Copy-DbaSystemDbUserObject -Source $global:instance2 -Destination $global:instance2 -Force $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Copy-DbaXESession.Tests.ps1 b/tests/Copy-DbaXESession.Tests.ps1 index 9433fa56b8..5a2f30ebe2 100644 --- a/tests/Copy-DbaXESession.Tests.ps1 +++ b/tests/Copy-DbaXESession.Tests.ps1 @@ -28,10 +28,10 @@ Describe "Copy-DbaXESession" { $CommandUnderTest | Should -HaveParameter ExcludeXeSession -Type Object[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Disable-DbaAgHadr.Tests.ps1 b/tests/Disable-DbaAgHadr.Tests.ps1 index 3c00065af9..297d199066 100644 --- a/tests/Disable-DbaAgHadr.Tests.ps1 +++ b/tests/Disable-DbaAgHadr.Tests.ps1 @@ -25,15 +25,15 @@ Describe "Disable-DbaAgHadr" { Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance3 = [Environment]::GetEnvironmentVariable('instance3') + $global:instance3 = [Environment]::GetEnvironmentVariable('instance3') } AfterAll { - Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + Enable-DbaAgHadr -SqlInstance $global:instance3 -Confirm:$false -Force } It "disables hadr" { - $results = Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + $results = Disable-DbaAgHadr -SqlInstance $global:instance3 -Confirm:$false -Force $results.IsHadrEnabled | Should -Be $false } } diff --git a/tests/Disable-DbaDbEncryption.Tests.ps1 b/tests/Disable-DbaDbEncryption.Tests.ps1 index e21b36320e..0a3d49b788 100644 --- a/tests/Disable-DbaDbEncryption.Tests.ps1 +++ b/tests/Disable-DbaDbEncryption.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Disable-DbaDbEncryption" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have NoEncryptionKeyDrop as a parameter" { - $CommandUnderTest | Should -HaveParameter NoEncryptionKeyDrop -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoEncryptionKeyDrop -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,18 +29,18 @@ Describe "Disable-DbaDbEncryption" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $global:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $global:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $global:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $global:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $global:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -70,7 +70,7 @@ Describe "Disable-DbaDbEncryption" { $null = $db | Enable-DbaDbEncryption -EncryptorName $mastercert.Name -Force # Give it time to finish encrypting or it'll error Start-Sleep 10 - $results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name + $results = Disable-DbaDbEncryption -SqlInstance $global:instance2 -Database $db.Name $results.EncryptionEnabled | Should -Be $false } } diff --git a/tests/Disable-DbaFilestream.Tests.ps1 b/tests/Disable-DbaFilestream.Tests.ps1 index aa4e84e121..aae7a3cd7d 100644 --- a/tests/Disable-DbaFilestream.Tests.ps1 +++ b/tests/Disable-DbaFilestream.Tests.ps1 @@ -15,10 +15,10 @@ Describe "Disable-DbaFilestream" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -26,16 +26,16 @@ Describe "Disable-DbaFilestream" { <# Describe "Disable-DbaFilestream Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $OriginalFileStream = Get-DbaFilestream -SqlInstance $script:instance1 + $OriginalFileStream = Get-DbaFilestream -SqlInstance $global:instance1 } AfterAll { - Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Force + Set-DbaFilestream -SqlInstance $global:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Force } Context "Changing FileStream Level" { BeforeAll { $NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division - $results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningAction SilentlyContinue -ErrorVariable errvar -ErrorAction SilentlyContinue + $results = Set-DbaFilestream -SqlInstance $global:instance1 -FileStreamLevel $NewLevel -Force -WarningAction SilentlyContinue -ErrorVariable errvar -ErrorAction SilentlyContinue } It "Should have changed the FileStream Level" { $results.InstanceAccessLevel | Should -Be $NewLevel diff --git a/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 b/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 index bc37cb3b79..a991e2ad0b 100644 --- a/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Disable-DbaForceNetworkEncryption" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { - $results = Disable-DbaForceNetworkEncryption -SqlInstance $script:instance1 -EnableException + $results = Disable-DbaForceNetworkEncryption -SqlInstance $global:instance1 -EnableException } It "returns false" { diff --git a/tests/Disable-DbaHideInstance.Tests.ps1 b/tests/Disable-DbaHideInstance.Tests.ps1 index 2564059ac7..8bb05b4601 100644 --- a/tests/Disable-DbaHideInstance.Tests.ps1 +++ b/tests/Disable-DbaHideInstance.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Disable-DbaHideInstance" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $results = Disable-DbaHideInstance -SqlInstance $script:instance1 -EnableException + $results = Disable-DbaHideInstance -SqlInstance $global:instance1 -EnableException } It "Returns false for HideInstance" { diff --git a/tests/Disable-DbaReplDistributor.Tests.ps1 b/tests/Disable-DbaReplDistributor.Tests.ps1 index f7625d8114..e514227791 100644 --- a/tests/Disable-DbaReplDistributor.Tests.ps1 +++ b/tests/Disable-DbaReplDistributor.Tests.ps1 @@ -17,10 +17,10 @@ Describe "Disable-DbaReplDistributor" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Disable-DbaReplPublishing.Tests.ps1 b/tests/Disable-DbaReplPublishing.Tests.ps1 index 44adb04a97..57e8b8dd32 100644 --- a/tests/Disable-DbaReplPublishing.Tests.ps1 +++ b/tests/Disable-DbaReplPublishing.Tests.ps1 @@ -17,10 +17,10 @@ Describe "Disable-DbaReplPublishing" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Disable-DbaStartupProcedure.Tests.ps1 b/tests/Disable-DbaStartupProcedure.Tests.ps1 index c26c7d6722..c477f3f545 100644 --- a/tests/Disable-DbaStartupProcedure.Tests.ps1 +++ b/tests/Disable-DbaStartupProcedure.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Disable-DbaStartupProcedure" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $startupProcName = "StartUpProc$random" $startupProc = "dbo.$startupProcName" @@ -38,7 +38,7 @@ Describe "Disable-DbaStartupProcedure" { } It "Disables the startup procedure" { - $result = Disable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Disable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure $startupProc -Confirm:$false $result.Schema | Should -Be "dbo" $result.Name | Should -Be $startupProcName $result.Action | Should -Be "Disable" @@ -47,7 +47,7 @@ Describe "Disable-DbaStartupProcedure" { } It "Returns correct output for already disabled procedure" { - $result = Disable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Disable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure $startupProc -Confirm:$false $result.Schema | Should -Be "dbo" $result.Name | Should -Be $startupProcName $result.Action | Should -Be "Disable" @@ -56,8 +56,8 @@ Describe "Disable-DbaStartupProcedure" { } It "Disables startup procedure using piped input" { - $null = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 | Disable-DbaStartupProcedure -Confirm:$false + $null = Enable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Get-DbaStartupProcedure -SqlInstance $global:instance2 | Disable-DbaStartupProcedure -Confirm:$false $result.Schema | Should -Be "dbo" $result.Name | Should -Be $startupProcName $result.Action | Should -Be "Disable" diff --git a/tests/Disable-DbaTraceFlag.Tests.ps1 b/tests/Disable-DbaTraceFlag.Tests.ps1 index 9116912bd8..aa5d681e90 100644 --- a/tests/Disable-DbaTraceFlag.Tests.ps1 +++ b/tests/Disable-DbaTraceFlag.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Disable-DbaTraceFlag" { $CommandUnderTest | Should -HaveParameter TraceFlag -Type Int32[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -25,7 +25,7 @@ Describe "Disable-DbaTraceFlag" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $startingtfs = Get-DbaTraceFlag -SqlInstance $server $safetraceflag = 3226 diff --git a/tests/Disconnect-DbaInstance.Tests.ps1 b/tests/Disconnect-DbaInstance.Tests.ps1 index eafa695eaa..4c659b12c8 100644 --- a/tests/Disconnect-DbaInstance.Tests.ps1 +++ b/tests/Disconnect-DbaInstance.Tests.ps1 @@ -62,7 +62,7 @@ Describe "Disconnect-DbaInstance" { } BeforeAll { - $null = Connect-DbaInstance -SqlInstance $script:instance1 + $null = Connect-DbaInstance -SqlInstance $global:instance1 } It "disconnects and returns some results" { diff --git a/tests/Dismount-DbaDatabase.Tests.ps1 b/tests/Dismount-DbaDatabase.Tests.ps1 index b6875fda08..7eae8abdbd 100644 --- a/tests/Dismount-DbaDatabase.Tests.ps1 +++ b/tests/Dismount-DbaDatabase.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Dismount-DbaDatabase" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have UpdateStatistics as a parameter" { - $CommandUnderTest | Should -HaveParameter UpdateStatistics -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UpdateStatistics -Type Switch } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -35,22 +35,22 @@ Describe "Dismount-DbaDatabase" { BeforeAll { $dbname = "dbatoolsci_detachattach" - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false - $db1 = New-DbaDatabase -SqlInstance $script:instance3 -Name $dbname + $null = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $db1 = New-DbaDatabase -SqlInstance $global:instance3 -Name $dbname $fileStructure = New-Object System.Collections.Specialized.StringCollection - foreach ($file in (Get-DbaDbFile -SqlInstance $script:instance3 -Database $dbname).PhysicalName) { + foreach ($file in (Get-DbaDbFile -SqlInstance $global:instance3 -Database $dbname).PhysicalName) { $null = $fileStructure.Add($file) } } AfterAll { - $null = Mount-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -FileStructure $fileStructure - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Mount-DbaDatabase -SqlInstance $global:instance3 -Database $dbname -FileStructure $fileStructure + $null = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false } It "Detaches a single database and tests to ensure the alias still exists" { - $results = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Force + $results = Dismount-DbaDatabase -SqlInstance $global:instance3 -Database $dbname -Force $results.DetachResult | Should -Be "Success" $results.DatabaseID | Should -Be $db1.ID $results.Database | Should -Be $dbname @@ -60,44 +60,44 @@ Describe "Dismount-DbaDatabase" { Context "Database Detachment" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + Get-DbaProcess -SqlInstance $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance3 $db1 = "dbatoolsci_dbsetstate_detached" $server.Query("CREATE DATABASE $db1") - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + Get-DbaProcess -SqlInstance $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance3 $db2 = "dbatoolsci_dbsetstate_detached_withSnap" $server.Query("CREATE DATABASE $db2") - $null = New-DbaDbSnapshot -SqlInstance $script:instance3 -Database $db2 + $null = New-DbaDbSnapshot -SqlInstance $global:instance3 -Database $db2 $fileStructure = New-Object System.Collections.Specialized.StringCollection - foreach ($file in (Get-DbaDbFile -SqlInstance $script:instance3 -Database $db1).PhysicalName) { + foreach ($file in (Get-DbaDbFile -SqlInstance $global:instance3 -Database $db1).PhysicalName) { $null = $fileStructure.Add($file) } - Stop-DbaProcess -SqlInstance $script:instance3 -Database $db1 + Stop-DbaProcess -SqlInstance $global:instance3 -Database $db1 } AfterAll { - $null = Remove-DbaDbSnapshot -SqlInstance $script:instance3 -Database $db2 -Force - $null = Mount-DbaDatabase -SqlInstance $script:instance3 -Database $db1 -FileStructure $fileStructure - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + $null = Remove-DbaDbSnapshot -SqlInstance $global:instance3 -Database $db2 -Force + $null = Mount-DbaDatabase -SqlInstance $global:instance3 -Database $db1 -FileStructure $fileStructure + $null = Get-DbaDatabase -SqlInstance $global:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false } It "Skips detachment if database is snapshotted" { - $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn + $result = Dismount-DbaDatabase -SqlInstance $global:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty $warn | Should -Match "snapshot" - $result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db2 + $result = Get-DbaDatabase -SqlInstance $global:instance3 -Database $db2 $result | Should -Not -BeNullOrEmpty } It "Detaches the database correctly" { - $null = Stop-DbaProcess -SqlInstance $script:instance3 -Database $db1 - $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db1 - $result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db1 + $null = Stop-DbaProcess -SqlInstance $global:instance3 -Database $db1 + $result = Dismount-DbaDatabase -SqlInstance $global:instance3 -Database $db1 + $result = Get-DbaDatabase -SqlInstance $global:instance3 -Database $db1 $result | Should -BeNullOrEmpty } } } } -#$script:instance2 - to make it show up in appveyor, long story +#$global:instance2 - to make it show up in appveyor, long story diff --git a/tests/Enable-DbaAgHadr.Tests.ps1 b/tests/Enable-DbaAgHadr.Tests.ps1 index 3698806cc7..deb5802992 100644 --- a/tests/Enable-DbaAgHadr.Tests.ps1 +++ b/tests/Enable-DbaAgHadr.Tests.ps1 @@ -16,20 +16,20 @@ Describe "Enable-DbaAgHadr" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + $null = Disable-DbaAgHadr -SqlInstance $global:instance3 -Confirm:$false -Force } It "enables hadr" { - $results = Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + $results = Enable-DbaAgHadr -SqlInstance $global:instance3 -Confirm:$false -Force $results.IsHadrEnabled | Should -Be $true } } diff --git a/tests/Enable-DbaDbEncryption.Tests.ps1 b/tests/Enable-DbaDbEncryption.Tests.ps1 index a003812a84..085c129cf9 100644 --- a/tests/Enable-DbaDbEncryption.Tests.ps1 +++ b/tests/Enable-DbaDbEncryption.Tests.ps1 @@ -20,11 +20,11 @@ Describe "Enable-DbaDbEncryption" { It "Should have InputObject as a non-mandatory parameter of type Database[]" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } - It "Should have Force as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + It "Should have Force as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -32,18 +32,18 @@ Describe "Enable-DbaDbEncryption" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $global:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $global:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $global:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $global:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $global:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -67,8 +67,8 @@ Describe "Enable-DbaDbEncryption" { } It "should enable encryption on a database" { - $null = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name - $results = Enable-DbaDbEncryption -SqlInstance $script:instance2 -EncryptorName $mastercert.Name -Database $db.Name -Force + $null = Disable-DbaDbEncryption -SqlInstance $global:instance2 -Database $db.Name + $results = Enable-DbaDbEncryption -SqlInstance $global:instance2 -EncryptorName $mastercert.Name -Database $db.Name -Force $results.EncryptionEnabled | Should -Be $true } } diff --git a/tests/Enable-DbaFilestream.Tests.ps1 b/tests/Enable-DbaFilestream.Tests.ps1 index df0b802bd1..a0a415e98e 100644 --- a/tests/Enable-DbaFilestream.Tests.ps1 +++ b/tests/Enable-DbaFilestream.Tests.ps1 @@ -31,25 +31,25 @@ Describe "Enable-DbaFilestream" { Describe "Enable-DbaFilestream Integration Tests" -Tag "IntegrationTests" { BeforeDiscovery { - $OriginalFileStream = Get-DbaFilestream -SqlInstance $script:instance1 + $OriginalFileStream = Get-DbaFilestream -SqlInstance $global:instance1 } BeforeAll { - $OriginalFileStream = Get-DbaFilestream -SqlInstance $script:instance1 + $OriginalFileStream = Get-DbaFilestream -SqlInstance $global:instance1 } AfterAll { if ($OriginalFileStream.InstanceAccessLevel -eq 0) { - Disable-DbaFilestream -SqlInstance $script:instance1 -Confirm:$false + Disable-DbaFilestream -SqlInstance $global:instance1 -Confirm:$false } else { - Enable-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Confirm:$false + Enable-DbaFilestream -SqlInstance $global:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Confirm:$false } } Context "Changing FileStream Level" { BeforeAll { $NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division - $results = Enable-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Confirm:$false + $results = Enable-DbaFilestream -SqlInstance $global:instance1 -FileStreamLevel $NewLevel -Confirm:$false } It "Should have changed the FileStream Level" { diff --git a/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 b/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 index 682207bb32..f5232043e8 100644 --- a/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Enable-DbaForceNetworkEncryption" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $results = Enable-DbaForceNetworkEncryption -SqlInstance $script:instance1 -EnableException + $results = Enable-DbaForceNetworkEncryption -SqlInstance $global:instance1 -EnableException } It "returns true" { diff --git a/tests/Enable-DbaHideInstance.Tests.ps1 b/tests/Enable-DbaHideInstance.Tests.ps1 index b4a2b5ad88..bfaa47778b 100644 --- a/tests/Enable-DbaHideInstance.Tests.ps1 +++ b/tests/Enable-DbaHideInstance.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Enable-DbaHideInstance" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $instance = $script:instance1 + $instance = $global:instance1 } AfterAll { diff --git a/tests/Enable-DbaReplPublishing.Tests.ps1 b/tests/Enable-DbaReplPublishing.Tests.ps1 index ae612dfc2c..8487276e24 100644 --- a/tests/Enable-DbaReplPublishing.Tests.ps1 +++ b/tests/Enable-DbaReplPublishing.Tests.ps1 @@ -23,13 +23,13 @@ Describe "Enable-DbaReplPublishing" { $CommandUnderTest | Should -HaveParameter PublisherSqlLogin -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -62,10 +62,10 @@ Describe "Enable-DbaReplPublishing" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } } diff --git a/tests/Enable-DbaStartupProcedure.Tests.ps1 b/tests/Enable-DbaStartupProcedure.Tests.ps1 index 5602cc9c2b..f9182c3058 100644 --- a/tests/Enable-DbaStartupProcedure.Tests.ps1 +++ b/tests/Enable-DbaStartupProcedure.Tests.ps1 @@ -15,14 +15,14 @@ Describe "Enable-DbaStartupProcedure" { $CommandUnderTest | Should -HaveParameter StartupProcedure -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $startupProcName = "StartUpProc$random" $startupProc = "dbo.$startupProcName" @@ -36,7 +36,7 @@ Describe "Enable-DbaStartupProcedure" { Context "Validate returns correct output for enable" { BeforeAll { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure $startupProc -Confirm:$false } It "returns correct schema" { $result.Schema | Should -Be "dbo" @@ -57,7 +57,7 @@ Describe "Enable-DbaStartupProcedure" { Context "Validate returns correct output for already existing state" { BeforeAll { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure $startupProc -Confirm:$false } It "returns correct schema" { $result.Schema | Should -Be "dbo" @@ -78,7 +78,7 @@ Describe "Enable-DbaStartupProcedure" { Context "Validate returns correct output for missing procedures" { BeforeAll { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure "Unknown.NotHere" -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure "Unknown.NotHere" -Confirm:$false } It "returns null" { $result | Should -BeNullOrEmpty @@ -87,7 +87,7 @@ Describe "Enable-DbaStartupProcedure" { Context "Validate returns correct output for incorrectly formed procedures" { BeforeAll { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure "Four.Part.Schema.Name" -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $global:instance2 -StartupProcedure "Four.Part.Schema.Name" -Confirm:$false } It "returns null" { $result | Should -BeNullOrEmpty diff --git a/tests/Enable-DbaTraceFlag.Tests.ps1 b/tests/Enable-DbaTraceFlag.Tests.ps1 index d3348e4dfb..171fcaf483 100644 --- a/tests/Enable-DbaTraceFlag.Tests.ps1 +++ b/tests/Enable-DbaTraceFlag.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Enable-DbaTraceFlag" { $CommandUnderTest | Should -HaveParameter TraceFlag -Type Int32[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -25,8 +25,8 @@ Describe "Enable-DbaTraceFlag" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $startingtfs = Get-DbaTraceFlag -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 + $startingtfs = Get-DbaTraceFlag -SqlInstance $global:instance2 $safetraceflag = 3226 if ($startingtfs.TraceFlag -contains $safetraceflag) { diff --git a/tests/Expand-DbaDbLogFile.Tests.ps1 b/tests/Expand-DbaDbLogFile.Tests.ps1 index 25c66cd114..f31f7758b8 100644 --- a/tests/Expand-DbaDbLogFile.Tests.ps1 +++ b/tests/Expand-DbaDbLogFile.Tests.ps1 @@ -35,7 +35,7 @@ Describe "Expand-DbaDbLogFile" { $CommandUnderTest | Should -HaveParameter LogFileId -Type Int32 } It "Should have ShrinkLogFile parameter" { - $CommandUnderTest | Should -HaveParameter ShrinkLogFile -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ShrinkLogFile -Type Switch } It "Should have ShrinkSize parameter" { $CommandUnderTest | Should -HaveParameter ShrinkSize -Type Int32 @@ -44,21 +44,21 @@ Describe "Expand-DbaDbLogFile" { $CommandUnderTest | Should -HaveParameter BackupDirectory -Type String } It "Should have ExcludeDiskSpaceValidation parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeDiskSpaceValidation -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeDiskSpaceValidation -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Ensure command functionality" { BeforeAll { - $db1 = New-DbaDatabase -SqlInstance $script:instance1 -Name $db1Name - $results = Expand-DbaDbLogFile -SqlInstance $script:instance1 -Database $db1 -TargetLogSize 128 + $db1 = New-DbaDatabase -SqlInstance $global:instance1 -Name $db1Name + $results = Expand-DbaDbLogFile -SqlInstance $global:instance1 -Database $db1 -TargetLogSize 128 } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db1Name + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance1 -Database $db1Name } It "Should have correct properties" { diff --git a/tests/Export-DbaBinaryFile.Tests.ps1 b/tests/Export-DbaBinaryFile.Tests.ps1 index f4fbe5ba92..eb3c5c4b61 100644 --- a/tests/Export-DbaBinaryFile.Tests.ps1 +++ b/tests/Export-DbaBinaryFile.Tests.ps1 @@ -45,16 +45,16 @@ Describe "Export-DbaBinaryFile" { $CommandUnderTest | Should -HaveParameter InputObject -Type Table[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFilezz]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") - $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz -FilePath $script:appveyorlabrepo\azure\adalsql.msi - $null = Get-ChildItem $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz + $null = Import-DbaBinaryFile -SqlInstance $global:instance2 -Database tempdb -Table BunchOFilezz -FilePath $global:appveyorlabrepo\azure\adalsql.msi + $null = Get-ChildItem $global:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $global:instance2 -Database tempdb -Table BunchOFilezz } AfterAll { @@ -67,13 +67,13 @@ Describe "Export-DbaBinaryFile" { } It "exports the table data to file" { - $results = Export-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Path C:\temp\exports + $results = Export-DbaBinaryFile -SqlInstance $global:instance2 -Database tempdb -Path C:\temp\exports $results.Name.Count | Should -Be 3 $results.Name | Should -Be @('adalsql.msi', 'localhost.crt', 'localhost.pfx') } It "exports the table data to file using pipeline" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb | Export-DbaBinaryFile -Path C:\temp\exports + $results = Get-DbaBinaryFileTable -SqlInstance $global:instance2 -Database tempdb | Export-DbaBinaryFile -Path C:\temp\exports $results.Name.Count | Should -Be 3 $results.Name | Should -Be @('adalsql.msi', 'localhost.crt', 'localhost.pfx') } diff --git a/tests/Export-DbaCredential.Tests.ps1 b/tests/Export-DbaCredential.Tests.ps1 index 5719715e29..d509968891 100644 --- a/tests/Export-DbaCredential.Tests.ps1 +++ b/tests/Export-DbaCredential.Tests.ps1 @@ -42,20 +42,20 @@ Describe "Export-DbaCredential Integration Tests" -Tag "IntegrationTests" { BeforeAll { $plaintext = "ReallyT3rrible!" $password = ConvertTo-SecureString $plaintext -AsPlainText -Force - $null = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_CaptainAcred -Identity dbatoolsci_CaptainAcredId -Password $password - $null = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_Hulk -Password $password + $null = New-DbaCredential -SqlInstance $global:instance2 -Name dbatoolsci_CaptainAcred -Identity dbatoolsci_CaptainAcredId -Password $password + $null = New-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_Hulk -Password $password $allfiles = @() } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_CaptainAcred, dbatoolsci_Hulk -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_CaptainAcred, dbatoolsci_Hulk -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } $null = $allfiles | Remove-Item -ErrorAction Ignore } Context "Should export all credentials" { BeforeAll { - $file = Export-DbaCredential -SqlInstance $script:instance2 + $file = Export-DbaCredential -SqlInstance $global:instance2 $results = Get-Content -Path $file -Raw $allfiles += $file } @@ -73,7 +73,7 @@ Describe "Export-DbaCredential Integration Tests" -Tag "IntegrationTests" { Context "Should export a specific credential" { BeforeAll { $filepath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath + $null = Export-DbaCredential -SqlInstance $global:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath $results = Get-Content -Path $filepath $allfiles += $filepath } @@ -91,7 +91,7 @@ Describe "Export-DbaCredential Integration Tests" -Tag "IntegrationTests" { Context "Should export a specific credential and append it to existing export" { BeforeAll { $filepath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_Hulk' -FilePath $filepath -Append + $null = Export-DbaCredential -SqlInstance $global:instance2 -Identity 'dbatoolsci_Hulk' -FilePath $filepath -Append $results = Get-Content -Path $filepath } It "Should have information" { @@ -108,7 +108,7 @@ Describe "Export-DbaCredential Integration Tests" -Tag "IntegrationTests" { Context "Should export a specific credential excluding the password" { BeforeAll { $filepath = "$env:USERPROFILE\Documents\temp-credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath -ExcludePassword + $null = Export-DbaCredential -SqlInstance $global:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath -ExcludePassword $results = Get-Content -Path $filepath $allfiles += $filepath } diff --git a/tests/Export-DbaDacPackage.Tests.ps1 b/tests/Export-DbaDacPackage.Tests.ps1 index 2e728a626f..d8a28defe2 100644 --- a/tests/Export-DbaDacPackage.Tests.ps1 +++ b/tests/Export-DbaDacPackage.Tests.ps1 @@ -54,9 +54,9 @@ Describe "Export-DbaDacPackage" { BeforeAll { $random = Get-Random $dbname = "dbatoolsci_exportdacpac_$random" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $null = $server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname $null = $db.Query("CREATE TABLE dbo.example (id int, PRIMARY KEY (id)); INSERT dbo.example SELECT top 100 object_id @@ -67,21 +67,21 @@ Describe "Export-DbaDacPackage" { $dbName2 = "dbatoolsci:2_$random" $dbName2Escaped = "dbatoolsci`$2_$random" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName2 + $null = New-DbaDatabase -SqlInstance $global:instance1 -Name $dbName2 } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbName2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance1 -Database $dbname, $dbName2 -Confirm:$false } Context "Ensure the database name is part of the generated filename" { It "Database name is included in the output filename" { - $result = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname + $result = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname $result.Path | Should -BeLike "*$($dbName)*" } It "Database names with invalid filesystem chars are successfully exported" { - $result = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname, $dbName2 + $result = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname, $dbName2 $result.Path.Count | Should -Be 2 $result.Path[0] | Should -BeLike "*$($dbName)*" $result.Path[1] | Should -BeLike "*$($dbName2Escaped)*" @@ -99,8 +99,8 @@ Describe "Export-DbaDacPackage" { Remove-Item $testFolder -Force -Recurse } - It "exports a dacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname + It "exports a dacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -108,18 +108,18 @@ Describe "Export-DbaDacPackage" { } } - It "exports to the correct directory" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + It "exports to the correct directory" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { $relativePath = '.\' $expectedPath = (Resolve-Path $relativePath).Path - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -Path $relativePath + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -Path $relativePath $results.Path | Split-Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true } - It "exports dacpac with a table list" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + It "exports dacpac with a table list" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { $relativePath = '.\extract.dacpac' $expectedPath = Join-Path (Get-Item .) 'extract.dacpac' - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -FilePath $relativePath -Table example + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -FilePath $relativePath -Table example $results.Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -127,9 +127,9 @@ Describe "Export-DbaDacPackage" { } } - It "uses EXE to extract dacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + It "uses EXE to extract dacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { $exportProperties = "/p:ExtractAllTableData=True" - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -ExtendedProperties $exportProperties + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -ExtendedProperties $exportProperties $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -149,8 +149,8 @@ Describe "Export-DbaDacPackage" { Remove-Item $testFolder -Force -Recurse } - It "exports a bacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -Type Bacpac + It "exports a bacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -Type Bacpac $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -158,10 +158,10 @@ Describe "Export-DbaDacPackage" { } } - It "exports bacpac with a table list" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + It "exports bacpac with a table list" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { $relativePath = '.\extract.bacpac' $expectedPath = Join-Path (Get-Item .) 'extract.bacpac' - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -FilePath $relativePath -Table example -Type Bacpac + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -FilePath $relativePath -Table example -Type Bacpac $results.Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -169,9 +169,9 @@ Describe "Export-DbaDacPackage" { } } - It "uses EXE to extract bacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + It "uses EXE to extract bacpac" -Skip:(-not (Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table example)) { $exportProperties = "/p:TargetEngineVersion=Default" - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -ExtendedProperties $exportProperties -Type Bacpac + $results = Export-DbaDacPackage -SqlInstance $global:instance1 -Database $dbname -ExtendedProperties $exportProperties -Type Bacpac $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { diff --git a/tests/Export-DbaDbRole.Tests.ps1 b/tests/Export-DbaDbRole.Tests.ps1 index e4f692ca4b..27ff23be77 100644 --- a/tests/Export-DbaDbRole.Tests.ps1 +++ b/tests/Export-DbaDbRole.Tests.ps1 @@ -27,10 +27,10 @@ Describe "Export-DbaDbRole Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeRole -Type Object[] -Not -Mandatory } It "Should have ExcludeFixedRole parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type Switch -Not -Mandatory } It "Should have IncludeRoleMember parameter" { - $CommandUnderTest | Should -HaveParameter IncludeRoleMember -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeRoleMember -Type Switch -Not -Mandatory } It "Should have Path parameter" { $CommandUnderTest | Should -HaveParameter Path -Type String -Not -Mandatory @@ -39,25 +39,25 @@ Describe "Export-DbaDbRole Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter FilePath -Type String -Not -Mandatory } It "Should have Passthru parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch -Not -Mandatory } It "Should have BatchSeparator parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String -Not -Mandatory } It "Should have NoClobber parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch -Not -Mandatory } It "Should have Append parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Append -Type Switch -Not -Mandatory } It "Should have NoPrefix parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch -Not -Mandatory } It "Should have Encoding parameter" { $CommandUnderTest | Should -HaveParameter Encoding -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -72,7 +72,7 @@ Describe "Export-DbaDbRole Integration Tests" -Tag "IntegrationTests" { $user1 = "dbatoolsci_exportdbadbrole_user1$random" $dbRole = "dbatoolsci_SpExecute$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = $server.Query("CREATE DATABASE [$dbname1]") $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $server.Databases[$dbname1].ExecuteNonQuery("CREATE USER [$user1] FOR LOGIN [$login1]") @@ -85,14 +85,14 @@ Describe "Export-DbaDbRole Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1 -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance2 -Login $login1 -Confirm:$false Remove-Item -Path $outputFile1 -ErrorAction SilentlyContinue } Context "Check if output file was created" { BeforeAll { - $null = Export-DbaDbRole -SqlInstance $script:instance2 -Database msdb -FilePath $outputFile1 + $null = Export-DbaDbRole -SqlInstance $global:instance2 -Database msdb -FilePath $outputFile1 } It "Exports results to one sql file" { @@ -106,9 +106,9 @@ Describe "Export-DbaDbRole Integration Tests" -Tag "IntegrationTests" { Context "Check piping support" { BeforeAll { - $role = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $dbRole + $role = Get-DbaDbRole -SqlInstance $global:instance2 -Database $dbname1 -Role $dbRole $null = $role | Export-DbaDbRole -FilePath $outputFile1 - $script:results = $role | Export-DbaDbRole -Passthru + $global:results = $role | Export-DbaDbRole -Passthru } It "Exports results to one sql file" { @@ -120,27 +120,27 @@ Describe "Export-DbaDbRole Integration Tests" -Tag "IntegrationTests" { } It "should include the defined BatchSeparator" { - $script:results | Should -Match "GO" + $global:results | Should -Match "GO" } It "should include the role" { - $script:results | Should -Match "CREATE ROLE [$dbRole]" + $global:results | Should -Match "CREATE ROLE [$dbRole]" } It "should include GRANT EXECUTE ON SCHEMA" { - $script:results | Should -Match "GRANT EXECUTE ON SCHEMA::\[dbo\] TO \[$dbRole\];" + $global:results | Should -Match "GRANT EXECUTE ON SCHEMA::\[dbo\] TO \[$dbRole\];" } It "should include GRANT SELECT ON SCHEMA" { - $script:results | Should -Match "GRANT SELECT ON SCHEMA::\[dbo\] TO \[$dbRole\];" + $global:results | Should -Match "GRANT SELECT ON SCHEMA::\[dbo\] TO \[$dbRole\];" } It "should include GRANT VIEW DEFINITION ON SCHEMA" { - $script:results | Should -Match "GRANT VIEW DEFINITION ON SCHEMA::\[dbo\] TO \[$dbRole\];" + $global:results | Should -Match "GRANT VIEW DEFINITION ON SCHEMA::\[dbo\] TO \[$dbRole\];" } It "should include ALTER ROLE ADD MEMBER" { - $script:results | Should -Match "ALTER ROLE \[$dbRole\] ADD MEMBER \[$user1\];" + $global:results | Should -Match "ALTER ROLE \[$dbRole\] ADD MEMBER \[$user1\];" } } } diff --git a/tests/Export-DbaDbTableData.Tests.ps1 b/tests/Export-DbaDbTableData.Tests.ps1 index 962af36c37..31b9178670 100644 --- a/tests/Export-DbaDbTableData.Tests.ps1 +++ b/tests/Export-DbaDbTableData.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Export-DbaDbTableData" { Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example SELECT top 10 1 @@ -59,16 +59,16 @@ Describe "Export-DbaDbTableData" { It "exports the table data" { $escaped = [regex]::escape('INSERT [dbo].[dbatoolsci_example] ([id]) VALUES (1)') $secondescaped = [regex]::escape('INSERT [dbo].[dbatoolsci_temp] ([name], [database_id],') - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example | Export-DbaDbTableData -Passthru "$results" | Should -Match $escaped - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_temp | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_temp | Export-DbaDbTableData -Passthru "$results" | Should -Match $secondescaped } It "supports piping more than one table" { $escaped = [regex]::escape('INSERT [dbo].[dbatoolsci_example] ([id]) VALUES (1)') $secondescaped = [regex]::escape('INSERT [dbo].[dbatoolsci_temp] ([name], [database_id],') - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example, dbatoolsci_temp | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database tempdb -Table dbatoolsci_example, dbatoolsci_temp | Export-DbaDbTableData -Passthru "$results" | Should -Match $escaped "$results" | Should -Match $secondescaped } diff --git a/tests/Export-DbaDiagnosticQuery.Tests.ps1 b/tests/Export-DbaDiagnosticQuery.Tests.ps1 index b9b7928b62..4f90070440 100644 --- a/tests/Export-DbaDiagnosticQuery.Tests.ps1 +++ b/tests/Export-DbaDiagnosticQuery.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Export-DbaDiagnosticQuery" { Get-Item $testPath | Remove-Item -ErrorAction Ignore } It "exports results to one file and creates directory if required" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' | Export-DbaDiagnosticQuery -Path $testPath + $null = Invoke-DbaDiagnosticQuery -SqlInstance $global:instance2 -QueryName 'Memory Clerk Usage' | Export-DbaDiagnosticQuery -Path $testPath (Get-ChildItem $testPath).Count | Should -Be 1 } } diff --git a/tests/Export-DbaExecutionPlan.Tests.ps1 b/tests/Export-DbaExecutionPlan.Tests.ps1 index 7a25e0c72a..49ef32b47b 100644 --- a/tests/Export-DbaExecutionPlan.Tests.ps1 +++ b/tests/Export-DbaExecutionPlan.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Export-DbaExecutionPlan" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Export-DbaInstance.Tests.ps1 b/tests/Export-DbaInstance.Tests.ps1 index 5ff8a65d88..08f7d8cbf8 100644 --- a/tests/Export-DbaInstance.Tests.ps1 +++ b/tests/Export-DbaInstance.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Export-DbaInstance Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Path -Type String -Not -Mandatory } It "Should have NoRecovery as a parameter" { - $CommandUnderTest | Should -HaveParameter NoRecovery -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoRecovery -Type Switch -Not -Mandatory } It "Should have AzureCredential as a parameter" { $CommandUnderTest | Should -HaveParameter AzureCredential -Type String -Not -Mandatory } It "Should have IncludeDbMasterKey as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeDbMasterKey -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeDbMasterKey -Type Switch -Not -Mandatory } It "Should have Exclude as a parameter" { $CommandUnderTest | Should -HaveParameter Exclude -Type String[] -Not -Mandatory @@ -42,16 +42,16 @@ Describe "Export-DbaInstance Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ScriptingOption -Type ScriptingOptions -Not -Mandatory } It "Should have NoPrefix as a parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch -Not -Mandatory } It "Should have ExcludePassword as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludePassword -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludePassword -Type Switch -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -65,7 +65,7 @@ Describe "Export-DbaInstance Integration Tests" -Tag "IntegrationTests" { $null = New-Item -Path $exportDir -ItemType Container } - $testServer = $script:instance2 + $testServer = $global:instance2 $server = Connect-DbaInstance -SqlInstance $testServer $srvName = "dbatoolsci-server1" $group = "dbatoolsci-group1" diff --git a/tests/Export-DbaLogin.Tests.ps1 b/tests/Export-DbaLogin.Tests.ps1 index 004d9c8687..c4d6ae968c 100644 --- a/tests/Export-DbaLogin.Tests.ps1 +++ b/tests/Export-DbaLogin.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Export-DbaLogin" { $login2 = "dbatoolsci_exportdbalogin_login2$random" $user2 = "dbatoolsci_exportdbalogin_user2$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = New-DbaDatabase -SqlInstance $server -Name $dbname1 $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $db1.Query("CREATE USER [$user1] FOR LOGIN [$login1]") @@ -42,18 +42,18 @@ Describe "Export-DbaLogin" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1 -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance2 -Login $login1 -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname2 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname2 -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance2 -Login $login2 -Confirm:$false $timenow = (Get-Date -uformat "%m%d%Y%H") $ExportedCredential = Get-ChildItem $DefaultExportPath, $AltExportPath | Where-Object { $_.Name -match "$timenow\d{4}-login.sql|Dbatoolsci_login_CustomFile.sql" } if ($ExportedCredential) { $null = Remove-Item -Path $($ExportedCredential.FullName) -ErrorAction SilentlyContinue } - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login3 -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance2 -Login $login3 -Confirm:$false } Context "Validate parameters" { @@ -79,13 +79,13 @@ Describe "Export-DbaLogin" { $CommandUnderTest | Should -HaveParameter Database -Type Object[] } It "Should have ExcludeJobs as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeJobs -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeJobs -Type Switch } It "Should have ExcludeDatabase as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Switch } It "Should have ExcludePassword as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ExcludePassword -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludePassword -Type Switch } It "Should have DefaultDatabase as a parameter" { $CommandUnderTest | Should -HaveParameter DefaultDatabase -Type String @@ -100,10 +100,10 @@ Describe "Export-DbaLogin" { $CommandUnderTest | Should -HaveParameter Encoding -Type String } It "Should have NoClobber as a switch parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch } It "Should have Append as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Append -Type Switch } It "Should have BatchSeparator as a parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String @@ -112,32 +112,32 @@ Describe "Export-DbaLogin" { $CommandUnderTest | Should -HaveParameter DestinationVersion -Type String } It "Should have NoPrefix as a switch parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch } It "Should have Passthru as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch } It "Should have ObjectLevel as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ObjectLevel -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ObjectLevel -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Executes with Exclude Parameters" { It "Should exclude databases when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -ExcludeDatabase -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Match '\nGo\r' } It "Should exclude Jobs when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeJobs -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -ExcludeJobs -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Not -Match 'Job' } It "Should exclude Go when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -BatchSeparator '' -ObjectLevel -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -BatchSeparator '' -ObjectLevel -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Not -Match 'GO' $results | Should -Match "GRANT SELECT ON OBJECT::\[sys\]\.\[tables\] TO \[$user2\] WITH GRANT OPTION" @@ -146,12 +146,12 @@ Describe "Export-DbaLogin" { $results | Should -Match "USE \[$dbname2\]" } It "Should exclude a specific login" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Not -Match "$login1" } It "Should exclude passwords" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue -ExcludePassword + $file = Export-DbaLogin -SqlInstance $global:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue -ExcludePassword $results = Get-Content -Path $file -Raw $results | Should -Not -Match '(?<=PASSWORD =\s0x)(\w+)' } @@ -159,14 +159,14 @@ Describe "Export-DbaLogin" { Context "Executes for various users, databases, and environments" { It "Should Export a specific user" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Database $dbname1 -DefaultDatabase master -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -Login $login1 -Database $dbname1 -DefaultDatabase master -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Not -Match "$login2|$dbname2" $results | Should -Match "$login1|$dbname1" $results | Should -Match ([regex]::Escape("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$user1')")) } It "Should Export with object level permissions" { - $results = Export-DbaLogin -SqlInstance $script:instance2 -Login $login2 -ObjectLevel -PassThru -WarningAction SilentlyContinue + $results = Export-DbaLogin -SqlInstance $global:instance2 -Login $login2 -ObjectLevel -PassThru -WarningAction SilentlyContinue $results | Should -Not -Match "$login1|$dbname1" $results | Should -Match "GRANT SELECT ON OBJECT::\[sys\]\.\[tables\] TO \[$user2\] WITH GRANT OPTION" $results | Should -Match "CREATE USER \[$user2\] FOR LOGIN \[$login2\]" @@ -174,7 +174,7 @@ Describe "Export-DbaLogin" { $results | Should -Match "USE \[$dbname2\]" } It "Should Export for the SQLVersion <_>" -ForEach @((Get-Command $CommandName).Parameters.DestinationVersion.attributes.validvalues) { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Database $dbname2 -DestinationVersion $_ -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -Login $login2 -Database $dbname2 -DestinationVersion $_ -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $results | Should -Match "$login2|$dbname2" $results | Should -Not -Match "$login1|$dbname1" @@ -190,26 +190,26 @@ Describe "Export-DbaLogin" { Context "Exports file to random and specified paths" { It "Should export file to the configured path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.DirectoryName $results | Should -Be $DefaultExportPath } It "Should export file to custom folder path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Path $AltExportPath -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -Path $AltExportPath -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.DirectoryName $results | Should -Be $AltExportPath } It "Should export file to custom file path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.Name $results | Should -Be "Dbatoolsci_login_CustomFile.sql" } It "Should export file to custom file path and Append" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -Append -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $global:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -Append -ExcludeDatabase -WarningAction SilentlyContinue $file.CreationTimeUtc.Ticks | Should -BeLessThan $file.LastWriteTimeUtc.Ticks } It "Should not export file to custom file path with NoClobber" { - { Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -NoClobber -WarningAction SilentlyContinue } | Should -Throw + { Export-DbaLogin -SqlInstance $global:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -NoClobber -WarningAction SilentlyContinue } | Should -Throw } } } diff --git a/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 b/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 index e195a4c6f5..37f6e2aef3 100644 --- a/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 +++ b/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 @@ -27,8 +27,8 @@ Describe "Export-DbaPfDataCollectorSetTemplate" { It "Should have InputObject as a non-mandatory Object[] parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch parameter" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Export-DbaRegServer.Tests.ps1 b/tests/Export-DbaRegServer.Tests.ps1 index 4cd2320a2c..2c7b8bf310 100644 --- a/tests/Export-DbaRegServer.Tests.ps1 +++ b/tests/Export-DbaRegServer.Tests.ps1 @@ -33,10 +33,10 @@ Describe "Export-DbaRegServer" { $CommandUnderTest | Should -HaveParameter ExcludeGroup -Type Object[] } It "Should have Overwrite as a parameter" { - $CommandUnderTest | Should -HaveParameter Overwrite -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Overwrite -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -47,30 +47,30 @@ Describe "Export-DbaRegServer" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc + $newGroup = Add-DbaRegServerGroup -SqlInstance $global:instance2 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $global:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group2" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $global:instance2 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $global:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $global:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 $random = Get-Random $newDirectory = "C:\temp-$random" } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $global:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $global:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false $results, $results2, $results3 | Remove-Item -ErrorAction Ignore Remove-Item $newDirectory -ErrorAction Ignore -Recurse -Force @@ -91,59 +91,59 @@ Describe "Export-DbaRegServer" { It "creates an importable xml file" { $results3 = $newServer3 | Export-DbaRegServer -Path C:\temp - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false - $results4 = Import-DbaRegServer -SqlInstance $script:instance2 -Path $results3 + Get-DbaRegServer -SqlInstance $global:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $global:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + $results4 = Import-DbaRegServer -SqlInstance $global:instance2 -Path $results3 $newServer3.ServerName | Should -BeIn $results4.ServerName $newServer3.Description | Should -BeIn $results4.Description } It "Create an xml file using FilePath" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Create a regsrvr file using the FilePath alias OutFile" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.regsrvr" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -OutFile $outputFileName + $results = Export-DbaRegServer -SqlInstance $global:instance2 -OutFile $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Try to create an invalid file using FilePath" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.txt" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName $results.length | Should -Be 0 } It "Create an xml file using the FilePath alias FileName in a directory that does not yet exist" { $outputFileName = "$newDirectory\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FileName $outputFileName + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FileName $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Ensure the Overwrite param is working" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName # test without -Overwrite - $invalidResults = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $invalidResults = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName $invalidResults.length | Should -Be 0 # test with -Overwrite - $resultsOverwrite = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Overwrite + $resultsOverwrite = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName -Overwrite $resultsOverwrite -is [System.IO.FileInfo] | Should -Be $true $resultsOverwrite.FullName | Should -Be $outputFileName } It "Test with the Group param" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Group $group + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName -Group $group $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName @@ -155,7 +155,7 @@ Describe "Export-DbaRegServer" { It "Test with the Group param and multiple group names" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Group @($group, $group2) + $results = Export-DbaRegServer -SqlInstance $global:instance2 -FilePath $outputFileName -Group @($group, $group2) $results.length | Should -Be 2 $fileText = Get-Content -Path $results[0] -Raw @@ -170,7 +170,7 @@ Describe "Export-DbaRegServer" { } It "Test with the ExcludeGroup param" { - $results = Export-DbaRegServer -SqlInstance $script:instance2 -ExcludeGroup $group2 + $results = Export-DbaRegServer -SqlInstance $global:instance2 -ExcludeGroup $group2 $results -is [System.IO.FileInfo] | Should -Be $true $fileText = Get-Content -Path $results -Raw diff --git a/tests/Export-DbaScript.Tests.ps1 b/tests/Export-DbaScript.Tests.ps1 index 5f247df50f..9858765709 100644 --- a/tests/Export-DbaScript.Tests.ps1 +++ b/tests/Export-DbaScript.Tests.ps1 @@ -48,26 +48,26 @@ Describe "Export-DbaScript" { Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 } It "should export some text matching create table" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru + $results = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru $results | Should -Match "CREATE TABLE" } It "should include BatchSeparator based on the Formatting.BatchSeparator configuration" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru + $results = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru $results | Should -Match "(Get-DbatoolsConfigValue -FullName 'Formatting.BatchSeparator')" } It "should include the defined BatchSeparator" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" + $results = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" $results | Should -Match "MakeItSo" } It "should not accept non-SMO objects" { - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" + $null = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" $null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction Continue $invalid | Should -Match "not a SQL Management Object" } @@ -75,11 +75,11 @@ Describe "Export-DbaScript" { It "should not append when using NoPrefix (#7455)" { BeforeAll { if (-not (Test-Path C:\temp)) { $null = New-Item -ItemType Directory -Path C:\temp } - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt + $null = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt $linecount1 = (Get-Content C:\temp\msdb.txt).Count - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt + $null = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt $linecount2 = (Get-Content C:\temp\msdb.txt).Count - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt -Append + $null = Get-DbaDbTable -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt -Append $linecount3 = (Get-Content C:\temp\msdb.txt).Count } diff --git a/tests/Export-DbaServerRole.Tests.ps1 b/tests/Export-DbaServerRole.Tests.ps1 index ba681a5318..d58c788958 100644 --- a/tests/Export-DbaServerRole.Tests.ps1 +++ b/tests/Export-DbaServerRole.Tests.ps1 @@ -30,10 +30,10 @@ Describe "Export-DbaServerRole Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeServerRole -Type String[] -Not -Mandatory } It "Should have ExcludeFixedRole parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type Switch -Not -Mandatory } It "Should have IncludeRoleMember parameter" { - $CommandUnderTest | Should -HaveParameter IncludeRoleMember -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeRoleMember -Type Switch -Not -Mandatory } It "Should have Path parameter" { $CommandUnderTest | Should -HaveParameter Path -Type String -Not -Mandatory @@ -42,25 +42,25 @@ Describe "Export-DbaServerRole Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter FilePath -Type String -Not -Mandatory } It "Should have Passthru parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch -Not -Mandatory } It "Should have BatchSeparator parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String -Not -Mandatory } It "Should have NoClobber parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch -Not -Mandatory } It "Should have Append parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Append -Type Switch -Not -Mandatory } It "Should have NoPrefix parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch -Not -Mandatory } It "Should have Encoding parameter" { $CommandUnderTest | Should -HaveParameter Encoding -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -76,7 +76,7 @@ Describe "Export-DbaServerRole Integration Tests" -Tag "IntegrationTests" { $login1 = "dbatoolsci_exportdbaserverrole_login1$random" $svRole = "dbatoolsci_ScriptPermissions$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $null = $server.Query("CREATE SERVER ROLE [$svRole] AUTHORIZATION [$login1]") $null = $server.Query("ALTER SERVER ROLE [dbcreator] ADD MEMBER [$svRole]") @@ -87,14 +87,14 @@ Describe "Export-DbaServerRole Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Remove-DbaServerRole -SqlInstance $script:instance2 -ServerRole $svRole -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaServerRole -SqlInstance $global:instance2 -ServerRole $svRole -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance2 -Login $login1 -Confirm:$false Remove-Item -Path $outputFile -ErrorAction SilentlyContinue } Context "Check if output file was created" { BeforeAll { - $null = Export-DbaServerRole -SqlInstance $script:instance2 -FilePath $outputFile + $null = Export-DbaServerRole -SqlInstance $global:instance2 -FilePath $outputFile } It "Exports results to one sql file" { @@ -108,9 +108,9 @@ Describe "Export-DbaServerRole Integration Tests" -Tag "IntegrationTests" { Context "Check using piped input created" { BeforeAll { - $role = Get-DbaServerRole -SqlInstance $script:instance2 -ServerRole $svRole + $role = Get-DbaServerRole -SqlInstance $global:instance2 -ServerRole $svRole $null = $role | Export-DbaServerRole -FilePath $outputFile - $script:results = $role | Export-DbaServerRole -Passthru + $global:results = $role | Export-DbaServerRole -Passthru } It "Exports results to one sql file" { @@ -122,31 +122,31 @@ Describe "Export-DbaServerRole Integration Tests" -Tag "IntegrationTests" { } It "should include the defined BatchSeparator" { - $script:results | Should -Match "GO" + $global:results | Should -Match "GO" } It "should include the role" { - $script:results | Should -Match "CREATE SERVER ROLE [$svRole]" + $global:results | Should -Match "CREATE SERVER ROLE [$svRole]" } It "should include ADD MEMBER" { - $script:results | Should -Match "ALTER SERVER ROLE [dbcreator] ADD MEMBER [$svRole]" + $global:results | Should -Match "ALTER SERVER ROLE [dbcreator] ADD MEMBER [$svRole]" } It "should include GRANT CREATE TRACE EVENT" { - $script:results | Should -Match "GRANT CREATE TRACE EVENT NOTIFICATION TO [$svRole]" + $global:results | Should -Match "GRANT CREATE TRACE EVENT NOTIFICATION TO [$svRole]" } It "should include DENY SELECT ALL USER SECURABLES" { - $script:results | Should -Match "DENY SELECT ALL USER SECURABLES TO [$svRole]" + $global:results | Should -Match "DENY SELECT ALL USER SECURABLES TO [$svRole]" } It "should include VIEW ANY DEFINITION" { - $script:results | Should -Match "GRANT VIEW ANY DEFINITION TO [$svRole];" + $global:results | Should -Match "GRANT VIEW ANY DEFINITION TO [$svRole];" } It "should include GRANT VIEW ANY DATABASE" { - $script:results | Should -Match "GRANT VIEW ANY DATABASE TO [$svRole];" + $global:results | Should -Match "GRANT VIEW ANY DATABASE TO [$svRole];" } } } diff --git a/tests/Export-DbaSpConfigure.Tests.ps1 b/tests/Export-DbaSpConfigure.Tests.ps1 index 69f1c4006c..5981d87fa6 100644 --- a/tests/Export-DbaSpConfigure.Tests.ps1 +++ b/tests/Export-DbaSpConfigure.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Export-DbaSpConfigure" { $CommandUnderTest | Should -HaveParameter FilePath -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Export-DbaSysDbUserObject.Tests.ps1 b/tests/Export-DbaSysDbUserObject.Tests.ps1 index 298384e66a..cd11a88114 100644 --- a/tests/Export-DbaSysDbUserObject.Tests.ps1 +++ b/tests/Export-DbaSysDbUserObject.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Export-DbaSysDbUserObject" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have IncludeDependencies as a switch parameter" { - $CommandUnderTest | Should -HaveParameter IncludeDependencies -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeDependencies -Type Switch } It "Should have BatchSeparator as a string parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String @@ -24,19 +24,19 @@ Describe "Export-DbaSysDbUserObject" { $CommandUnderTest | Should -HaveParameter FilePath -Type String } It "Should have NoPrefix as a switch parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch } It "Should have ScriptingOptionsObject as a ScriptingOptions parameter" { $CommandUnderTest | Should -HaveParameter ScriptingOptionsObject -Type ScriptingOptions } It "Should have NoClobber as a switch parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch } It "Should have PassThru as a switch parameter" { - $CommandUnderTest | Should -HaveParameter PassThru -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter PassThru -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -51,7 +51,7 @@ Describe "Export-DbaSysDbUserObject" { $tableFunctionName = "[dbatoolsci_TableFunction_$random]" $scalarFunctionName = "[dbatoolsci_ScalarFunction_$random]" $ruleName = "[dbatoolsci_Rule_$random]" - $server = Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential + $server = Connect-DbaInstance -SqlInstance $global:instance2 -SqlCredential $SqlCredential $server.Query("CREATE TABLE dbo.$tableName (Col1 int);", "master") $server.Query("CREATE VIEW dbo.$viewName AS SELECT 1 as Col1;", "master") $server.Query("CREATE PROCEDURE dbo.$procName as select 1;", "master") @@ -62,7 +62,7 @@ Describe "Export-DbaSysDbUserObject" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential + $server = Connect-DbaInstance -SqlInstance $global:instance2 -SqlCredential $SqlCredential $server.Query("DROP TABLE dbo.$tableName", "master") $server.Query("DROP VIEW dbo.$viewName", "master") $server.Query("DROP PROCEDURE dbo.$procName", "master") @@ -74,7 +74,7 @@ Describe "Export-DbaSysDbUserObject" { Context "works as expected with passthru" { BeforeAll { - $script = Export-DbaSysDbUserObject -SqlInstance $script:instance2 -PassThru | Out-String + $script = Export-DbaSysDbUserObject -SqlInstance $global:instance2 -PassThru | Out-String } It "should export text matching table name '$tableName'" { @@ -102,7 +102,7 @@ Describe "Export-DbaSysDbUserObject" { Context "works as expected with filename" { BeforeAll { - $null = Export-DbaSysDbUserObject -SqlInstance $script:instance2 -FilePath "C:\Temp\objects_$random.sql" + $null = Export-DbaSysDbUserObject -SqlInstance $global:instance2 -FilePath "C:\Temp\objects_$random.sql" $file = Get-Content "C:\Temp\objects_$random.sql" | Out-String } diff --git a/tests/Export-DbaUser.Tests.ps1 b/tests/Export-DbaUser.Tests.ps1 index b83055339e..4167566b79 100644 --- a/tests/Export-DbaUser.Tests.ps1 +++ b/tests/Export-DbaUser.Tests.ps1 @@ -36,25 +36,25 @@ Describe "Export-DbaUser Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Encoding -Type String -Not -Mandatory } It "Should have NoClobber parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch -Not -Mandatory } It "Should have Append parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Append -Type Switch -Not -Mandatory } It "Should have Passthru parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch -Not -Mandatory } It "Should have Template parameter" { - $CommandUnderTest | Should -HaveParameter Template -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Template -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have ScriptingOptionsObject parameter" { $CommandUnderTest | Should -HaveParameter ScriptingOptionsObject -Type ScriptingOptions -Not -Mandatory } It "Should have ExcludeGoBatchSeparator parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeGoBatchSeparator -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeGoBatchSeparator -Type Switch -Not -Mandatory } } } @@ -83,16 +83,16 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { $role02 = "dbatoolsci_exportdbauser_role02" $role03 = "dbatoolsci_exportdbauser_role03" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $null = $server.Query("CREATE DATABASE [$dbname]") $securePassword = $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login2 -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login01 -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login02 -Password $securePassword + $null = New-DbaLogin -SqlInstance $global:instance1 -Login $login -Password $securePassword + $null = New-DbaLogin -SqlInstance $global:instance1 -Login $login2 -Password $securePassword + $null = New-DbaLogin -SqlInstance $global:instance1 -Login $login01 -Password $securePassword + $null = New-DbaLogin -SqlInstance $global:instance1 -Login $login02 -Password $securePassword - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname $null = $db.Query("CREATE USER [$user] FOR LOGIN [$login]") $null = $db.Query("CREATE USER [$user2] FOR LOGIN [$login2]") $null = $db.Query("CREATE USER [$user01] FOR LOGIN [$login01]") @@ -113,9 +113,9 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance1 -Login $login -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance1 -Login $login2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance1 -Database $dbname -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance1 -Login $login -Confirm:$false + Remove-DbaLogin -SqlInstance $global:instance1 -Login $login2 -Confirm:$false Remove-Item -Path $outputFile -ErrorAction SilentlyContinue Remove-Item -Path $outputFile2 -ErrorAction SilentlyContinue Remove-Item -Path $outputPath -Recurse -ErrorAction SilentlyContinue -Confirm:$false @@ -123,9 +123,9 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { Context "Check if output file was created" { BeforeAll { - $userExists = Get-DbaDbUser -SqlInstance $script:instance1 -Database $dbname | Where-Object Name -eq $user + $userExists = Get-DbaDbUser -SqlInstance $global:instance1 -Database $dbname | Where-Object Name -eq $user if ($userExists) { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -User $user -FilePath $outputFile + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -User $user -FilePath $outputFile } } @@ -142,7 +142,7 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { It 'Excludes database context' { $scriptingOptions = New-DbaScriptingOption $scriptingOptions.IncludeDatabaseContext = $false - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should -Not -BeLike ('*USE `[' + $dbname + '`]*') } @@ -150,19 +150,19 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { It 'Includes database context' { $scriptingOptions = New-DbaScriptingOption $scriptingOptions.IncludeDatabaseContext = $true - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should -BeLike ('*USE `[' + $dbname + '`]*') } It 'Defaults to include database context' { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should -BeLike ('*USE `[' + $dbname + '`]*') } It 'Exports as template' { - $results = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -User $user -Template -DestinationVersion SQLServer2016 -WarningAction SilentlyContinue -Passthru + $results = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -User $user -Template -DestinationVersion SQLServer2016 -WarningAction SilentlyContinue -Passthru $results | Should -BeLike "*CREATE USER ``[{templateUser}``] FOR LOGIN ``[{templateLogin}``]*" $results | Should -BeLike "*GRANT SELECT ON OBJECT::``[dbo``].``[$table``] TO ``[{templateUser}``]*" $results | Should -BeLike "*ALTER ROLE ``[$role``] ADD MEMBER ``[{templateUser}``]*" @@ -171,11 +171,11 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { Context "Check if one output file per user was created" { BeforeAll { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -Path $outputPath + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -Path $outputPath } It "Exports files to the path" { - $userCount = (Get-DbaDbUser -SqlInstance $script:instance1 -Database $dbname | Where-Object { $_.Name -notin @("dbo", "guest", "sys", "INFORMATION_SCHEMA") } | Measure-Object).Count + $userCount = (Get-DbaDbUser -SqlInstance $global:instance1 -Database $dbname | Where-Object { $_.Name -notin @("dbo", "guest", "sys", "INFORMATION_SCHEMA") } | Measure-Object).Count (Get-ChildItem $outputPath).Count | Should -Be $userCount } @@ -191,7 +191,7 @@ Describe "Export-DbaUser Integration Tests" -Tag "IntegrationTests" { Context "Check if the output scripts were self-contained" { BeforeAll { Remove-Item -Path $outputPath -Recurse -ErrorAction SilentlyContinue - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -Path $outputPath + $null = Export-DbaUser -SqlInstance $global:instance1 -Database $dbname -Path $outputPath } It "Contains the CREATE ROLE and ALTER ROLE statements for its own roles" { diff --git a/tests/Export-DbaXECsv.Tests.ps1 b/tests/Export-DbaXECsv.Tests.ps1 index 7fe8dbb36d..738fb416dd 100644 --- a/tests/Export-DbaXECsv.Tests.ps1 +++ b/tests/Export-DbaXECsv.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Export-DbaXECsv" { $CommandUnderTest | Should -HaveParameter FilePath -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Export-DbaXESession.Tests.ps1 b/tests/Export-DbaXESession.Tests.ps1 index fd8401f8e1..a99d882768 100644 --- a/tests/Export-DbaXESession.Tests.ps1 +++ b/tests/Export-DbaXESession.Tests.ps1 @@ -40,28 +40,28 @@ Describe "Export-DbaXESession" { $CommandUnderTest | Should -HaveParameter Encoding -Type String } It "Should have Passthru parameter" { - $CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Passthru -Type Switch } It "Should have BatchSeparator parameter" { $CommandUnderTest | Should -HaveParameter BatchSeparator -Type String } It "Should have NoPrefix parameter" { - $CommandUnderTest | Should -HaveParameter NoPrefix -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoPrefix -Type Switch } It "Should have NoClobber parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch } It "Should have Append parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Append -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Check if output file was created" { BeforeAll { - $null = Export-DbaXESession -SqlInstance $script:instance2 -FilePath $outputFile + $null = Export-DbaXESession -SqlInstance $global:instance2 -FilePath $outputFile } It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should -Be 1 @@ -73,7 +73,7 @@ Describe "Export-DbaXESession" { Context "Check if session parameter is honored" { BeforeAll { - $null = Export-DbaXESession -SqlInstance $script:instance2 -FilePath $outputFile -Session system_health + $null = Export-DbaXESession -SqlInstance $global:instance2 -FilePath $outputFile -Session system_health } It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should -Be 1 @@ -85,7 +85,7 @@ Describe "Export-DbaXESession" { Context "Check if supports Pipeline input" { BeforeAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health | Export-DbaXESession -FilePath $outputFile + $null = Get-DbaXESession -SqlInstance $global:instance2 -Session system_health | Export-DbaXESession -FilePath $outputFile } It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should -Be 1 diff --git a/tests/Export-DbaXESessionTemplate.Tests.ps1 b/tests/Export-DbaXESessionTemplate.Tests.ps1 index 3272db2da8..6a5dfc152a 100644 --- a/tests/Export-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Export-DbaXESessionTemplate.Tests.ps1 @@ -34,16 +34,16 @@ Describe "Export-DbaXESessionTemplate" { } BeforeAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $global:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $global:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession Remove-Item -Path 'C:\windows\temp\Profiler TSQL Duration.xml' -ErrorAction SilentlyContinue } It "Exports session to disk" { - $session = Import-DbaXESessionTemplate -SqlInstance $script:instance2 -Template 'Profiler TSQL Duration' + $session = Import-DbaXESessionTemplate -SqlInstance $global:instance2 -Template 'Profiler TSQL Duration' $results = $session | Export-DbaXESessionTemplate -Path C:\windows\temp $results.Name | Should -Be 'Profiler TSQL Duration.xml' } diff --git a/tests/Export-DbatoolsConfig.Tests.ps1 b/tests/Export-DbatoolsConfig.Tests.ps1 index 5d3f149e04..0245824974 100644 --- a/tests/Export-DbatoolsConfig.Tests.ps1 +++ b/tests/Export-DbatoolsConfig.Tests.ps1 @@ -35,11 +35,11 @@ Describe "Export-DbatoolsConfig" { It "Should have OutPath as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter OutPath -Type String -Not -Mandatory } - It "Should have SkipUnchanged as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter SkipUnchanged -Type SwitchParameter -Not -Mandatory + It "Should have SkipUnchanged as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter SkipUnchanged -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Find-DbaAgentJob.Tests.ps1 b/tests/Find-DbaAgentJob.Tests.ps1 index 5c9e78ed2d..2a15755fa9 100644 --- a/tests/Find-DbaAgentJob.Tests.ps1 +++ b/tests/Find-DbaAgentJob.Tests.ps1 @@ -58,80 +58,80 @@ Describe "Find-DbaAgentJob Unit Tests" -Tag 'UnitTests' { Describe "Find-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $srvName = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select @@servername as sn" -as PSObject - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $srvName = Invoke-DbaQuery -SqlInstance $global:instance2 -Query "select @@servername as sn" -as PSObject + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = Start-DbaAgentJob -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob' + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'dbatoolsci_job_category' -Confirm:$false } Context "Command finds jobs using all parameters" { It "Should find a specific job" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob $results.name | Should -Be "dbatoolsci_testjob" } It "Should find a specific job but not an excluded job" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Job *dbatoolsci* -ExcludeJobName dbatoolsci_testjob_disabled + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -Job *dbatoolsci* -ExcludeJobName dbatoolsci_testjob_disabled $results.name | Should -Not -Be "dbatoolsci_testjob_disabled" } It "Should find a specific job with a specific step" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -StepName 'dbatoolsci Test Step' + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -StepName 'dbatoolsci Test Step' $results.name | Should -Be "dbatoolsci_testjob_disabled" } It "Should find jobs not used in the last 10 days" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -LastUsed 10 + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -LastUsed 10 $results | Should -Not -BeNullOrEmpty } It "Should find jobs disabled from running" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsDisabled + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsDisabled $results.name | Should -Be "dbatoolsci_testjob_disabled" } It "Should find 1 job disabled from running" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsDisabled + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsDisabled $results.count | Should -Be 1 } It "Should find jobs that have not been scheduled" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsNotScheduled $results | Should -Not -BeNullOrEmpty } It "Should find 2 jobs that have no schedule" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled -Job *dbatoolsci* + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsNotScheduled -Job *dbatoolsci* $results.count | Should -Be 2 } It "Should find jobs that have no email notification" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNoEmailNotification + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsNoEmailNotification $results | Should -Not -BeNullOrEmpty } It "Should find jobs that have a category of dbatoolsci_job_category" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -Category 'dbatoolsci_job_category' $results.name | Should -Be "dbatoolsci_testjob_disabled" } It "Should find jobs that are owned by sa" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Owner 'sa' + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -Owner 'sa' $results | Should -Not -BeNullOrEmpty } It "Should find jobs that have been failed since July of 2016" { - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsFailed -Since '2016-07-01 10:47:00' + $results = Find-DbaAgentJob -SqlInstance $global:instance2 -IsFailed -Since '2016-07-01 10:47:00' $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Find-DbaCommand.Tests.ps1 b/tests/Find-DbaCommand.Tests.ps1 index 044db594e7..6249712088 100644 --- a/tests/Find-DbaCommand.Tests.ps1 +++ b/tests/Find-DbaCommand.Tests.ps1 @@ -20,11 +20,11 @@ Describe "Find-DbaCommand" { It "Should have MaximumVersion as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter MaximumVersion -Type String -Not -Mandatory } - It "Should have Rebuild as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Rebuild -Type SwitchParameter -Not -Mandatory + It "Should have Rebuild as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Rebuild -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Find-DbaDatabase.Tests.ps1 b/tests/Find-DbaDatabase.Tests.ps1 index b139595c69..f4ce566ff9 100644 --- a/tests/Find-DbaDatabase.Tests.ps1 +++ b/tests/Find-DbaDatabase.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Find-DbaDatabase" { $CommandUnderTest | Should -HaveParameter Pattern -Type String -Not -Mandatory } It "Should have Exact as a parameter" { - $CommandUnderTest | Should -HaveParameter Exact -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Exact -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -31,29 +31,29 @@ Describe "Find-DbaDatabase" { } It "Should return correct properties" { - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Pattern Master + $results = Find-DbaDatabase -SqlInstance $global:instance2 -Pattern Master $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'Name', 'Id', 'Size', 'Owner', 'CreateDate', 'ServiceBrokerGuid', 'Tables', 'StoredProcedures', 'Views', 'ExtendedProperties' ($results[0].PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } It "Should return true if Database Master is Found" { - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Pattern Master + $results = Find-DbaDatabase -SqlInstance $global:instance2 -Pattern Master $results | Where-Object Name -match 'Master' | Should -Not -BeNullOrEmpty - $results.Id | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database Master).Id + $results.Id | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database Master).Id } It "Should return true if Creation Date of Master is '4/8/2003 9:13:36 AM'" { - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Pattern Master + $results = Find-DbaDatabase -SqlInstance $global:instance2 -Pattern Master $results.CreateDate.ToFileTimeUtc()[0] | Should -Be 126942668163900000 } - It "Should return true if Executed Against 2 instances: $script:instance1 and $script:instance2" { - $results = Find-DbaDatabase -SqlInstance $script:instance1, $script:instance2 -Pattern Master + It "Should return true if Executed Against 2 instances: $global:instance1 and $global:instance2" { + $results = Find-DbaDatabase -SqlInstance $global:instance1, $global:instance2 -Pattern Master ($results.InstanceName | Select-Object -Unique).Count | Should -Be 2 } It "Should return true if Database Found via Property Filter" { - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Property ServiceBrokerGuid -Pattern -0000-0000-000000000000 + $results = Find-DbaDatabase -SqlInstance $global:instance2 -Property ServiceBrokerGuid -Pattern -0000-0000-000000000000 $results.ServiceBrokerGuid | Should -BeLike '*-0000-0000-000000000000' } } diff --git a/tests/Find-DbaDbDisabledIndex.Tests.ps1 b/tests/Find-DbaDbDisabledIndex.Tests.ps1 index 35f40d404e..57b0c616b6 100644 --- a/tests/Find-DbaDbDisabledIndex.Tests.ps1 +++ b/tests/Find-DbaDbDisabledIndex.Tests.ps1 @@ -24,19 +24,19 @@ Describe "Find-DbaDbDisabledIndex" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have NoClobber as a parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch -Not -Mandatory } It "Should have Append as a parameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Append -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $random = Get-Random $databaseName1 = "dbatoolsci1_$random" $databaseName2 = "dbatoolsci2_$random" @@ -55,19 +55,19 @@ Describe "Find-DbaDbDisabledIndex" { } It "Should find disabled index: $indexName" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 + $results = Find-DbaDbDisabledIndex -SqlInstance $global:instance1 ($results | Where-Object { $_.IndexName -eq $indexName }).Count | Should -Be 2 ($results | Where-Object { $_.DatabaseName -in $databaseName1, $databaseName2 }).Count | Should -Be 2 ($results | Where-Object { $_.DatabaseId -in $db1.Id, $db2.Id }).Count | Should -Be 2 } It "Should find disabled index: $indexName for specific database" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 -Database $databaseName1 + $results = Find-DbaDbDisabledIndex -SqlInstance $global:instance1 -Database $databaseName1 $results.IndexName | Should -Be $indexName $results.DatabaseName | Should -Be $databaseName1 $results.DatabaseId | Should -Be $db1.Id } It "Should exclude specific database" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 -ExcludeDatabase $databaseName1 + $results = Find-DbaDbDisabledIndex -SqlInstance $global:instance1 -ExcludeDatabase $databaseName1 $results.IndexName | Should -Be $indexName $results.DatabaseName | Should -Be $databaseName2 $results.DatabaseId | Should -Be $db2.Id diff --git a/tests/Find-DbaDbDuplicateIndex.Tests.ps1 b/tests/Find-DbaDbDuplicateIndex.Tests.ps1 index 3877d3b7ad..bd8f50f147 100644 --- a/tests/Find-DbaDbDuplicateIndex.Tests.ps1 +++ b/tests/Find-DbaDbDuplicateIndex.Tests.ps1 @@ -15,16 +15,16 @@ Describe "Find-DbaDbDuplicateIndex" { $CommandUnderTest | Should -HaveParameter Database -Type Object[] } It "Should have IncludeOverlapping as a switch parameter" { - $CommandUnderTest | Should -HaveParameter IncludeOverlapping -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeOverlapping -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $sql = "CREATE DATABASE [dbatools_dupeindex]" $server.Query($sql) $sql = @" @@ -57,11 +57,11 @@ ALTER TABLE [dbatools_dupeindex].[dbo].[WABehaviorEvent] ADD UNIQUE NONCLUSTERED } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database dbatools_dupeindex -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance1 -Database dbatools_dupeindex -Confirm:$false } It "Returns at least two results" { - $results = Find-DbaDbDuplicateIndex -SqlInstance $script:instance1 -Database dbatools_dupeindex + $results = Find-DbaDbDuplicateIndex -SqlInstance $global:instance1 -Database dbatools_dupeindex $results.Count | Should -BeGreaterOrEqual 2 } } diff --git a/tests/Find-DbaDbGrowthEvent.Tests.ps1 b/tests/Find-DbaDbGrowthEvent.Tests.ps1 index 9bd58a079f..5359f78861 100644 --- a/tests/Find-DbaDbGrowthEvent.Tests.ps1 +++ b/tests/Find-DbaDbGrowthEvent.Tests.ps1 @@ -30,16 +30,16 @@ Describe "Find-DbaDbGrowthEvent" { $CommandUnderTest | Should -HaveParameter FileType -Type String } It "Should have UseLocalTime as a parameter" { - $CommandUnderTest | Should -HaveParameter UseLocalTime -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseLocalTime -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $random = Get-Random $databaseName1 = "dbatoolsci1_$random" $db1 = New-DbaDatabase -SqlInstance $server -Name $databaseName1 diff --git a/tests/Find-DbaDbUnusedIndex.Tests.ps1 b/tests/Find-DbaDbUnusedIndex.Tests.ps1 index af3400219c..5ba8ac512c 100644 --- a/tests/Find-DbaDbUnusedIndex.Tests.ps1 +++ b/tests/Find-DbaDbUnusedIndex.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Find-DbaDbUnusedIndex" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have IgnoreUptime parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreUptime -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IgnoreUptime -Type Switch } It "Should have Seeks parameter" { $CommandUnderTest | Should -HaveParameter Seeks -Type Int32 @@ -33,7 +33,7 @@ Describe "Find-DbaDbUnusedIndex" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -41,10 +41,10 @@ Describe "Find-DbaDbUnusedIndex" { Describe "Find-DbaDbUnusedIndex Integration Tests" -Tag "IntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $dbName = "dbatoolsci_$random" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbName + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name $dbName $indexName = "dbatoolsci_index_$random" $tableName = "dbatoolsci_table_$random" @@ -60,11 +60,11 @@ WAITFOR DELAY '00:00:05'; } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbName -Confirm:$false } It "Should find the 'unused' index" { - $results = Find-DbaDbUnusedIndex -SqlInstance $script:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 + $results = Find-DbaDbUnusedIndex -SqlInstance $global:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 $results.Database | Should -Be $dbName $results.IndexName | Should -Contain $indexName } @@ -72,7 +72,7 @@ WAITFOR DELAY '00:00:05'; It "Should return the expected columns" { $expectedColumns = @('CompressionDescription', 'ComputerName', 'Database', 'DatabaseId', 'IndexId', 'IndexName', 'IndexSizeMB', 'InstanceName', 'LastSystemLookup', 'LastSystemScan', 'LastSystemSeek', 'LastSystemUpdate', 'LastUserLookup', 'LastUserScan', 'LastUserSeek', 'LastUserUpdate', 'ObjectId', 'RowCount', 'Schema', 'SqlInstance', 'SystemLookup', 'SystemScans', 'SystemSeeks', 'SystemUpdates', 'Table', 'TypeDesc', 'UserLookups', 'UserScans', 'UserSeeks', 'UserUpdates') - $results = Find-DbaDbUnusedIndex -SqlInstance $script:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 + $results = Find-DbaDbUnusedIndex -SqlInstance $global:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 $resultColumns = $results | Get-Member -MemberType Property | Select-Object -ExpandProperty Name $missingColumns = $expectedColumns | Where-Object { $_ -notin $resultColumns } diff --git a/tests/Find-DbaInstance.Tests.ps1 b/tests/Find-DbaInstance.Tests.ps1 index c4c3f8b4a6..9fc91c2f42 100644 --- a/tests/Find-DbaInstance.Tests.ps1 +++ b/tests/Find-DbaInstance.Tests.ps1 @@ -42,7 +42,7 @@ Describe "Find-DbaInstance" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $results = Find-DbaInstance -ComputerName $script:instance3 -ScanType Browser, SqlConnect | Select-Object -First 1 + $results = Find-DbaInstance -ComputerName $global:instance3 -ScanType Browser, SqlConnect | Select-Object -First 1 } It "Returns an object type of [Dataplat.Dbatools.Discovery.DbaInstanceReport]" { $results | Should -BeOfType [Dataplat.Dbatools.Discovery.DbaInstanceReport] @@ -50,7 +50,7 @@ Describe "Find-DbaInstance" { It "FullName is populated" { $results.FullName | Should -Not -BeNullOrEmpty } - It "TcpConnected is true" -Skip:([DbaInstanceParameter]$script:instance3).IsLocalHost { + It "TcpConnected is true" -Skip:([DbaInstanceParameter]$global:instance3).IsLocalHost { $results.TcpConnected | Should -Be $true } It "successfully connects" { diff --git a/tests/Find-DbaLoginInGroup.Tests.ps1 b/tests/Find-DbaLoginInGroup.Tests.ps1 index 1433f54b49..e701f0bf10 100644 --- a/tests/Find-DbaLoginInGroup.Tests.ps1 +++ b/tests/Find-DbaLoginInGroup.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Find-DbaLoginInGroup" { $CommandUnderTest | Should -HaveParameter Login -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -65,7 +65,7 @@ Describe "Find-DbaLoginInGroup Integration Tests" -Tag "IntegrationTests" { Context "Command executes properly" { It "Should execute without throwing" { - { Find-DbaLoginInGroup -SqlInstance $script:instance1 } | Should -Not -Throw + { Find-DbaLoginInGroup -SqlInstance $global:instance1 } | Should -Not -Throw } } diff --git a/tests/Find-DbaOrphanedFile.Tests.ps1 b/tests/Find-DbaOrphanedFile.Tests.ps1 index 99c383566e..161c7f0d2a 100644 --- a/tests/Find-DbaOrphanedFile.Tests.ps1 +++ b/tests/Find-DbaOrphanedFile.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Find-DbaOrphanedFile" { Context "Orphaned files are correctly identified" { BeforeAll { $dbname = "dbatoolsci_orphanedfile_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = New-DbaDatabase -SqlInstance $server -Name $dbname $dbname2 = "dbatoolsci_orphanedfile_$(Get-Random)" @@ -58,13 +58,13 @@ Describe "Find-DbaOrphanedFile" { $tmpBackupPath2 = Join-Path $tmpdirInner2 "backup" $null = New-Item -Path $tmpBackupPath2 -type Container - $result = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname + $result = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname if ($result.count -eq 0) { Set-ItResult -Inconclusive -Because "Setup failed" } - $backupFile = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Path $tmpBackupPath -Type Full - $backupFile2 = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname2 -Path $tmpBackupPath2 -Type Full + $backupFile = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Path $tmpBackupPath -Type Full + $backupFile2 = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname2 -Path $tmpBackupPath2 -Type Full Copy-Item -Path $backupFile.BackupPath -Destination "C:\" -Confirm:$false $tmpBackupPath3 = Join-Path (Get-SqlDefaultPaths $server data) "dbatoolsci_$(Get-Random)" @@ -72,7 +72,7 @@ Describe "Find-DbaOrphanedFile" { } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname, $dbname2 | Remove-DbaDatabase -Confirm:$false Remove-Item $tmpdir -Recurse -Force -ErrorAction SilentlyContinue Remove-Item $tmpdir2 -Recurse -Force -ErrorAction SilentlyContinue Remove-Item "C:\$($backupFile.BackupFile)" -Force -ErrorAction SilentlyContinue @@ -80,8 +80,8 @@ Describe "Find-DbaOrphanedFile" { } It "Has the correct properties" { - $null = Detach-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Force - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $null = Detach-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Force + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 $ExpectedStdProps = 'ComputerName,InstanceName,SqlInstance,Filename,RemoteFilename'.Split(',') ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedStdProps | Sort-Object) $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Filename,RemoteFilename,Server'.Split(',') @@ -89,42 +89,42 @@ Describe "Find-DbaOrphanedFile" { } It "Finds two files" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 $results.Filename.Count | Should -Be 2 } It "Finds zero files after cleaning up" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 $results.FileName | Remove-Item - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 $results.Filename.Count | Should -Be 0 } It "works with -Recurse" { "a" | Out-File (Join-Path $tmpdir "out.mdf") - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Path $tmpdir $results.Filename.Count | Should -Be 1 Move-Item "$tmpdir\out.mdf" -destination $tmpdirInner - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Path $tmpdir $results.Filename.Count | Should -Be 0 - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir -Recurse + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Path $tmpdir -Recurse $results.Filename.Count | Should -Be 1 Copy-Item -Path "$tmpdirInner\out.mdf" -Destination $tmpBackupPath3 -Confirm:$false - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir, $tmpdir2 -Recurse -FileType bak + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Path $tmpdir, $tmpdir2 -Recurse -FileType bak $results.Filename | Should -Contain $backupFile.BackupPath $results.Filename | Should -Contain $backupFile2.BackupPath $results.Filename | Should -Contain "$tmpdirInner\out.mdf" $results.Filename | Should -Contain "$tmpBackupPath3\out.mdf" $results.Count | Should -Be 4 - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Recurse + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Recurse $results.Filename | Should -Be "$tmpBackupPath3\out.mdf" } It "works with -Path" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path "C:" -FileType bak + $results = Find-DbaOrphanedFile -SqlInstance $global:instance2 -Path "C:" -FileType bak $results.Filename | Should -Contain "C:\$($backupFile.BackupFile)" } } diff --git a/tests/Find-DbaSimilarTable.Tests.ps1 b/tests/Find-DbaSimilarTable.Tests.ps1 index 7a17466c90..fe119ee903 100644 --- a/tests/Find-DbaSimilarTable.Tests.ps1 +++ b/tests/Find-DbaSimilarTable.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Find-DbaSimilarTable" { Context "Testing if similar tables are discovered" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb $db.Query("CREATE TABLE dbatoolsci_table1 (id int identity, fname varchar(20), lname char(5), lol bigint, whatever datetime)") $db.Query("CREATE TABLE dbatoolsci_table2 (id int identity, fname varchar(20), lname char(5), lol bigint, whatever datetime)") } @@ -50,7 +50,7 @@ Describe "Find-DbaSimilarTable" { } It "returns at least two rows with correct database IDs and 100% match" { - $results = Find-DbaSimilarTable -SqlInstance $script:instance1 -Database tempdb | Where-Object Table -Match dbatoolsci + $results = Find-DbaSimilarTable -SqlInstance $global:instance1 -Database tempdb | Where-Object Table -Match dbatoolsci $results.Count | Should -BeGreaterOrEqual 2 $results.OriginalDatabaseId | Should -Be $db.ID, $db.ID $results.MatchingDatabaseId | Should -Be $db.ID, $db.ID diff --git a/tests/Find-DbaStoredProcedure.Tests.ps1 b/tests/Find-DbaStoredProcedure.Tests.ps1 index d942c9516f..7f909f10b4 100644 --- a/tests/Find-DbaStoredProcedure.Tests.ps1 +++ b/tests/Find-DbaStoredProcedure.Tests.ps1 @@ -52,44 +52,44 @@ AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $ServerProcedure + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'Master' -Query $ServerProcedure } AfterAll { $DropProcedure = "DROP PROCEDURE dbo.cp_dbatoolsci_sysadmin;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropProcedure + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'Master' -Query $DropProcedure } It "Should find a specific StoredProcedure named cp_dbatoolsci_sysadmin" { - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -IncludeSystemDatabases + $results = Find-DbaStoredProcedure -SqlInstance $global:instance2 -Pattern dbatools* -IncludeSystemDatabases $results.Name | Should -Contain "cp_dbatoolsci_sysadmin" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database master).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database master).ID } } Context "Command finds Procedures in a User Database" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_storedproceduredb' + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name 'dbatoolsci_storedproceduredb' $StoredProcedure = @" CREATE PROCEDURE dbo.sp_dbatoolsci_custom AS SET NOCOUNT ON; PRINT 'Dbatools Rocks'; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_storedproceduredb' -Query $StoredProcedure + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'dbatoolsci_storedproceduredb' -Query $StoredProcedure } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_storedproceduredb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database 'dbatoolsci_storedproceduredb' -Confirm:$false } It "Should find a specific StoredProcedure named sp_dbatoolsci_custom" { - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' + $results = Find-DbaStoredProcedure -SqlInstance $global:instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' $results.Name | Should -Contain "sp_dbatoolsci_custom" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolsci_storedproceduredb).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database dbatoolsci_storedproceduredb).ID } It "Should find sp_dbatoolsci_custom in dbatoolsci_storedproceduredb" { - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' + $results = Find-DbaStoredProcedure -SqlInstance $global:instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' $results.Database | Should -Contain "dbatoolsci_storedproceduredb" } It "Should find no results when Excluding dbatoolsci_storedproceduredb" { - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_storedproceduredb' + $results = Find-DbaStoredProcedure -SqlInstance $global:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_storedproceduredb' $results | Should -BeNullOrEmpty } } diff --git a/tests/Find-DbaTrigger.Tests.ps1 b/tests/Find-DbaTrigger.Tests.ps1 index b155ee8e31..29dd936d91 100644 --- a/tests/Find-DbaTrigger.Tests.ps1 +++ b/tests/Find-DbaTrigger.Tests.ps1 @@ -56,34 +56,34 @@ AS PRINT 'dbatoolsci Database Created.' SELECT EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)') "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $ServerTrigger + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Query $ServerTrigger } AfterAll { $DropTrigger = @" DROP TRIGGER dbatoolsci_ddl_trig_database ON ALL SERVER; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropTrigger + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'Master' -Query $DropTrigger } It "Should find a specific Trigger at the Server Level" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server $results.TriggerLevel | Should -Be "Server" $results.DatabaseId | Should -BeNullOrEmpty } It "Should find a specific Trigger named dbatoolsci_ddl_trig_database" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server $results.Name | Should -Be "dbatoolsci_ddl_trig_database" } It "Should find a specific Trigger when TriggerLevel is All" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -TriggerLevel All + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -TriggerLevel All $results.Name | Should -Be "dbatoolsci_ddl_trig_database" } } Context "Command finds Triggers at the Database and Object Level" { BeforeAll { - $dbatoolsci_triggerdb = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_triggerdb' + $dbatoolsci_triggerdb = New-DbaDatabase -SqlInstance $global:instance2 -Name 'dbatoolsci_triggerdb' $DatabaseTrigger = @" CREATE TRIGGER dbatoolsci_safety ON DATABASE @@ -94,7 +94,7 @@ RETURN; RAISERROR ('You must disable Trigger "safety" to drop synonyms!',10, 1) ROLLBACK "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Query $DatabaseTrigger + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'dbatoolsci_triggerdb' -Query $DatabaseTrigger $TableTrigger = @" CREATE TABLE dbo.Customer (id int, PRIMARY KEY (id)); GO @@ -104,36 +104,36 @@ AFTER INSERT, UPDATE AS RAISERROR ('Notify Customer Relations', 16, 10); GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Query $TableTrigger + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'dbatoolsci_triggerdb' -Query $TableTrigger } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database 'dbatoolsci_triggerdb' -Confirm:$false } It "Should find a specific Trigger at the Database Level" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database $results.TriggerLevel | Should -Be "Database" $results.DatabaseId | Should -Be $dbatoolsci_triggerdb.ID } It "Should find a specific Trigger named dbatoolsci_safety" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database $results.Name | Should -Be "dbatoolsci_safety" } It "Should find a specific Trigger at the Object Level" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object $results.TriggerLevel | Should -Be "Object" $results.DatabaseId | Should -Be $dbatoolsci_triggerdb.ID } It "Should find a specific Trigger named dbatoolsci_reminder1" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object $results.Name | Should -Be "dbatoolsci_reminder1" } It "Should find a specific Trigger on the Table [dbo].[Customer]" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object $results.Object | Should -Be "[dbo].[Customer]" } It "Should find 2 Triggers when TriggerLevel is All" { - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -TriggerLevel All + $results = Find-DbaTrigger -SqlInstance $global:instance2 -Pattern dbatoolsci* -TriggerLevel All $results.name | Should -Be @('dbatoolsci_safety', 'dbatoolsci_reminder1') $results.DatabaseId | Should -Be @($dbatoolsci_triggerdb.ID, $dbatoolsci_triggerdb.ID) } diff --git a/tests/Find-DbaUserObject.Tests.ps1 b/tests/Find-DbaUserObject.Tests.ps1 index 47e2aa381c..9013c20512 100644 --- a/tests/Find-DbaUserObject.Tests.ps1 +++ b/tests/Find-DbaUserObject.Tests.ps1 @@ -15,32 +15,32 @@ Describe "Find-DbaUserObject" { $CommandUnderTest | Should -HaveParameter Pattern -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command finds User Objects for SA" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_userObject' -Owner 'sa' + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name 'dbatoolsci_userObject' -Owner 'sa' } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_userObject' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database 'dbatoolsci_userObject' -Confirm:$false } It "Should find a specific Database Owned by sa" { - $results = Find-DbaUserObject -SqlInstance $script:instance2 -Pattern sa + $results = Find-DbaUserObject -SqlInstance $global:instance2 -Pattern sa $results.Where( {$_.name -eq 'dbatoolsci_userobject'}).Type | Should -Be "Database" } It "Should find more than 10 objects Owned by sa" { - $results = Find-DbaUserObject -SqlInstance $script:instance2 -Pattern sa + $results = Find-DbaUserObject -SqlInstance $global:instance2 -Pattern sa $results.Count | Should -BeGreaterThan 10 } } Context "Command finds User Objects" { It "Should find results" { - $results = Find-DbaUserObject -SqlInstance $script:instance2 + $results = Find-DbaUserObject -SqlInstance $global:instance2 $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Find-DbaView.Tests.ps1 b/tests/Find-DbaView.Tests.ps1 index fae844e4ed..dee8d89521 100644 --- a/tests/Find-DbaView.Tests.ps1 +++ b/tests/Find-DbaView.Tests.ps1 @@ -40,51 +40,51 @@ AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $ServerView + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'Master' -Query $ServerView } AfterAll { $DropView = "DROP VIEW dbo.v_dbatoolsci_sysadmin;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropView + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'Master' -Query $DropView } It "Should find a specific View named v_dbatoolsci_sysadmin" { - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -IncludeSystemDatabases + $results = Find-DbaView -SqlInstance $global:instance2 -Pattern dbatools* -IncludeSystemDatabases $results.Name | Should -Be "v_dbatoolsci_sysadmin" } It "Should find v_dbatoolsci_sysadmin in Master" { - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -IncludeSystemDatabases + $results = Find-DbaView -SqlInstance $global:instance2 -Pattern dbatools* -IncludeSystemDatabases $results.Database | Should -Be "Master" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database Master).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database Master).ID } } Context "Command finds View in a User Database" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_viewdb' + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name 'dbatoolsci_viewdb' $DatabaseView = @" CREATE VIEW dbo.v_dbatoolsci_sysadmin AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_viewdb' -Query $DatabaseView + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database 'dbatoolsci_viewdb' -Query $DatabaseView } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_viewdb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database 'dbatoolsci_viewdb' -Confirm:$false } It "Should find a specific view named v_dbatoolsci_sysadmin" { - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' + $results = Find-DbaView -SqlInstance $global:instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' $results.Name | Should -Be "v_dbatoolsci_sysadmin" } It "Should find v_dbatoolsci_sysadmin in dbatoolsci_viewdb Database" { - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' + $results = Find-DbaView -SqlInstance $global:instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' $results.Database | Should -Be "dbatoolsci_viewdb" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolsci_viewdb).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database dbatoolsci_viewdb).ID } It "Should find no results when Excluding dbatoolsci_viewdb" { - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_viewdb' + $results = Find-DbaView -SqlInstance $global:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_viewdb' $results | Should -BeNullOrEmpty } } diff --git a/tests/Get-DbaAgDatabase.Tests.ps1 b/tests/Get-DbaAgDatabase.Tests.ps1 index 893351c7c7..7d894c7d93 100644 --- a/tests/Get-DbaAgDatabase.Tests.ps1 +++ b/tests/Get-DbaAgDatabase.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaAgDatabase" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -32,14 +32,14 @@ Describe "Get-DbaAgDatabase Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $global:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance3 $agname = "dbatoolsci_getagdb_agroup" $dbname = "dbatoolsci_getagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup } AfterAll { @@ -49,10 +49,10 @@ Describe "Get-DbaAgDatabase Integration Tests" -Tag "IntegrationTests" { Context "Gets AG database" { It "Returns results" { - $results = Get-DbaAgDatabase -SqlInstance $script:instance3 -Database $dbname + $results = Get-DbaAgDatabase -SqlInstance $global:instance3 -Database $dbname $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.LocalReplicaRole | Should -Not -BeNullOrEmpty } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Get-DbaAgHadr.Tests.ps1 b/tests/Get-DbaAgHadr.Tests.ps1 index 149efa740b..793eda1268 100644 --- a/tests/Get-DbaAgHadr.Tests.ps1 +++ b/tests/Get-DbaAgHadr.Tests.ps1 @@ -16,17 +16,17 @@ Describe "Get-DbaAgHadr" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" -Skip:(-not $env:APPVEYOR) { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance3 } It "returns the correct properties" { - $results = Get-DbaAgHadr -SqlInstance $script:instance3 + $results = Get-DbaAgHadr -SqlInstance $global:instance3 $results.IsHadrEnabled | Should -Be $true } } diff --git a/tests/Get-DbaAgListener.Tests.ps1 b/tests/Get-DbaAgListener.Tests.ps1 index 6cdaf02b92..db16fe9fc6 100644 --- a/tests/Get-DbaAgListener.Tests.ps1 +++ b/tests/Get-DbaAgListener.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaAgListener Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -40,21 +40,21 @@ Describe "Get-DbaAgListener Integration Tests" -Tag "IntegrationTests" { BeforeAll { if (-not $SkipIntegrationTests) { $agname = "dbatoolsci_ag_listener" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } } AfterAll { if (-not $SkipIntegrationTests) { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false } } Context "Gets availability group listeners" -Skip:$SkipIntegrationTests { It "Returns results with proper data" { - $results = Get-DbaAgListener -SqlInstance $script:instance3 + $results = Get-DbaAgListener -SqlInstance $global:instance3 $results.PortNumber | Should -Contain 14330 } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Get-DbaAgReplica.Tests.ps1 b/tests/Get-DbaAgReplica.Tests.ps1 index b41f3394c9..dac0644060 100644 --- a/tests/Get-DbaAgReplica.Tests.ps1 +++ b/tests/Get-DbaAgReplica.Tests.ps1 @@ -26,27 +26,27 @@ Describe "Get-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { $agname = "dbatoolsci_agroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false } It "returns results with proper data" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 + $results = Get-DbaAgReplica -SqlInstance $global:instance3 $results.AvailabilityGroup | Should -Contain $agname $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' } It "returns just one result" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $global:instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' @@ -60,4 +60,4 @@ Describe "Get-DbaAgReplica" { { Get-DbaAgReplica -SqlInstance invalidSQLHostName -EnableException } | Should -Throw } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Get-DbaAgentAlert.Tests.ps1 b/tests/Get-DbaAgentAlert.Tests.ps1 index f5f4a6dc8f..2a533a9dce 100644 --- a/tests/Get-DbaAgentAlert.Tests.ps1 +++ b/tests/Get-DbaAgentAlert.Tests.ps1 @@ -23,7 +23,7 @@ Describe "Get-DbaAgentAlert Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeAlert -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -32,19 +32,19 @@ Describe "Get-DbaAgentAlert Integration Tests" -Tag "IntegrationTests" { BeforeAll { $PSDefaultParameterValues = @{ 'It:Skip' = $false } . (Join-Path $PSScriptRoot 'constants.ps1') - - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'dbatoolsci test alert',@message_id=0,@severity=6,@enabled=1,@delay_between_responses=0,@include_event_description_in=0,@category_name=N'[Uncategorized]',@job_id=N'00000000-0000-0000-0000-000000000000'") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $global:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'dbatoolsci test alert'") } Context "Command actually works" { BeforeAll { - $results = Get-DbaAgentAlert -SqlInstance $script:instance2 + $results = Get-DbaAgentAlert -SqlInstance $global:instance2 } It "gets the newly created alert" { diff --git a/tests/Get-DbaAgentAlertCategory.Tests.ps1 b/tests/Get-DbaAgentAlertCategory.Tests.ps1 index 871a32e478..25bc32aede 100644 --- a/tests/Get-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/Get-DbaAgentAlertCategory.Tests.ps1 @@ -15,24 +15,24 @@ Describe "Get-DbaAgentAlertCategory" { $CommandUnderTest | Should -HaveParameter Category -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command gets alert categories" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 + $null = New-DbaAgentAlertCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 } AfterAll { - $null = Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false + $null = Remove-DbaAgentAlertCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false } It "Should get at least 2 categories" { - $results = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentAlertCategory -SqlInstance $global:instance2 | Where-Object {$_.Name -match "dbatoolsci"} $results.count | Should -BeGreaterThan 1 } It "Should get the dbatoolsci_testcategory category" { - $results = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentAlertCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} $results.count | Should -Be 1 } } diff --git a/tests/Get-DbaAgentJob.Tests.ps1 b/tests/Get-DbaAgentJob.Tests.ps1 index 7d519fa041..357c793287 100644 --- a/tests/Get-DbaAgentJob.Tests.ps1 +++ b/tests/Get-DbaAgentJob.Tests.ps1 @@ -33,16 +33,16 @@ Describe "Get-DbaAgentJob Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeCategory -Type String[] -Not -Mandatory } It "Should have ExcludeDisabledJobs parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeDisabledJobs -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeDisabledJobs -Type Switch -Not -Mandatory } It "Should have IncludeExecution parameter" { - $CommandUnderTest | Should -HaveParameter IncludeExecution -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeExecution -Type Switch -Not -Mandatory } It "Should have Type parameter" { $CommandUnderTest | Should -HaveParameter Type -Type String[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -54,65 +54,65 @@ Describe "Get-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { Context "Command gets jobs" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } It "Should get 2 dbatoolsci jobs" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $global:instance2 | Where-Object { $_.Name -match "dbatoolsci_testjob" } $results.count | Should -Be 2 } It "Should get a specific job" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob + $results = Get-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob $results.name | Should -Be "dbatoolsci_testjob" } } Context "Command gets no disabled jobs" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } It "Should return only enabled jobs" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeDisabledJobs | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $global:instance2 -ExcludeDisabledJobs | Where-Object { $_.Name -match "dbatoolsci_testjob" } $results.enabled -contains $False | Should -Be $False } } Context "Command doesn't get excluded job" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } It "Should not return excluded job" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeJob dbatoolsci_testjob | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $global:instance2 -ExcludeJob dbatoolsci_testjob | Where-Object { $_.Name -match "dbatoolsci_testjob" } $results.name -contains "dbatoolsci_testjob" | Should -Be $False } } Context "Command doesn't get excluded category" { BeforeAll { - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat1' - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat2' + $null = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'Cat1' + $null = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'Cat2' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat1 -Category 'Cat1' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat2 -Category 'Cat2' + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_cat1 -Category 'Cat1' + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_cat2 -Category 'Cat2' } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat1', 'Cat2' -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $global:instance2 -Category 'Cat1', 'Cat2' -Confirm:$false - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat1, dbatoolsci_testjob_cat2 -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job dbatoolsci_testjob_cat1, dbatoolsci_testjob_cat2 -Confirm:$false } It "Should not return excluded job" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeCategory 'Cat2' | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $global:instance2 -ExcludeCategory 'Cat2' | Where-Object { $_.Name -match "dbatoolsci_testjob" } $results.name -contains "dbatoolsci_testjob_cat2" | Should -Be $False } } @@ -121,33 +121,33 @@ Describe "Get-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { BeforeAll { $jobName1 = "dbatoolsci_dbfilter_$(Get-Random)" $jobName2 = "dbatoolsci_dbfilter_$(Get-Random)" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1 -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-y" -Subsystem TransactSql -Database "tempdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName1 -Disabled + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName1 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName1 -StepName "TSQL-y" -Subsystem TransactSql -Database "tempdb" + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName1 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName2 -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-y" -Subsystem TransactSql -Database "model" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName2 -Disabled + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName2 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName2 -StepName "TSQL-y" -Subsystem TransactSql -Database "model" + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName2 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1, $jobName2 -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName1, $jobName2 -Confirm:$false } It "Returns result with single database" { - $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb + $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $global:instance2 -Database tempdb $resultSingleDatabase.Count | Should -BeGreaterOrEqual 1 } It "Returns job result for Database: tempdb" { - $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb + $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $global:instance2 -Database tempdb $resultSingleDatabase.name -contains $jobName1 | Should -BeTrue } It "Returns both jobs with double database" { - $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb, model + $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $global:instance2 -Database tempdb, model $resultMultipleDatabases.Count | Should -BeGreaterOrEqual 2 } It "Includes job result for Database: model" { - $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb, model + $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $global:instance2 -Database tempdb, model $resultMultipleDatabases.name -contains $jobName2 | Should -BeTrue } } diff --git a/tests/Get-DbaAgentJobCategory.Tests.ps1 b/tests/Get-DbaAgentJobCategory.Tests.ps1 index ca85231786..562f34952f 100644 --- a/tests/Get-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Get-DbaAgentJobCategory.Tests.ps1 @@ -18,28 +18,28 @@ Describe "Get-DbaAgentJobCategory" { $CommandUnderTest | Should -HaveParameter CategoryType -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command gets job categories" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 + $null = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false } It "Should get at least 2 categories" { - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $global:instance2 | Where-Object {$_.Name -match "dbatoolsci"} $results.count | Should -BeGreaterThan 1 } It "Should get the dbatoolsci_testcategory category" { - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $global:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} $results.count | Should -Be 1 } It "Should get at least 1 LocalJob" { - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -CategoryType LocalJob | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $global:instance2 -CategoryType LocalJob | Where-Object {$_.Name -match "dbatoolsci"} $results.count | Should -BeGreaterThan 1 } } diff --git a/tests/Get-DbaAgentJobHistory.Tests.ps1 b/tests/Get-DbaAgentJobHistory.Tests.ps1 index 8b5475fb81..5ad1d327f1 100644 --- a/tests/Get-DbaAgentJobHistory.Tests.ps1 +++ b/tests/Get-DbaAgentJobHistory.Tests.ps1 @@ -33,16 +33,16 @@ Describe "Get-DbaAgentJobHistory Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter OutcomeType -Type CompletionResult -Not -Mandatory } It "Should have ExcludeJobSteps parameter" { - $command | Should -HaveParameter ExcludeJobSteps -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter ExcludeJobSteps -Type Switch -Not -Mandatory } It "Should have WithOutputFile parameter" { - $command | Should -HaveParameter WithOutputFile -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter WithOutputFile -Type Switch -Not -Mandatory } It "Should have JobCollection parameter" { $command | Should -HaveParameter JobCollection -Type Job -Not -Mandatory } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Get-DbaAgentJobOutputFile.Tests.ps1 b/tests/Get-DbaAgentJobOutputFile.Tests.ps1 index 049f396761..d56c6fcb82 100644 --- a/tests/Get-DbaAgentJobOutputFile.Tests.ps1 +++ b/tests/Get-DbaAgentJobOutputFile.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaAgentJobOutputFile" { $CommandUnderTest | Should -HaveParameter ExcludeJob -Type Object[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaAgentJobStep.Tests.ps1 b/tests/Get-DbaAgentJobStep.Tests.ps1 index d571ff074d..2ea84980ad 100644 --- a/tests/Get-DbaAgentJobStep.Tests.ps1 +++ b/tests/Get-DbaAgentJobStep.Tests.ps1 @@ -32,28 +32,28 @@ Describe "Get-DbaAgentJobStep" { BeforeAll { . "$PSScriptRoot\constants.ps1" $jobName = "dbatoolsci_job_$(Get-Random)" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName -StepName dbatoolsci_jobstep1 -Subsystem TransactSql -Command 'select 1' + $null = New-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName + $null = New-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName -StepName dbatoolsci_jobstep1 -Subsystem TransactSql -Command 'select 1' } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName -Confirm:$false } It "Successfully gets job when not using Job param" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 + $results = Get-DbaAgentJobStep -SqlInstance $global:instance2 $results.Name | Should -Contain 'dbatoolsci_jobstep1' } It "Successfully gets job when using Job param" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName + $results = Get-DbaAgentJobStep -SqlInstance $global:instance2 -Job $jobName $results.Name | Should -Contain 'dbatoolsci_jobstep1' } It "Successfully gets job when excluding some jobs" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -ExcludeJob 'syspolicy_purge_history' + $results = Get-DbaAgentJobStep -SqlInstance $global:instance2 -ExcludeJob 'syspolicy_purge_history' $results.Name | Should -Contain 'dbatoolsci_jobstep1' } It "Successfully excludes disabled jobs" { - $null = Set-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Disabled - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -ExcludeDisabledJobs + $null = Set-DbaAgentJob -SqlInstance $global:instance2 -Job $jobName -Disabled + $results = Get-DbaAgentJobStep -SqlInstance $global:instance2 -ExcludeDisabledJobs $results.Name | Should -Not -Contain 'dbatoolsci_jobstep1' } } diff --git a/tests/Get-DbaAgentLog.Tests.ps1 b/tests/Get-DbaAgentLog.Tests.ps1 index e1b33f492c..aebe23738f 100644 --- a/tests/Get-DbaAgentLog.Tests.ps1 +++ b/tests/Get-DbaAgentLog.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaAgentLog" { $CommandUnderTest | Should -HaveParameter LogNumber -Type Int32[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -24,7 +24,7 @@ Describe "Get-DbaAgentLog" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $results = Get-DbaAgentLog -SqlInstance $script:instance2 + $results = Get-DbaAgentLog -SqlInstance $global:instance2 } It "Results are not empty" { $results | Should -Not -BeNullOrEmpty @@ -42,7 +42,7 @@ Describe "Get-DbaAgentLog" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $results = Get-DbaAgentLog -SqlInstance $script:instance2 -LogNumber 0 + $results = Get-DbaAgentLog -SqlInstance $global:instance2 -LogNumber 0 } It "Results are not empty" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaAgentOperator.Tests.ps1 b/tests/Get-DbaAgentOperator.Tests.ps1 index 5f7d1ba1e7..e7a136e691 100644 --- a/tests/Get-DbaAgentOperator.Tests.ps1 +++ b/tests/Get-DbaAgentOperator.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter ExcludeOperator -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -28,7 +28,7 @@ Describe "Get-DbaAgentOperator" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator', @enabled=1, @pager_days=0" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator2', @enabled=1, @pager_days=0" @@ -43,12 +43,12 @@ Describe "Get-DbaAgentOperator" { } It "Should return at least two results" { - $results = Get-DbaAgentOperator -SqlInstance $script:instance2 + $results = Get-DbaAgentOperator -SqlInstance $global:instance2 $results.Count | Should -BeGreaterOrEqual 2 } It "Should return one result when specifying an operator" { - $results = Get-DbaAgentOperator -SqlInstance $script:instance2 -Operator dbatoolsci_operator + $results = Get-DbaAgentOperator -SqlInstance $global:instance2 -Operator dbatoolsci_operator $results.Count | Should -Be 1 } } diff --git a/tests/Get-DbaAgentProxy.Tests.ps1 b/tests/Get-DbaAgentProxy.Tests.ps1 index 8e0f397418..515e8cab17 100644 --- a/tests/Get-DbaAgentProxy.Tests.ps1 +++ b/tests/Get-DbaAgentProxy.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaAgentProxy" { $CommandUnderTest | Should -HaveParameter ExcludeProxy -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,23 +31,23 @@ Describe "Get-DbaAgentProxy" { $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force $tUserName = "dbatoolsci_proxytest" New-LocalUser -Name $tUserName -Password $tPassword -Disabled:$false - New-DbaCredential -SqlInstance $script:instance2 -Name "$tUserName" -Identity "$env:COMPUTERNAME\$tUserName" -Password $tPassword - New-DbaAgentProxy -SqlInstance $script:instance2 -Name STIG -ProxyCredential "$tUserName" - New-DbaAgentProxy -SqlInstance $script:instance2 -Name STIGX -ProxyCredential "$tUserName" + New-DbaCredential -SqlInstance $global:instance2 -Name "$tUserName" -Identity "$env:COMPUTERNAME\$tUserName" -Password $tPassword + New-DbaAgentProxy -SqlInstance $global:instance2 -Name STIG -ProxyCredential "$tUserName" + New-DbaAgentProxy -SqlInstance $global:instance2 -Name STIGX -ProxyCredential "$tUserName" } AfterAll { $tUserName = "dbatoolsci_proxytest" Remove-LocalUser -Name $tUserName - $credential = Get-DbaCredential -SqlInstance $script:instance2 -Name $tUserName + $credential = Get-DbaCredential -SqlInstance $global:instance2 -Name $tUserName $credential.DROP() - $proxy = Get-DbaAgentProxy -SqlInstance $script:instance2 -Proxy "STIG", "STIGX" + $proxy = Get-DbaAgentProxy -SqlInstance $global:instance2 -Proxy "STIG", "STIGX" $proxy.DROP() } Context "Gets the list of Proxy" { BeforeAll { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 + $results = Get-DbaAgentProxy -SqlInstance $global:instance2 } It "Results are not empty" { @@ -65,7 +65,7 @@ Describe "Get-DbaAgentProxy" { Context "Gets a single Proxy" { BeforeAll { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 -Proxy "STIG" + $results = Get-DbaAgentProxy -SqlInstance $global:instance2 -Proxy "STIG" } It "Results are not empty" { @@ -83,7 +83,7 @@ Describe "Get-DbaAgentProxy" { Context "Gets the list of Proxy without excluded" { BeforeAll { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 -ExcludeProxy "STIG" + $results = Get-DbaAgentProxy -SqlInstance $global:instance2 -ExcludeProxy "STIG" } It "Results are not empty" { diff --git a/tests/Get-DbaAgentSchedule.Tests.ps1 b/tests/Get-DbaAgentSchedule.Tests.ps1 index 59dc806310..9c97d7b2fc 100644 --- a/tests/Get-DbaAgentSchedule.Tests.ps1 +++ b/tests/Get-DbaAgentSchedule.Tests.ps1 @@ -15,25 +15,25 @@ Describe "Get-DbaAgentSchedule Unit Tests" -Tag 'UnitTests' { $CommandName | Should -HaveParameter Schedule -Type String[] -Not -Mandatory $CommandName | Should -HaveParameter ScheduleUid -Type String[] -Not -Mandatory $CommandName | Should -HaveParameter Id -Type Int32[] -Not -Mandatory - $CommandName | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandName | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance2 = $env:COMPUTERNAME - $script:instance3 = $env:COMPUTERNAME + $global:instance2 = $env:COMPUTERNAME + $global:instance3 = $env:COMPUTERNAME - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 + $server3 = Connect-DbaInstance -SqlInstance $global:instance3 - $null = New-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force - $null = New-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force + $null = New-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force + $null = New-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force + $null = New-DbaAgentSchedule -SqlInstance $global:instance3 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Once' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -45,7 +45,7 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Hour' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -57,7 +57,7 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Minute' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -69,7 +69,7 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Second' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -81,21 +81,21 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = "Issue_6636_OneTime" FrequencyType = "OneTime" } $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = "Issue_6636_AutoStart" FrequencyType = "AutoStart" } $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = "Issue_6636_OnIdle" FrequencyType = "OnIdle" } @@ -103,12 +103,12 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest, Issue_6636_Once, Issue_6636_Once_Copy, Issue_6636_Hour, Issue_6636_Hour_Copy, Issue_6636_Minute, Issue_6636_Minute_Copy, Issue_6636_Second, Issue_6636_Second_Copy, Issue_6636_OneTime, Issue_6636_OneTime_Copy, Issue_6636_AutoStart, Issue_6636_AutoStart_Copy, Issue_6636_OnIdle, Issue_6636_OnIdle_Copy + $schedules = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest, Issue_6636_Once, Issue_6636_Once_Copy, Issue_6636_Hour, Issue_6636_Hour_Copy, Issue_6636_Minute, Issue_6636_Minute_Copy, Issue_6636_Second, Issue_6636_Second_Copy, Issue_6636_OneTime, Issue_6636_OneTime_Copy, Issue_6636_AutoStart, Issue_6636_AutoStart_Copy, Issue_6636_OnIdle, Issue_6636_OnIdle_Copy if ($null -ne $schedules) { $schedules | ForEach-Object { $_.Drop() } } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_MonthlyTest + $schedules = Get-DbaAgentSchedule -SqlInstance $global:instance3 -Schedule dbatoolsci_MonthlyTest if ($null -ne $schedules) { $schedules | ForEach-Object { $_.Drop() } } @@ -116,7 +116,7 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { Context "Gets the list of Schedules" { It "Results are not empty" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest + $results = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest $results | Should -Not -BeNullOrEmpty $results.Count | Should -Be 2 } @@ -124,14 +124,14 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { Context "Handles multiple instances" { It "Results contain two instances" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2, $script:instance3 + $results = Get-DbaAgentSchedule -SqlInstance $global:instance2, $global:instance3 ($results | Select-Object -Unique SqlInstance).Count | Should -Be 2 } } Context "Monthly schedule is correct" { It "verify schedule components" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_MonthlyTest + $results = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_MonthlyTest $results | Should -Not -BeNullOrEmpty $results.Count | Should -Be 1 @@ -139,7 +139,7 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $results.FrequencyInterval | Should -Be 10 $results.IsEnabled | Should -BeTrue $results.SqlInstance | Should -Not -BeNullOrEmpty - + $datetimeFormat = (Get-Culture).DateTimeFormat $startDate = Get-Date $results.ActiveStartDate -Format $datetimeFormat.ShortDatePattern $startTime = Get-Date '00:00:00' -Format $datetimeFormat.LongTimePattern @@ -149,10 +149,10 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { Context "Issue 6636 - provide flexibility in the FrequencySubdayType and FrequencyType input params" { It "Ensure frequency subday type of 'Once' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Once + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Once $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Once_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -164,17 +164,17 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Once_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Once_Copy $result.ScheduleName | Should -Be "Issue_6636_Once_Copy" $result.FrequencySubdayTypes | Should -Be "Once" } It "Ensure frequency subday type of 'Hour' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Hour + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Hour $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Hour_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -186,17 +186,17 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Hour_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Hour_Copy $result.ScheduleName | Should -Be "Issue_6636_Hour_Copy" $result.FrequencySubdayTypes | Should -Be "Hour" } It "Ensure frequency subday type of 'Minute' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Minute + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Minute $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Minute_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -208,17 +208,17 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Minute_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Minute_Copy $result.ScheduleName | Should -Be "Issue_6636_Minute_Copy" $result.FrequencySubdayTypes | Should -Be "Minute" } It "Ensure frequency subday type of 'Second' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Second + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Second $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_Second_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -230,17 +230,17 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Second_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_Second_Copy $result.ScheduleName | Should -Be "Issue_6636_Second_Copy" $result.FrequencySubdayTypes | Should -Be "Second" } It "Ensure frequency type of 'OneTime' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OneTime + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_OneTime $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_OneTime_Copy' FrequencyType = $result.FrequencyTypes StartTime = $result.ActiveStartTimeOfDay.ToString().Replace(":", "") @@ -248,17 +248,17 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OneTime_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_OneTime_Copy $result.ScheduleName | Should -Be "Issue_6636_OneTime_Copy" $result.FrequencyTypes | Should -Be "OneTime" } It "Ensure frequency type of 'AutoStart' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_AutoStart + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_AutoStart $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_AutoStart_Copy' FrequencyType = $result.FrequencyTypes StartTime = $result.ActiveStartTimeOfDay.ToString().Replace(":", "") @@ -266,24 +266,24 @@ Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_AutoStart_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_AutoStart_Copy $result.ScheduleName | Should -Be "Issue_6636_AutoStart_Copy" $result.FrequencyTypes | Should -Be "AutoStart" } It "Ensure frequency type of 'OnIdle' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OnIdle + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_OnIdle $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $global:instance2 Schedule = 'Issue_6636_OnIdle_Copy' FrequencyType = $result.FrequencyTypes } $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OnIdle_Copy + $result = Get-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule Issue_6636_OnIdle_Copy $result.ScheduleName | Should -Be "Issue_6636_OnIdle_Copy" $result.FrequencyTypes | Should -Be "OnIdle" diff --git a/tests/Get-DbaAgentServer.Tests.ps1 b/tests/Get-DbaAgentServer.Tests.ps1 index a63d4b3577..8ce05d6dfa 100644 --- a/tests/Get-DbaAgentServer.Tests.ps1 +++ b/tests/Get-DbaAgentServer.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaAgentServer" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -60,7 +60,7 @@ Describe "Get-DbaAgentServer" { Context "Command gets server agent" { BeforeAll { - $results = Get-DbaAgentServer -SqlInstance $script:instance2 + $results = Get-DbaAgentServer -SqlInstance $global:instance2 } It "Should get 1 agent server" { $results.count | Should -Be 1 diff --git a/tests/Get-DbaAvailabilityGroup.Tests.ps1 b/tests/Get-DbaAvailabilityGroup.Tests.ps1 index fd7fc56d9d..f84d927620 100644 --- a/tests/Get-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Get-DbaAvailabilityGroup.Tests.ps1 @@ -15,10 +15,10 @@ Describe "Get-DbaAvailabilityGroup" { $CommandUnderTest | Should -HaveParameter AvailabilityGroup -Type String[] } It "Should have IsPrimary as a switch parameter" { - $CommandUnderTest | Should -HaveParameter IsPrimary -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IsPrimary -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,21 +29,21 @@ Describe "Get-DbaAvailabilityGroup" { BeforeAll { $agname = "dbatoolsci_agroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false } It "returns results with proper data" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 + $results = Get-DbaAvailabilityGroup -SqlInstance $global:instance3 $results.AvailabilityGroup | Should -Contain $agname } It "returns a single result" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname } } -} #$script:instance2 for appveyor +} #$global:instance2 for appveyor diff --git a/tests/Get-DbaAvailableCollation.Tests.ps1 b/tests/Get-DbaAvailableCollation.Tests.ps1 index 68f71ffb12..09b337ab1d 100644 --- a/tests/Get-DbaAvailableCollation.Tests.ps1 +++ b/tests/Get-DbaAvailableCollation.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Get-DbaAvailableCollation" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -24,7 +24,7 @@ Describe "Get-DbaAvailableCollation" { . "$PSScriptRoot\constants.ps1" } It "Finds a collation that matches Slovenian" { - $results = Get-DbaAvailableCollation -SqlInstance $script:instance2 + $results = Get-DbaAvailableCollation -SqlInstance $global:instance2 ($results.Name -match 'Slovenian').Count | Should -BeGreaterThan 10 } } diff --git a/tests/Get-DbaBackupDevice.Tests.ps1 b/tests/Get-DbaBackupDevice.Tests.ps1 index 6046ae0762..124f7da0f7 100644 --- a/tests/Get-DbaBackupDevice.Tests.ps1 +++ b/tests/Get-DbaBackupDevice.Tests.ps1 @@ -18,18 +18,18 @@ Describe "Get-DbaBackupDevice" { Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC sp_addumpdevice 'tape', 'dbatoolsci_tape', '\\.\tape0';" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "EXEC sp_dropdevice 'dbatoolsci_tape';" $server.Query($sql) } It "Gets the backup devices" { - $results = Get-DbaBackupDevice -SqlInstance $script:instance2 + $results = Get-DbaBackupDevice -SqlInstance $global:instance2 $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be "dbatoolsci_tape" $results.BackupDeviceType | Should -Be "Tape" diff --git a/tests/Get-DbaBackupInformation.Tests.ps1 b/tests/Get-DbaBackupInformation.Tests.ps1 index 9efea5d933..b15ac0e266 100644 --- a/tests/Get-DbaBackupInformation.Tests.ps1 +++ b/tests/Get-DbaBackupInformation.Tests.ps1 @@ -14,17 +14,17 @@ Describe "Get-DbaBackupInformation" { } $random = Get-Random $dbname = "dbatoolsci_Backuphistory_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $global:instance1 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir $dbname2 = "dbatoolsci_Backuphistory2_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $global:instance1 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 + $db2 = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname2 $db2 | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db2 | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db2 | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir @@ -42,16 +42,16 @@ Describe "Get-DbaBackupInformation" { } $dbname3 = "dbatoolsci_BackuphistoryOla_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname3 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname3 -DestinationFilePrefix $dbname3 - $db3 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname3 + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname3 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $global:instance1 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname3 -DestinationFilePrefix $dbname3 + $db3 = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname3 $db3 | Backup-DbaDatabase -Type Full -BackupDirectory "$DestBackupDirOla\FULL" $db3 | Backup-DbaDatabase -Type Differential -BackupDirectory "$DestBackupDirOla\Diff" $db3 | Backup-DbaDatabase -Type Log -BackupDirectory "$DestBackupDirOla\LOG" } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbname2, $dbname3 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname, $dbname2, $dbname3 | Remove-DbaDatabase -Confirm:$false } Context "Validate parameters" { @@ -74,25 +74,25 @@ Describe "Get-DbaBackupInformation" { $CommandUnderTest | Should -HaveParameter SourceInstance -Type String[] -Not -Mandatory } It "Should have NoXpDirTree parameter" { - $CommandUnderTest | Should -HaveParameter NoXpDirTree -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoXpDirTree -Type Switch -Not -Mandatory } It "Should have NoXpDirRecurse parameter" { - $CommandUnderTest | Should -HaveParameter NoXpDirRecurse -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoXpDirRecurse -Type Switch -Not -Mandatory } It "Should have DirectoryRecurse parameter" { - $CommandUnderTest | Should -HaveParameter DirectoryRecurse -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DirectoryRecurse -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have MaintenanceSolution parameter" { - $CommandUnderTest | Should -HaveParameter MaintenanceSolution -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter MaintenanceSolution -Type Switch -Not -Mandatory } It "Should have IgnoreLogBackup parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreLogBackup -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IgnoreLogBackup -Type Switch -Not -Mandatory } It "Should have IgnoreDiffBackup parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreDiffBackup -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IgnoreDiffBackup -Type Switch -Not -Mandatory } It "Should have ExportPath parameter" { $CommandUnderTest | Should -HaveParameter ExportPath -Type String -Not -Mandatory @@ -101,22 +101,22 @@ Describe "Get-DbaBackupInformation" { $CommandUnderTest | Should -HaveParameter AzureCredential -Type String -Not -Mandatory } It "Should have Import parameter" { - $CommandUnderTest | Should -HaveParameter Import -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Import -Type Switch -Not -Mandatory } It "Should have Anonymise parameter" { - $CommandUnderTest | Should -HaveParameter Anonymise -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Anonymise -Type Switch -Not -Mandatory } It "Should have NoClobber parameter" { - $CommandUnderTest | Should -HaveParameter NoClobber -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoClobber -Type Switch -Not -Mandatory } It "Should have PassThru parameter" { - $CommandUnderTest | Should -HaveParameter PassThru -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter PassThru -Type Switch -Not -Mandatory } } Context "Get history for all database" { BeforeAll { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir + $results = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDir } It "Should be 6 backups returned" { $results.count | Should -Be 6 @@ -131,7 +131,7 @@ Describe "Get-DbaBackupInformation" { Context "Get history for one database" { BeforeAll { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir -DatabaseName $dbname2 + $results = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDir -DatabaseName $dbname2 } It "Should be 3 backups returned" { $results.count | Should -Be 3 @@ -149,7 +149,7 @@ Describe "Get-DbaBackupInformation" { Context "Check the export/import of backup history" { BeforeAll { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir -DatabaseName $dbname2 -ExportPath "$DestBackupDir\history.xml" + $results = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDir -DatabaseName $dbname2 -ExportPath "$DestBackupDir\history.xml" } It "Should restore cleanly" { ($results | Where-Object {$_.RestoreComplete -eq $false}).count | Should -Be 0 @@ -158,7 +158,7 @@ Describe "Get-DbaBackupInformation" { Context "Test Maintenance solution options" { BeforeAll { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -MaintenanceSolution + $results = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDirOla -MaintenanceSolution } It "Should be 3 backups returned" { $results.count | Should -Be 3 @@ -172,10 +172,10 @@ Describe "Get-DbaBackupInformation" { It "Should only be backups of $dbname3" { ($results | Where-Object {$_.Database -ne $dbname3 }).count | Should -Be 0 } - + Context "Ignore Log Backup" { BeforeAll { - $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -MaintenanceSolution -IgnoreLogBackup + $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDirOla -MaintenanceSolution -IgnoreLogBackup } It "Should be 2 backups returned" { $ResultsSanLog.count | Should -Be 2 @@ -187,10 +187,10 @@ Describe "Get-DbaBackupInformation" { ($resultsSanLog | Where-Object {$_.Type -eq 'Transaction Log'}).count | Should -Be 0 } } - + Context "Ignore Log Backup without MaintenanceSolution" { BeforeAll { - $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue + $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $global:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue } It "Should Warn if IgnoreLogBackup without MaintenanceSolution" { $warnVar | Should -Match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used" diff --git a/tests/Get-DbaBinaryFileTable.Tests.ps1 b/tests/Get-DbaBinaryFileTable.Tests.ps1 index f001a4a5af..1fdc5b6130 100644 --- a/tests/Get-DbaBinaryFileTable.Tests.ps1 +++ b/tests/Get-DbaBinaryFileTable.Tests.ps1 @@ -6,10 +6,10 @@ Describe "Get-DbaBinaryFileTable" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFilez]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") - $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilez -FilePath $script:appveyorlabrepo\azure\adalsql.msi - $null = Get-ChildItem $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilez + $null = Import-DbaBinaryFile -SqlInstance $global:instance2 -Database tempdb -Table BunchOFilez -FilePath $global:appveyorlabrepo\azure\adalsql.msi + $null = Get-ChildItem $global:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $global:instance2 -Database tempdb -Table BunchOFilez } AfterAll { @@ -43,18 +43,18 @@ Describe "Get-DbaBinaryFileTable" { $CommandUnderTest | Should -HaveParameter InputObject -Type Table[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { It "returns a table" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb + $results = Get-DbaBinaryFileTable -SqlInstance $global:instance2 -Database tempdb $results.Name.Count | Should -BeGreaterOrEqual 1 } It "supports piping" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database tempdb | Get-DbaBinaryFileTable + $results = Get-DbaDbTable -SqlInstance $global:instance2 -Database tempdb | Get-DbaBinaryFileTable $results.Name.Count | Should -BeGreaterOrEqual 1 } } diff --git a/tests/Get-DbaBuild.Tests.ps1 b/tests/Get-DbaBuild.Tests.ps1 index 8907825f96..4019d534db 100644 --- a/tests/Get-DbaBuild.Tests.ps1 +++ b/tests/Get-DbaBuild.Tests.ps1 @@ -36,10 +36,10 @@ Describe "Get-DbaBuild" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have Update parameter" { - $CommandUnderTest | Should -HaveParameter Update -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Update -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -169,7 +169,7 @@ Describe "Get-DbaBuild" { $result.Warning | Should -Be 'This version has been officially retired by Microsoft' } } - + Context "Recognizes version 'aliases', see #8915" { It 'works with versions with the minor being either not 0 or 50' { $result2016 = Get-DbaBuild -Build '13.3.6300' @@ -227,8 +227,8 @@ Describe "Get-DbaBuild" { Describe "Get-DbaBuild Integration Tests" -Tag 'IntegrationTests' { BeforeAll { - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $global:instance1 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 } Context "piping and params" { @@ -243,7 +243,7 @@ Describe "Get-DbaBuild Integration Tests" -Tag 'IntegrationTests' { Context "Test retrieving version from instances" { BeforeAll { - $results = Get-DbaBuild -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaBuild -SqlInstance $global:instance1, $global:instance2 } It "Should return an exact match" { diff --git a/tests/Get-DbaClientProtocol.Tests.ps1 b/tests/Get-DbaClientProtocol.Tests.ps1 index 173d6404c3..694228d37c 100644 --- a/tests/Get-DbaClientProtocol.Tests.ps1 +++ b/tests/Get-DbaClientProtocol.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaClientProtocol" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaCmObject.Tests.ps1 b/tests/Get-DbaCmObject.Tests.ps1 index 6633d5c044..cb1fe01843 100644 --- a/tests/Get-DbaCmObject.Tests.ps1 +++ b/tests/Get-DbaCmObject.Tests.ps1 @@ -29,14 +29,14 @@ Describe "Get-DbaCmObject" { It "Should have DoNotUse as a non-mandatory ManagementConnectionType[] parameter" { $CommandUnderTest | Should -HaveParameter DoNotUse -Type ManagementConnectionType[] -Not -Mandatory } - It "Should have Force as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + It "Should have Force as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } - It "Should have SilentlyContinue as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter SilentlyContinue -Type SwitchParameter -Not -Mandatory + It "Should have SilentlyContinue as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter SilentlyContinue -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaComputerCertificate.Tests.ps1 b/tests/Get-DbaComputerCertificate.Tests.ps1 index 1634fa9275..0b4d8985e6 100644 --- a/tests/Get-DbaComputerCertificate.Tests.ps1 +++ b/tests/Get-DbaComputerCertificate.Tests.ps1 @@ -38,7 +38,7 @@ Describe "Get-DbaComputerCertificate" { Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path $global:appveyorlabrepo\certificates\localhost.crt -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" } AfterAll { diff --git a/tests/Get-DbaComputerSystem.Tests.ps1 b/tests/Get-DbaComputerSystem.Tests.ps1 index 80ae96081a..689bc834b5 100644 --- a/tests/Get-DbaComputerSystem.Tests.ps1 +++ b/tests/Get-DbaComputerSystem.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Get-DbaComputerSystem" { Context "Validate output" -Skip:$env:CI { BeforeAll { - $result = Get-DbaComputerSystem -ComputerName $script:instance1 + $result = Get-DbaComputerSystem -ComputerName $global:instance1 $props = 'ComputerName', 'Domain', 'IsDaylightSavingsTime', 'Manufacturer', 'Model', 'NumberLogicalProcessors', 'NumberProcessors', 'IsHyperThreading', 'SystemFamily', 'SystemSkuNumber', 'SystemType', 'IsSystemManagedPageFile', 'TotalPhysicalMemory' diff --git a/tests/Get-DbaConnectedInstance.Tests.ps1 b/tests/Get-DbaConnectedInstance.Tests.ps1 index 49645b8b30..8543bbea47 100644 --- a/tests/Get-DbaConnectedInstance.Tests.ps1 +++ b/tests/Get-DbaConnectedInstance.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Get-DbaConnectedInstance" { Context "Command usage" { BeforeAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 + $null = Get-DbaDatabase -SqlInstance $global:instance1 } It "returns some results" { diff --git a/tests/Get-DbaConnection.Tests.ps1 b/tests/Get-DbaConnection.Tests.ps1 index 74988ae3e5..9736be7fe0 100644 --- a/tests/Get-DbaConnection.Tests.ps1 +++ b/tests/Get-DbaConnection.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Get-DbaConnection" { Context "Integration Tests" { BeforeAll { - $results = Get-DbaConnection -SqlInstance $script:instance1 + $results = Get-DbaConnection -SqlInstance $global:instance1 } It "Returns the proper authentication scheme" { diff --git a/tests/Get-DbaCpuRingBuffer.Tests.ps1 b/tests/Get-DbaCpuRingBuffer.Tests.ps1 index 7c7defa520..5cb42dc645 100644 --- a/tests/Get-DbaCpuRingBuffer.Tests.ps1 +++ b/tests/Get-DbaCpuRingBuffer.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaCpuRingBuffer" { $CommandUnderTest | Should -HaveParameter CollectionMinutes -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -24,7 +24,7 @@ Describe "Get-DbaCpuRingBuffer" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $results = Get-DbaCpuRingBuffer -SqlInstance $script:instance2 -CollectionMinutes 100 + $results = Get-DbaCpuRingBuffer -SqlInstance $global:instance2 -CollectionMinutes 100 } It "Returns results" { $results.Count | Should -BeGreaterThan 0 diff --git a/tests/Get-DbaCpuUsage.Tests.ps1 b/tests/Get-DbaCpuUsage.Tests.ps1 index 771bd41f1e..905cb511ad 100644 --- a/tests/Get-DbaCpuUsage.Tests.ps1 +++ b/tests/Get-DbaCpuUsage.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Get-DbaCpuUsage" { $CommandUnderTest | Should -HaveParameter Threshold -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets the CPU Usage" { BeforeAll { - $results = Get-DbaCPUUsage -SqlInstance $script:instance2 + $results = Get-DbaCPUUsage -SqlInstance $global:instance2 } It "Results are not empty" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaCredential.Tests.ps1 b/tests/Get-DbaCredential.Tests.ps1 index fc87d20ebb..0ded58a46c 100644 --- a/tests/Get-DbaCredential.Tests.ps1 +++ b/tests/Get-DbaCredential.Tests.ps1 @@ -13,21 +13,21 @@ Describe "Get-DbaCredential" { # Add user foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $global:instance2 } - $results = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password - $results = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma -Password $password + $results = New-DbaCredential -SqlInstance $global:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password + $results = New-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_thorsmomma -Password $password } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $global:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $global:instance2 } } @@ -54,23 +54,23 @@ Describe "Get-DbaCredential" { $CommandUnderTest | Should -HaveParameter ExcludeIdentity -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Get credentials" { It "Should get just one credential with the proper properties when using Identity" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_thorsmomma $results.Name | Should -Be "dbatoolsci_thorsmomma" $results.Identity | Should -Be "dbatoolsci_thorsmomma" } It "Should get just one credential with the proper properties when using Name" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $global:instance2 -Name dbatoolsci_thorsmomma $results.Name | Should -Be "dbatoolsci_thorsmomma" $results.Identity | Should -Be "dbatoolsci_thorsmomma" } It "gets more than one credential" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $global:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma $results.count | Should -BeGreaterThan 1 } } diff --git a/tests/Get-DbaCustomError.Tests.ps1 b/tests/Get-DbaCustomError.Tests.ps1 index 06ac22a520..b2ecef7270 100644 --- a/tests/Get-DbaCustomError.Tests.ps1 +++ b/tests/Get-DbaCustomError.Tests.ps1 @@ -18,18 +18,18 @@ Describe "Get-DbaCustomError" { Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $sql = "EXEC msdb.dbo.sp_addmessage 54321, 9, N'Dbatools is Awesome!';" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $sql = "EXEC msdb.dbo.sp_dropmessage 54321;" $server.Query($sql) } It "Gets the custom errors" { - $results = Get-DbaCustomError -SqlInstance $script:instance1 + $results = Get-DbaCustomError -SqlInstance $global:instance1 $results | Should -Not -BeNullOrEmpty $results.Text | Should -Be "Dbatools is Awesome!" $results.LanguageID | Should -Be 1033 diff --git a/tests/Get-DbaDBFileGroup.Tests.ps1 b/tests/Get-DbaDBFileGroup.Tests.ps1 index 12990a915e..8485742404 100644 --- a/tests/Get-DbaDBFileGroup.Tests.ps1 +++ b/tests/Get-DbaDBFileGroup.Tests.ps1 @@ -8,14 +8,14 @@ Describe "Get-DbaDbFileGroup" { $random = Get-Random $multifgdb = "dbatoolsci_multifgdb$random" - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $multifgdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $multifgdb - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("CREATE DATABASE $multifgdb; ALTER DATABASE $multifgdb ADD FILEGROUP [Test1]; ALTER DATABASE $multifgdb ADD FILEGROUP [Test2];") } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $multifgdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $multifgdb } Context "Validate parameters" { @@ -38,13 +38,13 @@ Describe "Get-DbaDbFileGroup" { $CommandUnderTest | Should -HaveParameter FileGroup -Type String[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Returns values for Instance" { BeforeAll { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 + $results = Get-DbaDbFileGroup -SqlInstance $global:instance2 } It "Results are not empty" { $results | Should -Not -BeNullOrEmpty @@ -56,19 +56,19 @@ Describe "Get-DbaDbFileGroup" { Context "Accepts database and filegroup input" { It "Reports the right number of filegroups" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $multifgdb + $results = Get-DbaDbFileGroup -SqlInstance $global:instance2 -Database $multifgdb $results.Count | Should -Be 3 } It "Reports the right number of filegroups when filtering" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $multifgdb -FileGroup Test1 + $results = Get-DbaDbFileGroup -SqlInstance $global:instance2 -Database $multifgdb -FileGroup Test1 $results.Count | Should -Be 1 } } Context "Accepts piped input" { BeforeAll { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeUser | Get-DbaDbFileGroup + $results = Get-DbaDatabase -SqlInstance $global:instance2 -ExcludeUser | Get-DbaDbFileGroup } It "Reports the right number of filegroups" { $results.Count | Should -Be 4 diff --git a/tests/Get-DbaDatabase.Tests.ps1 b/tests/Get-DbaDatabase.Tests.ps1 index 31c1964647..7649158266 100644 --- a/tests/Get-DbaDatabase.Tests.ps1 +++ b/tests/Get-DbaDatabase.Tests.ps1 @@ -63,7 +63,7 @@ Describe "Get-DbaDatabase" { Context "Count system databases on localhost" { BeforeAll { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -ExcludeUser + $results = Get-DbaDatabase -SqlInstance $global:instance1 -ExcludeUser } It "reports the right number of databases" { $results.Count | Should -Be 4 @@ -72,7 +72,7 @@ Describe "Get-DbaDatabase" { Context "Check that tempdb database is in Simple recovery mode" { BeforeAll { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb } It "tempdb's recovery mode is Simple" { $results.RecoveryModel | Should -Be "Simple" @@ -81,7 +81,7 @@ Describe "Get-DbaDatabase" { Context "Check that master database is accessible" { BeforeAll { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database master } It "master is accessible" { $results.IsAccessible | Should -Be $true @@ -93,19 +93,19 @@ Describe "Get-DbaDatabase" { $random = Get-Random $dbname1 = "dbatoolsci_Backup_$random" $dbname2 = "dbatoolsci_NoBackup_$random" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname1, $dbname2 - $null = Backup-DbaDatabase -SqlInstance $script:instance1 -Type Full -FilePath nul -Database $dbname1 + $null = New-DbaDatabase -SqlInstance $global:instance1 -Name $dbname1, $dbname2 + $null = Backup-DbaDatabase -SqlInstance $global:instance1 -Type Full -FilePath nul -Database $dbname1 } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false } It "Should not report as database has full backup" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname1 -NoFullBackup + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname1 -NoFullBackup $results.Count | Should -Be 0 } It "Should report 1 database with no full backup" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 -NoFullBackup + $results = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname2 -NoFullBackup $results.Count | Should -Be 1 } } diff --git a/tests/Get-DbaDbAssembly.Tests.ps1 b/tests/Get-DbaDbAssembly.Tests.ps1 index 4949457eb3..0a02e493c7 100644 --- a/tests/Get-DbaDbAssembly.Tests.ps1 +++ b/tests/Get-DbaDbAssembly.Tests.ps1 @@ -18,15 +18,15 @@ Describe "Get-DbaDbAssembly" { $CommandUnderTest | Should -HaveParameter Name -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets the Db Assembly" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $results = Get-DbaDbAssembly -SqlInstance $script:instance2 | Where-Object { $_.parent.name -eq 'master' } - $masterDb = Get-DbaDatabase -SqlInstance $script:instance2 -Database master + $results = Get-DbaDbAssembly -SqlInstance $global:instance2 | Where-Object { $_.parent.name -eq 'master' } + $masterDb = Get-DbaDatabase -SqlInstance $global:instance2 -Database master } It "Gets results" { diff --git a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 index a252be6133..113c942587 100644 --- a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaDbAsymmetricKey" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -36,15 +36,15 @@ Describe "Get-DbaDbAsymmetricKey" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'GetAsKey' - $newDB = New-DbaDatabase -SqlInstance $script:instance2 -Name $database + $newDB = New-DbaDatabase -SqlInstance $global:instance2 -Name $database $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false - New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + New-DbaDbMasterKey -SqlInstance $global:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false + New-DbaDbUser -SqlInstance $global:instance2 -Database $database -UserName $dbuser + $null = New-DbaDbAsymmetricKey -SqlInstance $global:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar } It "Should Create new key in $database called $keyname" { - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $results = Get-DbaDbAsymmetricKey -SqlInstance $global:instance2 -Name $keyname -Database $database $warnvar | Should -BeNullOrEmpty $results.database | Should -Be $database $results.DatabaseId | Should -Be $newDB.ID @@ -54,7 +54,7 @@ Describe "Get-DbaDbAsymmetricKey" { } It "Should work with a piped database" { - $pipeResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey + $pipeResults = Get-DbaDatabase -SqlInstance $global:instance2 -Database $database | Get-DbaDbAsymmetricKey $pipeResults.database | Should -Be $database $pipeResults.name | Should -Be $keyname $pipeResults.Owner | Should -Be $dbuser @@ -62,15 +62,15 @@ Describe "Get-DbaDbAsymmetricKey" { } It "Should return 2 keys" { - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar - $multiResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey + $null = New-DbaDbAsymmetricKey -SqlInstance $global:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $multiResults = Get-DbaDatabase -SqlInstance $global:instance2 -Database $database | Get-DbaDbAsymmetricKey $multiResults | Should -HaveCount 2 $multiResults.name | Should -Contain $keyname $multiResults.name | Should -Contain $keyname2 } AfterAll { - $drop = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + $drop = Remove-DbaDatabase -SqlInstance $global:instance2 -Database $database -Confirm:$false $drop.Status | Should -Be 'Dropped' } } diff --git a/tests/Get-DbaDbBackupHistory.Tests.ps1 b/tests/Get-DbaDbBackupHistory.Tests.ps1 index 84cddee8bb..7a9f641d39 100644 --- a/tests/Get-DbaDbBackupHistory.Tests.ps1 +++ b/tests/Get-DbaDbBackupHistory.Tests.ps1 @@ -80,26 +80,26 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { $random = Get-Random $dbname = "dbatoolsci_history_$random" $dbnameForked = "dbatoolsci_history_forked_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $global:instance1 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname + $server = Connect-DbaInstance -SqlInstance $global:instance1 $server.Databases['master'].ExecuteNonQuery("CREATE DATABASE $dbnameForked; ALTER DATABASE $dbnameForked SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database master | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir -BackupFileName CopyOnly.bak -CopyOnly } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false } Context "Get last history for single database" { BeforeAll { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Last + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname -Last } It "Should be 4 backups returned" { @@ -122,7 +122,7 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Get last history for all databases" { BeforeAll { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 } It "Should be more than one database" { @@ -132,22 +132,22 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "ExcludeDatabase is honored" { It "Should not report about excluded database master" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -ExcludeDatabase 'master' ($results | Where-Object Database -match "master").Count | Should -Be 0 } It "Should not report about excluded database master with -Type Full" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' -Type Full + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -ExcludeDatabase 'master' -Type Full ($results | Where-Object Database -match "master").Count | Should -Be 0 } It "Should not report about excluded database master with -LastFull" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' -LastFull + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -ExcludeDatabase 'master' -LastFull ($results | Where-Object Database -match "master").Count | Should -Be 0 } } Context "LastFull should work with multiple databases" { BeforeAll { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname, master -lastfull + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname, master -lastfull } It "Should return 2 records" { @@ -157,8 +157,8 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Testing IncludeCopyOnly with LastFull" { BeforeAll { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -LastFull -Database $dbname - $resultsCo = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -LastFull -IncludeCopyOnly -Database $dbname + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -LastFull -Database $dbname + $resultsCo = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -LastFull -IncludeCopyOnly -Database $dbname } It "Should return the CopyOnly Backup" { @@ -168,7 +168,7 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Testing IncludeCopyOnly with Last" { BeforeAll { - $resultsCo = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Last -IncludeCopyOnly -Database $dbname + $resultsCo = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Last -IncludeCopyOnly -Database $dbname } It "Should return just the CopyOnly Full Backup" { @@ -179,7 +179,7 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Testing TotalSize regression test for #3517" { It "supports large numbers" { $historyObject = New-Object Dataplat.Dbatools.Database.BackupHistory - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $global:instance1 $cast = $server.Query('select cast(1000000000000000 as numeric(20,0)) AS TotalSize') $historyObject.TotalSize = $cast.TotalSize ($historyObject.TotalSize.Byte) | Should -Be 1000000000000000 @@ -225,8 +225,8 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Testing IgnoreDiff parameter for #6914" { BeforeAll { - $noIgnore = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname - $Ignore = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -IgnoreDiffBackup + $noIgnore = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname + $Ignore = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname -IgnoreDiffBackup } It "Should return one less backup" { @@ -239,17 +239,17 @@ Describe "Get-DbaDbBackupHistory Integration Tests" -Tag "IntegrationTests" { Context "Testing the Since parameter" { It "DateTime for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since (Get-Date).AddMinutes(-5) + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname -Since (Get-Date).AddMinutes(-5) $results.count | Should -BeGreaterThan 0 } It "TimeSpan for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since (New-TimeSpan -Minutes -5) + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname -Since (New-TimeSpan -Minutes -5) $results.count | Should -BeGreaterThan 0 } It "Invalid type for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null + $results = Get-DbaDbBackupHistory -SqlInstance $global:instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null $results | Should -BeNullOrEmpty $warning | Should -BeLike "*-Since must be either a DateTime or TimeSpan object*" } diff --git a/tests/Get-DbaDbCertificate.Tests.ps1 b/tests/Get-DbaDbCertificate.Tests.ps1 index 2c18228d43..78a7b52e97 100644 --- a/tests/Get-DbaDbCertificate.Tests.ps1 +++ b/tests/Get-DbaDbCertificate.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -35,15 +35,15 @@ Describe "Get-DbaDbCertificate" { BeforeAll { . "$PSScriptRoot\constants.ps1" - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $global:instance1 -Database master)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $global:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } - $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $global:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $certificateName1 = "Cert_$(Get-Random)" $certificateName2 = "Cert_$(Get-Random)" - $cert1 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName1 -Confirm:$false - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName2 -Database "tempdb" -Confirm:$false + $cert1 = New-DbaDbCertificate -SqlInstance $global:instance1 -Name $certificateName1 -Confirm:$false + $cert2 = New-DbaDbCertificate -SqlInstance $global:instance1 -Name $certificateName2 -Database "tempdb" -Confirm:$false } AfterAll { @@ -54,19 +54,19 @@ Describe "Get-DbaDbCertificate" { } It "returns database certificate created in default, master database" { - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $certificateName1 + $cert = Get-DbaDbCertificate -SqlInstance $global:instance1 -Certificate $certificateName1 $cert.Database | Should -Match 'master' - $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id + $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database master).Id } It "returns database certificate created in tempdb database, looked up by certificate name" { - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb + $cert = Get-DbaDbCertificate -SqlInstance $global:instance1 -Database tempdb $cert.Name | Should -Match $certificateName2 - $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb).Id + $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb).Id } It "returns database certificates excluding those in the master database" { - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -ExcludeDatabase master + $cert = Get-DbaDbCertificate -SqlInstance $global:instance1 -ExcludeDatabase master $cert.Database | Should -Not -Match 'master' } } diff --git a/tests/Get-DbaDbCheckConstraint.Tests.ps1 b/tests/Get-DbaDbCheckConstraint.Tests.ps1 index e98b62f15a..3ab542e1ca 100644 --- a/tests/Get-DbaDbCheckConstraint.Tests.ps1 +++ b/tests/Get-DbaDbCheckConstraint.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Get-DbaDbCheckConstraint Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have ExcludeSystemTable as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -32,7 +32,7 @@ Describe "Get-DbaDbCheckConstraint Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -45,25 +45,25 @@ Describe "Get-DbaDbCheckConstraint Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command actually works" { It "returns no check constraints from excluded DB with -ExcludeDatabase" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbCheckConstraint -SqlInstance $global:instance2 -ExcludeDatabase master $results.where( { $_.Database -eq 'master' }).count | Should -Be 0 } It "returns only check constraints from selected DB with -Database" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbCheckConstraint -SqlInstance $global:instance2 -Database $dbname $results.where( { $_.Database -ne 'master' }).count | Should -Be 1 - $results.DatabaseId | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname).Id + $results.DatabaseId | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname).Id } It "Should include test check constraint: $ckName" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemTable + $results = Get-DbaDbCheckConstraint -SqlInstance $global:instance2 -Database $dbname -ExcludeSystemTable ($results | Where-Object Name -eq $ckName).Name | Should -Be $ckName } It "Should exclude system tables" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database master -ExcludeSystemTable + $results = Get-DbaDbCheckConstraint -SqlInstance $global:instance2 -Database master -ExcludeSystemTable ($results | Where-Object Name -eq 'spt_fallback_db') | Should -BeNullOrEmpty } } diff --git a/tests/Get-DbaDbCompatibility.Tests.ps1 b/tests/Get-DbaDbCompatibility.Tests.ps1 index 948f1e18da..e42bf5fe9c 100644 --- a/tests/Get-DbaDbCompatibility.Tests.ps1 +++ b/tests/Get-DbaDbCompatibility.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaDbCompatibility" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -27,13 +27,13 @@ Describe "Get-DbaDbCompatibility" { . "$PSScriptRoot\constants.ps1" } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $compatibilityLevel = $server.Databases['master'].CompatibilityLevel } Context "Gets compatibility for multiple databases" { BeforeAll { - $results = Get-DbaDbCompatibility -SqlInstance $script:instance1 + $results = Get-DbaDbCompatibility -SqlInstance $global:instance1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -43,20 +43,20 @@ Describe "Get-DbaDbCompatibility" { if ($_.DatabaseId -le 4) { $_.Compatibility | Should -Be $compatibilityLevel } - $_.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $_.Database).Id + $_.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database $_.Database).Id } } Context "Gets compatibility for one database" { BeforeAll { - $results = Get-DbaDbCompatibility -SqlInstance $script:instance1 -Database master + $results = Get-DbaDbCompatibility -SqlInstance $global:instance1 -Database master } It "Gets results" { $results | Should -Not -BeNullOrEmpty } It "Should return correct compatibility level for master" { $results.Compatibility | Should -Be $compatibilityLevel - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database master).Id } } } diff --git a/tests/Get-DbaDbCompression.Tests.ps1 b/tests/Get-DbaDbCompression.Tests.ps1 index a53f5a54fa..891bcd1591 100644 --- a/tests/Get-DbaDbCompression.Tests.ps1 +++ b/tests/Get-DbaDbCompression.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaDbCompression" { $CommandUnderTest | Should -HaveParameter Table -Type String[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -29,7 +29,7 @@ Describe "Get-DbaDbCompression" { BeforeAll { . "$PSScriptRoot\constants.ps1" $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("select * into syscols from sys.all_columns select * into sysallparams from sys.all_parameters @@ -37,13 +37,13 @@ Describe "Get-DbaDbCompression" { create nonclustered index NC_syscols on syscols (precision) include (collation_name)", $dbname) } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $global:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false } Context "Command handles heaps and clustered indexes" { BeforeAll { - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbCompression -SqlInstance $global:instance2 -Database $dbname } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -61,7 +61,7 @@ Describe "Get-DbaDbCompression" { Context "Command handles nonclustered indexes" { BeforeAll { - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbCompression -SqlInstance $global:instance2 -Database $dbname } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -76,7 +76,7 @@ Describe "Get-DbaDbCompression" { Context "Command excludes results for specified database" { It "Shouldn't get any results for $dbname" { - $result = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname + $result = Get-DbaDbCompression -SqlInstance $global:instance2 -Database $dbname -ExcludeDatabase $dbname $result | Should -Not -Contain $dbname } } diff --git a/tests/Get-DbaDbDbccOpenTran.Tests.ps1 b/tests/Get-DbaDbDbccOpenTran.Tests.ps1 index 63d38ffe8b..c486ddf20a 100644 --- a/tests/Get-DbaDbDbccOpenTran.Tests.ps1 +++ b/tests/Get-DbaDbDbccOpenTran.Tests.ps1 @@ -19,14 +19,14 @@ Describe "Get-DbaDbDbccOpenTran" { $CommandUnderTest | Should -HaveParameter Database -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets results for Open Transactions" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Cmd', 'Output', 'Field', 'Data' - $result = Get-DbaDbDbccOpenTran -SqlInstance $script:instance1 + $result = Get-DbaDbDbccOpenTran -SqlInstance $global:instance1 } It "returns results for DBCC OPENTRAN" { @@ -44,8 +44,8 @@ Describe "Get-DbaDbDbccOpenTran" { } It "returns results for a specific database" { - $tempDB = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempDB - $result = Get-DbaDbDbccOpenTran -SqlInstance $script:instance1 -Database tempDB + $tempDB = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempDB + $result = Get-DbaDbDbccOpenTran -SqlInstance $global:instance1 -Database tempDB $result | Should -Not -BeNullOrEmpty $result.Database | Get-Unique | Should -Be 'tempDB' diff --git a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 index 0e5c0a9701..b363508bdd 100644 --- a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 +++ b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaDbDetachedFileInfo" { $CommandUnderTest | Should -HaveParameter Path -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -25,44 +25,44 @@ Describe "Get-DbaDbDetachedFileInfo" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $versionName = $server.GetSqlServerVersionName() $random = Get-Random $dbname = "dbatoolsci_detatch_$random" $server.Query("CREATE DATABASE $dbname") - $path = (Get-DbaDbFile -SqlInstance $script:instance2 -Database $dbname | Where-Object {$_.PhysicalName -like '*.mdf'}).physicalname - Detach-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Force + $path = (Get-DbaDbFile -SqlInstance $global:instance2 -Database $dbname | Where-Object {$_.PhysicalName -like '*.mdf'}).physicalname + Detach-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Force } AfterAll { $server.Query("CREATE DATABASE $dbname ON (FILENAME = '$path') FOR ATTACH") - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false } It "Gets Results" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $global:instance2 -Path $path $results | Should -Not -BeNullOrEmpty } It "Should be created database" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $global:instance2 -Path $path $results.name | Should -Be $dbname } It "Should be the correct version" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $global:instance2 -Path $path $results.version | Should -Be $versionName } It "Should have Data files" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $global:instance2 -Path $path $results.DataFiles | Should -Not -BeNullOrEmpty } It "Should have Log files" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $global:instance2 -Path $path $results.LogFiles | Should -Not -BeNullOrEmpty } } diff --git a/tests/Get-DbaDbEncryption.Tests.ps1 b/tests/Get-DbaDbEncryption.Tests.ps1 index e8fa4ebd7e..a264064df7 100644 --- a/tests/Get-DbaDbEncryption.Tests.ps1 +++ b/tests/Get-DbaDbEncryption.Tests.ps1 @@ -31,15 +31,15 @@ Describe "Get-DbaDbEncryption" { $random = Get-Random $cert = "dbatoolsci_getcert$random" $password = ConvertTo-SecureString -String (Get-Random) -AsPlainText -Force - New-DbaDbCertificate -SqlInstance $script:instance1 -Name $cert -Password $password + New-DbaDbCertificate -SqlInstance $global:instance1 -Name $cert -Password $password } AfterAll { - Get-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert | Remove-DbaDbCertificate -Confirm:$false + Get-DbaDbCertificate -SqlInstance $global:instance1 -Certificate $cert | Remove-DbaDbCertificate -Confirm:$false } It "Should find a certificate named $cert" { - $results = Get-DbaDbEncryption -SqlInstance $script:instance1 + $results = Get-DbaDbEncryption -SqlInstance $global:instance1 ($results.Name -match 'dbatoolsci').Count | Should -BeGreaterThan 0 } } diff --git a/tests/Get-DbaDbEncryptionKey.Tests.ps1 b/tests/Get-DbaDbEncryptionKey.Tests.ps1 index d52bb74253..f97a018cb1 100644 --- a/tests/Get-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/Get-DbaDbEncryptionKey.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaDbEncryptionKey" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -29,18 +29,18 @@ Describe "Get-DbaDbEncryptionKey" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $global:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $global:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $global:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $global:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $global:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -64,7 +64,7 @@ Describe "Get-DbaDbEncryptionKey" { } It "should get an encryption key on a database" { - $results = Get-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name + $results = Get-DbaDbEncryptionKey -SqlInstance $global:instance2 -Database $db.Name $results.EncryptionType | Should -Be "ServerCertificate" } } diff --git a/tests/Get-DbaDbExtentDiff.Tests.ps1 b/tests/Get-DbaDbExtentDiff.Tests.ps1 index 6d649ff11b..44da988f48 100644 --- a/tests/Get-DbaDbExtentDiff.Tests.ps1 +++ b/tests/Get-DbaDbExtentDiff.Tests.ps1 @@ -7,12 +7,12 @@ Describe "Get-DbaDbExtentDiff" { . "$PSScriptRoot\constants.ps1" $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("Create Database [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false } Context "Validate parameters" { @@ -32,13 +32,13 @@ Describe "Get-DbaDbExtentDiff" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets Changed Extents for Multiple Databases" { BeforeAll { - $results = Get-DbaDbExtentDiff -SqlInstance $script:instance2 + $results = Get-DbaDbExtentDiff -SqlInstance $global:instance2 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -53,7 +53,7 @@ Describe "Get-DbaDbExtentDiff" { Context "Gets Changed Extents for Single Database" { BeforeAll { - $results = Get-DbaDbExtentDiff -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbExtentDiff -SqlInstance $global:instance2 -Database $dbname } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDbFeatureUsage.Tests.ps1 b/tests/Get-DbaDbFeatureUsage.Tests.ps1 index e6ac8641da..ebe2532df1 100644 --- a/tests/Get-DbaDbFeatureUsage.Tests.ps1 +++ b/tests/Get-DbaDbFeatureUsage.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaDbFeatureUsage" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -33,7 +33,7 @@ Describe "Get-DbaDbFeatureUsage" { BeforeAll { $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("Create Database [$dbname]") $server.Query("Create Table [$dbname].dbo.TestCompression (Column1 nvarchar(10), @@ -47,18 +47,18 @@ Describe "Get-DbaDbFeatureUsage" { } It "Gets Feature Usage" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 + $results = Get-DbaDbFeatureUsage -SqlInstance $global:instance2 $results | Should -Not -BeNullOrEmpty } It "Gets Feature Usage using -Database" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbFeatureUsage -SqlInstance $global:instance2 -Database $dbname $results | Should -Not -BeNullOrEmpty $results.Feature | Should -Be "Compression" } It "Gets Feature Usage using -ExcludeDatabase" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $results = Get-DbaDbFeatureUsage -SqlInstance $global:instance2 -ExcludeDatabase $dbname $results.database | Should -Not -Contain $dbname } } diff --git a/tests/Get-DbaDbFile.Tests.ps1 b/tests/Get-DbaDbFile.Tests.ps1 index 2876a17909..c291ff9224 100644 --- a/tests/Get-DbaDbFile.Tests.ps1 +++ b/tests/Get-DbaDbFile.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Get-DbaDbFile" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -45,7 +45,7 @@ Describe "Get-DbaDbFile" { Context "Should return file information" { BeforeAll { - $results = Get-DbaDbFile -SqlInstance $script:instance1 + $results = Get-DbaDbFile -SqlInstance $global:instance1 } It "returns information about tempdb files" { $results.Database -contains "tempdb" | Should -Be $true @@ -54,7 +54,7 @@ Describe "Get-DbaDbFile" { Context "Should return file information for only tempdb" { BeforeAll { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDbFile -SqlInstance $global:instance1 -Database tempdb } It "returns only tempdb files" { $results | ForEach-Object { @@ -65,7 +65,7 @@ Describe "Get-DbaDbFile" { Context "Should return file information for only tempdb primary filegroup" { BeforeAll { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database tempdb -FileGroup Primary + $results = Get-DbaDbFile -SqlInstance $global:instance1 -Database tempdb -FileGroup Primary } It "returns only tempdb files that are in Primary filegroup" { $results | ForEach-Object { @@ -77,7 +77,7 @@ Describe "Get-DbaDbFile" { Context "Physical name is populated" { BeforeAll { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database master + $results = Get-DbaDbFile -SqlInstance $global:instance1 -Database master } It "master returns proper results" { $result = $results | Where-Object LogicalName -eq 'master' @@ -89,11 +89,11 @@ Describe "Get-DbaDbFile" { Context "Database ID is populated" { It "returns proper results for the master db" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database master - $results.DatabaseID | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).ID + $results = Get-DbaDbFile -SqlInstance $global:instance1 -Database master + $results.DatabaseID | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $global:instance1 -Database master).ID } It "uses a pipeline input and returns proper results for the tempdb" { - $tempDB = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $tempDB = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb $results = $tempDB | Get-DbaDbFile $results.DatabaseID | Get-Unique | Should -Be $tempDB.ID } diff --git a/tests/Get-DbaDbFileGrowth.Tests.ps1 b/tests/Get-DbaDbFileGrowth.Tests.ps1 index 457ce85cc9..8bd1dca799 100644 --- a/tests/Get-DbaDbFileGrowth.Tests.ps1 +++ b/tests/Get-DbaDbFileGrowth.Tests.ps1 @@ -64,12 +64,12 @@ Describe "Get-DbaDbFileGrowth" { Context "Command usage" { It "Should return file information" { - $result = Get-DbaDbFileGrowth -SqlInstance $script:instance2 + $result = Get-DbaDbFileGrowth -SqlInstance $global:instance2 $result.Database | Should -Contain "msdb" } It "Should return file information for only msdb" { - $result = Get-DbaDbFileGrowth -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 + $result = Get-DbaDbFileGrowth -SqlInstance $global:instance2 -Database msdb | Select-Object -First 1 $result.Database | Should -Be "msdb" } } diff --git a/tests/Get-DbaDbFileMapping.Tests.ps1 b/tests/Get-DbaDbFileMapping.Tests.ps1 index 29d7352a90..217729a839 100644 --- a/tests/Get-DbaDbFileMapping.Tests.ps1 +++ b/tests/Get-DbaDbFileMapping.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Get-DbaDbFileMapping" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -66,17 +66,17 @@ Describe "Get-DbaDbFileMapping" { Context "Command usage" -Tag "IntegrationTests" { BeforeAll { - $script:instance1 = $script:instance1 # Assuming this is defined in constants.ps1 + $global:instance1 = $global:instance1 # Assuming this is defined in constants.ps1 } It "Should return file information for multiple databases" { - $results = Get-DbaDbFileMapping -SqlInstance $script:instance1 + $results = Get-DbaDbFileMapping -SqlInstance $global:instance1 $results.Database | Should -Contain "tempdb" $results.Database | Should -Contain "master" } It "Should return file information for a single database" { - $results = Get-DbaDbFileMapping -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDbFileMapping -SqlInstance $global:instance1 -Database tempdb $results.Database | Should -Contain "tempdb" $results.Database | Should -Not -Contain "master" } diff --git a/tests/Get-DbaDbForeignKey.Tests.ps1 b/tests/Get-DbaDbForeignKey.Tests.ps1 index 4ed2889df4..8fa914a3ab 100644 --- a/tests/Get-DbaDbForeignKey.Tests.ps1 +++ b/tests/Get-DbaDbForeignKey.Tests.ps1 @@ -23,17 +23,17 @@ Describe "Get-DbaDbForeignKey Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have ExcludeSystemTable parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } Describe "Get-DbaDbForeignKey Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -46,31 +46,31 @@ Describe "Get-DbaDbForeignKey Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command actually works" { It "returns no foreign keys from excluded DB with -ExcludeDatabase" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbForeignKey -SqlInstance $global:instance2 -ExcludeDatabase master $results.where( { $_.Database -eq 'master' }).count | Should -Be 0 } It "returns only foreign keys from selected DB with -Database" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbForeignKey -SqlInstance $global:instance2 -Database $dbname $results.where( { $_.Database -ne 'master' }).count | Should -Be 1 } It "Should include test foreign keys: $fkName" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemTable + $results = Get-DbaDbForeignKey -SqlInstance $global:instance2 -Database $dbname -ExcludeSystemTable ($results | Where-Object Name -eq $fkName).Name | Should -Be $fkName } It "Should exclude system tables" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database master -ExcludeSystemTable + $results = Get-DbaDbForeignKey -SqlInstance $global:instance2 -Database master -ExcludeSystemTable ($results | Where-Object Name -eq 'spt_fallback_db') | Should -BeNullOrEmpty } } Context "Parameters are returned correctly" { BeforeAll { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbForeignKey -SqlInstance $global:instance2 -ExcludeDatabase master } It "Has the correct default properties" { $expectedStdProps = 'ComputerName,CreateDate,Database,DateLastModified,ID,InstanceName,IsChecked,IsEnabled,Name,NotForReplication,ReferencedKey,ReferencedTable,ReferencedTableSchema,SqlInstance,Table'.split(',') diff --git a/tests/Get-DbaDbIdentity.Tests.ps1 b/tests/Get-DbaDbIdentity.Tests.ps1 index f584bcf272..c365573f9f 100644 --- a/tests/Get-DbaDbIdentity.Tests.ps1 +++ b/tests/Get-DbaDbIdentity.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Get-DbaDbIdentity" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (Id int NOT NULL IDENTITY (125, 1), Value varchar(5)); INSERT INTO dbo.dbatoolsci_example(Value) Select 1; CREATE TABLE dbo.dbatoolsci_example2 (Id int NOT NULL IDENTITY (5, 1), Value varchar(5)); @@ -39,14 +39,14 @@ Describe "Get-DbaDbIdentity" { $CommandUnderTest | Should -HaveParameter Table -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Validate standard output" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Table', 'Cmd', 'IdentityValue', 'ColumnValue', 'Output' - $result = Get-DbaDbIdentity -SqlInstance $script:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example2' + $result = Get-DbaDbIdentity -SqlInstance $global:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example2' } It "Should return property: <_>" -ForEach $props { diff --git a/tests/Get-DbaDbLogShipError.Tests.ps1 b/tests/Get-DbaDbLogShipError.Tests.ps1 index da10645594..ba6d7965bb 100644 --- a/tests/Get-DbaDbLogShipError.Tests.ps1 +++ b/tests/Get-DbaDbLogShipError.Tests.ps1 @@ -31,13 +31,13 @@ Describe "Get-DbaDbLogShipError Unit Tests" -Tag 'UnitTests' { $CommandName | Should -HaveParameter DateTimeTo -Type DateTime -Not -Mandatory } It "Should have Primary as a parameter" { - $CommandName | Should -HaveParameter Primary -Type SwitchParameter -Not -Mandatory + $CommandName | Should -HaveParameter Primary -Type Switch -Not -Mandatory } It "Should have Secondary as a parameter" { - $CommandName | Should -HaveParameter Secondary -Type SwitchParameter -Not -Mandatory + $CommandName | Should -HaveParameter Secondary -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandName | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandName | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -50,7 +50,7 @@ Describe "Get-DbaDbLogShipError Integration Tests" -Tag "IntegrationTests" { Context "Return values" { It "Get the log shipping errors" { - $Results = Get-DbaDbLogShipError -SqlInstance $script:instance2 + $Results = Get-DbaDbLogShipError -SqlInstance $global:instance2 $Results.Count | Should -Be 0 } } diff --git a/tests/Get-DbaDbLogSpace.Tests.ps1 b/tests/Get-DbaDbLogSpace.Tests.ps1 index f7793af652..df50380603 100644 --- a/tests/Get-DbaDbLogSpace.Tests.ps1 +++ b/tests/Get-DbaDbLogSpace.Tests.ps1 @@ -31,11 +31,11 @@ Describe "Get-DbaDbLogSpace" { $dbCreate = ("CREATE DATABASE [{0}] GO ALTER DATABASE [{0}] MODIFY FILE ( NAME = N'{0}_log', SIZE = 10MB )" -f $db1) - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $dbCreate - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -Database $db1 + $null = Invoke-DbaQuery -SqlInstance $global:instance2 -Database master -Query $dbCreate + $results = Get-DbaDbLogSpace -SqlInstance $global:instance2 -Database $db1 } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $db1 } It "Should have correct properties" { @@ -50,7 +50,7 @@ Describe "Get-DbaDbLogSpace" { ($results | Where-Object { $_.Database -eq $db1 }).LogSize.Kilobyte | Should -Be 10232 } - It "Calculation for space used should work for servers < 2012" -Skip:((Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential).versionMajor -ge 11) { + It "Calculation for space used should work for servers < 2012" -Skip:((Connect-DbaInstance -SqlInstance $global:instance2 -SqlCredential $SqlCredential).versionMajor -ge 11) { $db1Result = $results | Where-Object { $_.Database -eq $db1 } $db1Result.logspaceused | Should -Be ($db1Result.logsize * ($db1Result.LogSpaceUsedPercent / 100)) } @@ -58,7 +58,7 @@ Describe "Get-DbaDbLogSpace" { Context "System databases exclusions work" { BeforeAll { - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -ExcludeSystemDatabase + $results = Get-DbaDbLogSpace -SqlInstance $global:instance2 -ExcludeSystemDatabase } It "Should exclude system databases" { $results.Database | Should -Not -BeIn @('model', 'master', 'tempdb', 'msdb') @@ -70,7 +70,7 @@ Describe "Get-DbaDbLogSpace" { Context "User databases exclusions work" { BeforeAll { - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -ExcludeDatabase $db1 + $results = Get-DbaDbLogSpace -SqlInstance $global:instance2 -ExcludeDatabase $db1 } It "Should include system databases" { @('model', 'master', 'tempdb', 'msdb') | Should -BeIn $results.Database @@ -82,7 +82,7 @@ Describe "Get-DbaDbLogSpace" { Context "Piping servers works" { BeforeAll { - $results = $script:instance2 | Get-DbaDbLogSpace + $results = $global:instance2 | Get-DbaDbLogSpace } It "Should have database name of $db1" { $results.Database | Should -Contain $db1 diff --git a/tests/Get-DbaDbMail.Tests.ps1 b/tests/Get-DbaDbMail.Tests.ps1 index 5cdd2b71a9..acadfb1668 100644 --- a/tests/Get-DbaDbMail.Tests.ps1 +++ b/tests/Get-DbaDbMail.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Get-DbaDbMail" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailSettings = @{ AccountRetryAttempts = '1' AccountRetryDelay = '60' @@ -39,7 +39,7 @@ Describe "Get-DbaDbMail" { Context "Gets DbMail Settings" { BeforeAll { - $results = Get-DbaDbMail -SqlInstance $script:instance2 + $results = Get-DbaDbMail -SqlInstance $global:instance2 } It "Gets results" { diff --git a/tests/Get-DbaDbMailAccount.Tests.ps1 b/tests/Get-DbaDbMailAccount.Tests.ps1 index 53e3a21225..aaac3d1728 100644 --- a/tests/Get-DbaDbMailAccount.Tests.ps1 +++ b/tests/Get-DbaDbMailAccount.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Get-DbaDbMailAccount" { BeforeAll { $accountname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailAccountSettings = @" EXEC msdb.dbo.sysmail_add_account_sp @account_name='$accountname', @@ -46,14 +46,14 @@ Describe "Get-DbaDbMailAccount" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" $server.Query($mailAccountSettings) } Context "Gets DbMail Account" { BeforeAll { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 | Where-Object { $_.Name -eq $accountname } + $results = Get-DbaDbMailAccount -SqlInstance $global:instance2 | Where-Object { $_.Name -eq $accountname } } It "Gets results" { @@ -83,7 +83,7 @@ Describe "Get-DbaDbMailAccount" { Context "Gets DbMail when using -Account" { BeforeAll { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 -Account $accountname + $results = Get-DbaDbMailAccount -SqlInstance $global:instance2 -Account $accountname } It "Gets results" { @@ -113,7 +113,7 @@ Describe "Get-DbaDbMailAccount" { Context "Gets no DbMail when using -ExcludeAccount" { BeforeAll { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 -ExcludeAccount $accountname + $results = Get-DbaDbMailAccount -SqlInstance $global:instance2 -ExcludeAccount $accountname } It "Gets no results" { diff --git a/tests/Get-DbaDbMailConfig.Tests.ps1 b/tests/Get-DbaDbMailConfig.Tests.ps1 index 976fb04921..bc58fed81f 100644 --- a/tests/Get-DbaDbMailConfig.Tests.ps1 +++ b/tests/Get-DbaDbMailConfig.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Get-DbaDbMailConfig" { Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailSettings = @{ AccountRetryAttempts = '1' AccountRetryDelay = '60' @@ -42,7 +42,7 @@ Describe "Get-DbaDbMailConfig" { Context "Gets DbMail Settings" { BeforeAll { - $results = Get-DbaDbMailConfig -SqlInstance $script:instance2 + $results = Get-DbaDbMailConfig -SqlInstance $global:instance2 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -57,7 +57,7 @@ Describe "Get-DbaDbMailConfig" { Context "Gets DbMail Settings when using -Name" { BeforeAll { - $results = Get-DbaDbMailConfig -SqlInstance $script:instance2 -Name "ProhibitedExtensions" + $results = Get-DbaDbMailConfig -SqlInstance $global:instance2 -Name "ProhibitedExtensions" } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDbMailHistory.Tests.ps1 b/tests/Get-DbaDbMailHistory.Tests.ps1 index 376f0378a2..1a3a367d5e 100644 --- a/tests/Get-DbaDbMailHistory.Tests.ps1 +++ b/tests/Get-DbaDbMailHistory.Tests.ps1 @@ -18,14 +18,14 @@ Describe "Get-DbaDbMailHistory" { $CommandUnderTest | Should -HaveParameter Status -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("INSERT INTO msdb.[dbo].[sysmail_profile] ([name] ,[description] @@ -77,7 +77,7 @@ Describe "Get-DbaDbMailHistory" { Context "Gets Db Mail History" { BeforeAll { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 | Where-Object {$_.Subject -eq 'Test Job'} + $results = Get-DbaDbMailHistory -SqlInstance $global:instance2 | Where-Object {$_.Subject -eq 'Test Job'} } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -91,7 +91,7 @@ Describe "Get-DbaDbMailHistory" { } Context "Gets Db Mail History using -Status" { BeforeAll { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 -Status Sent + $results = Get-DbaDbMailHistory -SqlInstance $global:instance2 -Status Sent } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -108,7 +108,7 @@ Describe "Get-DbaDbMailHistory" { } Context "Gets Db Mail History using -Since" { BeforeAll { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 -Since '2018-01-01' + $results = Get-DbaDbMailHistory -SqlInstance $global:instance2 -Since '2018-01-01' } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDbMailLog.Tests.ps1 b/tests/Get-DbaDbMailLog.Tests.ps1 index c5dd988114..a5e2dc9f31 100644 --- a/tests/Get-DbaDbMailLog.Tests.ps1 +++ b/tests/Get-DbaDbMailLog.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaDbMailLog" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,7 +29,7 @@ Describe "Get-DbaDbMailLog" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("INSERT INTO msdb.[dbo].[sysmail_log] ([event_type] ,[log_date] @@ -49,7 +49,7 @@ Describe "Get-DbaDbMailLog" { Context "Gets Db Mail Log" { BeforeAll { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 | Where-Object {$_.Login -eq 'dbatools\dbatoolssci'} + $results = Get-DbaDbMailLog -SqlInstance $global:instance2 | Where-Object {$_.Login -eq 'dbatools\dbatoolssci'} } It "Gets results" { @@ -67,7 +67,7 @@ Describe "Get-DbaDbMailLog" { Context "Gets Db Mail Log using -Type" { BeforeAll { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 -Type Information + $results = Get-DbaDbMailLog -SqlInstance $global:instance2 -Type Information } It "Gets results" { @@ -85,7 +85,7 @@ Describe "Get-DbaDbMailLog" { Context "Gets Db Mail History using -Since" { BeforeAll { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 -Since '2018-01-01' + $results = Get-DbaDbMailLog -SqlInstance $global:instance2 -Since '2018-01-01' } It "Gets results" { diff --git a/tests/Get-DbaDbMailProfile.Tests.ps1 b/tests/Get-DbaDbMailProfile.Tests.ps1 index 1a80304c94..d37b698943 100644 --- a/tests/Get-DbaDbMailProfile.Tests.ps1 +++ b/tests/Get-DbaDbMailProfile.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaDbMailProfile Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type SqlMail[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -38,7 +38,7 @@ Describe "Get-DbaDbMailProfile Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance2, $global:instance3 $mailProfile = "EXEC msdb.dbo.sysmail_add_profile_sp @profile_name='$profilename', @description='Profile for system email';" @@ -46,7 +46,7 @@ Describe "Get-DbaDbMailProfile Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $server = Connect-DbaInstance -SqlInstance $global:instance2, $global:instance3 $mailProfile = "EXEC msdb.dbo.sysmail_delete_profile_sp @profile_name='$profilename';" $server.Query($mailProfile) @@ -54,17 +54,17 @@ Describe "Get-DbaDbMailProfile Integration Tests" -Tag "IntegrationTests" { Context "Gets DbMail Profile" { It "Gets results" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 | Where-Object { $_.Name -eq $profilename } + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 | Where-Object { $_.Name -eq $profilename } $results | Should -Not -BeNullOrEmpty } It "Should have Name of $profilename" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 | Where-Object { $_.Name -eq $profilename } + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 | Where-Object { $_.Name -eq $profilename } $results.Name | Should -Be $profilename } It "Should have Description of 'Profile for system email'" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 | Where-Object { $_.Name -eq $profilename } + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 | Where-Object { $_.Name -eq $profilename } $results.Description | Should -Be 'Profile for system email' } @@ -77,24 +77,24 @@ Describe "Get-DbaDbMailProfile Integration Tests" -Tag "IntegrationTests" { Context "Gets DbMailProfile when using -Profile" { It "Gets results" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -Profile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 -Profile $profilename $results | Should -Not -BeNullOrEmpty } It "Should have Name of $profilename" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -Profile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 -Profile $profilename $results.Name | Should -Be $profilename } It "Should have Description of 'Profile for system email'" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -Profile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 -Profile $profilename $results.Description | Should -Be 'Profile for system email' } } Context "Gets no DbMailProfile when using -ExcludeProfile" { It "Gets no results" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -ExcludeProfile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $global:instance2 -ExcludeProfile $profilename $results | Should -Not -Contain $profilename } } diff --git a/tests/Get-DbaDbMailServer.Tests.ps1 b/tests/Get-DbaDbMailServer.Tests.ps1 index d03e505313..97eba2f347 100644 --- a/tests/Get-DbaDbMailServer.Tests.ps1 +++ b/tests/Get-DbaDbMailServer.Tests.ps1 @@ -20,8 +20,8 @@ Describe "Get-DbaDbMailServer" { It "Should have InputObject as a non-mandatory parameter of type SqlMail[]" { $CommandUnderTest | Should -HaveParameter InputObject -Type SqlMail[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -32,7 +32,7 @@ Describe "Get-DbaDbMailServer" { BeforeAll { $accountname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_add_account_sp @account_name='$accountname', @description='Mail account for email alerts', @@ -44,7 +44,7 @@ Describe "Get-DbaDbMailServer" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" $server.Query($mailAccountSettings) @@ -52,7 +52,7 @@ Describe "Get-DbaDbMailServer" { Context "Gets DbMailServer" { BeforeAll { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 | Where-Object {$_.Account -eq $accountname} + $results = Get-DbaDbMailServer -SqlInstance $global:instance2 | Where-Object {$_.Account -eq $accountname} } It "Gets results" { @@ -77,7 +77,7 @@ Describe "Get-DbaDbMailServer" { Context "Gets DbMailServer using -Server" { BeforeAll { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 -Server 'smtp.dbatools.io' + $results = Get-DbaDbMailServer -SqlInstance $global:instance2 -Server 'smtp.dbatools.io' } It "Gets results" { @@ -87,7 +87,7 @@ Describe "Get-DbaDbMailServer" { Context "Gets DbMailServer using -Account" { BeforeAll { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 -Account $accountname + $results = Get-DbaDbMailServer -SqlInstance $global:instance2 -Account $accountname } It "Gets results" { diff --git a/tests/Get-DbaDbMasterKey.Tests.ps1 b/tests/Get-DbaDbMasterKey.Tests.ps1 index 6282c48036..9618984395 100644 --- a/tests/Get-DbaDbMasterKey.Tests.ps1 +++ b/tests/Get-DbaDbMasterKey.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaDbMasterKey Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -35,18 +35,18 @@ Describe "Get-DbaDbMasterKey Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbMasterKey Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $null = $server.Query("Create Database [$dbname]") - $null = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname -Password (ConvertTo-SecureString -AsPlainText -Force -String 'ThisIsAPassword!') -Confirm:$false + $null = New-DbaDbMasterKey -SqlInstance $global:instance1 -Database $dbname -Password (ConvertTo-SecureString -AsPlainText -Force -String 'ThisIsAPassword!') -Confirm:$false } AfterAll { - Remove-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDbMasterKey -SqlInstance $global:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance1 -Database $dbname -Confirm:$false } Context "Gets DbMasterKey" { BeforeAll { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 | Where-Object {$_.Database -eq "$dbname"} + $results = Get-DbaDbMasterKey -SqlInstance $global:instance1 | Where-Object {$_.Database -eq "$dbname"} } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -61,7 +61,7 @@ Describe "Get-DbaDbMasterKey Integration Tests" -Tag "IntegrationTests" { Context "Gets DbMasterKey when using -database" { BeforeAll { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname + $results = Get-DbaDbMasterKey -SqlInstance $global:instance1 -Database $dbname } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -76,7 +76,7 @@ Describe "Get-DbaDbMasterKey Integration Tests" -Tag "IntegrationTests" { Context "Gets no DbMasterKey when using -ExcludeDatabase" { BeforeAll { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 -ExcludeDatabase $dbname + $results = Get-DbaDbMasterKey -SqlInstance $global:instance1 -ExcludeDatabase $dbname } It "Gets no results" { $results | Should -BeNullOrEmpty diff --git a/tests/Get-DbaDbMemoryUsage.Tests.ps1 b/tests/Get-DbaDbMemoryUsage.Tests.ps1 index 7d3bd9c25c..b663a8e6c5 100644 --- a/tests/Get-DbaDbMemoryUsage.Tests.ps1 +++ b/tests/Get-DbaDbMemoryUsage.Tests.ps1 @@ -18,17 +18,17 @@ Describe "Get-DbaDbMemoryUsage" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have IncludeSystemDb as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSystemDb -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeSystemDb -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $global:instance2 } It 'Returns data' { diff --git a/tests/Get-DbaDbMirror.Tests.ps1 b/tests/Get-DbaDbMirror.Tests.ps1 index eae4ecec8c..0393fcb2d7 100644 --- a/tests/Get-DbaDbMirror.Tests.ps1 +++ b/tests/Get-DbaDbMirror.Tests.ps1 @@ -21,40 +21,40 @@ Describe "Get-DbaDbMirror" { $CommandUnderTest | Should -HaveParameter Database -Type String[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $global:instance2, $global:instance3 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = "dbatoolsci_mirroring" $db2 = "dbatoolsci_mirroring_db2" - Remove-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbMirror -SqlInstance $global:instance2, $global:instance3 -Database $db1, $db2 -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $null = $server.Query("CREATE DATABASE $db1") $null = $server.Query("CREATE DATABASE $db2") } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 | Remove-DbaDbMirror -Confirm:$false - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 -ErrorAction SilentlyContinue + $null = Get-DbaDatabase -SqlInstance $global:instance2, $global:instance3 -Database $db1, $db2 | Remove-DbaDbMirror -Confirm:$false + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2, $global:instance3 -Database $db1, $db2 -ErrorAction SilentlyContinue } It "returns more than one database" -Skip { - $null = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1, $db2 -Confirm:$false -Force -SharedPath C:\temp -WarningAction Continue - (Get-DbaDbMirror -SqlInstance $script:instance3).Count | Should -BeGreaterThan 1 + $null = Invoke-DbaDbMirroring -Primary $global:instance2 -Mirror $global:instance3 -Database $db1, $db2 -Confirm:$false -Force -SharedPath C:\temp -WarningAction Continue + (Get-DbaDbMirror -SqlInstance $global:instance3).Count | Should -BeGreaterThan 1 } It "returns just one database" -Skip { - (Get-DbaDbMirror -SqlInstance $script:instance3 -Database $db2).Count | Should -Be 1 + (Get-DbaDbMirror -SqlInstance $global:instance3 -Database $db2).Count | Should -Be 1 } It "returns 2x1 database" -Skip { - (Get-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db2).Count | Should -Be 2 + (Get-DbaDbMirror -SqlInstance $global:instance2, $global:instance3 -Database $db2).Count | Should -Be 2 } } } diff --git a/tests/Get-DbaDbMirrorMonitor.Tests.ps1 b/tests/Get-DbaDbMirrorMonitor.Tests.ps1 index 9885eb910a..b8023f0dfe 100644 --- a/tests/Get-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Get-DbaDbMirrorMonitor.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Get-DbaDbMirrorMonitor" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have Update parameter" { - $CommandUnderTest | Should -HaveParameter Update -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Update -Type Switch -Not -Mandatory } It "Should have LimitResults parameter" { $CommandUnderTest | Should -HaveParameter LimitResults -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Get-DbaDbObjectTrigger.Tests.ps1 b/tests/Get-DbaDbObjectTrigger.Tests.ps1 index a0cc7e7db3..0e9eef6575 100644 --- a/tests/Get-DbaDbObjectTrigger.Tests.ps1 +++ b/tests/Get-DbaDbObjectTrigger.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Get-DbaDbObjectTrigger Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -61,7 +61,7 @@ CREATE TRIGGER $triggerviewname SELECT 'TRIGGER on $viewname view' END "@ - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("create database $dbname") $server.Query("CREATE TABLE $tablename (id int);", $dbname) @@ -70,16 +70,16 @@ CREATE TRIGGER $triggerviewname $server.Query("CREATE VIEW $viewname AS SELECT * FROM $tablename;", $dbname) $server.Query("$triggerview", $dbname) - $systemDbs = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeUser + $systemDbs = Get-DbaDatabase -SqlInstance $global:instance2 -ExcludeUser } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Gets Table Trigger" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -94,7 +94,7 @@ CREATE TRIGGER $triggerviewname Context "Gets Table Trigger when using -Database" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -109,7 +109,7 @@ CREATE TRIGGER $triggerviewname Context "Gets Table Trigger passing table object using pipeline" { BeforeAll { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbname -Table "dbatoolsci_trigger" | Get-DbaDbObjectTrigger + $results = Get-DbaDbTable -SqlInstance $global:instance2 -Database $dbname -Table "dbatoolsci_trigger" | Get-DbaDbObjectTrigger } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -124,7 +124,7 @@ CREATE TRIGGER $triggerviewname Context "Gets View Trigger" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -139,7 +139,7 @@ CREATE TRIGGER $triggerviewname Context "Gets View Trigger when using -Database" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -154,7 +154,7 @@ CREATE TRIGGER $triggerviewname Context "Gets View Trigger passing table object using pipeline" { BeforeAll { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemView | Get-DbaDbObjectTrigger + $results = Get-DbaDbView -SqlInstance $global:instance2 -Database $dbname -ExcludeSystemView | Get-DbaDbObjectTrigger } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -169,8 +169,8 @@ CREATE TRIGGER $triggerviewname Context "Gets Table and View Trigger passing both objects using pipeline" { BeforeAll { - $tableResults = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbname -Table "dbatoolsci_trigger" - $viewResults = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemView + $tableResults = Get-DbaDbTable -SqlInstance $global:instance2 -Database $dbname -Table "dbatoolsci_trigger" + $viewResults = Get-DbaDbView -SqlInstance $global:instance2 -Database $dbname -ExcludeSystemView $results = $tableResults, $viewResults | Get-DbaDbObjectTrigger } It "Gets results" { @@ -183,7 +183,7 @@ CREATE TRIGGER $triggerviewname Context "Gets All types Trigger when using -Type" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type All + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -Database $dbname -Type All } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -195,7 +195,7 @@ CREATE TRIGGER $triggerviewname Context "Gets only Table Trigger when using -Type" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type Table + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -Database $dbname -Type Table } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -210,7 +210,7 @@ CREATE TRIGGER $triggerviewname Context "Gets only View Trigger when using -Type" { BeforeAll { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type View + $results = Get-DbaDbObjectTrigger -SqlInstance $global:instance2 -Database $dbname -Type View } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDbOrphanUser.Tests.ps1 b/tests/Get-DbaDbOrphanUser.Tests.ps1 index 0ee984282c..f814c4bf04 100644 --- a/tests/Get-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Get-DbaDbOrphanUser.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaDbOrphanUser" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,7 +32,7 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION CREATE LOGIN [dbatoolsci_orphan3] WITH PASSWORD = N'password3', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF; CREATE DATABASE dbatoolsci_orphan; '@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false $null = Invoke-DbaQuery -SqlInstance $server -Query $loginsq @@ -47,13 +47,13 @@ CREATE USER [dbatoolsci_orphan3] FROM LOGIN [dbatoolsci_orphan3]; } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false } It "Finds two orphans" { - $results = Get-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Get-DbaDbOrphanUser -SqlInstance $global:instance1 -Database dbatoolsci_orphan $results.Count | Should -Be 2 foreach ($user in $results) { $user.User | Should -BeIn @('dbatoolsci_orphan1', 'dbatoolsci_orphan2') @@ -62,7 +62,7 @@ CREATE USER [dbatoolsci_orphan3] FROM LOGIN [dbatoolsci_orphan3]; } It "Has the correct properties" { - $results = Get-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Get-DbaDbOrphanUser -SqlInstance $global:instance1 -Database dbatoolsci_orphan $result = $results[0] $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'DatabaseName', 'User', 'SmoUser' ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) diff --git a/tests/Get-DbaDbPageInfo.Tests.ps1 b/tests/Get-DbaDbPageInfo.Tests.ps1 index 894e1130b7..b80bb27b65 100644 --- a/tests/Get-DbaDbPageInfo.Tests.ps1 +++ b/tests/Get-DbaDbPageInfo.Tests.ps1 @@ -32,8 +32,8 @@ Describe "Get-DbaDbPageInfo" { BeforeAll { $random = Get-Random $dbname = "dbatoolsci_pageinfo_$random" - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $global:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance2 $server.Query("CREATE DATABASE $dbname;") $server.Databases[$dbname].Query('CREATE TABLE [dbo].[TestTable](TestText VARCHAR(MAX) NOT NULL)') $query = " @@ -52,11 +52,11 @@ Describe "Get-DbaDbPageInfo" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false } It "returns the proper results" { - $result = Get-DbaDbPageInfo -SqlInstance $script:instance2 -Database $dbname + $result = Get-DbaDbPageInfo -SqlInstance $global:instance2 -Database $dbname $result.Count | Should -Be 9 ($result | Where-Object { $_.IsAllocated -eq $false }).Count | Should -Be 5 ($result | Where-Object { $_.IsAllocated -eq $true }).Count | Should -Be 4 diff --git a/tests/Get-DbaDbPartitionFunction.Tests.ps1 b/tests/Get-DbaDbPartitionFunction.Tests.ps1 index 7f57710f70..7e64fdc507 100644 --- a/tests/Get-DbaDbPartitionFunction.Tests.ps1 +++ b/tests/Get-DbaDbPartitionFunction.Tests.ps1 @@ -30,40 +30,40 @@ Describe "Get-DbaDbPartitionFunction" { $tempguid = [guid]::newguid(); $PFName = "dbatoolssci_$($tempguid.guid)" $CreateTestPartitionFunction = "CREATE PARTITION FUNCTION [$PFName] (int) AS RANGE LEFT FOR VALUES (1, 100, 1000, 10000, 100000);" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestPartitionFunction -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $CreateTestPartitionFunction -Database master } AfterAll { $DropTestPartitionFunction = "DROP PARTITION FUNCTION [$PFName];" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestPartitionFunction -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $DropTestPartitionFunction -Database master } It "Should execute and return results" { - $results2 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 + $results2 = Get-DbaDbPartitionFunction -SqlInstance $global:instance2 $results2 | Should -Not -BeNullOrEmpty } It "Should execute against Master and return results" { - $results1 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -Database master | Select-Object * + $results1 = Get-DbaDbPartitionFunction -SqlInstance $global:instance2 -Database master | Select-Object * $results1 | Should -Not -BeNullOrEmpty } It "Should have matching name $PFName" { - $results1 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -Database master | Select-Object * + $results1 = Get-DbaDbPartitionFunction -SqlInstance $global:instance2 -Database master | Select-Object * $results1.name | Should -Be $PFName } It "Should have range values of @(1, 100, 1000, 10000, 100000)" { - $results1 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -Database master | Select-Object * + $results1 = Get-DbaDbPartitionFunction -SqlInstance $global:instance2 -Database master | Select-Object * $results1.rangeValues | Should -Be @(1, 100, 1000, 10000, 100000) } It "Should have PartitionFunctionParameters of Int" { - $results1 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -Database master | Select-Object * + $results1 = Get-DbaDbPartitionFunction -SqlInstance $global:instance2 -Database master | Select-Object * $results1.PartitionFunctionParameters | Should -Be "[int]" } It "Should not Throw an Error when excluding master database" { - { Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -ExcludeDatabase master } | Should -Not -Throw + { Get-DbaDbPartitionFunction -SqlInstance $global:instance2 -ExcludeDatabase master } | Should -Not -Throw } } } diff --git a/tests/Get-DbaDbPartitionScheme.Tests.ps1 b/tests/Get-DbaDbPartitionScheme.Tests.ps1 index 9deae92d32..0ef23dc1d0 100644 --- a/tests/Get-DbaDbPartitionScheme.Tests.ps1 +++ b/tests/Get-DbaDbPartitionScheme.Tests.ps1 @@ -20,8 +20,8 @@ Describe "Get-DbaDbPartitionScheme" { It "Should have PartitionScheme as a non-mandatory parameter of type String[]" { $CommandUnderTest | Should -HaveParameter PartitionScheme -Type String[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -42,7 +42,7 @@ GO CREATE PARTITION SCHEME $PFScheme AS PARTITION [$PFName] ALL TO ( [PRIMARY] ); "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestPartitionScheme -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $CreateTestPartitionScheme -Database master } AfterAll { @@ -51,37 +51,37 @@ DROP PARTITION SCHEME [$PFScheme]; GO DROP PARTITION FUNCTION [$PFName]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestPartitionScheme -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $DropTestPartitionScheme -Database master } Context "Partition Schemes are correctly located" { It "Should execute and return results" { - $results2 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 + $results2 = Get-DbaDbPartitionScheme -SqlInstance $global:instance2 $results2 | Should -Not -BeNullOrEmpty } It "Should execute against Master and return results" { - $results1 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -Database master + $results1 = Get-DbaDbPartitionScheme -SqlInstance $global:instance2 -Database master $results1 | Should -Not -BeNullOrEmpty } It "Should have matching name $PFScheme" { - $results1 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -Database master + $results1 = Get-DbaDbPartitionScheme -SqlInstance $global:instance2 -Database master $results1.name | Should -Be $PFScheme } It "Should have PartitionFunction of $PFName" { - $results1 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -Database master + $results1 = Get-DbaDbPartitionScheme -SqlInstance $global:instance2 -Database master $results1.PartitionFunction | Should -Be $PFName } It "Should have FileGroups of [Primary]" { - $results1 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -Database master + $results1 = Get-DbaDbPartitionScheme -SqlInstance $global:instance2 -Database master $results1.FileGroups | Should -Be @('PRIMARY', 'PRIMARY', 'PRIMARY', 'PRIMARY', 'PRIMARY', 'PRIMARY') } It "Should not Throw an Error when excluding master database" { - { Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -ExcludeDatabase master } | Should -Not -Throw + { Get-DbaDbPartitionScheme -SqlInstance $global:instance2 -ExcludeDatabase master } | Should -Not -Throw } } } diff --git a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 index b4649d8c58..94ec622428 100644 --- a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 @@ -22,13 +22,13 @@ Describe "Get-DbaDbQueryStoreOption" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -66,18 +66,18 @@ Describe "Get-DbaDbQueryStoreOption" { # For example: # Context "Integration Tests" { # BeforeAll { - # $server = Connect-DbaInstance -SqlInstance $script:instance2 + # $server = Connect-DbaInstance -SqlInstance $global:instance2 # $randomDb = "dbatoolsci_$(Get-Random)" # $server.Query("CREATE DATABASE $randomDb") # $server.Query("ALTER DATABASE $randomDb SET QUERY_STORE = ON") # } - # + # # AfterAll { # $server.Query("DROP DATABASE $randomDb") # } - # + # # It "Returns query store options" { - # $results = Get-DbaDbQueryStoreOption -SqlInstance $script:instance2 -Database $randomDb + # $results = Get-DbaDbQueryStoreOption -SqlInstance $global:instance2 -Database $randomDb # $results | Should -Not -BeNullOrEmpty # $results.Database | Should -Be $randomDb # $results.ActualState | Should -Be "ReadWrite" diff --git a/tests/Get-DbaDbRecoveryModel.Tests.ps1 b/tests/Get-DbaDbRecoveryModel.Tests.ps1 index c8863e4685..8e9d9c9f20 100644 --- a/tests/Get-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Get-DbaDbRecoveryModel.Tests.ps1 @@ -27,13 +27,13 @@ Describe "Get-DbaDbRecoveryModel" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Recovery model is correctly identified" { BeforeAll { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database master + $results = Get-DbaDbRecoveryModel -SqlInstance $global:instance2 -Database master } It "returns a single database" { @@ -45,30 +45,30 @@ Describe "Get-DbaDbRecoveryModel" { } It "returns accurate number of results" { - $allResults = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 + $allResults = Get-DbaDbRecoveryModel -SqlInstance $global:instance2 $allResults.Count | Should -BeGreaterOrEqual 4 } } Context "RecoveryModel parameter works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $dbname = "dbatoolsci_getrecoverymodel" Get-DbaDatabase -SqlInstance $server -Database $dbname | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $dbname; ALTER DATABASE $dbname SET RECOVERY BULK_LOGGED WITH NO_WAIT;") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } It "gets the newly created database with the correct recovery model" { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbRecoveryModel -SqlInstance $global:instance2 -Database $dbname $results.RecoveryModel | Should -Be 'BulkLogged' } It "honors the RecoveryModel parameter filter" { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel BulkLogged + $results = Get-DbaDbRecoveryModel -SqlInstance $global:instance2 -RecoveryModel BulkLogged $results.Name | Should -Contain $dbname } } diff --git a/tests/Get-DbaDbRestoreHistory.Tests.ps1 b/tests/Get-DbaDbRestoreHistory.Tests.ps1 index 0823df33b7..bab0d57846 100644 --- a/tests/Get-DbaDbRestoreHistory.Tests.ps1 +++ b/tests/Get-DbaDbRestoreHistory.Tests.ps1 @@ -46,40 +46,40 @@ Describe "Get-DbaDbRestoreHistory Integration Tests" -Tag "IntegrationTests" { $random = Get-Random $dbname1 = "dbatoolsci_restorehistory1_$random" $dbname2 = "dbatoolsci_restorehistory2_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname1 -DestinationFilePrefix $dbname1 - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix "rsh_pre_$dbname2" -WithReplace - $fullBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Full - $diffBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Diff - $logBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Log + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $global:instance2 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname1 -DestinationFilePrefix $dbname1 + $null = Restore-DbaDatabase -SqlInstance $global:instance2 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 + $null = Restore-DbaDatabase -SqlInstance $global:instance2 -Path $global:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix "rsh_pre_$dbname2" -WithReplace + $fullBackup = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1 -Type Full + $diffBackup = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1 -Type Diff + $logBackup = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1 -Type Log - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $diffBackup.BackupPath, $logBackup.BackupPath -DatabaseName $dbname1 -WithReplace + $null = Restore-DbaDatabase -SqlInstance $global:instance2 -Path $diffBackup.BackupPath, $logBackup.BackupPath -DatabaseName $dbname1 -WithReplace } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false Remove-Item -Path $fullBackup.BackupPath -Force Remove-Item -Path $logBackup.BackupPath -Force } Context "Get last restore history for single database" { BeforeAll { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname2 -Last) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname2 -Last) } It "Results holds 1 object" { $results.count | Should -Be 1 } It "Should return the full restore with the correct properties" { $results[0].RestoreType | Should -Be "Database" - $results[0].From | Should -Be $script:appveyorlabrepo\singlerestore\singlerestore.bak + $results[0].From | Should -Be $global:appveyorlabrepo\singlerestore\singlerestore.bak $results[0].To | Should -Match "\\rsh_pre_$dbname2" } } Context "Get last restore history for multiple database" { BeforeAll { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 -Last) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1, $dbname2 -Last) } It "Results holds 2 objects" { $results.count | Should -Be 2 @@ -87,7 +87,7 @@ Describe "Get-DbaDbRestoreHistory Integration Tests" -Tag "IntegrationTests" { It "Should return the full restore with the correct properties" { $results[0].RestoreType | Should -Be "Database" $results[1].RestoreType | Should -Be "Log" - $results[0].From | Should -Be $script:appveyorlabrepo\singlerestore\singlerestore.bak + $results[0].From | Should -Be $global:appveyorlabrepo\singlerestore\singlerestore.bak $results[1].From | Should -Be $logBackup.BackupPath ($results | Where-Object Database -eq $dbname1).To | Should -Match "\\$dbname1" ($results | Where-Object Database -eq $dbname2).To | Should -Match "\\rsh_pre_$dbname2" @@ -96,7 +96,7 @@ Describe "Get-DbaDbRestoreHistory Integration Tests" -Tag "IntegrationTests" { Context "Get complete restore history for multiple database" { BeforeAll { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1, $dbname2) } It "Results holds correct number of objects" { $results.Count | Should -Be 6 @@ -109,7 +109,7 @@ Describe "Get-DbaDbRestoreHistory Integration Tests" -Tag "IntegrationTests" { Context "return object properties" { It "has the correct properties" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 + $results = Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1, $dbname2 $result = $results[0] $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,Username,RestoreType,Date,From,To,first_lsn,last_lsn,checkpoint_lsn,database_backup_lsn,backup_finish_date,BackupFinishDate,RowError,RowState,Table,ItemArray,HasErrors'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) @@ -120,17 +120,17 @@ Describe "Get-DbaDbRestoreHistory Integration Tests" -Tag "IntegrationTests" { Context "Get restore history by restore type" { It "returns the correct history records for full db restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 -RestoreType Database + $results = Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1, $dbname2 -RestoreType Database $results.count | Should -Be 4 @($results | Where-Object RestoreType -eq Database).Count | Should -Be 4 } It "returns the correct history records for differential restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1 -RestoreType Differential + $results = Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1 -RestoreType Differential $results.Database | Should -Be $dbname1 $results.RestoreType | Should -Be Differential } It "returns the correct history records for log restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1 -RestoreType Log + $results = Get-DbaDbRestoreHistory -SqlInstance $global:instance2 -Database $dbname1 -RestoreType Log $results.Database | Should -Be $dbname1 $results.RestoreType | Should -Be Log } diff --git a/tests/Get-DbaDbRole.Tests.ps1 b/tests/Get-DbaDbRole.Tests.ps1 index 4de43a989b..943b7cdec2 100644 --- a/tests/Get-DbaDbRole.Tests.ps1 +++ b/tests/Get-DbaDbRole.Tests.ps1 @@ -24,19 +24,19 @@ Describe "Get-DbaDbRole" { $CommandUnderTest | Should -HaveParameter ExcludeRole -Type String[] -Not -Mandatory } It "Should have ExcludeFixedRole parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $global:instance2 $allDatabases = $instance.Databases } diff --git a/tests/Get-DbaDbRoleMember.Tests.ps1 b/tests/Get-DbaDbRoleMember.Tests.ps1 index 18e8a7bc30..5023548a27 100644 --- a/tests/Get-DbaDbRoleMember.Tests.ps1 +++ b/tests/Get-DbaDbRoleMember.Tests.ps1 @@ -44,7 +44,7 @@ Describe "Get-DbaDbRoleMember Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $global:instance2 $allDatabases = $instance.Databases } diff --git a/tests/Get-DbaDbSchema.Tests.ps1 b/tests/Get-DbaDbSchema.Tests.ps1 index 44ea3a9d03..318c61550e 100644 --- a/tests/Get-DbaDbSchema.Tests.ps1 +++ b/tests/Get-DbaDbSchema.Tests.ps1 @@ -44,8 +44,8 @@ Describe "Get-DbaDbSchema Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbSchema Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $global:instance1 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName diff --git a/tests/Get-DbaDbSequence.Tests.ps1 b/tests/Get-DbaDbSequence.Tests.ps1 index 72dcccbf47..bd871851f8 100644 --- a/tests/Get-DbaDbSequence.Tests.ps1 +++ b/tests/Get-DbaDbSequence.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Get-DbaDbSequence Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -38,7 +38,7 @@ Describe "Get-DbaDbSequence Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbSequence Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $newDbName = "dbatoolsci_newdb_$random" $newDbName2 = "dbatoolsci_newdb2_$random" $newDb, $newDb2 = New-DbaDatabase -SqlInstance $server -Name $newDbName, $newDbName2 diff --git a/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 b/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 index ac276a80bc..bbb2679206 100644 --- a/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 +++ b/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Get-DbaDbServiceBrokerQueue" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have ExcludeSystemQueue as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemQueue -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemQueue -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,7 +31,7 @@ Describe "Get-DbaDbServiceBrokerQueue" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $procname = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE PROCEDURE $procname AS SELECT 1", 'tempdb') $queuename = ("dbatools_{0}" -f $(Get-Random)) @@ -44,7 +44,7 @@ Describe "Get-DbaDbServiceBrokerQueue" { } It "Gets the service broker queue" { - $results = Get-DbaDbServiceBrokerQueue -SqlInstance $script:instance2 -Database tempdb -ExcludeSystemQueue + $results = Get-DbaDbServiceBrokerQueue -SqlInstance $global:instance2 -Database tempdb -ExcludeSystemQueue $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be $queuename $results.Schema | Should -Be "dbo" diff --git a/tests/Get-DbaDbServiceBrokerService.Tests.ps1 b/tests/Get-DbaDbServiceBrokerService.Tests.ps1 index 7c16899e51..281c750b8f 100644 --- a/tests/Get-DbaDbServiceBrokerService.Tests.ps1 +++ b/tests/Get-DbaDbServiceBrokerService.Tests.ps1 @@ -18,16 +18,16 @@ Describe "Get-DbaDbServiceBrokerService" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have ExcludeSystemService as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemService -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemService -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $procname = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE PROCEDURE $procname AS SELECT 1", 'tempdb') $queuename = ("dbatools_{0}" -f $(Get-Random)) @@ -43,7 +43,7 @@ Describe "Get-DbaDbServiceBrokerService" { } It "Gets the service broker service" { - $results = Get-DbaDbServiceBrokerService -SqlInstance $script:instance2 -Database tempdb -ExcludeSystemService + $results = Get-DbaDbServiceBrokerService -SqlInstance $global:instance2 -Database tempdb -ExcludeSystemService $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be $servicename $results.Owner | Should -Be "dbo" diff --git a/tests/Get-DbaDbSharePoint.Tests.ps1 b/tests/Get-DbaDbSharePoint.Tests.ps1 index c647624240..16f9824306 100644 --- a/tests/Get-DbaDbSharePoint.Tests.ps1 +++ b/tests/Get-DbaDbSharePoint.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaDbSharePoint" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -26,15 +26,15 @@ Describe "Get-DbaDbSharePoint" { BeforeAll { $skip = $false $spdb = 'SharePoint_Admin_7c0c491d0e6f43858f75afa5399d49ab', 'WSS_Logging', 'SecureStoreService_20e1764876504335a6d8dd0b1937f4bf', 'DefaultWebApplicationDB', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0', 'DefaultPowerPivotServiceApplicationDB-5b638361-c6fc-4ad9-b8ba-d05e63e48ac6', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0' - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $global:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance2 foreach ($db in $spdb) { try { $null = $server.Query("Create Database [$db]") } catch { continue } } - - $bacpac = "$script:appveyorlabrepo\bacpac\sharepoint_config.bacpac" + + $bacpac = "$global:appveyorlabrepo\bacpac\sharepoint_config.bacpac" if (Test-Path -Path $bacpac) { $sqlpackage = (Get-Command sqlpackage -ErrorAction Ignore).Source if (-not $sqlpackage) { @@ -55,11 +55,11 @@ Describe "Get-DbaDbSharePoint" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $spdb -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $spdb -Confirm:$false } It "Returns <_> from in the SharePoint database list" -Skip:$skip -ForEach $spdb { - $results = Get-DbaDbSharePoint -SqlInstance $script:instance2 + $results = Get-DbaDbSharePoint -SqlInstance $global:instance2 $_ | Should -BeIn $results.Name } } diff --git a/tests/Get-DbaDbSnapshot.Tests.ps1 b/tests/Get-DbaDbSnapshot.Tests.ps1 index 3e699c7a01..9db95eb552 100644 --- a/tests/Get-DbaDbSnapshot.Tests.ps1 +++ b/tests/Get-DbaDbSnapshot.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Get-DbaDbSnapshot Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeSnapshot -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -43,52 +43,52 @@ Describe "Get-DbaDbSnapshot Integration Tests" -Tag "IntegrationTests" { Context "Operations on snapshots" -Skip:$SkipTests { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $global:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = "dbatoolsci_GetSnap" $db1_snap1 = "dbatoolsci_GetSnap_snapshotted1" $db1_snap2 = "dbatoolsci_GetSnap_snapshotted2" $db2 = "dbatoolsci_GetSnap2" $db2_snap1 = "dbatoolsci_GetSnap2_snapshotted" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -WarningAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -WarningAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db1 -Name $db1_snap1 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db1 -Name $db1_snap2 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db2 -Name $db2_snap1 -WarningAction SilentlyContinue } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue -Confirm:$false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue -Confirm:$false + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } It "Gets all snapshots by default" { - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 + $results = Get-DbaDbSnapshot -SqlInstance $global:instance2 ($results | Where-Object Name -Like 'dbatoolsci_GetSnap*').Count | Should -Be 3 } It "Honors the Database parameter, returning only snapshots of that database" { - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $results = Get-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db1 $results.Count | Should -Be 2 - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db2 $result.SnapshotOf | Should -Be $db2 } It "Honors the ExcludeDatabase parameter, returning relevant snapshots" { - $alldbs = (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeDatabase $alldbs + $alldbs = (Get-DbaDatabase -SqlInstance $global:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name + $results = Get-DbaDbSnapshot -SqlInstance $global:instance2 -ExcludeDatabase $alldbs $results.Count | Should -Be 3 } It "Honors the Snapshot parameter" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 + $result = Get-DbaDbSnapshot -SqlInstance $global:instance2 -Snapshot $db1_snap1 $result.Name | Should -Be $db1_snap1 $result.SnapshotOf | Should -Be $db1 } It "Honors the ExcludeSnapshot parameter" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeSnapshot $db1_snap1 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $global:instance2 -ExcludeSnapshot $db1_snap1 -Database $db1 $result.Name | Should -Be $db1_snap2 } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $global:instance2 -Database $db2 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } diff --git a/tests/Get-DbaDbSpace.Tests.ps1 b/tests/Get-DbaDbSpace.Tests.ps1 index e36b356f34..56f5022dc7 100644 --- a/tests/Get-DbaDbSpace.Tests.ps1 +++ b/tests/Get-DbaDbSpace.Tests.ps1 @@ -36,16 +36,16 @@ Describe "Get-DbaDbSpace" { Context "Command usage" { BeforeAll { $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = $server.Query("Create Database [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -Confirm:$false } Context "Gets DbSpace" { BeforeAll { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 | Where-Object { $_.Database -eq "$dbname" } + $results = Get-DbaDbSpace -SqlInstance $global:instance2 | Where-Object { $_.Database -eq "$dbname" } } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -65,7 +65,7 @@ Describe "Get-DbaDbSpace" { Context "Gets DbSpace when using -Database" { BeforeAll { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbSpace -SqlInstance $global:instance2 -Database $dbname } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -85,7 +85,7 @@ Describe "Get-DbaDbSpace" { Context "Gets no DbSpace for specific database when using -ExcludeDatabase" { BeforeAll { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $results = Get-DbaDbSpace -SqlInstance $global:instance2 -ExcludeDatabase $dbname } It "Gets no results for excluded database" { $results.Database | Should -Not -Contain $dbname diff --git a/tests/Get-DbaDbState.Tests.ps1 b/tests/Get-DbaDbState.Tests.ps1 index 95b5124432..971be4ca04 100644 --- a/tests/Get-DbaDbState.Tests.ps1 +++ b/tests/Get-DbaDbState.Tests.ps1 @@ -22,13 +22,13 @@ Describe "Get-DbaDbState" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Reading db statuses" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = "dbatoolsci_dbstate_online" $db2 = "dbatoolsci_dbstate_offline" $db3 = "dbatoolsci_dbstate_emergency" @@ -37,7 +37,7 @@ Describe "Get-DbaDbState" { $db6 = "dbatoolsci_dbstate_multi" $db7 = "dbatoolsci_dbstate_rw" $db8 = "dbatoolsci_dbstate_ro" - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $global:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2; ALTER DATABASE $db2 SET OFFLINE WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $db3; ALTER DATABASE $db3 SET EMERGENCY WITH ROLLBACK IMMEDIATE") @@ -48,85 +48,85 @@ Describe "Get-DbaDbState" { $server.Query("CREATE DATABASE $db8; ALTER DATABASE $db8 SET READ_ONLY WITH ROLLBACK IMMEDIATE") $needed_ = $server.Query("select name from sys.databases") $needed = $needed_ | Where-Object name -in $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 - $script:setupright = $needed.Count -eq 8 + $global:setupright = $needed.Count -eq 8 } AfterAll { - $null = Set-DbaDbState -Sqlinstance $script:instance2 -Database $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 + $null = Set-DbaDbState -Sqlinstance $global:instance2 -Database $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 } - It "Honors the Database parameter" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db2 + It "Honors the Database parameter" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db2 $result.DatabaseName | Should -Be $db2 - $results = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1, $db2 + $results = Get-DbaDbState -SqlInstance $global:instance2 -Database $db1, $db2 $results.Count | Should -Be 2 } - It "Honors the ExcludeDatabase parameter" -Skip:(-not $script:setupright) { + It "Honors the ExcludeDatabase parameter" -Skip:(-not $global:setupright) { $alldbs_ = $server.Query("select name from sys.databases") $alldbs = ($alldbs_ | Where-Object Name -notin @($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)).name - $results = Get-DbaDbState -SqlInstance $script:instance2 -ExcludeDatabase $alldbs + $results = Get-DbaDbState -SqlInstance $global:instance2 -ExcludeDatabase $alldbs $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)) $comparison.Count | Should -Be 0 } - It "Identifies online database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1 + It "Identifies online database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db1 $result.DatabaseName | Should -Be $db1 $result.Status | Should -Be "ONLINE" } - It "Identifies offline database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db2 + It "Identifies offline database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db2 $result.DatabaseName | Should -Be $db2 $result.Status | Should -Be "OFFLINE" } - It "Identifies emergency database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db3 + It "Identifies emergency database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db3 $result.DatabaseName | Should -Be $db3 $result.Status | Should -Be "EMERGENCY" } - It "Identifies single_user database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db4 + It "Identifies single_user database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db4 $result.DatabaseName | Should -Be $db4 $result.Access | Should -Be "SINGLE_USER" } - It "Identifies restricted_user database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db5 + It "Identifies restricted_user database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db5 $result.DatabaseName | Should -Be $db5 $result.Access | Should -Be "RESTRICTED_USER" } - It "Identifies multi_user database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db6 + It "Identifies multi_user database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db6 $result.DatabaseName | Should -Be $db6 $result.Access | Should -Be "MULTI_USER" } - It "Identifies read_write database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db7 + It "Identifies read_write database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db7 $result.DatabaseName | Should -Be $db7 $result.RW | Should -Be "READ_WRITE" } - It "Identifies read_only database" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db8 + It "Identifies read_only database" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db8 $result.DatabaseName | Should -Be $db8 $result.RW | Should -Be "READ_ONLY" } - It "Has the correct properties" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1 + It "Has the correct properties" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db1 $ExpectedProps = 'SqlInstance,InstanceName,ComputerName,DatabaseName,RW,Status,Access,Database'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } - It "Has the correct default properties" -Skip:(-not $script:setupright) { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1 + It "Has the correct default properties" -Skip:(-not $global:setupright) { + $result = Get-DbaDbState -SqlInstance $global:instance2 -Database $db1 $ExpectedPropsDefault = 'SqlInstance,InstanceName,ComputerName,DatabaseName,RW,Status,Access'.Split(',') ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } diff --git a/tests/Get-DbaDbStoredProcedure.Tests.ps1 b/tests/Get-DbaDbStoredProcedure.Tests.ps1 index bce841512b..deeb9af6ea 100644 --- a/tests/Get-DbaDbStoredProcedure.Tests.ps1 +++ b/tests/Get-DbaDbStoredProcedure.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Get-DbaDbStoredProcedure Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbStoredProcedure Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $db1Name = "dbatoolsci_$random" $db1 = New-DbaDatabase -SqlInstance $server -Name $db1Name @@ -62,74 +62,74 @@ Describe "Get-DbaDbStoredProcedure Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { It "Should have standard properties" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name + $results = Get-DbaDbStoredProcedure -SqlInstance $global:instance2 -Database $db1Name $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance' $results[0].PsObject.Properties.Name | Should -Contain $ExpectedProps } It "Should get test procedure: $procName" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name + $results = Get-DbaDbStoredProcedure -SqlInstance $global:instance2 -Database $db1Name $results | Where-Object Name -eq $procName | Should -Not -BeNullOrEmpty } It "Should include system procedures" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name + $results = Get-DbaDbStoredProcedure -SqlInstance $global:instance2 -Database $db1Name $results | Where-Object Name -eq 'sp_columns' | Should -Not -BeNullOrEmpty } } Context "Exclusions work correctly" { It "Should contain no procs from master database" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbStoredProcedure -SqlInstance $global:instance2 -ExcludeDatabase master $results.Database | Should -Not -Contain 'master' } It "Should exclude system procedures" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name -ExcludeSystemSp + $results = Get-DbaDbStoredProcedure -SqlInstance $global:instance2 -Database $db1Name -ExcludeSystemSp $results | Where-Object Name -eq 'sp_helpdb' | Should -BeNullOrEmpty } } Context "Piping works" { It "Should allow piping from string" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name + $results = $global:instance2 | Get-DbaDbStoredProcedure -Database $db1Name $results | Where-Object Name -eq $procName | Should -Not -BeNullOrEmpty } It "Should allow piping from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1Name | Get-DbaDbStoredProcedure + $results = Get-DbaDatabase -SqlInstance $global:instance2 -Database $db1Name | Get-DbaDbStoredProcedure $results | Where-Object Name -eq $procName | Should -Not -BeNullOrEmpty } } Context "Search by name and schema" { It "Search by name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName + $results = $global:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName $results.Name | Should -Be $procName $results.DatabaseId | Should -Be $db1.Id } It "Search by 2 part name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name "$schemaName.$procName2" + $results = $global:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name "$schemaName.$procName2" $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } It "Search by 3 part name and omit the -Database param" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Name "$db1Name.$schemaName.$procName2" + $results = $global:instance2 | Get-DbaDbStoredProcedure -Name "$db1Name.$schemaName.$procName2" $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName $results.Database | Should -Be $db1Name } It "Search by name and schema params" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName2 -Schema $schemaName + $results = $global:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName2 -Schema $schemaName $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } It "Search by schema name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Schema $schemaName + $results = $global:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Schema $schemaName $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } diff --git a/tests/Get-DbaDbSynonym.Tests.ps1 b/tests/Get-DbaDbSynonym.Tests.ps1 index de23294e1c..0788e4a9aa 100644 --- a/tests/Get-DbaDbSynonym.Tests.ps1 +++ b/tests/Get-DbaDbSynonym.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Get-DbaDbSynonym Unit Tests" -Tag "UnitTests" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -46,65 +46,65 @@ Describe "Get-DbaDbSynonym Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb2_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema sch2 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym syn1 -BaseObject obj1 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym syn2 -BaseObject obj2 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Schema sch2 -Synonym syn3 -BaseObject obj2 + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $global:instance2 -Name $dbname2 + $null = New-DbaDbSchema -SqlInstance $global:instance2 -Database $dbname2 -Schema sch2 + $null = New-DbaDbSynonym -SqlInstance $global:instance2 -Database $dbname -Synonym syn1 -BaseObject obj1 + $null = New-DbaDbSynonym -SqlInstance $global:instance2 -Database $dbname2 -Synonym syn2 -BaseObject obj2 + $null = New-DbaDbSynonym -SqlInstance $global:instance2 -Database $dbname2 -Schema sch2 -Synonym syn3 -BaseObject obj2 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $global:instance2 -Confirm:$false } Context "Functionality" { It 'Returns Results' { - $result1 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result1 = Get-DbaDbSynonym -SqlInstance $global:instance2 $result1.Count | Should -BeGreaterThan 0 } It 'Returns all synonyms for all databases' { - $result2 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result2 = Get-DbaDbSynonym -SqlInstance $global:instance2 $uniqueDatabases = $result2.Database | Select-Object -Unique $uniqueDatabases.Count | Should -BeGreaterThan 1 $result2.Count | Should -BeGreaterThan 2 } It 'Accepts a list of databases' { - $result3 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 + $result3 = Get-DbaDbSynonym -SqlInstance $global:instance2 -Database $dbname, $dbname2 $result3.Database | Select-Object -Unique | Should -Be @($dbname, $dbname2) } It 'Excludes databases' { - $result4 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeDatabase $dbname2 + $result4 = Get-DbaDbSynonym -SqlInstance $global:instance2 -ExcludeDatabase $dbname2 $uniqueDatabases = $result4.Database | Select-Object -Unique $uniqueDatabases | Should -Not -Contain $dbname2 } It 'Accepts a list of synonyms' { - $result5 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn1', 'syn2' + $result5 = Get-DbaDbSynonym -SqlInstance $global:instance2 -Synonym 'syn1', 'syn2' $result5.Name | Select-Object -Unique | Should -Be @('syn1', 'syn2') } It 'Excludes synonyms' { - $result6 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSynonym 'syn2' + $result6 = Get-DbaDbSynonym -SqlInstance $global:instance2 -ExcludeSynonym 'syn2' $result6.Name | Select-Object -Unique | Should -Not -Contain 'syn2' } It 'Finds synonyms for specified schema only' { - $result7 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'sch2' + $result7 = Get-DbaDbSynonym -SqlInstance $global:instance2 -Schema 'sch2' $result7.Count | Should -Be 1 } It 'Accepts a list of schemas' { - $result8 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'dbo','sch2' + $result8 = Get-DbaDbSynonym -SqlInstance $global:instance2 -Schema 'dbo','sch2' $result8.Schema | Select-Object -Unique | Should -Be @('dbo','sch2') } It 'Excludes schemas' { - $result9 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSchema 'dbo' + $result9 = Get-DbaDbSynonym -SqlInstance $global:instance2 -ExcludeSchema 'dbo' $result9.Schema | Select-Object -Unique | Should -Not -Contain 'dbo' } diff --git a/tests/Get-DbaDbTable.Tests.ps1 b/tests/Get-DbaDbTable.Tests.ps1 index 93bf6851cb..d2fb23c016 100644 --- a/tests/Get-DbaDbTable.Tests.ps1 +++ b/tests/Get-DbaDbTable.Tests.ps1 @@ -7,14 +7,14 @@ Describe "Get-DbaDbTable" { . "$PSScriptRoot\constants.ps1" $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa + $null = New-DbaDatabase -SqlInstance $global:instance1 -Name $dbname -Owner sa $tablename = "dbatoolssci_$(Get-Random)" - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "Create table $tablename (col1 int)" + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -Database $dbname -Query "Create table $tablename (col1 int)" } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "drop table $tablename" - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -Database $dbname -Query "drop table $tablename" + $null = Remove-DbaDatabase -SqlInstance $global:instance1 -Database $dbname -Confirm:$false } Context "Validate parameters" { @@ -34,7 +34,7 @@ Describe "Get-DbaDbTable" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type String[] } It "Should have IncludeSystemDBs as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSystemDBs -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeSystemDBs -Type Switch } It "Should have Table as a parameter" { $CommandUnderTest | Should -HaveParameter Table -Type String[] @@ -46,24 +46,24 @@ Describe "Get-DbaDbTable" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Should get the table" { It "Gets the table" { - $result = Get-DbaDbTable -SqlInstance $script:instance1 + $result = Get-DbaDbTable -SqlInstance $global:instance1 $result.Name | Should -Contain $tablename } It "Gets the table when you specify the database" { - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname + $result = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname $result.Name | Should -Contain $tablename } } Context "Should not get the table if database is excluded" { It "Doesn't find the table" { - $result = Get-DbaDbTable -SqlInstance $script:instance1 -ExcludeDatabase $dbname + $result = Get-DbaDbTable -SqlInstance $global:instance1 -ExcludeDatabase $dbname $result.Name | Should -Not -Contain $tablename } } diff --git a/tests/Get-DbaDbTrigger.Tests.ps1 b/tests/Get-DbaDbTrigger.Tests.ps1 index ab9b9d8a4a..88a18aa227 100644 --- a/tests/Get-DbaDbTrigger.Tests.ps1 +++ b/tests/Get-DbaDbTrigger.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaDbTrigger Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -29,7 +29,7 @@ Describe "Get-DbaDbTrigger Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbTrigger Integration Tests" -Tag "IntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $trigger = @" CREATE TRIGGER dbatoolsci_safety ON DATABASE @@ -44,14 +44,14 @@ CREATE TRIGGER dbatoolsci_safety } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $trigger = "DROP TRIGGER dbatoolsci_safety ON DATABASE;" $server.Query("$trigger") } Context "Gets Database Trigger" { BeforeAll { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 | Where-Object {$_.name -eq "dbatoolsci_safety"} + $results = Get-DbaDbTrigger -SqlInstance $global:instance2 | Where-Object {$_.name -eq "dbatoolsci_safety"} } It "Gets results" { @@ -69,7 +69,7 @@ CREATE TRIGGER dbatoolsci_safety Context "Gets Database Trigger when using -Database" { BeforeAll { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 -Database Master + $results = Get-DbaDbTrigger -SqlInstance $global:instance2 -Database Master } It "Gets results" { @@ -87,7 +87,7 @@ CREATE TRIGGER dbatoolsci_safety Context "Gets no Database Trigger when using -ExcludeDatabase" { BeforeAll { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 -ExcludeDatabase Master + $results = Get-DbaDbTrigger -SqlInstance $global:instance2 -ExcludeDatabase Master } It "Gets no results" { diff --git a/tests/Get-DbaDbUdf.Tests.ps1 b/tests/Get-DbaDbUdf.Tests.ps1 index a203b40e08..a8d833fde4 100644 --- a/tests/Get-DbaDbUdf.Tests.ps1 +++ b/tests/Get-DbaDbUdf.Tests.ps1 @@ -66,18 +66,18 @@ BEGIN RETURN(@ISOweek); END; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUDFunction -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $CreateTestUDFunction -Database master } AfterAll { $DropTestUDFunction = "DROP FUNCTION dbo.dbatoolssci_ISOweek;" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestUDFunction -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $DropTestUDFunction -Database master } Context "User Functions are correctly located" { BeforeAll { - $results1 = Get-DbaDbUdf -SqlInstance $script:instance2 -Database master -Name dbatoolssci_ISOweek | Select-Object * - $results2 = Get-DbaDbUdf -SqlInstance $script:instance2 + $results1 = Get-DbaDbUdf -SqlInstance $global:instance2 -Database master -Name dbatoolssci_ISOweek | Select-Object * + $results2 = Get-DbaDbUdf -SqlInstance $global:instance2 } It "Should execute and return results" { @@ -102,7 +102,7 @@ END; } It "Should not Throw an Error" { - { Get-DbaDbUdf -SqlInstance $script:instance2 -ExcludeDatabase master -ExcludeSystemUdf } | Should -Not -Throw + { Get-DbaDbUdf -SqlInstance $global:instance2 -ExcludeDatabase master -ExcludeSystemUdf } | Should -Not -Throw } } } diff --git a/tests/Get-DbaDbUser.Tests.ps1 b/tests/Get-DbaDbUser.Tests.ps1 index 6d46de102c..1b25c217f9 100644 --- a/tests/Get-DbaDbUser.Tests.ps1 +++ b/tests/Get-DbaDbUser.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaDbUser Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have ExcludeSystemUser as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemUser -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemUser -Type Switch } It "Should have User as a parameter" { $CommandUnderTest | Should -HaveParameter User -Type String[] @@ -33,7 +33,7 @@ Describe "Get-DbaDbUser Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Login -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -55,7 +55,7 @@ USE Master; CREATE USER [$DBUserName2] FOR LOGIN [$DBUserName2] WITH DEFAULT_SCHEMA = dbo; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUser -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $CreateTestUser -Database master } AfterAll { @@ -65,19 +65,19 @@ DROP USER [$DBUserName2]; DROP LOGIN [$DBUserName]; DROP LOGIN [$DBUserName2]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestUser -Database master + Invoke-DbaQuery -SqlInstance $global:instance2 -Query $DropTestUser -Database master } Context "Users are correctly located" { BeforeAll { - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database master | Where-Object { $_.name -eq "$DBUserName" } | Select-Object * - $results2 = Get-DbaDbUser -SqlInstance $script:instance2 + $results1 = Get-DbaDbUser -SqlInstance $global:instance2 -Database master | Where-Object { $_.name -eq "$DBUserName" } | Select-Object * + $results2 = Get-DbaDbUser -SqlInstance $global:instance2 - $resultsByUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database master -User $DBUserName2 - $resultsByMultipleUser = Get-DbaDbUser -SqlInstance $script:instance2 -User $DBUserName, $DBUserName2 + $resultsByUser = Get-DbaDbUser -SqlInstance $global:instance2 -Database master -User $DBUserName2 + $resultsByMultipleUser = Get-DbaDbUser -SqlInstance $global:instance2 -User $DBUserName, $DBUserName2 - $resultsByLogin = Get-DbaDbUser -SqlInstance $script:instance2 -Database master -Login $DBUserName2 - $resultsByMultipleLogin = Get-DbaDbUser -SqlInstance $script:instance2 -Login $DBUserName, $DBUserName2 + $resultsByLogin = Get-DbaDbUser -SqlInstance $global:instance2 -Database master -Login $DBUserName2 + $resultsByMultipleLogin = Get-DbaDbUser -SqlInstance $global:instance2 -Login $DBUserName, $DBUserName2 } It "Should execute and return results" { @@ -106,7 +106,7 @@ DROP LOGIN [$DBUserName2]; } It "Should not Throw an Error" { - { Get-DbaDbUser -SqlInstance $script:instance2 -ExcludeDatabase master -ExcludeSystemUser } | Should -Not -Throw + { Get-DbaDbUser -SqlInstance $global:instance2 -ExcludeDatabase master -ExcludeSystemUser } | Should -Not -Throw } It "Should return a specific user" { diff --git a/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 b/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 index 3945f3f85c..beca1ea051 100644 --- a/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 +++ b/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Get-DbaDbUserDefinedTableType" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $tabletypename = ("dbatools_{0}" -f $(Get-Random)) $tabletypename1 = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE TYPE $tabletypename AS TABLE([column1] INT NULL)", 'tempdb') @@ -40,7 +40,7 @@ Describe "Get-DbaDbUserDefinedTableType" { Context "Gets a Db User Defined Table Type" { BeforeAll { - $results = Get-DbaDbUserDefinedTableType -SqlInstance $script:instance2 -Database tempdb -Type $tabletypename + $results = Get-DbaDbUserDefinedTableType -SqlInstance $global:instance2 -Database tempdb -Type $tabletypename } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -58,7 +58,7 @@ Describe "Get-DbaDbUserDefinedTableType" { Context "Gets all the Db User Defined Table Type" { BeforeAll { - $results = Get-DbaDbUserDefinedTableType -SqlInstance $script:instance2 -Database tempdb + $results = Get-DbaDbUserDefinedTableType -SqlInstance $global:instance2 -Database tempdb } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDbView.Tests.ps1 b/tests/Get-DbaDbView.Tests.ps1 index ff28989c11..ecf9df2bed 100644 --- a/tests/Get-DbaDbView.Tests.ps1 +++ b/tests/Get-DbaDbView.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaDbView Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have ExcludeSystemView as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemView -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSystemView -Type Switch } It "Should have View as a parameter" { $CommandUnderTest | Should -HaveParameter View -Type String[] @@ -36,7 +36,7 @@ Describe "Get-DbaDbView Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -47,7 +47,7 @@ Describe "Get-DbaDbView Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $viewName = ("dbatoolsci_{0}" -f $(Get-Random)) $viewNameWithSchema = ("dbatoolsci_{0}" -f $(Get-Random)) $server.Query("CREATE VIEW $viewName AS (SELECT 1 as col1)", 'tempdb') @@ -63,7 +63,7 @@ Describe "Get-DbaDbView Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { BeforeAll { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database tempdb + $results = Get-DbaDbView -SqlInstance $global:instance2 -Database tempdb } It "Should have standard properties" { $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance' @@ -79,29 +79,29 @@ Describe "Get-DbaDbView Integration Tests" -Tag "IntegrationTests" { Context "Exclusions work correctly" { It "Should contain no views from master database" { - $results = Get-DbaDbView -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbView -SqlInstance $global:instance2 -ExcludeDatabase master $results.Database | Should -Not -Contain 'master' } It "Should exclude system views" { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database master -ExcludeSystemView + $results = Get-DbaDbView -SqlInstance $global:instance2 -Database master -ExcludeSystemView $results | Where-Object IsSystemObject -eq $true | Should -BeNullOrEmpty } } Context "Piping works" { It "Should allow piping from string" { - $results = $script:instance2 | Get-DbaDbView -Database tempdb + $results = $global:instance2 | Get-DbaDbView -Database tempdb $results | Where-Object Name -eq $viewName | Select-Object -ExpandProperty Name | Should -Be $viewName } It "Should allow piping from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb | Get-DbaDbView + $results = Get-DbaDatabase -SqlInstance $global:instance2 -Database tempdb | Get-DbaDbView $results | Where-Object Name -eq $viewName | Select-Object -ExpandProperty Name | Should -Be $viewName } } - + Context "Schema parameter (see #9445)" { It "Should return just one view with schema 'someschema'" { - $results = $script:instance2 | Get-DbaDbView -Database tempdb -Schema 'someschema' + $results = $global:instance2 | Get-DbaDbView -Database tempdb -Schema 'someschema' $results | Where-Object Name -eq $viewNameWithSchema | Select-Object -ExpandProperty Name | Should -Be $viewNameWithSchema $results | Where-Object Schema -ne 'someschema' | Should -BeNullOrEmpty } diff --git a/tests/Get-DbaDbVirtualLogFile.Tests.ps1 b/tests/Get-DbaDbVirtualLogFile.Tests.ps1 index 9a96332671..212999719d 100644 --- a/tests/Get-DbaDbVirtualLogFile.Tests.ps1 +++ b/tests/Get-DbaDbVirtualLogFile.Tests.ps1 @@ -34,10 +34,10 @@ Describe "Get-DbaDbVirtualLogFile Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDbVirtualLogFile Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $db1 = "dbatoolsci_getvlf" $server.Query("CREATE DATABASE $db1") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $global:instance2 -Database $db1 $setupright = $true if ($needed.Count -ne 1) { $setupright = $false @@ -46,12 +46,12 @@ Describe "Get-DbaDbVirtualLogFile Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $global:instance2 -Database $db1 } Context "Command actually works" { BeforeAll { - $results = Get-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Get-DbaDbVirtualLogFile -SqlInstance $global:instance2 -Database $db1 } It "Should have correct properties" { diff --git a/tests/Get-DbaDbccHelp.Tests.ps1 b/tests/Get-DbaDbccHelp.Tests.ps1 index 1ab06e91e2..cf0314c3e9 100644 --- a/tests/Get-DbaDbccHelp.Tests.ps1 +++ b/tests/Get-DbaDbccHelp.Tests.ps1 @@ -29,21 +29,21 @@ Describe "Get-DbaDbccHelp" { } It "Returns the right results for FREESYSTEMCACHE" { - $result = Get-DbaDbccHelp -SqlInstance $script:instance2 -Statement FREESYSTEMCACHE + $result = Get-DbaDbccHelp -SqlInstance $global:instance2 -Statement FREESYSTEMCACHE $result.Operation | Should -Be 'FREESYSTEMCACHE' $result.Cmd | Should -Be 'DBCC HELP(FREESYSTEMCACHE)' $result.Output | Should -Not -BeNullOrEmpty } It "Returns the right results for PAGE with IncludeUndocumented" { - $result = Get-DbaDbccHelp -SqlInstance $script:instance2 -Statement PAGE -IncludeUndocumented + $result = Get-DbaDbccHelp -SqlInstance $global:instance2 -Statement PAGE -IncludeUndocumented $result.Operation | Should -Be 'PAGE' $result.Cmd | Should -Be 'DBCC HELP(PAGE)' $result.Output | Should -Not -BeNullOrEmpty } It "Returns expected properties" { - $result = Get-DbaDbccHelp -SqlInstance $script:instance2 -Statement FREESYSTEMCACHE + $result = Get-DbaDbccHelp -SqlInstance $global:instance2 -Statement FREESYSTEMCACHE foreach ($prop in $props) { $result.PSObject.Properties.Name | Should -Contain $prop } diff --git a/tests/Get-DbaDbccMemoryStatus.Tests.ps1 b/tests/Get-DbaDbccMemoryStatus.Tests.ps1 index fcfb2024fd..ed06dab95c 100644 --- a/tests/Get-DbaDbccMemoryStatus.Tests.ps1 +++ b/tests/Get-DbaDbccMemoryStatus.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Get-DbaDbccMemoryStatus" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -23,7 +23,7 @@ Describe "Get-DbaDbccMemoryStatus" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'RecordSet', 'RowId', 'RecordSetId', 'Type', 'Name', 'Value', 'ValueType' - $result = Get-DbaDbccMemoryStatus -SqlInstance $script:instance2 + $result = Get-DbaDbccMemoryStatus -SqlInstance $global:instance2 } It "Should return property: <_>" -ForEach $props { diff --git a/tests/Get-DbaDbccProcCache.Tests.ps1 b/tests/Get-DbaDbccProcCache.Tests.ps1 index e659311d59..784e962300 100644 --- a/tests/Get-DbaDbccProcCache.Tests.ps1 +++ b/tests/Get-DbaDbccProcCache.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaDbccProcCache" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -59,7 +59,7 @@ Describe "Get-DbaDbccProcCache" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Count', 'Used', 'Active', 'CacheSize', 'CacheUsed', 'CacheActive' - $result = Get-DbaDbccProcCache -SqlInstance $script:instance2 + $result = Get-DbaDbccProcCache -SqlInstance $global:instance2 } It "Should return property: <_>" -ForEach $props { diff --git a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 index b02dacc82f..4d2f3fedf7 100644 --- a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 +++ b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 @@ -21,22 +21,22 @@ Describe "Get-DbaDbccSessionBuffer" { $CommandUnderTest | Should -HaveParameter RequestId -Type Int32 } It "Should have All parameter" { - $CommandUnderTest | Should -HaveParameter All -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter All -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $global:instance1 -Database tempdb $queryResult = $db.Query('SELECT top 10 object_id, @@Spid as MySpid FROM sys.objects') } Context "Validate standard output for all databases" { It "returns results for InputBuffer" { - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation InputBuffer -All + $result = Get-DbaDbccSessionBuffer -SqlInstance $global:instance1 -Operation InputBuffer -All $result.Count | Should -BeGreaterThan 0 $result[0].PSObject.Properties.Name | Should -Contain 'ComputerName' $result[0].PSObject.Properties.Name | Should -Contain 'InstanceName' @@ -48,7 +48,7 @@ Describe "Get-DbaDbccSessionBuffer" { } It "returns results for OutputBuffer" { - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation OutputBuffer -All + $result = Get-DbaDbccSessionBuffer -SqlInstance $global:instance1 -Operation OutputBuffer -All $result.Count | Should -BeGreaterThan 0 $result[0].PSObject.Properties.Name | Should -Contain 'ComputerName' $result[0].PSObject.Properties.Name | Should -Contain 'InstanceName' @@ -62,13 +62,13 @@ Describe "Get-DbaDbccSessionBuffer" { Context "Validate returns results for SessionId" { It "returns results for InputBuffer" { $spid = $queryResult[0].MySpid - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation InputBuffer -SessionId $spid + $result = Get-DbaDbccSessionBuffer -SqlInstance $global:instance1 -Operation InputBuffer -SessionId $spid $result.SessionId | Should -Be $spid } It "returns results for OutputBuffer" { $spid = $queryResult[0].MySpid - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation OutputBuffer -SessionId $spid + $result = Get-DbaDbccSessionBuffer -SqlInstance $global:instance1 -Operation OutputBuffer -SessionId $spid $result.SessionId | Should -Be $spid } } diff --git a/tests/Get-DbaDbccStatistic.Tests.ps1 b/tests/Get-DbaDbccStatistic.Tests.ps1 index 73ccbb6624..9a64e5bd7e 100644 --- a/tests/Get-DbaDbccStatistic.Tests.ps1 +++ b/tests/Get-DbaDbccStatistic.Tests.ps1 @@ -24,17 +24,17 @@ Describe "Get-DbaDbccStatistic" { $CommandUnderTest | Should -HaveParameter Option -Type String } It "Should have NoInformationalMessages parameter" { - $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . (Join-Path $PSScriptRoot 'constants.ps1') - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -53,12 +53,12 @@ Describe "Get-DbaDbccStatistic" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output for StatHeader option" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option StatHeader + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Option StatHeader } It "returns correct number of results" { @@ -73,7 +73,7 @@ Describe "Get-DbaDbccStatistic" { Context "Validate standard output for DensityVector option" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option DensityVector + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Option DensityVector } It "returns results" { @@ -88,7 +88,7 @@ Describe "Get-DbaDbccStatistic" { Context "Validate standard output for Histogram option" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option Histogram + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Option Histogram } It "returns results" { @@ -103,7 +103,7 @@ Describe "Get-DbaDbccStatistic" { Context "Validate standard output for StatsStream option" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option StatsStream + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Option StatsStream } It "returns results" { @@ -118,7 +118,7 @@ Describe "Get-DbaDbccStatistic" { Context "Validate returns results for single Object" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Object $tableName2 -Option StatsStream + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Object $tableName2 -Option StatsStream } It "returns results" { @@ -128,7 +128,7 @@ Describe "Get-DbaDbccStatistic" { Context "Validate returns results for single Object and Target" { BeforeAll { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Object $tableName2 -Target 'TestStat2' -Option DensityVector + $result = Get-DbaDbccStatistic -SqlInstance $global:instance2 -Database $dbname -Object $tableName2 -Target 'TestStat2' -Option DensityVector } It "returns results" { diff --git a/tests/Get-DbaDbccUserOption.Tests.ps1 b/tests/Get-DbaDbccUserOption.Tests.ps1 index 0c23c69134..41f9ef6787 100644 --- a/tests/Get-DbaDbccUserOption.Tests.ps1 +++ b/tests/Get-DbaDbccUserOption.Tests.ps1 @@ -26,7 +26,7 @@ Describe "Get-DbaDbccUserOption" { Context "Command usage" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Option', 'Value' - $result = Get-DbaDbccUserOption -SqlInstance $script:instance2 + $result = Get-DbaDbccUserOption -SqlInstance $global:instance2 } It "Should return property: <_>" -ForEach $props { @@ -38,7 +38,7 @@ Describe "Get-DbaDbccUserOption" { } It "Should accept an Option value" { - $optionResult = Get-DbaDbccUserOption -SqlInstance $script:instance2 -Option ansi_nulls + $optionResult = Get-DbaDbccUserOption -SqlInstance $global:instance2 -Option ansi_nulls $optionResult | Should -Not -BeNullOrEmpty $optionResult.Option | Should -Be 'ansi_nulls' } diff --git a/tests/Get-DbaDefaultPath.Tests.ps1 b/tests/Get-DbaDefaultPath.Tests.ps1 index c89a1b43d7..55362d29c8 100644 --- a/tests/Get-DbaDefaultPath.Tests.ps1 +++ b/tests/Get-DbaDefaultPath.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaDefaultPath" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { - $results = Get-DbaDefaultPath -SqlInstance $script:instance1 + $results = Get-DbaDefaultPath -SqlInstance $global:instance1 } It "Data returns a value that contains :\" { diff --git a/tests/Get-DbaDependency.Tests.ps1 b/tests/Get-DbaDependency.Tests.ps1 index e7553e5b8c..35a344c37d 100644 --- a/tests/Get-DbaDependency.Tests.ps1 +++ b/tests/Get-DbaDependency.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Get-DbaDependency Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaDependency Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $null = New-DbaDatabase -SqlInstance $global:instance1 -Name $dbname $createTableScript = @" IF OBJECT_ID('dbo.dbatoolsci_nodependencies') IS NOT NULL @@ -114,41 +114,41 @@ ALTER TABLE dbo.dbatoolsci_circrefA ADD CONSTRAINT FK_circref_A_B FOREIGN KEY(BI ALTER TABLE dbo.dbatoolsci_circrefB ADD CONSTRAINT FK_circref_B_A FOREIGN KEY(AID) REFERENCES dbo.dbatoolsci_circrefA (ID) "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $createTableScript + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -Database $dbname -Query $createTableScript } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $global:instance1 -Database $dbname -Confirm:$false } It "Test with a table that has no dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_nodependencies | Get-DbaDependency -Parents + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci_nodependencies | Get-DbaDependency -Parents $results.length | Should -Be 0 } It "Test with a table that has parent dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -Parents + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -Parents $results.length | Should -Be 1 $results[0].Dependent | Should -Be "dbatoolsci1" $results[0].Tier | Should -Be -1 } It "Test with a table that has child dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -IncludeSelf + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -IncludeSelf $results.length | Should -Be 2 $results[1].Dependent | Should -Be "dbatoolsci3" $results[1].Tier | Should -Be 1 } It "Test with a table that has multiple levels of dependencies and use -IncludeSelf" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci3 | Get-DbaDependency -IncludeSelf -Parents + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci3 | Get-DbaDependency -IncludeSelf -Parents $results.length | Should -Be 3 $results[0].Dependent | Should -Be "dbatoolsci1" $results[0].Tier | Should -Be -2 } It "Test with a tables that have circular dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency $results.length | Should -Be 2 $results[0].Dependent | Should -Be "dbatoolsci_circrefB" $results[0].Tier | Should -Be 1 @@ -157,7 +157,7 @@ ALTER TABLE dbo.dbatoolsci_circrefB ADD CONSTRAINT FK_circref_B_A FOREIGN KEY(AI } It "Test with a tables that have circular dependencies and use -IncludeSelf" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf + $results = Get-DbaDbTable -SqlInstance $global:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf $results.length | Should -Be 3 $results[0].Dependent | Should -Be "dbatoolsci_circrefA" $results[0].Tier | Should -Be 0 diff --git a/tests/Get-DbaDeprecatedFeature.Tests.ps1 b/tests/Get-DbaDeprecatedFeature.Tests.ps1 index f8c150c9e0..9a4dd8e087 100644 --- a/tests/Get-DbaDeprecatedFeature.Tests.ps1 +++ b/tests/Get-DbaDeprecatedFeature.Tests.ps1 @@ -58,7 +58,7 @@ Describe "Get-DbaDeprecatedFeature" { Context "Gets Deprecated Features" { BeforeAll { - $results = Get-DbaDeprecatedFeature -SqlInstance $script:instance1 + $results = Get-DbaDeprecatedFeature -SqlInstance $global:instance1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaDump.Tests.ps1 b/tests/Get-DbaDump.Tests.ps1 index eca5cc065d..d39873cd94 100644 --- a/tests/Get-DbaDump.Tests.ps1 +++ b/tests/Get-DbaDump.Tests.ps1 @@ -12,20 +12,20 @@ Describe "Get-DbaDump" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" -Skip:($env:appveyor) { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $global:instance1 $server.Query("DBCC STACKDUMP") $server.Query("DBCC STACKDUMP") } It "finds at least one dump" { - $results = Get-DbaDump -SqlInstance $script:instance1 + $results = Get-DbaDump -SqlInstance $global:instance1 $results.Count | Should -BeGreaterOrEqual 1 } } diff --git a/tests/Get-DbaEndpoint.Tests.ps1 b/tests/Get-DbaEndpoint.Tests.ps1 index ed96a82b26..7cb8294cdd 100644 --- a/tests/Get-DbaEndpoint.Tests.ps1 +++ b/tests/Get-DbaEndpoint.Tests.ps1 @@ -24,23 +24,23 @@ Describe "Get-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 } It "gets some endpoints" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 + $results = Get-DbaEndpoint -SqlInstance $global:instance2 $results.Count | Should -BeGreaterThan 1 $results.Name | Should -Contain 'TSQL Default TCP' } It "gets one endpoint" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' + $results = Get-DbaEndpoint -SqlInstance $global:instance2 -Endpoint 'TSQL Default TCP' $results.Name | Should -Be 'TSQL Default TCP' $results.Count | Should -Be 1 } diff --git a/tests/Get-DbaErrorLog.Tests.ps1 b/tests/Get-DbaErrorLog.Tests.ps1 index 89298fa98c..bd03b82715 100644 --- a/tests/Get-DbaErrorLog.Tests.ps1 +++ b/tests/Get-DbaErrorLog.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaErrorLog" { $CommandUnderTest | Should -HaveParameter Before -Type DateTime } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -37,10 +37,10 @@ Describe "Get-DbaErrorLog" { $sourceFilter = "Logon" $textFilter = "All rights reserved" $login = 'DaperDan' - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $l = Get-DbaLogin -SqlInstance $script:instance1 -Login $login + $server = Connect-DbaInstance -SqlInstance $global:instance1 + $l = Get-DbaLogin -SqlInstance $global:instance1 -Login $login if ($l) { - Get-DbaProcess -SqlInstance $script:instance1 -Login $login | Stop-DbaProcess + Get-DbaProcess -SqlInstance $global:instance1 -Login $login | Stop-DbaProcess $l.Drop() } # (1) Cycle errorlog message: The error log has been reinitialized @@ -50,61 +50,61 @@ Describe "Get-DbaErrorLog" { $pwd = "p0w3rsh3llrules" | ConvertTo-SecureString -Force -AsPlainText $sqlCred = New-Object System.Management.Automation.PSCredential($login, $pwd) try { - Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $sqlCred -ErrorVariable whatever + Connect-DbaInstance -SqlInstance $global:instance1 -SqlCredential $sqlCred -ErrorVariable whatever } catch {} } It "Has the correct default properties" { $expectedProps = 'ComputerName,InstanceName,SqlInstance,LogDate,Source,Text'.Split(',') - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 0 ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($expectedProps | Sort-Object) } It "Returns filtered results for [Source = $sourceFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Source $sourceFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -Source $sourceFilter $results[0].Source | Should -Be $sourceFilter } It "Returns filtered result for [LogNumber = 0] and [Source = $sourceFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 -Source $sourceFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 0 -Source $sourceFilter $results[0].Source | Should -Be $sourceFilter } It "Returns filtered results for [Text = $textFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Text $textFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -Text $textFilter $results[0].Text | Should -BeLike "*$textFilter*" } It "Returns filtered result for [LogNumber = 0] and [Text = $textFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 -Text $textFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 0 -Text $textFilter $results[0].Text | Should -BeLike "*$textFilter*" } It "Returns filtered results for [After = `$afterFilter]" { - $after = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -First 1 + $after = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 | Select-Object -First 1 $afterFilter = $after.LogDate.AddMinutes(+1) - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -After $afterFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -After $afterFilter $results[0].LogDate | Should -BeGreaterOrEqual $afterFilter } It "Returns filtered results for [LogNumber = 1] and [After = `$afterFilter]" { - $after = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -First 1 + $after = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 | Select-Object -First 1 $afterFilter = $after.LogDate.AddMinutes(+1) - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 -After $afterFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 -After $afterFilter $results[0].LogDate | Should -BeGreaterOrEqual $afterFilter } It "Returns filtered result for [Before = `$beforeFilter]" { - $before = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -Last 1 + $before = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 | Select-Object -Last 1 $beforeFilter = $before.LogDate.AddMinutes(-1) - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Before $beforeFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -Before $beforeFilter $results[-1].LogDate | Should -BeLessOrEqual $beforeFilter } It "Returns filtered result for [LogNumber = 1] and [Before = `$beforeFilter]" { - $before = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -Last 1 + $before = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 | Select-Object -Last 1 $beforeFilter = $before.LogDate.AddMinutes(-1) - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 -Before $beforeFilter + $results = Get-DbaErrorLog -SqlInstance $global:instance1 -LogNumber 1 -Before $beforeFilter $results[-1].LogDate | Should -BeLessOrEqual $beforeFilter } } diff --git a/tests/Get-DbaErrorLogConfig.Tests.ps1 b/tests/Get-DbaErrorLogConfig.Tests.ps1 index ad9d51cc92..79bd109d8b 100644 --- a/tests/Get-DbaErrorLogConfig.Tests.ps1 +++ b/tests/Get-DbaErrorLogConfig.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaErrorLogConfig" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -60,7 +60,7 @@ Describe "Get-DbaErrorLogConfig" { Context "Get NumberErrorLog for multiple instances" { BeforeAll { - $results = Get-DbaErrorLogConfig -SqlInstance $script:instance3, $script:instance2 + $results = Get-DbaErrorLogConfig -SqlInstance $global:instance3, $global:instance2 } It 'returns 3 values for each result' { diff --git a/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 b/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 index 5b45f09b81..77ca21f225 100644 --- a/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 +++ b/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaEstimatedCompletionTime" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -28,22 +28,22 @@ Describe "Get-DbaEstimatedCompletionTime" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = Get-DbaDatabase -SqlInstance $server -Database checkdbTestDatabase | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $server -Path $script:appveyorlabrepo\sql2008-backups\db1\SQL2008_db1_FULL_20170518_041738.bak -DatabaseName checkdbTestDatabase + $null = Restore-DbaDatabase -SqlInstance $server -Path $global:appveyorlabrepo\sql2008-backups\db1\SQL2008_db1_FULL_20170518_041738.bak -DatabaseName checkdbTestDatabase $null = New-DbaAgentJob -SqlInstance $server -Job checkdbTestJob $null = New-DbaAgentJobStep -SqlInstance $server -Job checkdbTestJob -StepName checkdb -Subsystem TransactSql -Command "DBCC CHECKDB('checkdbTestDatabase')" } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = Remove-DbaAgentJob -SqlInstance $server -Job checkdbTestJob -Confirm:$false $null = Get-DbaDatabase -SqlInstance $server -Database checkdbTestDatabase | Remove-DbaDatabase -Confirm:$false } Context "Gets Query Estimated Completion" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob $results = Get-DbaEstimatedCompletionTime -SqlInstance $server $null = Remove-DbaAgentJob -SqlInstance $server -Job checkdb -Confirm:$false @@ -63,7 +63,7 @@ Describe "Get-DbaEstimatedCompletionTime" { Context "Gets Query Estimated Completion when using -Database" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob $results = Get-DbaEstimatedCompletionTime -SqlInstance $server -Database checkdbTestDatabase Start-Sleep -Seconds 5 @@ -82,7 +82,7 @@ Describe "Get-DbaEstimatedCompletionTime" { Context "Gets no Query Estimated Completion when using -ExcludeDatabase" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob $results = Get-DbaEstimatedCompletionTime -SqlInstance $server -ExcludeDatabase checkdbTestDatabase Start-Sleep -Seconds 5 diff --git a/tests/Get-DbaExecutionPlan.Tests.ps1 b/tests/Get-DbaExecutionPlan.Tests.ps1 index 16c4176d01..4ac3add27c 100644 --- a/tests/Get-DbaExecutionPlan.Tests.ps1 +++ b/tests/Get-DbaExecutionPlan.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Get-DbaExecutionPlan" { $CommandUnderTest | Should -HaveParameter SinceLastExecution -Type DateTime } It "Should have ExcludeEmptyQueryPlan as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeEmptyQueryPlan -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeEmptyQueryPlan -Type Switch } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -41,7 +41,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets Execution Plan" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 | Where-Object {$_.statementtype -eq 'SELECT'} | Select-Object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 | Where-Object {$_.statementtype -eq 'SELECT'} | Select-Object -First 1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -50,7 +50,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets Execution Plan when using -Database" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master | Select-Object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 -Database Master | Select-Object -First 1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -62,7 +62,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets no Execution Plan when using -ExcludeDatabase" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -ExcludeDatabase Master | Select-Object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 -ExcludeDatabase Master | Select-Object -First 1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -74,7 +74,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets Execution Plan when using -SinceCreation" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master -SinceCreation '01-01-2000' | Select-Object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 -Database Master -SinceCreation '01-01-2000' | Select-Object -First 1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -89,7 +89,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets Execution Plan when using -SinceLastExecution" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master -SinceLastExecution '01-01-2000' | Select-Object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 -Database Master -SinceLastExecution '01-01-2000' | Select-Object -First 1 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -104,7 +104,7 @@ Describe "Get-DbaExecutionPlan" { Context "Gets Execution Plan when using -ExcludeEmptyQueryPlan" { BeforeAll { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -ExcludeEmptyQueryPlan + $results = Get-DbaExecutionPlan -SqlInstance $global:instance2 -ExcludeEmptyQueryPlan } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaExtendedProperty.Tests.ps1 b/tests/Get-DbaExtendedProperty.Tests.ps1 index 1b176de57d..f327ed61cb 100644 --- a/tests/Get-DbaExtendedProperty.Tests.ps1 +++ b/tests/Get-DbaExtendedProperty.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Get-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $global:instance2 $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName diff --git a/tests/Get-DbaExtendedProtection.Tests.ps1 b/tests/Get-DbaExtendedProtection.Tests.ps1 index 095760e083..e9f5e53fd0 100644 --- a/tests/Get-DbaExtendedProtection.Tests.ps1 +++ b/tests/Get-DbaExtendedProtection.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Get-DbaExtendedProtection" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -55,16 +55,16 @@ Describe "Get-DbaExtendedProtection" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { - $results = Get-DbaExtendedProtection -SqlInstance $script:instance1 -EnableException + $results = Get-DbaExtendedProtection -SqlInstance $global:instance1 -EnableException } It "returns a value" { diff --git a/tests/Get-DbaExternalProcess.Tests.ps1 b/tests/Get-DbaExternalProcess.Tests.ps1 index 7bed1d94e1..11301c3a2e 100644 --- a/tests/Get-DbaExternalProcess.Tests.ps1 +++ b/tests/Get-DbaExternalProcess.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaExternalProcess" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Query @" + $null = Invoke-DbaQuery -SqlInstance $global:instance1 -Query @" -- To allow advanced options to be changed. EXECUTE sp_configure 'show advanced options', 1; GO @@ -33,7 +33,7 @@ Describe "Get-DbaExternalProcess" { GO "@ $query = "xp_cmdshell 'powershell -command ""sleep 20""'" - Start-Process -FilePath sqlcmd -ArgumentList "-S $script:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null + Start-Process -FilePath sqlcmd -ArgumentList "-S $global:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null Start-Sleep -Seconds 1 } diff --git a/tests/Get-DbaFeature.Tests.ps1 b/tests/Get-DbaFeature.Tests.ps1 index e8c754f4cf..e27d35a502 100644 --- a/tests/Get-DbaFeature.Tests.ps1 +++ b/tests/Get-DbaFeature.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Get-DbaFeature" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaFile.Tests.ps1 b/tests/Get-DbaFile.Tests.ps1 index e196622b45..d0dc894975 100644 --- a/tests/Get-DbaFile.Tests.ps1 +++ b/tests/Get-DbaFile.Tests.ps1 @@ -27,29 +27,29 @@ Describe "Get-DbaFile" { Context "Returns some files" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $db = "dbatoolsci_getfile$random" $server.Query("CREATE DATABASE $db") } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $db | Remove-DbaDatabase -Confirm:$false } It "Should find the new database file" { - $results = Get-DbaFile -SqlInstance $script:instance2 + $results = Get-DbaFile -SqlInstance $global:instance2 ($results.Filename -match 'dbatoolsci').Count | Should -BeGreaterThan 0 } It "Should find the new database log file" { - $logPath = (Get-DbaDefaultPath -SqlInstance $script:instance2).Log - $results = Get-DbaFile -SqlInstance $script:instance2 -Path $logPath + $logPath = (Get-DbaDefaultPath -SqlInstance $global:instance2).Log + $results = Get-DbaFile -SqlInstance $global:instance2 -Path $logPath ($results.Filename -like '*dbatoolsci*ldf').Count | Should -BeGreaterThan 0 } It "Should find the master database file" { $masterpath = $server.MasterDBPath - $results = Get-DbaFile -SqlInstance $script:instance2 -Path $masterpath + $results = Get-DbaFile -SqlInstance $global:instance2 -Path $masterpath ($results.Filename -match 'master.mdf').Count | Should -BeGreaterThan 0 } } diff --git a/tests/Get-DbaFilestream.Tests.ps1 b/tests/Get-DbaFilestream.Tests.ps1 index be3f472edb..dc321e3b4c 100644 --- a/tests/Get-DbaFilestream.Tests.ps1 +++ b/tests/Get-DbaFilestream.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaFilestream" { Context "Getting FileStream Level" { BeforeAll { - $results = Get-DbaFilestream -SqlInstance $script:instance2 + $results = Get-DbaFilestream -SqlInstance $global:instance2 } It "Should have changed the FileStream Level" { $results.InstanceAccess | Should -BeIn 'Disabled', 'T-SQL access enabled', 'Full access enabled' diff --git a/tests/Get-DbaFirewallRule.Tests.ps1 b/tests/Get-DbaFirewallRule.Tests.ps1 index d73cfa6a10..f7bd9e7e67 100644 --- a/tests/Get-DbaFirewallRule.Tests.ps1 +++ b/tests/Get-DbaFirewallRule.Tests.ps1 @@ -19,13 +19,13 @@ Describe "Get-DbaFirewallRule" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaForceNetworkEncryption.Tests.ps1 b/tests/Get-DbaForceNetworkEncryption.Tests.ps1 index d5a73553d8..55bd50660b 100644 --- a/tests/Get-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Get-DbaForceNetworkEncryption.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Get-DbaForceNetworkEncryption" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -23,7 +23,7 @@ Describe "Get-DbaForceNetworkEncryption" { Context "Integration Tests" -Skip:($env:appveyor) { BeforeAll { - $results = Get-DbaForceNetworkEncryption -SqlInstance $script:instance1 -EnableException + $results = Get-DbaForceNetworkEncryption -SqlInstance $global:instance1 -EnableException } It "returns true or false" { diff --git a/tests/Get-DbaHelpIndex.Tests.ps1 b/tests/Get-DbaHelpIndex.Tests.ps1 index 019fdd22cc..e572434809 100644 --- a/tests/Get-DbaHelpIndex.Tests.ps1 +++ b/tests/Get-DbaHelpIndex.Tests.ps1 @@ -50,7 +50,7 @@ Describe "Get-DbaHelpIndex Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $dbname = "dbatoolsci_$random" $server.Query("CREATE DATABASE $dbname") @@ -65,12 +65,12 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $global:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command works for indexes" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname -ObjectName Test } It 'Results should be returned' { @@ -92,7 +92,7 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { Context "Command works when including statistics" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeStats | Where-Object { $_.Statistics } + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname -ObjectName Test -IncludeStats | Where-Object { $_.Statistics } } It 'Results should be returned' { @@ -106,7 +106,7 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { Context "Command output includes data types" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeDataTypes + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname -ObjectName Test -IncludeDataTypes } It 'Results should be returned' { @@ -120,7 +120,7 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { Context "Formatting is correct" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname -ObjectName Test -IncludeFragmentation } It 'Formatted as strings' { @@ -136,7 +136,7 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { Context "Formatting is correct for raw" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -raw -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname -ObjectName Test -raw -IncludeFragmentation } It 'Formatted as Long' { @@ -154,7 +154,7 @@ Describe "Get-DbaHelpIndex Integration Tests" -Tags "IntegrationTests" { Context "Result is correct for tables having the indexes with the same names" { BeforeAll { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaHelpIndex -SqlInstance $global:instance2 -Database $dbname } It 'Table t1 has correct index key columns and included columns' { diff --git a/tests/Get-DbaHideInstance.Tests.ps1 b/tests/Get-DbaHideInstance.Tests.ps1 index e7b9d84505..3dc7edd0a3 100644 --- a/tests/Get-DbaHideInstance.Tests.ps1 +++ b/tests/Get-DbaHideInstance.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Get-DbaHideInstance" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -58,7 +58,7 @@ Describe "Get-DbaHideInstance" { Context "Command usage" { BeforeAll { - $results = Get-DbaHideInstance -SqlInstance $script:instance1 -EnableException + $results = Get-DbaHideInstance -SqlInstance $global:instance1 -EnableException } It "returns true or false" { diff --git a/tests/Get-DbaInstalledPatch.Tests.ps1 b/tests/Get-DbaInstalledPatch.Tests.ps1 index 79e960e6a8..fd0cbdeb51 100644 --- a/tests/Get-DbaInstalledPatch.Tests.ps1 +++ b/tests/Get-DbaInstalledPatch.Tests.ps1 @@ -58,7 +58,7 @@ Describe "Get-DbaInstalledPatch" { Context "Command usage" { It "Returns output when run against a valid instance" { - $result = Get-DbaInstalledPatch -ComputerName $script:instance1 + $result = Get-DbaInstalledPatch -ComputerName $global:instance1 $result | Should -Not -BeNullOrEmpty } } diff --git a/tests/Get-DbaInstanceAudit.Tests.ps1 b/tests/Get-DbaInstanceAudit.Tests.ps1 index 2a8f6266b3..831c53f749 100644 --- a/tests/Get-DbaInstanceAudit.Tests.ps1 +++ b/tests/Get-DbaInstanceAudit.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Get-DbaInstanceAudit" { $CommandUnderTest | Should -HaveParameter ExcludeAudit -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $global:instance2 $sql = "CREATE SERVER AUDIT LoginAudit TO FILE (FILEPATH = N'C:\temp',MAXSIZE = 10 MB,MAX_ROLLOVER_FILES = 1,RESERVE_DISK_SPACE = OFF) WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE) @@ -49,11 +49,11 @@ Describe "Get-DbaInstanceAudit" { $server.Query($sql) } It "returns some results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 + $results = Get-DbaInstanceAudit -SqlInstance $global:instance2 $results | Should -Not -BeNullOrEmpty } It "returns LoginAudit results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit + $results = Get-DbaInstanceAudit -SqlInstance $global:instance2 -Audit LoginAudit $results.Name | Should -Be 'LoginAudit' $results.Enabled | Should -BeTrue } diff --git a/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 b/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 index d0ad8d830e..8d4ccf3200 100644 --- a/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 +++ b/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaInstanceAuditSpecification" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbaInstanceInstallDate.Tests.ps1 b/tests/Get-DbaInstanceInstallDate.Tests.ps1 index f858cd28a3..e3726c9f65 100644 --- a/tests/Get-DbaInstanceInstallDate.Tests.ps1 +++ b/tests/Get-DbaInstanceInstallDate.Tests.ps1 @@ -21,16 +21,16 @@ Describe "Get-DbaInstanceInstallDate" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have IncludeWindows as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeWindows -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeWindows -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets SQL Server Install Date" { BeforeAll { - $results = Get-DbaInstanceInstallDate -SqlInstance $script:instance2 + $results = Get-DbaInstanceInstallDate -SqlInstance $global:instance2 } It "Gets results" { $results | Should -Not -BeNullOrEmpty @@ -39,7 +39,7 @@ Describe "Get-DbaInstanceInstallDate" { Context "Gets SQL Server Install Date and Windows Install Date" { BeforeAll { - $results = Get-DbaInstanceInstallDate -SqlInstance $script:instance2 -IncludeWindows + $results = Get-DbaInstanceInstallDate -SqlInstance $global:instance2 -IncludeWindows } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaInstanceProperty.Tests.ps1 b/tests/Get-DbaInstanceProperty.Tests.ps1 index 39c7b7fb1b..e7d6803f6c 100644 --- a/tests/Get-DbaInstanceProperty.Tests.ps1 +++ b/tests/Get-DbaInstanceProperty.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Get-DbaInstanceProperty" { Context "Command actually works" { BeforeAll { - $results = Get-DbaInstanceProperty -SqlInstance $script:instance2 + $results = Get-DbaInstanceProperty -SqlInstance $global:instance2 } It "Should have correct properties" { $ExpectedProps = 'ComputerName', 'InstanceName', 'PropertyType', 'SqlInstance' @@ -43,15 +43,15 @@ Describe "Get-DbaInstanceProperty" { ($results | Where-Object { $_.Name -eq 'DisableDefaultConstraintCheck' }).Value | Should -Be $false } It "Should get the correct DefaultFile location" { - $defaultFiles = Get-DbaDefaultPath -SqlInstance $script:instance2 + $defaultFiles = Get-DbaDefaultPath -SqlInstance $global:instance2 ($results | Where-Object { $_.Name -eq 'DefaultFile' }).Value | Should -BeLike "$($defaultFiles.Data)*" } } Context "Property filters work" { BeforeAll { - $resultInclude = Get-DbaInstanceProperty -SqlInstance $script:instance2 -InstanceProperty DefaultFile - $resultExclude = Get-DbaInstanceProperty -SqlInstance $script:instance2 -ExcludeInstanceProperty DefaultFile + $resultInclude = Get-DbaInstanceProperty -SqlInstance $global:instance2 -InstanceProperty DefaultFile + $resultExclude = Get-DbaInstanceProperty -SqlInstance $global:instance2 -ExcludeInstanceProperty DefaultFile } It "Should only return DefaultFile property" { $resultInclude.Name | Should -Contain 'DefaultFile' @@ -63,7 +63,7 @@ Describe "Get-DbaInstanceProperty" { Context "Command can handle multiple instances" { It "Should have results for 2 instances" { - $results = Get-DbaInstanceProperty -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaInstanceProperty -SqlInstance $global:instance1, $global:instance2 ($results | Select-Object -Unique SqlInstance).Count | Should -Be 2 } } diff --git a/tests/Get-DbaInstanceProtocol.Tests.ps1 b/tests/Get-DbaInstanceProtocol.Tests.ps1 index 1dc917ddb6..00d81be74a 100644 --- a/tests/Get-DbaInstanceProtocol.Tests.ps1 +++ b/tests/Get-DbaInstanceProtocol.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Get-DbaInstanceProtocol" { Context "Command actually works" { BeforeAll { - $results = Get-DbaInstanceProtocol -ComputerName $script:instance1, $script:instance2 + $results = Get-DbaInstanceProtocol -ComputerName $global:instance1, $global:instance2 } It "shows some services" { diff --git a/tests/Get-DbaInstanceTrigger.Tests.ps1 b/tests/Get-DbaInstanceTrigger.Tests.ps1 index 4125b292c0..ab12357efa 100644 --- a/tests/Get-DbaInstanceTrigger.Tests.ps1 +++ b/tests/Get-DbaInstanceTrigger.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaInstanceTrigger Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -61,7 +61,7 @@ Describe "Get-DbaInstanceTrigger Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaInstanceTrigger Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $global:instance2 $random = Get-Random $trigger1 = "dbatoolsci_trigger1_$random" $trigger2 = "dbatoolsci_trigger2_$random" @@ -78,7 +78,7 @@ Describe "Get-DbaInstanceTrigger Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { BeforeAll { - $results = Get-DbaInstanceTrigger -SqlInstance $script:instance2 + $results = Get-DbaInstanceTrigger -SqlInstance $global:instance2 } It "Should return results" { diff --git a/tests/Get-DbaInstanceUserOption.Tests.ps1 b/tests/Get-DbaInstanceUserOption.Tests.ps1 index 6130250cfc..253f6c7bac 100644 --- a/tests/Get-DbaInstanceUserOption.Tests.ps1 +++ b/tests/Get-DbaInstanceUserOption.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Get-DbaInstanceUserOption" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Gets UserOptions for the Instance" { BeforeAll { - $results = Get-DbaInstanceUserOption -SqlInstance $script:instance2 | Where-Object {$_.name -eq 'AnsiNullDefaultOff'} + $results = Get-DbaInstanceUserOption -SqlInstance $global:instance2 | Where-Object {$_.name -eq 'AnsiNullDefaultOff'} } It "Gets results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaIoLatency.Tests.ps1 b/tests/Get-DbaIoLatency.Tests.ps1 index 0db653a715..cd9935426f 100644 --- a/tests/Get-DbaIoLatency.Tests.ps1 +++ b/tests/Get-DbaIoLatency.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaIoLatency" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -58,7 +58,7 @@ Describe "Get-DbaIoLatency" { } It "returns results" { - $results = Get-DbaIoLatency -SqlInstance $script:instance2 + $results = Get-DbaIoLatency -SqlInstance $global:instance2 $results.Count | Should -BeGreaterThan 0 } } diff --git a/tests/Get-DbaKbUpdate.Tests.ps1 b/tests/Get-DbaKbUpdate.Tests.ps1 index efed0a55e8..e0a4107566 100644 --- a/tests/Get-DbaKbUpdate.Tests.ps1 +++ b/tests/Get-DbaKbUpdate.Tests.ps1 @@ -13,14 +13,14 @@ Describe "Get-DbaKbUpdate" { It "Should have Name as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Name -Type String[] -Not -Mandatory } - It "Should have Simple as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Simple -Type SwitchParameter -Not -Mandatory + It "Should have Simple as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Simple -Type Switch -Not -Mandatory } It "Should have Language as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Language -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaLastBackup.Tests.ps1 b/tests/Get-DbaLastBackup.Tests.ps1 index 8e8dfe81a8..f0346d08d7 100644 --- a/tests/Get-DbaLastBackup.Tests.ps1 +++ b/tests/Get-DbaLastBackup.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaLastBackup Unit Tests" -Tag 'UnitTests' { $Command | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $Command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -35,7 +35,7 @@ Describe "Get-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $random = Get-Random $dbname = "dbatoolsci_getlastbackup$random" $server.Query("CREATE DATABASE $dbname") @@ -47,13 +47,13 @@ Describe "Get-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false Remove-Item -Path $backupdir -Recurse -Force -ErrorAction SilentlyContinue } Context "Get null history for database" { It "doesn't have any values for last backups because none exist yet" { - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaLastBackup -SqlInstance $env:instance2 -Database $dbname $results.LastFullBackup | Should -BeNullOrEmpty $results.LastDiffBackup | Should -BeNullOrEmpty $results.LastLogBackup | Should -BeNullOrEmpty @@ -63,10 +63,10 @@ Describe "Get-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Get last history for single database" { It "returns a date within the proper range" { $yesterday = (Get-Date).AddDays(-1) - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Differential - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Log - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Differential + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Log + $results = Get-DbaLastBackup -SqlInstance $global:instance2 -Database $dbname [datetime]$results.LastFullBackup | Should -BeGreaterThan $yesterday [datetime]$results.LastDiffBackup | Should -BeGreaterThan $yesterday [datetime]$results.LastLogBackup | Should -BeGreaterThan $yesterday @@ -75,7 +75,7 @@ Describe "Get-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Get last history for all databases" { It "returns more than 3 databases" { - $results = Get-DbaLastBackup -SqlInstance $script:instance2 + $results = Get-DbaLastBackup -SqlInstance $global:instance2 $results.count | Should -BeGreaterThan 3 $results.Database | Should -Contain $dbname } @@ -83,28 +83,28 @@ Describe "Get-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Get last history for one split database" { It "supports multi-file backups" { - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -FileCount 4 - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname | Select-Object -First 1 + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -FileCount 4 + $results = Get-DbaLastBackup -SqlInstance $global:instance2 -Database $dbname | Select-Object -First 1 $results.LastFullBackup | Should -BeOfType [DbaDateTime] } } Context "Filter backups" { It "by 'is_copy_only'" { - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full -CopyOnly - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log -CopyOnly + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full -CopyOnly + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log -CopyOnly - $results = Get-DbaLastBackup -SqlInstance $script:instance2 + $results = Get-DbaLastBackup -SqlInstance $global:instance2 $copyOnlyFullBackup = ($results | Where-Object { $_.Database -eq $dbname -and $_.LastFullBackupIsCopyOnly -eq $true }) $copyOnlyLogBackup = ($results | Where-Object { $_.Database -eq $dbname -and $_.LastLogBackupIsCopyOnly -eq $true }) $copyOnlyFullBackup.Database | Should -Be $dbname $copyOnlyLogBackup.Database | Should -Be $dbname - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full + $null = Backup-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaLastBackup -SqlInstance $global:instance2 -Database $dbname $results.LastFullBackupIsCopyOnly | Should -Be $false $results.LastLogBackupIsCopyOnly | Should -Be $false diff --git a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 index 7ad47fa272..9c838a9f5f 100644 --- a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 +++ b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 @@ -21,35 +21,35 @@ Describe "Get-DbaLastGoodCheckDb" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + $server = Connect-DbaInstance -SqlInstance $env:instance1 -Database master $server.Query("DBCC CHECKDB") $dbname = "dbatoolsci_]_$(Get-Random)" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname -Owner sa $db.Query("DBCC CHECKDB") } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "LastGoodCheckDb is a valid date" { - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -Database master + $results = Get-DbaLastGoodCheckDb -SqlInstance $env:instance1 -Database master $results.LastGoodCheckDb | Should -Not -BeNullOrEmpty $results.LastGoodCheckDb | Should -BeOfType [datetime] } It "returns more than 3 results" { - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -WarningAction SilentlyContinue + $results = Get-DbaLastGoodCheckDb -SqlInstance $env:instance1 -WarningAction SilentlyContinue $results.Count | Should -BeGreaterThan 3 } It "LastGoodCheckDb is a valid date for database with embedded ] characters" { - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -Database $dbname + $results = Get-DbaLastGoodCheckDb -SqlInstance $env:instance1 -Database $dbname $results.LastGoodCheckDb | Should -Not -BeNullOrEmpty $results.LastGoodCheckDb | Should -BeOfType [datetime] } @@ -57,12 +57,12 @@ Describe "Get-DbaLastGoodCheckDb" { Context "Piping works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $dbname = "dbatoolsci_]_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa + $null = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname -Owner sa } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "LastGoodCheckDb accepts piped input from Connect-DbaInstance" { @@ -71,7 +71,7 @@ Describe "Get-DbaLastGoodCheckDb" { } It "LastGoodCheckDb accepts piped input from Get-DbaDatabase" { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, master + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbname, master $results = $db | Get-DbaLastGoodCheckDb $results.Count | Should -Be 2 } @@ -80,10 +80,10 @@ Describe "Get-DbaLastGoodCheckDb" { Context "Doesn't return duplicate results" { It "LastGoodCheckDb doesn't return duplicates when multiple servers are passed in" { $dbname = "dbatoolsci_]_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1, $script:instance2 -Database $dbname + $null = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname -Owner sa + $results = Get-DbaLastGoodCheckDb -SqlInstance $env:instance1, $env:instance2 -Database $dbname ($results | Group-Object SqlInstance, Database | Where-Object Count -gt 1) | Should -BeNullOrEmpty - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } } } diff --git a/tests/Get-DbaLatchStatistic.Tests.ps1 b/tests/Get-DbaLatchStatistic.Tests.ps1 index 13c45e3584..b06006e8de 100644 --- a/tests/Get-DbaLatchStatistic.Tests.ps1 +++ b/tests/Get-DbaLatchStatistic.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Get-DbaLatchStatistic" { $CommandUnderTest | Should -HaveParameter Threshold -Type Int32 -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command returns proper info" { BeforeAll { - $results = Get-DbaLatchStatistic -SqlInstance $script:instance2 -Threshold 100 + $results = Get-DbaLatchStatistic -SqlInstance $env:instance2 -Threshold 100 } It "returns results" { diff --git a/tests/Get-DbaLinkedServer.Tests.ps1 b/tests/Get-DbaLinkedServer.Tests.ps1 index f1b949c0b7..747f0a3a1d 100644 --- a/tests/Get-DbaLinkedServer.Tests.ps1 +++ b/tests/Get-DbaLinkedServer.Tests.ps1 @@ -30,24 +30,24 @@ Describe "Get-DbaLinkedServer" { Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $null = $server.Query("EXEC master.dbo.sp_addlinkedserver - @server = N'$script:instance3', + @server = N'$env:instance3', @srvproduct=N'SQL Server' ;") } AfterAll { - $null = $server.Query("EXEC master.dbo.sp_dropserver '$script:instance3', 'droplogins'; ") + $null = $server.Query("EXEC master.dbo.sp_dropserver '$env:instance3', 'droplogins'; ") } Context "Gets Linked Servers" { BeforeAll { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 | Where-Object {$_.name -eq "$script:instance3"} + $results = Get-DbaLinkedServer -SqlInstance $env:instance2 | Where-Object {$_.name -eq "$env:instance3"} } It "Gets results" { $results | Should -Not -BeNullOrEmpty } - It "Should have Remote Server of $script:instance3" { - $results.RemoteServer | Should -Be "$script:instance3" + It "Should have Remote Server of $env:instance3" { + $results.RemoteServer | Should -Be "$env:instance3" } It "Should have a product name of SQL Server" { $results.productname | Should -Be 'SQL Server' @@ -59,13 +59,13 @@ Describe "Get-DbaLinkedServer" { Context "Gets Linked Servers using -LinkedServer" { BeforeAll { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer "$script:instance3" + $results = Get-DbaLinkedServer -SqlInstance $env:instance2 -LinkedServer "$env:instance3" } It "Gets results" { $results | Should -Not -BeNullOrEmpty } - It "Should have Remote Server of $script:instance3" { - $results.RemoteServer | Should -Be "$script:instance3" + It "Should have Remote Server of $env:instance3" { + $results.RemoteServer | Should -Be "$env:instance3" } It "Should have a product name of SQL Server" { $results.productname | Should -Be 'SQL Server' @@ -77,7 +77,7 @@ Describe "Get-DbaLinkedServer" { Context "Gets Linked Servers using -ExcludeLinkedServer" { BeforeAll { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -ExcludeLinkedServer "$script:instance3" + $results = Get-DbaLinkedServer -SqlInstance $env:instance2 -ExcludeLinkedServer "$env:instance3" } It "Gets results" { $results | Should -BeNullOrEmpty diff --git a/tests/Get-DbaLinkedServerLogin.Tests.ps1 b/tests/Get-DbaLinkedServerLogin.Tests.ps1 index 6f5f0c74b8..fb428f2f17 100644 --- a/tests/Get-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Get-DbaLinkedServerLogin.Tests.ps1 @@ -7,8 +7,8 @@ Describe "Get-DbaLinkedServerLogin" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 + $server3 = Connect-DbaInstance -SqlInstance $env:instance3 $securePassword = ConvertTo-SecureString -String 's3cur3P4ssw0rd?' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -78,7 +78,7 @@ Describe "Get-DbaLinkedServerLogin" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaLogin.Tests.ps1 b/tests/Get-DbaLogin.Tests.ps1 index b7ba9d6ca6..eecebb9b2e 100644 --- a/tests/Get-DbaLogin.Tests.ps1 +++ b/tests/Get-DbaLogin.Tests.ps1 @@ -8,12 +8,12 @@ Describe "Get-DbaLogin" { $random = Get-Random $password = ConvertTo-SecureString -String "password1A@" -AsPlainText -Force - New-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Password $password - New-DbaLogin -SqlInstance $script:instance1 -Login "testlogin2_$random" -Password $password + New-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Password $password + New-DbaLogin -SqlInstance $env:instance1 -Login "testlogin2_$random" -Password $password } AfterAll { - Remove-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force + Remove-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force } Context "Validate parameters" { @@ -66,25 +66,25 @@ Describe "Get-DbaLogin" { Context "Does sql instance have a SA account" { It "Should report that one account named SA exists" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login sa $results.Count | Should -Be 1 } } Context "Check that SA account is enabled" { It "Should say the SA account is disabled FALSE" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login sa $results.IsDisabled | Should -Be "False" } } Context "Check that SA account is SQL Login" { It "Should report that one SQL Login named SA exists" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa -Type SQL -Detailed + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login sa -Type SQL -Detailed $results.Count | Should -Be 1 } It "Should get LoginProperties via Detailed switch" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa -Type SQL -Detailed + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login sa -Type SQL -Detailed $results.BadPasswordCount | Should -Not -BeNullOrEmpty $results.PasswordHash | Should -Not -BeNullOrEmpty } @@ -92,55 +92,55 @@ Describe "Get-DbaLogin" { Context "Validate params" { It "Multiple logins" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Type SQL $results.Count | Should -Be 2 $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "ExcludeLogin" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeLogin "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -ExcludeLogin "testlogin2_$random" -Type SQL $results.Name | Should -Not -Contain "testlogin2_$random" $results.Name | Should -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeLogin "testlogin1_$random", "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -ExcludeLogin "testlogin1_$random", "testlogin2_$random" -Type SQL $results.Name | Should -Not -Contain "testlogin2_$random" $results.Name | Should -Not -Contain "testlogin1_$random" } It "IncludeFilter" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -IncludeFilter "*$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -IncludeFilter "*$random" -Type SQL $results.Count | Should -Be 2 $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "ExcludeFilter" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeFilter "*$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -ExcludeFilter "*$random" -Type SQL $results.Name | Should -Not -Contain "testlogin1_$random" $results.Name | Should -Not -Contain "testlogin2_$random" } It "ExcludeSystemLogin" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeSystemLogin -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -ExcludeSystemLogin -Type SQL $results.Name | Should -Not -Contain "sa" } It "HasAccess" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -HasAccess -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -HasAccess -Type SQL $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "Disabled" { - $null = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Disable - $result = Get-DbaLogin -SqlInstance $script:instance1 -Disabled + $null = Set-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Disable + $result = Get-DbaLogin -SqlInstance $env:instance1 -Disabled $result.Name | Should -Contain "testlogin1_$random" - $null = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Enable + $null = Set-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Enable } It "Detailed" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Detailed -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -Detailed -Type SQL $results.Count | Should -BeGreaterOrEqual 2 @@ -155,10 +155,10 @@ Describe "Get-DbaLogin" { } It "MustChangePassword" { - $changeResult = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -MustChange -Password $password -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -MustChange -Password $password -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.MustChangePassword | Should -Be $true - $result = Get-DbaLogin -SqlInstance $script:instance1 -MustChangePassword + $result = Get-DbaLogin -SqlInstance $env:instance1 -MustChangePassword $result.Name | Should -Contain "testlogin1_$random" } } @@ -168,7 +168,7 @@ Describe "Get-DbaLogin" { $SkipLocalTest = [Environment]::GetEnvironmentVariable('SkipLocalTest') -eq $true } It "Should lock and unlock a login" -Skip:$SkipLocalTest { - $results = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $results = Set-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $results.PasswordPolicyEnforced | Should -Be $true # simulate a lockout @@ -178,26 +178,26 @@ Describe "Get-DbaLogin" { # exceed the lockout count for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $env:instance1 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 } } - $results = Get-DbaLogin -SqlInstance $script:instance1 -Locked + $results = Get-DbaLogin -SqlInstance $env:instance1 -Locked $results.Name | Should -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Type SQL $results.IsLocked | Should -Be $true - $results = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Unlock -Force + $results = Set-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Unlock -Force $results.IsLocked | Should -Be $false - $results = Get-DbaLogin -SqlInstance $script:instance1 -Locked + $results = Get-DbaLogin -SqlInstance $env:instance1 -Locked $results.Name | Should -Not -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $env:instance1 -Login "testlogin1_$random" -Type SQL $results.IsLocked | Should -Be $false } } diff --git a/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 b/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 index 37fd77bc97..3518c80735 100644 --- a/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 +++ b/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 @@ -27,13 +27,13 @@ Describe "Get-DbaMaintenanceSolutionLog" { $CommandUnderTest | Should -HaveParameter Path -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaManagementObject.Tests.ps1 b/tests/Get-DbaManagementObject.Tests.ps1 index fb1f455731..de25b31219 100644 --- a/tests/Get-DbaManagementObject.Tests.ps1 +++ b/tests/Get-DbaManagementObject.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Get-DbaManagementObject" { $CommandUnderTest | Should -HaveParameter VersionNumber -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaMaxMemory.Tests.ps1 b/tests/Get-DbaMaxMemory.Tests.ps1 index 58a159d4a1..65cc2aa627 100644 --- a/tests/Get-DbaMaxMemory.Tests.ps1 +++ b/tests/Get-DbaMaxMemory.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Get-DbaMaxMemory" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -51,7 +51,7 @@ Describe "Get-DbaMaxMemory" { Context "Connects to multiple instances" -Skip:$env:CI { BeforeAll { - $instances = $script:instance1, $script:instance2 + $instances = $env:instance1, $env:instance2 } It 'Returns multiple objects' { @@ -61,7 +61,7 @@ Describe "Get-DbaMaxMemory" { It 'Returns the right amount of memory' { $null = Set-DbaMaxMemory -SqlInstance $instances -Max 1024 - $results = Get-DbaMaxMemory -SqlInstance $script:instance1 + $results = Get-DbaMaxMemory -SqlInstance $env:instance1 $results.MaxValue | Should -Be 1024 } } diff --git a/tests/Get-DbaMemoryCondition.Tests.ps1 b/tests/Get-DbaMemoryCondition.Tests.ps1 index 1b30829bd1..9ba4e14135 100644 --- a/tests/Get-DbaMemoryCondition.Tests.ps1 +++ b/tests/Get-DbaMemoryCondition.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaMemoryCondition" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -60,7 +60,7 @@ Describe "Get-DbaMemoryCondition Integration Test" -Tag "IntegrationTests" { Context "Command actually works" { BeforeAll { - $results = Get-DbaMemoryCondition -SqlInstance $script:instance1 + $results = Get-DbaMemoryCondition -SqlInstance $env:instance1 } It "returns results" { diff --git a/tests/Get-DbaMemoryUsage.Tests.ps1 b/tests/Get-DbaMemoryUsage.Tests.ps1 index 6ef70fc18f..67b3cd5292 100644 --- a/tests/Get-DbaMemoryUsage.Tests.ps1 +++ b/tests/Get-DbaMemoryUsage.Tests.ps1 @@ -32,14 +32,14 @@ Describe "Get-DbaMemoryUsage" { $CommandUnderTest | Should -HaveParameter SSISCounterRegex -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Get-DbaMemoryUsage -ComputerName $script:instance1 - $resultsSimple = Get-DbaMemoryUsage -ComputerName $script:instance1 + $results = Get-DbaMemoryUsage -ComputerName $env:instance1 + $resultsSimple = Get-DbaMemoryUsage -ComputerName $env:instance1 } It "returns results" { diff --git a/tests/Get-DbaModule.Tests.ps1 b/tests/Get-DbaModule.Tests.ps1 index bcbe0c0746..a3d1cf53d3 100644 --- a/tests/Get-DbaModule.Tests.ps1 +++ b/tests/Get-DbaModule.Tests.ps1 @@ -45,7 +45,7 @@ Describe "Get-DbaModule" { Context "Modules are properly retrieved" { BeforeAll { - $results = Get-DbaModule -SqlInstance $script:instance1 | Select-Object -First 101 + $results = Get-DbaModule -SqlInstance $env:instance1 | Select-Object -First 101 } It "Should have a high count" { @@ -53,19 +53,19 @@ Describe "Get-DbaModule" { } It "Should only have one type of object when filtering by View" { - $viewResults = Get-DbaModule -SqlInstance $script:instance1 -Type View -Database msdb + $viewResults = Get-DbaModule -SqlInstance $env:instance1 -Type View -Database msdb ($viewResults | Select-Object -Unique Type | Measure-Object).Count | Should -Be 1 } It "Should only have one database when filtering by msdb" { - $msdbResults = Get-DbaModule -SqlInstance $script:instance1 -Type View -Database msdb + $msdbResults = Get-DbaModule -SqlInstance $env:instance1 -Type View -Database msdb ($msdbResults | Select-Object -Unique Database | Measure-Object).Count | Should -Be 1 } } Context "Accepts Piped Input" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database msdb, master + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database msdb, master $results = $db | Get-DbaModule } @@ -78,12 +78,12 @@ Describe "Get-DbaModule" { } It "Should only have one type of object when filtering by View" { - $viewResults = Get-DbaDatabase -SqlInstance $script:instance1 -Database msdb | Get-DbaModule -Type View + $viewResults = Get-DbaDatabase -SqlInstance $env:instance1 -Database msdb | Get-DbaModule -Type View ($viewResults | Select-Object -Unique Type | Measure-Object).Count | Should -Be 1 } It "Should only have one database when filtering by msdb" { - $msdbResults = Get-DbaDatabase -SqlInstance $script:instance1 -Database msdb | Get-DbaModule -Type View + $msdbResults = Get-DbaDatabase -SqlInstance $env:instance1 -Database msdb | Get-DbaModule -Type View ($msdbResults | Select-Object -Unique Database | Measure-Object).Count | Should -Be 1 } } diff --git a/tests/Get-DbaMsdtc.Tests.ps1 b/tests/Get-DbaMsdtc.Tests.ps1 index 9b84d0ae82..3246f0f71c 100644 --- a/tests/Get-DbaMsdtc.Tests.ps1 +++ b/tests/Get-DbaMsdtc.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Get-DbaMsdtc" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaNetworkCertificate.Tests.ps1 b/tests/Get-DbaNetworkCertificate.Tests.ps1 index 7aa474a7fc..cf6baef1d4 100644 --- a/tests/Get-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Get-DbaNetworkCertificate.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaNetworkCertificate" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaNetworkConfiguration.Tests.ps1 b/tests/Get-DbaNetworkConfiguration.Tests.ps1 index dfae8fc766..125650133c 100644 --- a/tests/Get-DbaNetworkConfiguration.Tests.ps1 +++ b/tests/Get-DbaNetworkConfiguration.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaNetworkConfiguration" { $CommandUnderTest | Should -HaveParameter OutputType -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -24,8 +24,8 @@ Describe "Get-DbaNetworkConfiguration" { . (Join-Path $PSScriptRoot 'constants.ps1') } BeforeAll { - $resultsFull = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 - $resultsTcpIpProperties = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 -OutputType TcpIpProperties + $resultsFull = Get-DbaNetworkConfiguration -SqlInstance $env:instance2 + $resultsTcpIpProperties = Get-DbaNetworkConfiguration -SqlInstance $env:instance2 -OutputType TcpIpProperties } It "Should Return a Result" { diff --git a/tests/Get-DbaOleDbProvider.Tests.ps1 b/tests/Get-DbaOleDbProvider.Tests.ps1 index e1a7a87a0a..11df0f1f51 100644 --- a/tests/Get-DbaOleDbProvider.Tests.ps1 +++ b/tests/Get-DbaOleDbProvider.Tests.ps1 @@ -61,7 +61,7 @@ Describe "Get-DbaOleDbProvider" { . (Join-Path $PSScriptRoot 'constants.ps1') } - It "Returns output when executed against <_>" -ForEach $script:instance1, $script:instance2 { + It "Returns output when executed against <_>" -ForEach $env:instance1, $env:instance2 { $result = Get-DbaOleDbProvider -SqlInstance $_ $result | Should -Not -BeNullOrEmpty } diff --git a/tests/Get-DbaOpenTransaction.Tests.ps1 b/tests/Get-DbaOpenTransaction.Tests.ps1 index 7563bdd738..41619475fe 100644 --- a/tests/Get-DbaOpenTransaction.Tests.ps1 +++ b/tests/Get-DbaOpenTransaction.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaOpenTransaction" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -60,7 +60,7 @@ Describe "Get-DbaOpenTransaction" { Context "Command execution" { It "doesn't throw" { - { Get-DbaOpenTransaction -SqlInstance $script:instance1 } | Should -Not -Throw + { Get-DbaOpenTransaction -SqlInstance $env:instance1 } | Should -Not -Throw } } } diff --git a/tests/Get-DbaOperatingSystem.Tests.ps1 b/tests/Get-DbaOperatingSystem.Tests.ps1 index 729ee023b7..dc7a82ce40 100644 --- a/tests/Get-DbaOperatingSystem.Tests.ps1 +++ b/tests/Get-DbaOperatingSystem.Tests.ps1 @@ -16,7 +16,7 @@ Describe "Get-DbaOperatingSystem" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,7 +29,7 @@ Describe "Get-DbaOperatingSystem" { Context "Get-DbaOperatingSystem Integration Test" -Tag "IntegrationTests" { BeforeAll { - $result = Get-DbaOperatingSystem -ComputerName $script:instance1 + $result = Get-DbaOperatingSystem -ComputerName $env:instance1 $props = 'ComputerName', 'Manufacturer', 'Organization', 'Architecture', 'Build', 'Version', 'InstallDate', 'LastBootTime', 'LocalDateTime', diff --git a/tests/Get-DbaPbmCategory.Tests.ps1 b/tests/Get-DbaPbmCategory.Tests.ps1 index 41fca77a1b..b6ba89e01b 100644 --- a/tests/Get-DbaPbmCategory.Tests.ps1 +++ b/tests/Get-DbaPbmCategory.Tests.ps1 @@ -24,16 +24,16 @@ Describe "Get-DbaPbmCategory" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] -Not -Mandatory } It "Should have ExcludeSystemObject as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemObject -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeSystemObject -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 + $results = Get-DbaPbmCategory -SqlInstance $env:instance2 } It "Gets Results" { $results | Should -Not -BeNullOrEmpty @@ -42,7 +42,7 @@ Describe "Get-DbaPbmCategory" { Context "Command actually works using -Category" { BeforeAll { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 -Category 'Availability database errors' + $results = Get-DbaPbmCategory -SqlInstance $env:instance2 -Category 'Availability database errors' } It "Gets Results" { $results | Should -Not -BeNullOrEmpty @@ -51,7 +51,7 @@ Describe "Get-DbaPbmCategory" { Context "Command actually works using -ExcludeSystemObject" { BeforeAll { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 -ExcludeSystemObject + $results = Get-DbaPbmCategory -SqlInstance $env:instance2 -ExcludeSystemObject } It "Gets Results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaPbmCondition.Tests.ps1 b/tests/Get-DbaPbmCondition.Tests.ps1 index 882a859163..7f138ab2e6 100644 --- a/tests/Get-DbaPbmCondition.Tests.ps1 +++ b/tests/Get-DbaPbmCondition.Tests.ps1 @@ -52,7 +52,7 @@ Describe "Get-DbaPbmCondition Integration Tests" -Tag "IntegrationTests" { SELECT @condition_id AS conditionId "@ - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $conditionId = $server.Query($conditionQuery) | Select-Object -ExpandProperty conditionId } @@ -63,24 +63,24 @@ Describe "Get-DbaPbmCondition Integration Tests" -Tag "IntegrationTests" { Context "Command returns results" { It "Should get results" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 + $results = Get-DbaPbmCondition -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should have name property '$conditionName'" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 + $results = Get-DbaPbmCondition -SqlInstance $env:instance2 $results.Name | Should -Contain $conditionName } } Context "Command actually works by condition name" { It "Should get results" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 -Condition $conditionName + $results = Get-DbaPbmCondition -SqlInstance $env:instance2 -Condition $conditionName $results | Should -Not -BeNullOrEmpty } It "Should have name property '$conditionName'" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 -Condition $conditionName + $results = Get-DbaPbmCondition -SqlInstance $env:instance2 -Condition $conditionName $results.Name | Should -Be $conditionName } } diff --git a/tests/Get-DbaPbmObjectSet.Tests.ps1 b/tests/Get-DbaPbmObjectSet.Tests.ps1 index 548137c9c2..9389130687 100644 --- a/tests/Get-DbaPbmObjectSet.Tests.ps1 +++ b/tests/Get-DbaPbmObjectSet.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Get-DbaPbmObjectSet" { # Add your integration tests here # Example: # It "Should return object sets" { - # $results = Get-DbaPbmObjectSet -SqlInstance $script:instance1 + # $results = Get-DbaPbmObjectSet -SqlInstance $env:instance1 # $results | Should -Not -BeNullOrEmpty # } } diff --git a/tests/Get-DbaPbmPolicy.Tests.ps1 b/tests/Get-DbaPbmPolicy.Tests.ps1 index 6c0808e7c4..32eb37859a 100644 --- a/tests/Get-DbaPbmPolicy.Tests.ps1 +++ b/tests/Get-DbaPbmPolicy.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Get-DbaPbmPolicy" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] } It "Should have IncludeSystemObject as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSystemObject -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeSystemObject -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -63,7 +63,7 @@ Describe "Get-DbaPbmPolicy" { EXEC msdb.dbo.sp_syspolicy_add_policy @name=N'dbatoolsci_TestPolicy', @condition_name=N'dbatoolsci_Condition', @policy_category=N'', @description=N'', @help_text=N'', @help_link=N'', @schedule_uid=N'00000000-0000-0000-0000-000000000000', @execution_mode=2, @is_enabled=True, @policy_id=@policy_id OUTPUT, @root_condition_name=N'', @object_set=N'dbatoolsci_TestPolicy_ObjectSet' SELECT @policy_id" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $conditionid = $server.ConnectionContext.ExecuteScalar($sqlconditionid) $objectsetid = $server.ConnectionContext.ExecuteScalar($sqlobjectsetid) $policyid = $server.ConnectionContext.ExecuteScalar($sqlpolicyid) @@ -76,17 +76,17 @@ Describe "Get-DbaPbmPolicy" { } It "returns the test policy" { - $results = Get-DbaPbmPolicy -SqlInstance $script:instance2 + $results = Get-DbaPbmPolicy -SqlInstance $env:instance2 $results.Name | Should -Contain 'dbatoolsci_TestPolicy' } It "returns only the test policy named dbatoolsci_TestPolicy" { - $results = Get-DbaPbmPolicy -SqlInstance $script:instance2 -Policy dbatoolsci_TestPolicy + $results = Get-DbaPbmPolicy -SqlInstance $env:instance2 -Policy dbatoolsci_TestPolicy $results.Name | Should -Be 'dbatoolsci_TestPolicy' } It "returns a policy with a condition named dbatoolsci_Condition" { - $results = Get-DbaPbmPolicy -SqlInstance $script:instance2 -Policy dbatoolsci_TestPolicy + $results = Get-DbaPbmPolicy -SqlInstance $env:instance2 -Policy dbatoolsci_TestPolicy $results.Condition | Should -Be 'dbatoolsci_Condition' } } diff --git a/tests/Get-DbaPbmStore.Tests.ps1 b/tests/Get-DbaPbmStore.Tests.ps1 index f84f196c03..e1261af985 100644 --- a/tests/Get-DbaPbmStore.Tests.ps1 +++ b/tests/Get-DbaPbmStore.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaPbmStore" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbaPermission.Tests.ps1 b/tests/Get-DbaPermission.Tests.ps1 index 79c346bae0..7520ca7509 100644 --- a/tests/Get-DbaPermission.Tests.ps1 +++ b/tests/Get-DbaPermission.Tests.ps1 @@ -37,7 +37,7 @@ Describe "Get-DbaPermission Unit Tests" -Tag 'UnitTests' { Describe "Get-DbaPermission Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = $script:instance1 + $server = $env:instance1 $random = Get-Random $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force diff --git a/tests/Get-DbaPfAvailableCounter.Tests.ps1 b/tests/Get-DbaPfAvailableCounter.Tests.ps1 index 978b0cce46..fd94e467c6 100644 --- a/tests/Get-DbaPfAvailableCounter.Tests.ps1 +++ b/tests/Get-DbaPfAvailableCounter.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaPfAvailableCounter" { $CommandUnderTest | Should -HaveParameter Pattern -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaPfDataCollector.Tests.ps1 b/tests/Get-DbaPfDataCollector.Tests.ps1 index b6b3e2f28b..81086cf2ff 100644 --- a/tests/Get-DbaPfDataCollector.Tests.ps1 +++ b/tests/Get-DbaPfDataCollector.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaPfDataCollector" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 index b3fc173c23..65d2c9a165 100644 --- a/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Get-DbaPfDataCollectorCounter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 index a6a49cdcc9..251ea63901 100644 --- a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Get-DbaPfDataCollectorCounterSample" { $CommandUnderTest | Should -HaveParameter Counter -Type String[] } It "Should have Continuous as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Continuous -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Continuous -Type Switch } It "Should have ListSet as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ListSet -Type SwitchParameter[] + $CommandUnderTest | Should -HaveParameter ListSet -Type Switch[] } It "Should have MaxSamples as a parameter" { $CommandUnderTest | Should -HaveParameter MaxSamples -Type Int32 @@ -36,7 +36,7 @@ Describe "Get-DbaPfDataCollectorCounterSample" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 b/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 index 3eccfeb81e..c836d30372 100644 --- a/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 @@ -20,8 +20,8 @@ Describe "Get-DbaPfDataCollectorSetTemplate" { It "Should have Template as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Template -Type String[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaPlanCache.Tests.ps1 b/tests/Get-DbaPlanCache.Tests.ps1 index 41283ee721..8331d06e4f 100644 --- a/tests/Get-DbaPlanCache.Tests.ps1 +++ b/tests/Get-DbaPlanCache.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Get-DbaPlanCache" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -58,11 +58,11 @@ Describe "Get-DbaPlanCache" { Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 } It "returns correct datatypes" { - $results = Get-DbaPlanCache -SqlInstance $script:instance1 | Clear-DbaPlanCache -Threshold 1024 + $results = Get-DbaPlanCache -SqlInstance $env:instance1 | Clear-DbaPlanCache -Threshold 1024 $results.Size | Should -BeOfType [dbasize] } } diff --git a/tests/Get-DbaPowerPlan.Tests.ps1 b/tests/Get-DbaPowerPlan.Tests.ps1 index 3d3a934c02..8c9a1d8338 100644 --- a/tests/Get-DbaPowerPlan.Tests.ps1 +++ b/tests/Get-DbaPowerPlan.Tests.ps1 @@ -27,10 +27,10 @@ Describe "Get-DbaPowerPlan" { Context "Command actually works" { BeforeDiscovery { - $script:instance2 = $script:instance2 # Ensure this variable is available in the discovery phase + $env:instance2 = $env:instance2 # Ensure this variable is available in the discovery phase } It "Should return result for the server" { - $results = Get-DbaPowerPlan -ComputerName $script:instance2 + $results = Get-DbaPowerPlan -ComputerName $env:instance2 $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Get-DbaProcess.Tests.ps1 b/tests/Get-DbaProcess.Tests.ps1 index 6d40e8bca4..1b74aac349 100644 --- a/tests/Get-DbaProcess.Tests.ps1 +++ b/tests/Get-DbaProcess.Tests.ps1 @@ -45,7 +45,7 @@ Describe "Get-DbaProcess" { Context "Testing Get-DbaProcess results" { BeforeAll { - $results = Get-DbaProcess -SqlInstance $script:instance1 + $results = Get-DbaProcess -SqlInstance $env:instance1 } It "matches self as a login at least once" { @@ -54,14 +54,14 @@ Describe "Get-DbaProcess" { } It "returns only dbatools processes" { - $results = Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' + $results = Get-DbaProcess -SqlInstance $env:instance1 -Program 'dbatools PowerShell module - dbatools.io' $results | ForEach-Object { $_.Program | Should -Be 'dbatools PowerShell module - dbatools.io' } } It "returns only processes from master database" { - $results = Get-DbaProcess -SqlInstance $script:instance1 -Database master + $results = Get-DbaProcess -SqlInstance $env:instance1 -Database master $results | ForEach-Object { $_.Database | Should -Be 'master' } diff --git a/tests/Get-DbaQueryExecutionTime.Tests.ps1 b/tests/Get-DbaQueryExecutionTime.Tests.ps1 index ff5d89abf8..2de1e0ebdc 100644 --- a/tests/Get-DbaQueryExecutionTime.Tests.ps1 +++ b/tests/Get-DbaQueryExecutionTime.Tests.ps1 @@ -40,7 +40,7 @@ Describe "Get-DbaQueryExecutionTime" { . (Join-Path $PSScriptRoot 'constants.ps1') } - Context "Connects and retrieves query execution times" -ForEach $script:instance1, $script:instance2 { + Context "Connects and retrieves query execution times" -ForEach $env:instance1, $env:instance2 { BeforeAll { $server = Connect-DbaInstance -SqlInstance $_ } diff --git a/tests/Get-DbaRandomizedDataset.Tests.ps1 b/tests/Get-DbaRandomizedDataset.Tests.ps1 index c606b10832..8f07f3761b 100644 --- a/tests/Get-DbaRandomizedDataset.Tests.ps1 +++ b/tests/Get-DbaRandomizedDataset.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Get-DbaRandomizedDataset" { It "Should have InputObject as a non-mandatory parameter of type Object[]" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaRandomizedValue.Tests.ps1 b/tests/Get-DbaRandomizedValue.Tests.ps1 index 5a635b501b..cd59d7ebdc 100644 --- a/tests/Get-DbaRandomizedValue.Tests.ps1 +++ b/tests/Get-DbaRandomizedValue.Tests.ps1 @@ -41,8 +41,8 @@ Describe "Get-DbaRandomizedValue" { It "Should have Locale as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Locale -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaRegServer.Tests.ps1 b/tests/Get-DbaRegServer.Tests.ps1 index 5fd6483d55..8d1c836d8d 100644 --- a/tests/Get-DbaRegServer.Tests.ps1 +++ b/tests/Get-DbaRegServer.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Get-DbaRegServer" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $env:instance1 $regStore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbStore = $regStore.DatabaseEngineServerGroup @@ -52,8 +52,8 @@ Describe "Get-DbaRegServer" { } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } Context "Validate parameters" { @@ -97,7 +97,7 @@ Describe "Get-DbaRegServer" { Context "Command usage" { It "Should return multiple objects" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $group + $results = Get-DbaRegServer -SqlInstance $env:instance1 -Group $group $results.Count | Should -Be 2 $results[0].ParentServer | Should -Not -BeNullOrEmpty $results[0].ComputerName | Should -Not -BeNullOrEmpty @@ -110,17 +110,17 @@ Describe "Get-DbaRegServer" { } It "Should allow searching subgroups" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $env:instance1 -Group "$group\$group2" $results.Count | Should -Be 1 } It "Should return the root server when excluding (see #3529)" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -ExcludeGroup "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $env:instance1 -ExcludeGroup "$group\$group2" @($results | Where-Object Name -eq $srvName3).Count | Should -Be 1 } It "Should filter subgroups" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $group -ExcludeGroup "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $env:instance1 -Group $group -ExcludeGroup "$group\$group2" $results.Count | Should -Be 1 $results.Group | Should -Be $group } diff --git a/tests/Get-DbaRegServerGroup.Tests.ps1 b/tests/Get-DbaRegServerGroup.Tests.ps1 index 499e942b67..1ce37d7479 100644 --- a/tests/Get-DbaRegServerGroup.Tests.ps1 +++ b/tests/Get-DbaRegServerGroup.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Get-DbaRegServerGroup" { $CommandUnderTest | Should -HaveParameter Id -Type Int32[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $env:instance1 $regStore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbStore = $regStore.DatabaseEngineServerGroup @@ -94,31 +94,31 @@ Describe "Get-DbaRegServerGroup" { } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "Should return one group" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group $group $results.Count | Should -Be 1 } It "Should allow searching subgroups" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group "$group\$subGroup" + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group "$group\$subGroup" $results.Count | Should -Be 1 } It "Should return two groups" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group @($group, "$group\$subGroup") + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group @($group, "$group\$subGroup") $results.Count | Should -Be 2 } It "Verify the ExcludeGroup param is working" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group @($group, $group2) -ExcludeGroup $group + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group @($group, $group2) -ExcludeGroup $group $results.Count | Should -Be 1 $results.Name | Should -Be $group2 - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -ExcludeGroup $group + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -ExcludeGroup $group $results.Count | Should -Be 2 ($results.Name -contains $group2 -and $results.Name -contains $group3) | Should -Be $true } diff --git a/tests/Get-DbaRegServerStore.Tests.ps1 b/tests/Get-DbaRegServerStore.Tests.ps1 index da1cf46c6d..d940a90a28 100644 --- a/tests/Get-DbaRegServerStore.Tests.ps1 +++ b/tests/Get-DbaRegServerStore.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaRegServerStore" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Components are properly retrieved" { It "Should return the right values" { - $results = Get-DbaRegServerStore -SqlInstance $script:instance2 + $results = Get-DbaRegServerStore -SqlInstance $env:instance2 $results.InstanceName | Should -Not -BeNullOrEmpty $results.DisplayName | Should -Be "Central Management Servers" } diff --git a/tests/Get-DbaReplDistributor.Tests.ps1 b/tests/Get-DbaReplDistributor.Tests.ps1 index 979c2dd2aa..ee90af7047 100644 --- a/tests/Get-DbaReplDistributor.Tests.ps1 +++ b/tests/Get-DbaReplDistributor.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaReplDistributor" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -58,7 +58,7 @@ Describe "Get-DbaReplDistributor" { } BeforeAll { - $results = Get-DbaReplDistributor -SqlInstance $script:instance1 + $results = Get-DbaReplDistributor -SqlInstance $env:instance1 } It "accurately reports that the distributor is not installed" { diff --git a/tests/Get-DbaReplPublication.Tests.ps1 b/tests/Get-DbaReplPublication.Tests.ps1 index 83db7315fc..84f0370c54 100644 --- a/tests/Get-DbaReplPublication.Tests.ps1 +++ b/tests/Get-DbaReplPublication.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Get-DbaReplPublication" { $CommandUnderTest | Should -HaveParameter Type -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaReplPublisher.Tests.ps1 b/tests/Get-DbaReplPublisher.Tests.ps1 index a1a748240d..ade8525793 100644 --- a/tests/Get-DbaReplPublisher.Tests.ps1 +++ b/tests/Get-DbaReplPublisher.Tests.ps1 @@ -17,13 +17,13 @@ Describe "Get-DbaReplPublisher" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaReplServer.Tests.ps1 b/tests/Get-DbaReplServer.Tests.ps1 index cc2fd17f2d..2a0a2cdf46 100644 --- a/tests/Get-DbaReplServer.Tests.ps1 +++ b/tests/Get-DbaReplServer.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaReplServer" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbaReplSubscription.Tests.ps1 b/tests/Get-DbaReplSubscription.Tests.ps1 index 353832b35b..f966adb9a1 100644 --- a/tests/Get-DbaReplSubscription.Tests.ps1 +++ b/tests/Get-DbaReplSubscription.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Get-DbaReplSubscription" { $CommandUnderTest | Should -HaveParameter Type -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Get-DbaResourceGovernor.Tests.ps1 b/tests/Get-DbaResourceGovernor.Tests.ps1 index 2f9288c64d..819e908dd9 100644 --- a/tests/Get-DbaResourceGovernor.Tests.ps1 +++ b/tests/Get-DbaResourceGovernor.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaResourceGovernor" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaRgClassifierFunction.Tests.ps1 b/tests/Get-DbaRgClassifierFunction.Tests.ps1 index 7a18707afc..5e784390a6 100644 --- a/tests/Get-DbaRgClassifierFunction.Tests.ps1 +++ b/tests/Get-DbaRgClassifierFunction.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbaRgClassifierFunction" { $CommandUnderTest | Should -HaveParameter InputObject -Type ResourceGovernor[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -29,16 +29,16 @@ Describe "Get-DbaRgClassifierFunction" { RETURN N'gOffHoursProcessing' END" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sql - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query $sql + Invoke-DbaQuery -SqlInstance $env:instance2 -Query "ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE" } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG]" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG]" } It "returns the proper classifier function" { - $results = Get-DbaRgClassifierFunction -SqlInstance $script:instance2 + $results = Get-DbaRgClassifierFunction -SqlInstance $env:instance2 $results.Name | Should -Be 'dbatoolsci_fnRG' } } diff --git a/tests/Get-DbaRgResourcePool.Tests.ps1 b/tests/Get-DbaRgResourcePool.Tests.ps1 index 0740c5d824..b56c6bb02b 100644 --- a/tests/Get-DbaRgResourcePool.Tests.ps1 +++ b/tests/Get-DbaRgResourcePool.Tests.ps1 @@ -22,13 +22,13 @@ Describe "Get-DbaRgResourcePool" { $CommandUnderTest | Should -HaveParameter InputObject -Type ResourceGovernor[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $results = Get-DbaRgResourcePool -SqlInstance $env:instance2 } It "Gets Results" { $results | Should -Not -BeNullOrEmpty @@ -37,7 +37,7 @@ Describe "Get-DbaRgResourcePool" { Context "Command actually works using -Type" { BeforeAll { - $results = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $results = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type Internal } It "Gets Results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaRgWorkloadGroup.Tests.ps1 b/tests/Get-DbaRgWorkloadGroup.Tests.ps1 index 8ad9af7779..bb0f075953 100644 --- a/tests/Get-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Get-DbaRgWorkloadGroup.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Get-DbaRgWorkloadGroup" { . (Join-Path $PSScriptRoot 'constants.ps1') } - Context "Connects and retrieves workload groups" -ForEach $script:instance1, $script:instance2 { + Context "Connects and retrieves workload groups" -ForEach $env:instance1, $env:instance2 { BeforeAll { $server = Connect-DbaInstance -SqlInstance $_ } @@ -49,7 +49,7 @@ Describe "Get-DbaRgWorkloadGroup" { Context "Handles pipeline input" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $resourcePools = Get-DbaRgResourcePool -SqlInstance $server } diff --git a/tests/Get-DbaRunningJob.Tests.ps1 b/tests/Get-DbaRunningJob.Tests.ps1 index 1925fbdd19..e43a813cc7 100644 --- a/tests/Get-DbaRunningJob.Tests.ps1 +++ b/tests/Get-DbaRunningJob.Tests.ps1 @@ -63,7 +63,7 @@ Describe "Get-DbaRunningJob" { BeforeAll { # Setup code for all tests in this context - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 } It "Returns running jobs" { diff --git a/tests/Get-DbaSchemaChangeHistory.Tests.ps1 b/tests/Get-DbaSchemaChangeHistory.Tests.ps1 index 5f7fd26228..5fd94686a6 100644 --- a/tests/Get-DbaSchemaChangeHistory.Tests.ps1 +++ b/tests/Get-DbaSchemaChangeHistory.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Get-DbaSchemaChangeHistory Integration Tests" -Tag "IntegrationTests" Context "Testing if schema changes are discovered" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database tempdb $db.Query("CREATE TABLE dbatoolsci_schemachange (id int identity)") $db.Query("EXEC sp_rename 'dbatoolsci_schemachange', 'dbatoolsci_schemachange1'") } @@ -45,7 +45,7 @@ Describe "Get-DbaSchemaChangeHistory Integration Tests" -Tag "IntegrationTests" } It "notices dbatoolsci_schemachange changed" { - $results = Get-DbaSchemaChangeHistory -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaSchemaChangeHistory -SqlInstance $env:instance1 -Database tempdb $results.Object -match 'dbatoolsci_schemachange' | Should -Be $true } } diff --git a/tests/Get-DbaServerRole.Tests.ps1 b/tests/Get-DbaServerRole.Tests.ps1 index 01fdc3dc4e..814587fcb6 100644 --- a/tests/Get-DbaServerRole.Tests.ps1 +++ b/tests/Get-DbaServerRole.Tests.ps1 @@ -22,16 +22,16 @@ Describe "Get-DbaServerRole" { $CommandUnderTest | Should -HaveParameter ExcludeServerRole -Type String[] -Not -Mandatory } It "Should have ExcludeFixedRole parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeFixedRole -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $results = Get-DbaServerRole -SqlInstance $script:instance2 + $results = Get-DbaServerRole -SqlInstance $env:instance2 } It "Should have correct properties" { @@ -40,17 +40,17 @@ Describe "Get-DbaServerRole" { } It "Shows only one value with ServerRole parameter" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ServerRole sysadmin + $results = Get-DbaServerRole -SqlInstance $env:instance2 -ServerRole sysadmin $results[0].Role | Should -Be "sysadmin" } It "Should exclude sysadmin from output" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ExcludeServerRole sysadmin + $results = Get-DbaServerRole -SqlInstance $env:instance2 -ExcludeServerRole sysadmin $results.Role | Should -Not -Contain 'sysadmin' } It "Should exclude fixed server-level roles" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ExcludeFixedRole + $results = Get-DbaServerRole -SqlInstance $env:instance2 -ExcludeFixedRole $results.Role | Should -Not -Contain 'sysadmin' } } diff --git a/tests/Get-DbaServerRoleMember.Tests.ps1 b/tests/Get-DbaServerRoleMember.Tests.ps1 index 05e2191b85..8e43e797f4 100644 --- a/tests/Get-DbaServerRoleMember.Tests.ps1 +++ b/tests/Get-DbaServerRoleMember.Tests.ps1 @@ -35,14 +35,14 @@ Describe "Get-DbaServerRoleMember Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $password1 = ConvertTo-SecureString 'password1' -AsPlainText -Force $testLogin = 'getDbaInstanceRoleMemberLogin' $null = New-DbaLogin -SqlInstance $server2 -Login $testLogin -Password $password1 $null = Set-DbaLogin -SqlInstance $server2 -Login $testLogin -AddRole 'dbcreator' - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 $null = New-DbaLogin -SqlInstance $server1 -Login $testLogin -Password $password1 $null = Set-DbaLogin -SqlInstance $server1 -Login $testLogin -AddRole 'dbcreator' } diff --git a/tests/Get-DbaService.Tests.ps1 b/tests/Get-DbaService.Tests.ps1 index 9bab81e3d2..a9f1d7f394 100644 --- a/tests/Get-DbaService.Tests.ps1 +++ b/tests/Get-DbaService.Tests.ps1 @@ -47,10 +47,10 @@ Describe "Get-DbaService" { Context "Command actually works" { BeforeAll { - $instanceName = (Connect-DbaInstance -SqlInstance $script:instance2).ServiceName - $results = Get-DbaService -ComputerName $script:instance2 - $agentResults = Get-DbaService -ComputerName $script:instance2 -Type Agent - $advancedResults = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent -AdvancedProperties + $instanceName = (Connect-DbaInstance -SqlInstance $env:instance2).ServiceName + $results = Get-DbaService -ComputerName $env:instance2 + $agentResults = Get-DbaService -ComputerName $env:instance2 -Type Agent + $advancedResults = Get-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent -AdvancedProperties } It "shows some services" { @@ -72,23 +72,23 @@ Describe "Get-DbaService" { } It "sets startup mode of the service to 'Manual'" { - $service = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $service = Get-DbaService -ComputerName $env:instance2 -Type Agent -InstanceName $instanceName { $service.ChangeStartMode('Manual') } | Should -Not -Throw - $results = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $results = Get-DbaService -ComputerName $env:instance2 -Type Agent -InstanceName $instanceName $results.StartMode | Should -Be 'Manual' } It "sets startup mode of the service to 'Automatic'" { - $service = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $service = Get-DbaService -ComputerName $env:instance2 -Type Agent -InstanceName $instanceName { $service.ChangeStartMode('Automatic') } | Should -Not -Throw - $results = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $results = Get-DbaService -ComputerName $env:instance2 -Type Agent -InstanceName $instanceName $results.StartMode | Should -Be 'Automatic' } } Context "Command actually works with SqlInstance" { BeforeAll { - $results = @( Get-DbaService -SqlInstance $script:instance2 -Type Engine ) + $results = @( Get-DbaService -SqlInstance $env:instance2 -Type Engine ) } It "shows exactly one service" { diff --git a/tests/Get-DbaSpConfigure.Tests.ps1 b/tests/Get-DbaSpConfigure.Tests.ps1 index 976d3d0170..9feb0fe23b 100644 --- a/tests/Get-DbaSpConfigure.Tests.ps1 +++ b/tests/Get-DbaSpConfigure.Tests.ps1 @@ -24,34 +24,34 @@ Describe "Get-DbaSpConfigure" { $CommandUnderTest | Should -HaveParameter ExcludeName -Type String[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Get configuration" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $configs = $server.Query("sp_configure") $remotequerytimeout = $configs | Where-Object name -match 'remote query timeout' } It "returns equal to results of the straight T-SQL query" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 + $results = Get-DbaSpConfigure -SqlInstance $env:instance1 $results.count | Should -Be $configs.count } It "returns two results" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteQueryTimeout, AllowUpdates + $results = Get-DbaSpConfigure -SqlInstance $env:instance1 -Name RemoteQueryTimeout, AllowUpdates $results.Count | Should -Be 2 } It "returns two results less than all data" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -ExcludeName "remote query timeout (s)", AllowUpdates + $results = Get-DbaSpConfigure -SqlInstance $env:instance1 -ExcludeName "remote query timeout (s)", AllowUpdates $results.Count | Should -Be ($configs.count - 2) } It "matches the output of sp_configure " { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteQueryTimeout + $results = Get-DbaSpConfigure -SqlInstance $env:instance1 -Name RemoteQueryTimeout $results.ConfiguredValue | Should -Be $remotequerytimeout.config_value $results.RunningValue | Should -Be $remotequerytimeout.run_value } diff --git a/tests/Get-DbaSpinLockStatistic.Tests.ps1 b/tests/Get-DbaSpinLockStatistic.Tests.ps1 index 805a7978c3..5fc095670d 100644 --- a/tests/Get-DbaSpinLockStatistic.Tests.ps1 +++ b/tests/Get-DbaSpinLockStatistic.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaSpinLockStatistic" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -60,7 +60,7 @@ Describe "Get-DbaSpinLockStatistic" { Context "Command returns proper info" { BeforeAll { - $results = Get-DbaSpinLockStatistic -SqlInstance $script:instance2 + $results = Get-DbaSpinLockStatistic -SqlInstance $env:instance2 } It "returns results" { diff --git a/tests/Get-DbaSpn.Tests.ps1 b/tests/Get-DbaSpn.Tests.ps1 index 82078176fe..f6fc7dd9d8 100644 --- a/tests/Get-DbaSpn.Tests.ps1 +++ b/tests/Get-DbaSpn.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Get-DbaSpn" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Accepts Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Accepts Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Accepts ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -61,11 +61,11 @@ Describe "Get-DbaSpn" { # BeforeAll { # # Setup code for integration tests # } - # + # # It "Should return valid SPNs" { # # Test code # } - # + # # AfterAll { # # Cleanup code for integration tests # } diff --git a/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 b/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 index 18c322eccf..0651e1193f 100644 --- a/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 +++ b/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Get-DbaSsisEnvironmentVariable" { $CommandUnderTest | Should -HaveParameter FolderExclude -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Get-DbaSsisExecutionHistory.Tests.ps1 b/tests/Get-DbaSsisExecutionHistory.Tests.ps1 index 9cd7bdf5e6..be271546b7 100644 --- a/tests/Get-DbaSsisExecutionHistory.Tests.ps1 +++ b/tests/Get-DbaSsisExecutionHistory.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaSsisExecutionHistory" { $CommandUnderTest | Should -HaveParameter Environment -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Get-DbaStartupParameter.Tests.ps1 b/tests/Get-DbaStartupParameter.Tests.ps1 index 1b7a17b613..454954aaf0 100644 --- a/tests/Get-DbaStartupParameter.Tests.ps1 +++ b/tests/Get-DbaStartupParameter.Tests.ps1 @@ -15,15 +15,15 @@ Describe "Get-DbaStartupParameter" { It "Should have Credential as a non-mandatory parameter of type PSCredential" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } - It "Should have Simple as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Simple -Type SwitchParameter -Not -Mandatory + It "Should have Simple as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Simple -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have common parameters" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory $CommandUnderTest | Should -HaveParameter WarningAction -Type ActionPreference -Not -Mandatory $CommandUnderTest | Should -HaveParameter InformationAction -Type ActionPreference -Not -Mandatory @@ -39,7 +39,7 @@ Describe "Get-DbaStartupParameter" { Context "Command actually works" { BeforeAll { - $results = Get-DbaStartupParameter -SqlInstance $script:instance2 + $results = Get-DbaStartupParameter -SqlInstance $env:instance2 } It "Gets Results" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Get-DbaStartupProcedure.Tests.ps1 b/tests/Get-DbaStartupProcedure.Tests.ps1 index 47b20ea582..f1933c3fa6 100644 --- a/tests/Get-DbaStartupProcedure.Tests.ps1 +++ b/tests/Get-DbaStartupProcedure.Tests.ps1 @@ -15,14 +15,14 @@ Describe "Get-DbaStartupProcedure" { $CommandUnderTest | Should -HaveParameter StartupProcedure -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $random = Get-Random $startupProc = "dbo.StartUpProc$random" $dbname = 'master' @@ -35,19 +35,19 @@ Describe "Get-DbaStartupProcedure" { } It "returns correct results" { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 + $result = Get-DbaStartupProcedure -SqlInstance $env:instance2 $result.Schema | Should -Be 'dbo' $result.Name | Should -Be "StartUpProc$random" } It "returns correct results for StartupProcedure parameter" { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc + $result = Get-DbaStartupProcedure -SqlInstance $env:instance2 -StartupProcedure $startupProc $result.Schema | Should -Be 'dbo' $result.Name | Should -Be "StartUpProc$random" } It "returns null for incorrect StartupProcedure parameter" { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure 'Not.Here' + $result = Get-DbaStartupProcedure -SqlInstance $env:instance2 -StartupProcedure 'Not.Here' $result | Should -BeNullOrEmpty } } diff --git a/tests/Get-DbaSuspectPage.Tests.ps1 b/tests/Get-DbaSuspectPage.Tests.ps1 index a309cb0a0e..a69f172e68 100644 --- a/tests/Get-DbaSuspectPage.Tests.ps1 +++ b/tests/Get-DbaSuspectPage.Tests.ps1 @@ -15,14 +15,14 @@ Describe "Get-DbaSuspectPage" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Testing if suspect pages are present" { BeforeAll { $dbname = "dbatoolsci_GetSuspectPage" - $Server = Connect-DbaInstance -SqlInstance $script:instance2 + $Server = Connect-DbaInstance -SqlInstance $env:instance2 $null = $Server.Query("Create Database [$dbname]") $db = Get-DbaDatabase -SqlInstance $Server -Database $dbname @@ -34,14 +34,14 @@ Describe "Get-DbaSuspectPage" { # make darn sure suspect pages show up, run twice try { - $null = Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + $null = Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database $dbname -Confirm:$false $null = $db.Query("select top 100 from example") $null = $server.Query("ALTER DATABASE $dbname SET PAGE_VERIFY CHECKSUM WITH NO_WAIT") $null = Start-DbccCheck -Server $Server -dbname $dbname -WarningAction SilentlyContinue } catch {} # should fail try { - $null = Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + $null = Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database $dbname -Confirm:$false $null = $db.Query("select top 100 from example") $null = $server.Query("ALTER DATABASE $dbname SET PAGE_VERIFY CHECKSUM WITH NO_WAIT") $null = Start-DbccCheck -Server $Server -dbname $dbname -WarningAction SilentlyContinue diff --git a/tests/Get-DbaTcpPort.Tests.ps1 b/tests/Get-DbaTcpPort.Tests.ps1 index 2addcb8752..b15a0647e8 100644 --- a/tests/Get-DbaTcpPort.Tests.ps1 +++ b/tests/Get-DbaTcpPort.Tests.ps1 @@ -21,21 +21,21 @@ Describe "Get-DbaTcpPort" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have All as a switch parameter" { - $CommandUnderTest | Should -HaveParameter All -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter All -Type Switch } It "Should have ExcludeIpv6 as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeIpv6 -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeIpv6 -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Get-DbaTcpPort -SqlInstance $script:instance2 - $resultsIpv6 = Get-DbaTcpPort -SqlInstance $script:instance2 -All -ExcludeIpv6 - $resultsAll = Get-DbaTcpPort -SqlInstance $script:instance2 -All + $results = Get-DbaTcpPort -SqlInstance $env:instance2 + $resultsIpv6 = Get-DbaTcpPort -SqlInstance $env:instance2 -All -ExcludeIpv6 + $resultsAll = Get-DbaTcpPort -SqlInstance $env:instance2 -All } It "Should Return a Result" { diff --git a/tests/Get-DbaTempdbUsage.Tests.ps1 b/tests/Get-DbaTempdbUsage.Tests.ps1 index edb90ab919..e05061544c 100644 --- a/tests/Get-DbaTempdbUsage.Tests.ps1 +++ b/tests/Get-DbaTempdbUsage.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaTempdbUsage" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbaTrace.Tests.ps1 b/tests/Get-DbaTrace.Tests.ps1 index eaa6408622..72631c1d70 100644 --- a/tests/Get-DbaTrace.Tests.ps1 +++ b/tests/Get-DbaTrace.Tests.ps1 @@ -6,10 +6,10 @@ Describe "Get-DbaTrace" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $traceconfig = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName DefaultTraceEnabled + $traceconfig = Get-DbaSpConfigure -SqlInstance $env:instance2 -ConfigName DefaultTraceEnabled if ($traceconfig.RunningValue -eq $false) { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("EXEC sp_configure 'show advanced options', 1;") $server.Query("RECONFIGURE WITH OVERRIDE") $server.Query("EXEC sp_configure 'default trace enabled', 1;") @@ -53,7 +53,7 @@ Describe "Get-DbaTrace" { Context "Test Check Default Trace" { BeforeAll { - $results = Get-DbaTrace -SqlInstance $script:instance2 + $results = Get-DbaTrace -SqlInstance $env:instance2 } It "Should find at least one trace file" { $results.Id.Count | Should -BeGreaterThan 0 diff --git a/tests/Get-DbaTraceFlag.Tests.ps1 b/tests/Get-DbaTraceFlag.Tests.ps1 index efd18b2eda..1e632018e5 100644 --- a/tests/Get-DbaTraceFlag.Tests.ps1 +++ b/tests/Get-DbaTraceFlag.Tests.ps1 @@ -26,7 +26,7 @@ Describe "Get-DbaTraceFlag" { BeforeAll { $safetraceflag = 3226 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $startingtfs = $server.Query("DBCC TRACESTATUS(-1)") $startingtfscount = $startingtfs.Count @@ -44,17 +44,17 @@ Describe "Get-DbaTraceFlag" { It "Has the right default properties" { $expectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'TraceFlag', 'Global', 'Status' - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 + $results = Get-DbaTraceFlag -SqlInstance $env:instance2 ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($expectedProps | Sort-Object) } It "Returns filtered results" { - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag $safetraceflag + $results = Get-DbaTraceFlag -SqlInstance $env:instance2 -TraceFlag $safetraceflag $results.TraceFlag.Count | Should -Be 1 } It "Returns following number of TFs: $startingtfscount" { - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 + $results = Get-DbaTraceFlag -SqlInstance $env:instance2 $results.TraceFlag.Count | Should -Be $startingtfscount } } diff --git a/tests/Get-DbaUpTime.Tests.ps1 b/tests/Get-DbaUpTime.Tests.ps1 index ebbb7d133b..40cd82bdcb 100644 --- a/tests/Get-DbaUpTime.Tests.ps1 +++ b/tests/Get-DbaUpTime.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Get-DbaUptime" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Get-DbaUptime -SqlInstance $script:instance1 + $results = Get-DbaUptime -SqlInstance $env:instance1 } It "Should have correct properties" { $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlServer', 'SqlUptime', 'WindowsUptime', 'SqlStartTime', 'WindowsBootTime', 'SinceSqlStart', 'SinceWindowsBoot' @@ -37,7 +37,7 @@ Describe "Get-DbaUptime" { Context "Command can handle multiple SqlInstances" { BeforeAll { - $results = Get-DbaUptime -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaUptime -SqlInstance $env:instance1, $env:instance2 } It "Command resultset should contain 2 results" { $results.count | Should -Be 2 @@ -51,7 +51,7 @@ Describe "Get-DbaUptime" { Context "Properties should return expected types" { BeforeAll { - $results = Get-DbaUptime -SqlInstance $script:instance1 + $results = Get-DbaUptime -SqlInstance $env:instance1 } It "SqlStartTime should be a DbaDateTime" { $results.SqlStartTime | Should -BeOfType DbaDateTime diff --git a/tests/Get-DbaUserPermission.Tests.ps1 b/tests/Get-DbaUserPermission.Tests.ps1 index c8a4a792ab..cf8cbdab10 100644 --- a/tests/Get-DbaUserPermission.Tests.ps1 +++ b/tests/Get-DbaUserPermission.Tests.ps1 @@ -52,17 +52,17 @@ exec sp_addrolemember 'userrole','alice'; exec sp_addrolemember 'userrole','bob'; '@ - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbName $db.ExecuteNonQuery($sql) } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbName -Confirm:$false } Context "Command returns proper info" { BeforeAll { - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbName + $results = Get-DbaUserPermission -SqlInstance $env:instance1 -Database $dbName } It "returns results" { @@ -87,21 +87,21 @@ exec sp_addrolemember 'userrole','bob'; $dbNameDiffCollation = "dbatoolsci_UserPermissionDiffCollation" $dbCollation = "Latin1_General_CI_AI" - New-DbaDatabase -SqlInstance $script:instance1 -Name $dbNameDiffCollation -Collation $dbCollation + New-DbaDatabase -SqlInstance $env:instance1 -Name $dbNameDiffCollation -Collation $dbCollation } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbNameDiffCollation -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbNameDiffCollation -Confirm:$false } It "Should not warn about collation conflict" { $warnVar = $null - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbNameDiffCollation -WarningVariable warnVar 3> $null + $results = Get-DbaUserPermission -SqlInstance $env:instance1 -Database $dbNameDiffCollation -WarningVariable warnVar 3> $null $warnVar | Should -BeNullOrEmpty } It "returns results" { - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbNameDiffCollation + $results = Get-DbaUserPermission -SqlInstance $env:instance1 -Database $dbNameDiffCollation $results.Count | Should -BeGreaterThan 0 } } diff --git a/tests/Get-DbaWaitResource.Tests.ps1 b/tests/Get-DbaWaitResource.Tests.ps1 index 883caa8b0e..e0044e0ed4 100644 --- a/tests/Get-DbaWaitResource.Tests.ps1 +++ b/tests/Get-DbaWaitResource.Tests.ps1 @@ -15,10 +15,10 @@ Describe "Get-DbaWaitResource" { $CommandUnderTest | Should -HaveParameter WaitResource -Type String } It "Should have Row parameter" { - $CommandUnderTest | Should -HaveParameter Row -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Row -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -27,7 +27,7 @@ Describe "Get-DbaWaitResource Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random $WaitResourceDB = "WaitResource$random" - Restore-DbaDatabase -SqlInstance $script:instance1 -DatabaseName $WaitResourceDB -ReplaceDbNameInFile -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak + Restore-DbaDatabase -SqlInstance $env:instance1 -DatabaseName $WaitResourceDB -ReplaceDbNameInFile -Path $env:appveyorlabrepo\singlerestore\singlerestore.bak $sql = @" create table waittest ( col1 int, @@ -38,11 +38,11 @@ Describe "Get-DbaWaitResource Integration Tests" -Tag "IntegrationTests" { go "@ - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $sql + Invoke-DbaQuery -SqlInstance $env:instance1 -Database $WaitResourceDB -Query $sql } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database $WaitResourceDB | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance1 -Database $WaitResourceDB | Remove-DbaDatabase -Confirm:$false } Context "Test getting a Page resource" { @@ -72,9 +72,9 @@ Describe "Get-DbaWaitResource Integration Tests" -Tag "IntegrationTests" { select @pageid=PagePid from #TmpIndex where PageType=10 select 'PAGE: '+convert(varchar(3),DB_ID())+':1:'+convert(varchar(15),@pageid) "@ - $page = (Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $Pagesql).Column1 - $file = Get-DbaDbFile -SqlInstance $script:instance1 -Database $WaitResourceDB | Where-Object TypeDescription -eq 'ROWS' - $results = Get-DbaWaitResource -SqlInstance $script:instance1 -WaitResource $page + $page = (Invoke-DbaQuery -SqlInstance $env:instance1 -Database $WaitResourceDB -Query $Pagesql).Column1 + $file = Get-DbaDbFile -SqlInstance $env:instance1 -Database $WaitResourceDB | Where-Object TypeDescription -eq 'ROWS' + $results = Get-DbaWaitResource -SqlInstance $env:instance1 -WaitResource $page } It "Should return databasename $WaitResourceDB" { @@ -115,8 +115,8 @@ Describe "Get-DbaWaitResource Integration Tests" -Tag "IntegrationTests" { select 'KEY: '+convert(varchar(3),db_id())+':'+convert(varchar(30),@hobt_id)+' '+ %%lockres%% from keytest where col1=1 "@ - $key = (Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $SqlKey).Column1 - $resultskey = Get-DbaWaitResource -SqlInstance $script:instance1 -WaitResource $key -Row + $key = (Invoke-DbaQuery -SqlInstance $env:instance1 -Database $WaitResourceDB -Query $SqlKey).Column1 + $resultskey = Get-DbaWaitResource -SqlInstance $env:instance1 -WaitResource $key -Row } It "Should return databasename $WaitResourceDB" { diff --git a/tests/Get-DbaWaitStatistic.Tests.ps1 b/tests/Get-DbaWaitStatistic.Tests.ps1 index 6e08f726c1..7256768b80 100644 --- a/tests/Get-DbaWaitStatistic.Tests.ps1 +++ b/tests/Get-DbaWaitStatistic.Tests.ps1 @@ -21,16 +21,16 @@ Describe "Get-DbaWaitStatistic" { $CommandUnderTest | Should -HaveParameter Threshold -Type Int32 -Not -Mandatory } It "Should have IncludeIgnorable as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeIgnorable -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeIgnorable -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command returns proper info" { BeforeAll { - $results = Get-DbaWaitStatistic -SqlInstance $script:instance2 -Threshold 100 + $results = Get-DbaWaitStatistic -SqlInstance $env:instance2 -Threshold 100 } It "returns results" { @@ -47,7 +47,7 @@ Describe "Get-DbaWaitStatistic" { Context "Command returns proper info when using parameter IncludeIgnorable" { BeforeAll { $ignoredWaits = 'REQUEST_FOR_DEADLOCK_SEARCH', 'SLEEP_MASTERDBREADY', 'SLEEP_TASK', 'LAZYWRITER_SLEEP' - $results = Get-DbaWaitStatistic -SqlInstance $script:instance2 -Threshold 100 -IncludeIgnorable | Where-Object { + $results = Get-DbaWaitStatistic -SqlInstance $env:instance2 -Threshold 100 -IncludeIgnorable | Where-Object { $ignoredWaits -contains $_.WaitType } } diff --git a/tests/Get-DbaWaitingTask.Tests.ps1 b/tests/Get-DbaWaitingTask.Tests.ps1 index f879c2ef67..1904d248fc 100644 --- a/tests/Get-DbaWaitingTask.Tests.ps1 +++ b/tests/Get-DbaWaitingTask.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Get-DbaWaitingTask" { $flag = "dbatools_$(Get-Random)" $time = '00:15:00' $sql = "SELECT '$flag'; WAITFOR DELAY '$time'" - $instance = $script:instance2 + $instance = $env:instance2 $modulePath = 'C:\Github\dbatools\dbatools.psm1' $job = 'YouHaveBeenFoundWaiting' diff --git a/tests/Get-DbaWindowsLog.Tests.ps1 b/tests/Get-DbaWindowsLog.Tests.ps1 index 129e6c9a97..0a8a4d962f 100644 --- a/tests/Get-DbaWindowsLog.Tests.ps1 +++ b/tests/Get-DbaWindowsLog.Tests.ps1 @@ -30,13 +30,13 @@ Describe "Get-DbaWindowsLog" { $CommandUnderTest | Should -HaveParameter MaxRemoteThreads -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command returns proper info" { BeforeAll { - $results = Get-DbaWindowsLog -SqlInstance $script:instance2 + $results = Get-DbaWindowsLog -SqlInstance $env:instance2 } It "returns results" { $results.Count | Should -BeGreaterThan 0 diff --git a/tests/Get-DbaWsfcCluster.Tests.ps1 b/tests/Get-DbaWsfcCluster.Tests.ps1 index 028681090d..83318cbc8d 100644 --- a/tests/Get-DbaWsfcCluster.Tests.ps1 +++ b/tests/Get-DbaWsfcCluster.Tests.ps1 @@ -16,13 +16,13 @@ Describe "Get-DbaWsfcCluster" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaWsfcNetwork.Tests.ps1 b/tests/Get-DbaWsfcNetwork.Tests.ps1 index e5be63d423..4077c529c1 100644 --- a/tests/Get-DbaWsfcNetwork.Tests.ps1 +++ b/tests/Get-DbaWsfcNetwork.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaWsfcNetwork" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 b/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 index 6e25dd4001..14c73cccd7 100644 --- a/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 +++ b/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaWsfcNetworkInterface" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaWsfcResourceType.Tests.ps1 b/tests/Get-DbaWsfcResourceType.Tests.ps1 index fa65c7db1b..08c30a2148 100644 --- a/tests/Get-DbaWsfcResourceType.Tests.ps1 +++ b/tests/Get-DbaWsfcResourceType.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Get-DbaWsfcResourceType" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbaWsfcRole.Tests.ps1 b/tests/Get-DbaWsfcRole.Tests.ps1 index 0ca150aef2..524b14ad7b 100644 --- a/tests/Get-DbaWsfcRole.Tests.ps1 +++ b/tests/Get-DbaWsfcRole.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaWsfcRole" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaWsfcSharedVolume.Tests.ps1 b/tests/Get-DbaWsfcSharedVolume.Tests.ps1 index 7d9daa2bbd..fa66e4338b 100644 --- a/tests/Get-DbaWsfcSharedVolume.Tests.ps1 +++ b/tests/Get-DbaWsfcSharedVolume.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaWsfcSharedVolume" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DbaXEObject.Tests.ps1 b/tests/Get-DbaXEObject.Tests.ps1 index fd790878ca..491f3375d3 100644 --- a/tests/Get-DbaXEObject.Tests.ps1 +++ b/tests/Get-DbaXEObject.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Get-DbaXEObject" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -64,7 +64,7 @@ Describe "Get-DbaXEObject" { # Add your integration tests here # Example: # It "Should return XE objects" { - # $results = Get-DbaXEObject -SqlInstance $script:instance1 + # $results = Get-DbaXEObject -SqlInstance $env:instance1 # $results | Should -Not -BeNullOrEmpty # } } diff --git a/tests/Get-DbaXESession.Tests.ps1 b/tests/Get-DbaXESession.Tests.ps1 index 56b1a1923c..b8e32cad6d 100644 --- a/tests/Get-DbaXESession.Tests.ps1 +++ b/tests/Get-DbaXESession.Tests.ps1 @@ -25,12 +25,12 @@ Describe "Get-DbaXESession" { Context "Verifying command output" { It "returns some results" { - $results = Get-DbaXESession -SqlInstance $script:instance2 + $results = Get-DbaXESession -SqlInstance $env:instance2 $results.Count | Should -BeGreaterThan 1 } It "returns only the system_health session" { - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health + $results = Get-DbaXESession -SqlInstance $env:instance2 -Session system_health $results.Name | Should -Be 'system_health' } } diff --git a/tests/Get-DbaXESessionTarget.Tests.ps1 b/tests/Get-DbaXESessionTarget.Tests.ps1 index 803ff16a3d..ed90be96d2 100644 --- a/tests/Get-DbaXESessionTarget.Tests.ps1 +++ b/tests/Get-DbaXESessionTarget.Tests.ps1 @@ -31,14 +31,14 @@ Describe "Get-DbaXESessionTarget" { } It "returns only the system_health session" { - $results = Get-DbaXESessionTarget -SqlInstance $script:instance2 -Target package0.event_file + $results = Get-DbaXESessionTarget -SqlInstance $env:instance2 -Target package0.event_file foreach ($result in $results) { $result.Name | Should -Be 'package0.event_file' } } It "supports the pipeline" { - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health | Get-DbaXESessionTarget -Target package0.event_file + $results = Get-DbaXESession -SqlInstance $env:instance2 -Session system_health | Get-DbaXESessionTarget -Target package0.event_file $results.Count | Should -BeGreaterThan 0 } } diff --git a/tests/Get-DbaXESessionTargetFile.Tests.ps1 b/tests/Get-DbaXESessionTargetFile.Tests.ps1 index 71e281b7ec..e4c2f2e770 100644 --- a/tests/Get-DbaXESessionTargetFile.Tests.ps1 +++ b/tests/Get-DbaXESessionTargetFile.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Get-DbaXESessionTargetFile" { $CommandUnderTest | Should -HaveParameter InputObject -Type Target[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Get-DbaXESessionTemplate.Tests.ps1 b/tests/Get-DbaXESessionTemplate.Tests.ps1 index 4b7f7d1cb5..90d045748e 100644 --- a/tests/Get-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Get-DbaXESessionTemplate.Tests.ps1 @@ -20,8 +20,8 @@ Describe "Get-DbaXESessionTemplate" { It "Should have Template as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Template -Type String[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbaXESmartTarget.Tests.ps1 b/tests/Get-DbaXESmartTarget.Tests.ps1 index 60f6875470..34d372903a 100644 --- a/tests/Get-DbaXESmartTarget.Tests.ps1 +++ b/tests/Get-DbaXESmartTarget.Tests.ps1 @@ -5,13 +5,13 @@ Describe "Get-DbaXESmartTarget" { BeforeAll { $CommandUnderTest = Get-Command Get-DbaXESmartTarget } - It "Should have EnableException as a SwitchParameter that is not mandatory" { + It "Should have EnableException as a Switch that is not mandatory" { $CommandUnderTest | Should -HaveParameter EnableException -Type switch -Not -Mandatory } - It "Should have Verbose as a SwitchParameter that is not mandatory" { + It "Should have Verbose as a Switch that is not mandatory" { $CommandUnderTest | Should -HaveParameter Verbose -Type switch -Not -Mandatory } - It "Should have Debug as a SwitchParameter that is not mandatory" { + It "Should have Debug as a Switch that is not mandatory" { $CommandUnderTest | Should -HaveParameter Debug -Type switch -Not -Mandatory } It "Should have ErrorAction as an ActionPreference that is not mandatory" { diff --git a/tests/Get-DbaXEStore.Tests.ps1 b/tests/Get-DbaXEStore.Tests.ps1 index 4a646d16d4..b60e4ce7f6 100644 --- a/tests/Get-DbaXEStore.Tests.ps1 +++ b/tests/Get-DbaXEStore.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Get-DbaXEStore" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Get-DbatoolsChangeLog.Tests.ps1 b/tests/Get-DbatoolsChangeLog.Tests.ps1 index 4e1010cef7..9147b1b9db 100644 --- a/tests/Get-DbatoolsChangeLog.Tests.ps1 +++ b/tests/Get-DbatoolsChangeLog.Tests.ps1 @@ -5,16 +5,16 @@ Describe "Get-DbatoolsChangeLog" { BeforeAll { $CommandUnderTest = Get-Command Get-DbatoolsChangeLog } - It "Should have Local as a SwitchParameter" { + It "Should have Local as a Switch" { $CommandUnderTest | Should -HaveParameter Local -Type switch } - It "Should have EnableException as a SwitchParameter" { + It "Should have EnableException as a Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type switch } - It "Should have Verbose as a SwitchParameter" { + It "Should have Verbose as a Switch" { $CommandUnderTest | Should -HaveParameter Verbose -Type switch } - It "Should have Debug as a SwitchParameter" { + It "Should have Debug as a Switch" { $CommandUnderTest | Should -HaveParameter Debug -Type switch } It "Should have ErrorAction as an ActionPreference" { diff --git a/tests/Get-DbatoolsConfig.Tests.ps1 b/tests/Get-DbatoolsConfig.Tests.ps1 index 3b08444e43..e567bbdeaa 100644 --- a/tests/Get-DbatoolsConfig.Tests.ps1 +++ b/tests/Get-DbatoolsConfig.Tests.ps1 @@ -14,8 +14,8 @@ Describe "Get-DbatoolsConfig" { It "Should have parameter Module of type String" { $CommandUnderTest | Should -HaveParameter Module -Type String -Not -Mandatory } - It "Should have parameter Force of type SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + It "Should have parameter Force of type Switch" { + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbatoolsError.Tests.ps1 b/tests/Get-DbatoolsError.Tests.ps1 index 5f2ccdbef5..23f03c8fe0 100644 --- a/tests/Get-DbatoolsError.Tests.ps1 +++ b/tests/Get-DbatoolsError.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-DbatoolsError" { $CommandUnderTest | Should -HaveParameter Skip -Type Int32 } It "Accepts All as a parameter" { - $CommandUnderTest | Should -HaveParameter All -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter All -Type Switch } } diff --git a/tests/Get-DbatoolsLog.Tests.ps1 b/tests/Get-DbatoolsLog.Tests.ps1 index 7c73b1ee06..5282603284 100644 --- a/tests/Get-DbatoolsLog.Tests.ps1 +++ b/tests/Get-DbatoolsLog.Tests.ps1 @@ -24,8 +24,8 @@ Describe "Get-DbatoolsLog" { It "Should have Last as a non-mandatory Int32 parameter" { $CommandUnderTest | Should -HaveParameter Last -Type Int32 -Not -Mandatory } - It "Should have LastError as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter LastError -Type SwitchParameter -Not -Mandatory + It "Should have LastError as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter LastError -Type Switch -Not -Mandatory } It "Should have Skip as a non-mandatory Int32 parameter" { $CommandUnderTest | Should -HaveParameter Skip -Type Int32 -Not -Mandatory @@ -36,11 +36,11 @@ Describe "Get-DbatoolsLog" { It "Should have Level as a non-mandatory MessageLevel[] parameter" { $CommandUnderTest | Should -HaveParameter Level -Type MessageLevel[] -Not -Mandatory } - It "Should have Raw as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Raw -Type SwitchParameter -Not -Mandatory + It "Should have Raw as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Raw -Type Switch -Not -Mandatory } - It "Should have Errors as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Errors -Type SwitchParameter -Not -Mandatory + It "Should have Errors as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Errors -Type Switch -Not -Mandatory } } diff --git a/tests/Get-DbatoolsPath.Tests.ps1 b/tests/Get-DbatoolsPath.Tests.ps1 index f4c1e6b330..03fb2dfa87 100644 --- a/tests/Get-DbatoolsPath.Tests.ps1 +++ b/tests/Get-DbatoolsPath.Tests.ps1 @@ -13,10 +13,10 @@ Describe "Get-DbatoolsPath" { $CommandUnderTest | Should -HaveParameter Name -Type String } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Get-DirectoryRestoreFile.Tests.ps1 b/tests/Get-DirectoryRestoreFile.Tests.ps1 index 7ab3c64064..5c009faad1 100644 --- a/tests/Get-DirectoryRestoreFile.Tests.ps1 +++ b/tests/Get-DirectoryRestoreFile.Tests.ps1 @@ -13,10 +13,10 @@ Describe "Get-DirectoryRestoreFile" { It "Should have Path as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Path -Type String -Not -Mandatory } - It "Should have Recurse as a non-mandatory SwitchParameter" { + It "Should have Recurse as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter Recurse -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Get-XpDirTreeRestoreFile.Tests.ps1 b/tests/Get-XpDirTreeRestoreFile.Tests.ps1 index 91a38dae68..434667021b 100644 --- a/tests/Get-XpDirTreeRestoreFile.Tests.ps1 +++ b/tests/Get-XpDirTreeRestoreFile.Tests.ps1 @@ -18,11 +18,11 @@ Describe "Get-XpDirTreeRestoreFile" { It "Should have SqlCredential as a non-mandatory PSCredential parameter" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } - It "Should have NoRecurse as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter NoRecurse -Type SwitchParameter -Not -Mandatory + It "Should have NoRecurse as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter NoRecurse -Type Switch -Not -Mandatory } } diff --git a/tests/Grant-DbaAgPermission.Tests.ps1 b/tests/Grant-DbaAgPermission.Tests.ps1 index 5ef3800b4b..b31db7c640 100644 --- a/tests/Grant-DbaAgPermission.Tests.ps1 +++ b/tests/Grant-DbaAgPermission.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Grant-DbaAgPermission" { $CommandUnderTest | Should -HaveParameter InputObject -Type Login[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -35,17 +35,17 @@ Describe "Grant-DbaAgPermission" { Describe "Grant-DbaAgPermission Integration Tests" -Tag "IntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue + $null = Invoke-DbaQuery -SqlInstance $env:instance3 -InputFile $env:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue $agname = "dbatoolsci_ag_grant" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "grants big perms" { It "returns results with proper data" { - $results = Get-DbaLogin -SqlInstance $script:instance3 -Login tester | Grant-DbaAgPermission -Type EndPoint + $results = Get-DbaLogin -SqlInstance $env:instance3 -Login tester | Grant-DbaAgPermission -Type EndPoint $results.Status | Should -Be 'Success' } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Import-DbaBinaryFile.Tests.ps1 b/tests/Import-DbaBinaryFile.Tests.ps1 index de38a6d448..2a338e2447 100644 --- a/tests/Import-DbaBinaryFile.Tests.ps1 +++ b/tests/Import-DbaBinaryFile.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Import-DbaBinaryFile" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $env:instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFiles]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") } @@ -65,19 +65,19 @@ Describe "Import-DbaBinaryFile" { Context "Command usage" { It "imports files into table data" { - $results = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles -FilePath $script:appveyorlabrepo\azure\adalsql.msi -WarningAction Continue -ErrorAction Stop -EnableException + $results = Import-DbaBinaryFile -SqlInstance $env:instance2 -Database tempdb -Table BunchOFiles -FilePath $env:appveyorlabrepo\azure\adalsql.msi -WarningAction Continue -ErrorAction Stop -EnableException $results.Database | Should -Be "tempdb" $results.FilePath | Should -Match "adalsql.msi" } It "imports files into table data from piped" { - $results = Get-ChildItem -Path $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles -WarningAction Continue -ErrorAction Stop -EnableException + $results = Get-ChildItem -Path $env:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $env:instance2 -Database tempdb -Table BunchOFiles -WarningAction Continue -ErrorAction Stop -EnableException $results.Database | Should -Be @("tempdb", "tempdb") Split-Path -Path $results.FilePath -Leaf | Should -Be @("localhost.crt", "localhost.pfx") } It "piping from Get-DbaBinaryFileTable works" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles | Import-DbaBinaryFile -WarningAction Continue -ErrorAction Stop -EnableException -Path $script:appveyorlabrepo\certificates + $results = Get-DbaBinaryFileTable -SqlInstance $env:instance2 -Database tempdb -Table BunchOFiles | Import-DbaBinaryFile -WarningAction Continue -ErrorAction Stop -EnableException -Path $env:appveyorlabrepo\certificates $results.Database | Should -Be @("tempdb", "tempdb") Split-Path -Path $results.FilePath -Leaf | Should -Be @("localhost.crt", "localhost.pfx") } diff --git a/tests/Import-DbaCsv.Tests.ps1 b/tests/Import-DbaCsv.Tests.ps1 index 8d8e92dba8..e460431743 100644 --- a/tests/Import-DbaCsv.Tests.ps1 +++ b/tests/Import-DbaCsv.Tests.ps1 @@ -6,15 +6,15 @@ Describe "Import-DbaCsv" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $path = "$script:appveyorlabrepo\csv\SuperSmall.csv" - $CommaSeparatedWithHeader = "$script:appveyorlabrepo\csv\CommaSeparatedWithHeader.csv" - $col1 = "$script:appveyorlabrepo\csv\cols.csv" - $col2 = "$script:appveyorlabrepo\csv\col2.csv" - $pipe3 = "$script:appveyorlabrepo\csv\pipe3.psv" + $path = "$env:appveyorlabrepo\csv\SuperSmall.csv" + $CommaSeparatedWithHeader = "$env:appveyorlabrepo\csv\CommaSeparatedWithHeader.csv" + $col1 = "$env:appveyorlabrepo\csv\cols.csv" + $col2 = "$env:appveyorlabrepo\csv\col2.csv" + $pipe3 = "$env:appveyorlabrepo\csv\pipe3.psv" } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader" + Invoke-DbaQuery -SqlInstance $env:instance1, $env:instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader" } Context "Validate parameters" { @@ -40,13 +40,13 @@ Describe "Import-DbaCsv" { $CommandUnderTest | Should -HaveParameter Schema -Type String -Not -Mandatory } It "Should have Truncate parameter" { - $CommandUnderTest | Should -HaveParameter Truncate -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Truncate -Type Switch } It "Should have Delimiter parameter" { $CommandUnderTest | Should -HaveParameter Delimiter -Type Char -Not -Mandatory } It "Should have SingleColumn parameter" { - $CommandUnderTest | Should -HaveParameter SingleColumn -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SingleColumn -Type Switch } It "Should have BatchSize parameter" { $CommandUnderTest | Should -HaveParameter BatchSize -Type Int32 -Not -Mandatory @@ -55,19 +55,19 @@ Describe "Import-DbaCsv" { $CommandUnderTest | Should -HaveParameter NotifyAfter -Type Int32 -Not -Mandatory } It "Should have TableLock parameter" { - $CommandUnderTest | Should -HaveParameter TableLock -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter TableLock -Type Switch } It "Should have CheckConstraints parameter" { - $CommandUnderTest | Should -HaveParameter CheckConstraints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CheckConstraints -Type Switch } It "Should have FireTriggers parameter" { - $CommandUnderTest | Should -HaveParameter FireTriggers -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter FireTriggers -Type Switch } It "Should have KeepIdentity parameter" { - $CommandUnderTest | Should -HaveParameter KeepIdentity -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepIdentity -Type Switch } It "Should have KeepNulls parameter" { - $CommandUnderTest | Should -HaveParameter KeepNulls -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepNulls -Type Switch } It "Should have Column parameter" { $CommandUnderTest | Should -HaveParameter Column -Type String[] -Not -Mandatory @@ -76,19 +76,19 @@ Describe "Import-DbaCsv" { $CommandUnderTest | Should -HaveParameter ColumnMap -Type Hashtable -Not -Mandatory } It "Should have KeepOrdinalOrder parameter" { - $CommandUnderTest | Should -HaveParameter KeepOrdinalOrder -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepOrdinalOrder -Type Switch } It "Should have AutoCreateTable parameter" { - $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type Switch } It "Should have NoProgress parameter" { - $CommandUnderTest | Should -HaveParameter NoProgress -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoProgress -Type Switch } It "Should have NoHeaderRow parameter" { - $CommandUnderTest | Should -HaveParameter NoHeaderRow -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoHeaderRow -Type Switch } It "Should have UseFileNameForSchema parameter" { - $CommandUnderTest | Should -HaveParameter UseFileNameForSchema -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseFileNameForSchema -Type Switch } It "Should have Quote parameter" { $CommandUnderTest | Should -HaveParameter Quote -Type Char -Not -Mandatory @@ -118,42 +118,42 @@ Describe "Import-DbaCsv" { $CommandUnderTest | Should -HaveParameter MaxQuotedFieldLength -Type Int32 -Not -Mandatory } It "Should have SkipEmptyLine parameter" { - $CommandUnderTest | Should -HaveParameter SkipEmptyLine -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SkipEmptyLine -Type Switch } It "Should have SupportsMultiline parameter" { - $CommandUnderTest | Should -HaveParameter SupportsMultiline -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SupportsMultiline -Type Switch } It "Should have UseColumnDefault parameter" { - $CommandUnderTest | Should -HaveParameter UseColumnDefault -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseColumnDefault -Type Switch } It "Should have NoTransaction parameter" { - $CommandUnderTest | Should -HaveParameter NoTransaction -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoTransaction -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { It "accepts piped input and doesn't add rows if the table does not exist" { - $results = $path | Import-DbaCsv -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn + $results = $path | Import-DbaCsv -SqlInstance $env:instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn $results | Should -BeNullOrEmpty } It "creates the right columnmap (#7630), handles pipe delimiters (#7806)" { - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $col2 -Database tempdb -Table cols - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable - $results = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query "select * from cols" + $null = Import-DbaCsv -SqlInstance $env:instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols + $null = Import-DbaCsv -SqlInstance $env:instance1 -Path $col2 -Database tempdb -Table cols + $null = Import-DbaCsv -SqlInstance $env:instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable + $results = Invoke-DbaQuery -SqlInstance $env:instance1 -Database tempdb -Query "select * from cols" $results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty $results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty - $results = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query "select * from cols2" + $results = Invoke-DbaQuery -SqlInstance $env:instance1 -Database tempdb -Query "select * from cols2" $results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty $results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty } It "performs 4 imports" -Skip:($env:appveyor) { - $results = Import-DbaCsv -Path $path, $path -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable + $results = Import-DbaCsv -Path $path, $path -SqlInstance $env:instance1, $env:instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable $results.Count | Should -Be 4 foreach ($result in $results) { @@ -164,25 +164,25 @@ Describe "Import-DbaCsv" { } It "doesn't break when truncate is passed" -Skip:($env:appveyor) { - $result = Import-DbaCsv -Path $path -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate + $result = Import-DbaCsv -Path $path -SqlInstance $env:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb $result.Table | Should -Be SuperSmall } It "works with NoTransaction" -Skip:($env:appveyor) { - $result = Import-DbaCsv -Path $path -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction + $result = Import-DbaCsv -Path $path -SqlInstance $env:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb $result.Table | Should -Be SuperSmall } It "Catches the scenario where the database param does not match the server object passed into the command" { - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb $result = Import-DbaCsv -Path $path -SqlInstance $server -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable $result | Should -BeNullOrEmpty - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb $result = Import-DbaCsv -Path $path -SqlInstance $server -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb @@ -190,7 +190,7 @@ Describe "Import-DbaCsv" { } It "Catches the scenario where the header is not properly parsed causing param errors" { - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb $null = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -AutoCreateTable $result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Truncate @@ -201,7 +201,7 @@ Describe "Import-DbaCsv" { } It "works with NoHeaderRow" { - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE NoHeaderRow (c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50))' $result = Import-DbaCsv -Path $col1 -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow' -WarningVariable warnNoHeaderRow $data = Invoke-DbaQuery -SqlInstance $server -Query 'SELECT * FROM NoHeaderRow' -As PSObject @@ -214,7 +214,7 @@ Describe "Import-DbaCsv" { } It "works with tables which have non-varchar types (date)" { - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithTypes ([date] DATE, col1 VARCHAR(50), col2 VARCHAR(50))' $result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Table 'WithTypes' Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes' @@ -225,7 +225,7 @@ Describe "Import-DbaCsv" { It "works with tables which have non-varchar types (guid, bit)" { $filePath = '.\foo.csv' - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $env:instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)' $row = [pscustomobject]@{ one_guid = (New-Guid).Guid diff --git a/tests/Import-DbaRegServer.Tests.ps1 b/tests/Import-DbaRegServer.Tests.ps1 index 0c1bf386af..f6002203ac 100644 --- a/tests/Import-DbaRegServer.Tests.ps1 +++ b/tests/Import-DbaRegServer.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Import-DbaRegServer" { $CommandUnderTest | Should -HaveParameter Group -Type Object -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -38,51 +38,51 @@ Describe "Import-DbaRegServer" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $env:instance2 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $env:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group1a" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $env:instance2 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $env:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $env:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 } BeforeEach { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } AfterEach { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false $results, $results2, $results3 | Remove-Item -ErrorAction Ignore } It "imports group objects" { - $results = $newServer.Parent | Import-DbaRegServer -SqlInstance $script:instance2 + $results = $newServer.Parent | Import-DbaRegServer -SqlInstance $env:instance2 $results.Description | Should -Be $regSrvDesc $results.ServerName | Should -Be $srvName $results.Parent.Name | Should -Be $group } It "imports registered server objects" { - $results2 = $newServer2 | Import-DbaRegServer -SqlInstance $script:instance2 + $results2 = $newServer2 | Import-DbaRegServer -SqlInstance $env:instance2 $results2.ServerName | Should -Be $newServer2.ServerName $results2.Parent.Name | Should -Be $newServer2.Parent.Name } It "imports a file from Export-DbaRegServer" { $results3 = $newServer3 | Export-DbaRegServer -Path C:\temp - $results4 = Import-DbaRegServer -SqlInstance $script:instance2 -Path $results3 + $results4 = Import-DbaRegServer -SqlInstance $env:instance2 -Path $results3 $results4.ServerName | Should -Be @('dbatoolsci-server3') $results4.Description | Should -Be @('dbatoolsci-server3desc') } @@ -91,7 +91,7 @@ Describe "Import-DbaRegServer" { $object = [pscustomobject]@{ ServerName = 'dbatoolsci-randobject' } - $results = $object | Import-DbaRegServer -SqlInstance $script:instance2 + $results = $object | Import-DbaRegServer -SqlInstance $env:instance2 $results.ServerName | Should -Be 'dbatoolsci-randobject' $results.Name | Should -Be 'dbatoolsci-randobject' } @@ -100,7 +100,7 @@ Describe "Import-DbaRegServer" { $object = [pscustomobject]@{ Name = 'dbatoolsci-randobject' } - $results = $object | Import-DbaRegServer -SqlInstance $script:instance2 -WarningAction SilentlyContinue -WarningVariable warn + $results = $object | Import-DbaRegServer -SqlInstance $env:instance2 -WarningAction SilentlyContinue -WarningVariable warn $results | Should -BeNullOrEmpty $warn | Should -Match 'No servers added' } diff --git a/tests/Import-DbaSpConfigure.Tests.ps1 b/tests/Import-DbaSpConfigure.Tests.ps1 index d3cb3f985c..87c97797ac 100644 --- a/tests/Import-DbaSpConfigure.Tests.ps1 +++ b/tests/Import-DbaSpConfigure.Tests.ps1 @@ -33,10 +33,10 @@ Describe "Import-DbaSpConfigure" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Import-DbaXESessionTemplate.Tests.ps1 b/tests/Import-DbaXESessionTemplate.Tests.ps1 index 31c12b4104..8eb1f6a223 100644 --- a/tests/Import-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Import-DbaXESessionTemplate.Tests.ps1 @@ -36,21 +36,21 @@ Describe "Import-DbaXESessionTemplate" { $CommandUnderTest | Should -HaveParameter StartUpState -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Test Importing Session Template" { BeforeAll { - $script:instanceName = $script:instance2 + $env:instanceName = $env:instance2 } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instanceName -Session 'Overly Complex Queries' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $env:instanceName -Session 'Overly Complex Queries' | Remove-DbaXESession } It "Session imports with proper name and non-default target file location" -Skip { - $result = Import-DbaXESessionTemplate -SqlInstance $script:instanceName -Template 'Overly Complex Queries' -TargetFilePath C:\temp + $result = Import-DbaXESessionTemplate -SqlInstance $env:instanceName -Template 'Overly Complex Queries' -TargetFilePath C:\temp $result.Name | Should -Be "Overly Complex Queries" $result.TargetFile | Should -Match 'C:\\temp' } diff --git a/tests/Import-DbatoolsConfig.Tests.ps1 b/tests/Import-DbatoolsConfig.Tests.ps1 index ed24e1d567..83f6a3f6e3 100644 --- a/tests/Import-DbatoolsConfig.Tests.ps1 +++ b/tests/Import-DbatoolsConfig.Tests.ps1 @@ -29,11 +29,11 @@ Describe "Import-DbatoolsConfig" { It "Should have ExcludeFilter as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter ExcludeFilter -Type String[] -Not -Mandatory } - It "Should have Peek as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Peek -Type SwitchParameter -Not -Mandatory + It "Should have Peek as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Peek -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Install-DbaAgentAdminAlert.Tests.ps1 b/tests/Install-DbaAgentAdminAlert.Tests.ps1 index 93689291f7..f5221d0b19 100644 --- a/tests/Install-DbaAgentAdminAlert.Tests.ps1 +++ b/tests/Install-DbaAgentAdminAlert.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Install-DbaAgentAdminAlert" { $CommandUnderTest | Should -HaveParameter DelayBetweenResponses -Type Int32 } It "Should have Disabled as a parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch } It "Should have EventDescriptionKeyword as a parameter" { $CommandUnderTest | Should -HaveParameter EventDescriptionKeyword -Type String @@ -56,17 +56,17 @@ Describe "Install-DbaAgentAdminAlert" { $CommandUnderTest | Should -HaveParameter NotifyMethod -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $script:instances = @($script:instance2, $script:instance3) + $env:instances = @($env:instance2, $env:instance3) } BeforeEach { - foreach ($instance in $script:instances) { + foreach ($instance in $env:instances) { Get-DbaAgentAlert -SqlInstance $instance | Remove-DbaAgentAlert -Confirm:$false } } @@ -74,7 +74,7 @@ Describe "Install-DbaAgentAdminAlert" { Context 'Creating a new SQL Server Agent alert' { It 'Should create a bunch of new alerts on instance2' { $parms = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 DelayBetweenResponses = 60 Disabled = $false NotifyMethod = "NotifyEmail" @@ -94,7 +94,7 @@ Describe "Install-DbaAgentAdminAlert" { It 'Should create a bunch of new alerts on instance3' { $parms = @{ - SqlInstance = $script:instance3 + SqlInstance = $env:instance3 DelayBetweenResponses = 60 Disabled = $false NotifyMethod = "NotifyEmail" @@ -108,7 +108,7 @@ Describe "Install-DbaAgentAdminAlert" { $alerts = Install-DbaAgentAdminAlert @parms $alerts.Severity | Should -Not -Contain 17 - Get-DbaAgentAlert -SqlInstance $script:instance3 | Should -Not -BeNullOrEmpty + Get-DbaAgentAlert -SqlInstance $env:instance3 | Should -Not -BeNullOrEmpty } } } diff --git a/tests/Install-DbaDarlingData.Tests.ps1 b/tests/Install-DbaDarlingData.Tests.ps1 index d2aae0bd16..411e19e6f4 100644 --- a/tests/Install-DbaDarlingData.Tests.ps1 +++ b/tests/Install-DbaDarlingData.Tests.ps1 @@ -24,23 +24,23 @@ Describe "Install-DbaDarlingData" { $CommandUnderTest | Should -HaveParameter LocalFile -Type String } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Testing DarlingData installer with download" { BeforeAll { $database = "dbatoolsci_darling_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaDarlingData -SqlInstance $script:instance3 -Database $database -Branch main -Force -Verbose:$false + $resultsDownload = Install-DbaDarlingData -SqlInstance $env:instance3 -Database $database -Branch main -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -59,7 +59,7 @@ Describe "Install-DbaDarlingData" { Context "Testing DarlingData installer with LocalFile" { BeforeAll { $database = "dbatoolsci_darling_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $server.Query("CREATE DATABASE $database") $outfile = "DarlingData-main.zip" @@ -67,10 +67,10 @@ Describe "Install-DbaDarlingData" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaDarlingData -SqlInstance $script:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaDarlingData -SqlInstance $env:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { diff --git a/tests/Install-DbaFirstResponderKit.Tests.ps1 b/tests/Install-DbaFirstResponderKit.Tests.ps1 index aef3ed97b5..808c1ec0e2 100644 --- a/tests/Install-DbaFirstResponderKit.Tests.ps1 +++ b/tests/Install-DbaFirstResponderKit.Tests.ps1 @@ -28,23 +28,23 @@ Describe "Install-DbaFirstResponderKit" { $CommandUnderTest | Should -HaveParameter OnlyScript -Type String[] } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Testing First Responder Kit installer with download" { BeforeAll { $database = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Branch main -Force -Verbose:$false + $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $env:instance2 -Database $database -Branch main -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -63,14 +63,14 @@ Describe "Install-DbaFirstResponderKit" { $result.PsObject.Properties.Name | Should -Be $ExpectedProps } It "Shows status of Updated" { - $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Verbose:$false + $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $env:instance2 -Database $database -Verbose:$false $resultsDownload[0].Status | Should -Be 'Updated' } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "SQL-Server-First-Responder-Kit-main" $sqlScript = (Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1).FullName Add-Content $sqlScript (New-Guid).ToString() - $result = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Verbose:$false + $result = Install-DbaFirstResponderKit -SqlInstance $env:instance2 -Database $database -Verbose:$false $result[0].Status | Should -Be "Error" } } @@ -78,7 +78,7 @@ Describe "Install-DbaFirstResponderKit" { Context "Testing First Responder Kit installer with LocalFile" { BeforeAll { $database = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $server.Query("CREATE DATABASE $database") $outfile = "SQL-Server-First-Responder-Kit-main.zip" @@ -86,10 +86,10 @@ Describe "Install-DbaFirstResponderKit" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $env:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -108,14 +108,14 @@ Describe "Install-DbaFirstResponderKit" { $result.PsObject.Properties.Name | Should -Be $ExpectedProps } It "Shows status of Updated" { - $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database + $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $env:instance3 -Database $database $resultsLocalFile[0].Status | Should -Be 'Updated' } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "SQL-Server-First-Responder-Kit-main" $sqlScript = (Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1).FullName Add-Content $sqlScript (New-Guid).ToString() - $result = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database + $result = Install-DbaFirstResponderKit -SqlInstance $env:instance3 -Database $database $result[0].Status | Should -Be "Error" } } diff --git a/tests/Install-DbaInstance.Tests.ps1 b/tests/Install-DbaInstance.Tests.ps1 index 8785ad1bae..99a6753067 100644 --- a/tests/Install-DbaInstance.Tests.ps1 +++ b/tests/Install-DbaInstance.Tests.ps1 @@ -122,16 +122,16 @@ Describe "Install-DbaInstance" { $command | Should -HaveParameter SaveConfiguration -Type String -Not -Mandatory } It "Should have PerformVolumeMaintenanceTasks parameter" { - $command | Should -HaveParameter PerformVolumeMaintenanceTasks -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter PerformVolumeMaintenanceTasks -Type Switch -Not -Mandatory } It "Should have Restart parameter" { - $command | Should -HaveParameter Restart -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Restart -Type Switch -Not -Mandatory } It "Should have NoPendingRenameCheck parameter" { - $command | Should -HaveParameter NoPendingRenameCheck -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter NoPendingRenameCheck -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Install-DbaMaintenanceSolution.Tests.ps1 b/tests/Install-DbaMaintenanceSolution.Tests.ps1 index f5b734a5fe..adf581a35a 100644 --- a/tests/Install-DbaMaintenanceSolution.Tests.ps1 +++ b/tests/Install-DbaMaintenanceSolution.Tests.ps1 @@ -28,16 +28,16 @@ Describe "Install-DbaMaintenanceSolution" { $CommandUnderTest | Should -HaveParameter OutputFileDirectory -Type String } It "Should have ReplaceExisting parameter" { - $CommandUnderTest | Should -HaveParameter ReplaceExisting -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ReplaceExisting -Type Switch } It "Should have LogToTable parameter" { - $CommandUnderTest | Should -HaveParameter LogToTable -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter LogToTable -Type Switch } It "Should have Solution parameter" { $CommandUnderTest | Should -HaveParameter Solution -Type String[] } It "Should have InstallJobs parameter" { - $CommandUnderTest | Should -HaveParameter InstallJobs -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter InstallJobs -Type Switch } It "Should have AutoScheduleJobs parameter" { $CommandUnderTest | Should -HaveParameter AutoScheduleJobs -Type String[] @@ -49,34 +49,34 @@ Describe "Install-DbaMaintenanceSolution" { $CommandUnderTest | Should -HaveParameter LocalFile -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have InstallParallel parameter" { - $CommandUnderTest | Should -HaveParameter InstallParallel -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter InstallParallel -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Limited testing of Maintenance Solution installer" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Databases['tempdb'].Query("CREATE TABLE CommandLog (id int)") } AfterAll { $server.Databases['tempdb'].Query("DROP TABLE CommandLog") - Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;" + Invoke-DbaQuery -SqlInstance $env:instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;" } It "does not overwrite existing" { $warn = $null - $results = Install-DbaMaintenanceSolution -SqlInstance $script:instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue + $results = Install-DbaMaintenanceSolution -SqlInstance $env:instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue $warn | Should -Match "already exists" } It "Continues the installation on other servers" { - $results2 = Install-DbaMaintenanceSolution -SqlInstance $script:instance2, $script:instance3 -Database tempdb - $sproc = Get-DbaDbModule -SqlInstance $script:instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" } + $results2 = Install-DbaMaintenanceSolution -SqlInstance $env:instance2, $env:instance3 -Database tempdb + $sproc = Get-DbaDbModule -SqlInstance $env:instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" } $sproc | Should -Not -BeNullOrEmpty } } diff --git a/tests/Install-DbaMultiTool.Tests.ps1 b/tests/Install-DbaMultiTool.Tests.ps1 index 68bbccbe24..97801efe3f 100644 --- a/tests/Install-DbaMultiTool.Tests.ps1 +++ b/tests/Install-DbaMultiTool.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Install-DbaMultiTool" { $CommandUnderTest | Should -HaveParameter LocalFile -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -33,13 +33,13 @@ Describe "Install-DbaMultiTool" { . "$PSScriptRoot\constants.ps1" $branch = "main" $database = "dbatoolsci_multitool_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Branch $branch -Force -Verbose:$false + $resultsDownload = Install-DbaMultiTool -SqlInstance $env:instance2 -Database $database -Branch $branch -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -60,14 +60,14 @@ Describe "Install-DbaMultiTool" { $result.PsObject.Properties.Name | Should -Be $ExpectedProps } It "Shows status of Updated" { - $resultsDownload = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Verbose:$false + $resultsDownload = Install-DbaMultiTool -SqlInstance $env:instance2 -Database $database -Verbose:$false $resultsDownload[0].Status | Should -Be 'Updated' } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch" $sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1 Add-Content $sqlScript.FullName (New-Guid).ToString() - $result = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Verbose:$false + $result = Install-DbaMultiTool -SqlInstance $env:instance2 -Database $database -Verbose:$false $result = $result | Where-Object Name -eq $sqlScript.BaseName $result.Status | Should -Be "Error" } @@ -78,7 +78,7 @@ Describe "Install-DbaMultiTool" { . "$PSScriptRoot\constants.ps1" $branch = "main" $database = "dbatoolsci_multitool_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 $server.Query("CREATE DATABASE $database") $outfile = "dba-multitool-$branch.zip" @@ -86,10 +86,10 @@ Describe "Install-DbaMultiTool" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database -Branch $branch -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaMultiTool -SqlInstance $env:instance3 -Database $database -Branch $branch -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -110,14 +110,14 @@ Describe "Install-DbaMultiTool" { $result.PsObject.Properties.Name | Should -Be $ExpectedProps } It "Shows status of Updated" { - $resultsLocalFile = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database + $resultsLocalFile = Install-DbaMultiTool -SqlInstance $env:instance3 -Database $database $resultsLocalFile[0].Status | Should -Be 'Updated' } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch" $sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1 Add-Content $sqlScript.FullName (New-Guid).ToString() - $result = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database -Verbose:$false + $result = Install-DbaMultiTool -SqlInstance $env:instance3 -Database $database -Verbose:$false $result = $result | Where-Object Name -eq $sqlScript.BaseName $result.Status | Should -Be "Error" } diff --git a/tests/Install-DbaSqlWatch.Tests.ps1 b/tests/Install-DbaSqlWatch.Tests.ps1 index aaeea01aae..42f0215403 100644 --- a/tests/Install-DbaSqlWatch.Tests.ps1 +++ b/tests/Install-DbaSqlWatch.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Install-DbaSqlWatch" { $CommandUnderTest | Should -HaveParameter LocalFile -Type String } It "Should have PreRelease as a switch parameter" { - $CommandUnderTest | Should -HaveParameter PreRelease -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter PreRelease -Type Switch } It "Should have Force as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -35,43 +35,43 @@ Describe "Install-DbaSqlWatch" { BeforeAll { $database = "dbatoolsci_sqlwatch_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE $database") } AfterAll { - Uninstall-DbaSqlWatch -SqlInstance $script:instance2 -Database $database - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Uninstall-DbaSqlWatch -SqlInstance $env:instance2 -Database $database + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Installs to specified database: " { - $results = Install-DbaSqlWatch -SqlInstance $script:instance2 -Database $database + $results = Install-DbaSqlWatch -SqlInstance $env:instance2 -Database $database $results[0].Database | Should -Be $database } It "Returns an object with the expected properties" { - $results = Install-DbaSqlWatch -SqlInstance $script:instance2 -Database $database + $results = Install-DbaSqlWatch -SqlInstance $env:instance2 -Database $database $result = $results[0] $ExpectedProps = 'SqlInstance', 'InstanceName', 'ComputerName', 'Database', 'Status', 'DashboardPath' $result.PsObject.Properties.Name | Should -Be $ExpectedProps } It "Installed tables" { - $tableCount = (Get-DbaDbTable -SqlInstance $script:instance2 -Database $database | Where-Object { $_.Name -like "sqlwatch_*" }).Count + $tableCount = (Get-DbaDbTable -SqlInstance $env:instance2 -Database $database | Where-Object { $_.Name -like "sqlwatch_*" }).Count $tableCount | Should -BeGreaterThan 0 } It "Installed views" { - $viewCount = (Get-DbaDbView -SqlInstance $script:instance2 -Database $database | Where-Object { $_.Name -like "vw_sqlwatch_*" }).Count + $viewCount = (Get-DbaDbView -SqlInstance $env:instance2 -Database $database | Where-Object { $_.Name -like "vw_sqlwatch_*" }).Count $viewCount | Should -BeGreaterThan 0 } It "Installed stored procedures" { - $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $database | Where-Object { $_.Name -like "usp_sqlwatch_*" }).Count + $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $env:instance2 -Database $database | Where-Object { $_.Name -like "usp_sqlwatch_*" }).Count $sprocCount | Should -BeGreaterThan 0 } It "Installed SQL Agent jobs" { - $agentCount = (Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object { ($_.Name -like "SqlWatch-*") -or ($_.Name -like "DBA-PERF-*") }).Count + $agentCount = (Get-DbaAgentJob -SqlInstance $env:instance2 | Where-Object { ($_.Name -like "SqlWatch-*") -or ($_.Name -like "DBA-PERF-*") }).Count $agentCount | Should -BeGreaterThan 0 } } diff --git a/tests/Install-DbaWhoIsActive.Tests.ps1 b/tests/Install-DbaWhoIsActive.Tests.ps1 index 650e73e8f0..ce9fee78b0 100644 --- a/tests/Install-DbaWhoIsActive.Tests.ps1 +++ b/tests/Install-DbaWhoIsActive.Tests.ps1 @@ -174,7 +174,7 @@ ALTER PROC dbo.sp_WhoIsActive AfterAll { Remove-Item -Path $testfilepath, $testzippath, "$testtemp\who_MOCKED_is_active_v11_32.sql", "$DbatoolsData\spwhoisactive.zip" -Force -ErrorAction SilentlyContinue - Invoke-DbaQuery -SqlInstance $script:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } Context "Validate parameters" { @@ -204,22 +204,22 @@ ALTER PROC dbo.sp_WhoIsActive } It "Should have EnableException parameter" { $ParameterList['EnableException'] | Should -Not -BeNullOrEmpty - $ParameterList['EnableException'].ParameterType.Name | Should -Be 'SwitchParameter' + $ParameterList['EnableException'].ParameterType.Name | Should -Be 'Switch' $ParameterList['EnableException'].IsMandatory | Should -Be $false } It "Should have Force parameter" { $ParameterList['Force'] | Should -Not -BeNullOrEmpty - $ParameterList['Force'].ParameterType.Name | Should -Be 'SwitchParameter' + $ParameterList['Force'].ParameterType.Name | Should -Be 'Switch' $ParameterList['Force'].IsMandatory | Should -Be $false } } Context "Should Install SPWhoisActive with Mock" { BeforeAll { - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -Database Master + $results = Install-DbaWhoIsActive -SqlInstance $env:instance1 -Database Master } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } It "Should simulate install from internet" { $results | Should -Not -BeNullOrEmpty @@ -228,10 +228,10 @@ ALTER PROC dbo.sp_WhoIsActive Context "Should Install SPWhoisActive from File" { BeforeAll { - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testfilepath -Database Master + $results = Install-DbaWhoIsActive -SqlInstance $env:instance1 -LocalFile $testfilepath -Database Master } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } It "Should install against .sql file" { $results | Should -Not -BeNullOrEmpty @@ -240,10 +240,10 @@ ALTER PROC dbo.sp_WhoIsActive Context "Should Install SPWhoisActive from Zip" { BeforeAll { - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database tempdb + $results = Install-DbaWhoIsActive -SqlInstance $env:instance1 -LocalFile $testzippath -Database tempdb } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } It "Should install against ZIP" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Invoke-DbaAdvancedInstall.Tests.ps1 b/tests/Invoke-DbaAdvancedInstall.Tests.ps1 index c6ddb68dc1..0b0bdf1ec7 100644 --- a/tests/Invoke-DbaAdvancedInstall.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedInstall.Tests.ps1 @@ -74,11 +74,11 @@ Describe "Invoke-DbaAdvancedInstall" { It "Should have SaCredential as a non-mandatory PSCredential parameter" { $CommandUnderTest | Should -HaveParameter SaCredential -Type PSCredential -Not -Mandatory } - It "Should have NoPendingRenameCheck as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter NoPendingRenameCheck -Type SwitchParameter -Not -Mandatory + It "Should have NoPendingRenameCheck as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter NoPendingRenameCheck -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Invoke-DbaAdvancedRestore.Tests.ps1 b/tests/Invoke-DbaAdvancedRestore.Tests.ps1 index 3918af1f72..55fd65577a 100644 --- a/tests/Invoke-DbaAdvancedRestore.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedRestore.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Invoke-DbaAdvancedRestore" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have OutputScriptOnly parameter" { - $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type Switch } It "Should have VerifyOnly parameter" { - $CommandUnderTest | Should -HaveParameter VerifyOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter VerifyOnly -Type Switch } It "Should have RestoreTime parameter" { $CommandUnderTest | Should -HaveParameter RestoreTime -Type DateTime @@ -33,7 +33,7 @@ Describe "Invoke-DbaAdvancedRestore" { $CommandUnderTest | Should -HaveParameter StandbyDirectory -Type String } It "Should have NoRecovery parameter" { - $CommandUnderTest | Should -HaveParameter NoRecovery -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoRecovery -Type Switch } It "Should have MaxTransferSize parameter" { $CommandUnderTest | Should -HaveParameter MaxTransferSize -Type Int32 @@ -45,19 +45,19 @@ Describe "Invoke-DbaAdvancedRestore" { $CommandUnderTest | Should -HaveParameter BufferCount -Type Int32 } It "Should have Continue parameter" { - $CommandUnderTest | Should -HaveParameter Continue -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Continue -Type Switch } It "Should have AzureCredential parameter" { $CommandUnderTest | Should -HaveParameter AzureCredential -Type String } It "Should have WithReplace parameter" { - $CommandUnderTest | Should -HaveParameter WithReplace -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WithReplace -Type Switch } It "Should have KeepReplication parameter" { - $CommandUnderTest | Should -HaveParameter KeepReplication -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepReplication -Type Switch } It "Should have KeepCDC parameter" { - $CommandUnderTest | Should -HaveParameter KeepCDC -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepCDC -Type Switch } It "Should have PageRestore parameter" { $CommandUnderTest | Should -HaveParameter PageRestore -Type Object[] @@ -66,7 +66,7 @@ Describe "Invoke-DbaAdvancedRestore" { $CommandUnderTest | Should -HaveParameter ExecuteAs -Type String } It "Should have StopBefore parameter" { - $CommandUnderTest | Should -HaveParameter StopBefore -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter StopBefore -Type Switch } It "Should have StopMark parameter" { $CommandUnderTest | Should -HaveParameter StopMark -Type String @@ -75,7 +75,7 @@ Describe "Invoke-DbaAdvancedRestore" { $CommandUnderTest | Should -HaveParameter StopAfterDate -Type DateTime } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 b/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 index aa92db722a..a4f8052ddf 100644 --- a/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 @@ -47,11 +47,11 @@ Describe "Invoke-DbaAdvancedUpdate" { It "Should have ArgumentList as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter ArgumentList -Type String[] -Not -Mandatory } - It "Should have NoPendingRenameCheck as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter NoPendingRenameCheck -Type SwitchParameter -Not -Mandatory + It "Should have NoPendingRenameCheck as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter NoPendingRenameCheck -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Invoke-DbaAgFailover.Tests.ps1 b/tests/Invoke-DbaAgFailover.Tests.ps1 index 5917081832..6ae90c1f01 100644 --- a/tests/Invoke-DbaAgFailover.Tests.ps1 +++ b/tests/Invoke-DbaAgFailover.Tests.ps1 @@ -22,14 +22,14 @@ Describe "Invoke-DbaAgFailover" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have common parameters" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory $CommandUnderTest | Should -HaveParameter WarningAction -Type ActionPreference -Not -Mandatory $CommandUnderTest | Should -HaveParameter InformationAction -Type ActionPreference -Not -Mandatory @@ -40,8 +40,8 @@ Describe "Invoke-DbaAgFailover" { $CommandUnderTest | Should -HaveParameter OutVariable -Type String -Not -Mandatory $CommandUnderTest | Should -HaveParameter OutBuffer -Type Int32 -Not -Mandatory $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } @@ -51,11 +51,11 @@ Describe "Invoke-DbaAgFailover" { # BeforeAll { # # Setup mock SQL Server environment or use constants for testing # } - # + # # It "Successfully fails over an availability group" { # # Test code here # } - # + # # It "Handles errors appropriately" { # # Test code here # } diff --git a/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 b/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 index 5963e4a144..ff6885744d 100644 --- a/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 +++ b/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 @@ -54,24 +54,24 @@ Describe "Invoke-DbaAzSqlDbTip" { Context "Run the tips against Azure database" { BeforeDiscovery { - $script:skipAzureTests = [Environment]::GetEnvironmentVariable('azuredbpasswd') -ne "failstoooften" + $env:skipAzureTests = [Environment]::GetEnvironmentVariable('azuredbpasswd') -ne "failstoooften" } BeforeAll { $securePassword = ConvertTo-SecureString $env:azuredbpasswd -AsPlainText -Force - $cred = New-Object System.Management.Automation.PSCredential ($script:azuresqldblogin, $securePassword) - $results = Invoke-DbaAzSqlDbTip -SqlInstance $script:azureserver -Database test -SqlCredential $cred -ReturnAllTips + $cred = New-Object System.Management.Automation.PSCredential ($env:azuresqldblogin, $securePassword) + $results = Invoke-DbaAzSqlDbTip -SqlInstance $env:azureserver -Database test -SqlCredential $cred -ReturnAllTips } - It "Should get some results" -Skip:$script:skipAzureTests { + It "Should get some results" -Skip:$env:skipAzureTests { $results | Should -Not -BeNullOrEmpty } - It "Should have the right ComputerName" -Skip:$script:skipAzureTests { - $results.ComputerName | Should -Be $script:azureserver + It "Should have the right ComputerName" -Skip:$env:skipAzureTests { + $results.ComputerName | Should -Be $env:azureserver } - It "Database name should be 'test'" -Skip:$script:skipAzureTests { + It "Database name should be 'test'" -Skip:$env:skipAzureTests { $results.Database | Should -Be 'test' } } diff --git a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 index 3a868bc67c..0023b92224 100644 --- a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 +++ b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Invoke-DbaBalanceDataFiles" { $CommandUnderTest | Should -HaveParameter Table -Type Object[] -Not -Mandatory } It "Should have RebuildOffline parameter" { - $CommandUnderTest | Should -HaveParameter RebuildOffline -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter RebuildOffline -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } } } @@ -35,7 +35,7 @@ Describe "Invoke-DbaBalanceDataFiles Integration Tests" -Tag "IntegrationTests" } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $defaultdata = (Get-DbaDefaultPath -SqlInstance $server).Data $dbname = "dbatoolscsi_balance" diff --git a/tests/Invoke-DbaCycleErrorLog.Tests.ps1 b/tests/Invoke-DbaCycleErrorLog.Tests.ps1 index 5b13abb37a..05d3c7585b 100644 --- a/tests/Invoke-DbaCycleErrorLog.Tests.ps1 +++ b/tests/Invoke-DbaCycleErrorLog.Tests.ps1 @@ -25,12 +25,12 @@ Describe "Invoke-DbaCycleErrorLog Unit Tests" -Tag "UnitTests" { } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have common parameters" { - $command | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Verbose -Type Switch -Not -Mandatory + $command | Should -HaveParameter Debug -Type Switch -Not -Mandatory $command | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory $command | Should -HaveParameter WarningAction -Type ActionPreference -Not -Mandatory $command | Should -HaveParameter InformationAction -Type ActionPreference -Not -Mandatory @@ -40,8 +40,8 @@ Describe "Invoke-DbaCycleErrorLog Unit Tests" -Tag "UnitTests" { $command | Should -HaveParameter OutVariable -Type String -Not -Mandatory $command | Should -HaveParameter OutBuffer -Type Int32 -Not -Mandatory $command | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory - $command | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory + $command | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } } @@ -50,7 +50,7 @@ Describe "Invoke-DbaCycleErrorLog Integration Tests" -Tag "IntegrationTests" { BeforeAll { # Importing constants and any necessary setup . "$PSScriptRoot\constants.ps1" - $results = Invoke-DbaCycleErrorLog -SqlInstance $script:instance1 -Type instance + $results = Invoke-DbaCycleErrorLog -SqlInstance $env:instance1 -Type instance } Context "Validate output" { diff --git a/tests/Invoke-DbaDbClone.Tests.ps1 b/tests/Invoke-DbaDbClone.Tests.ps1 index 21c185d4f7..b2ff14add9 100644 --- a/tests/Invoke-DbaDbClone.Tests.ps1 +++ b/tests/Invoke-DbaDbClone.Tests.ps1 @@ -27,16 +27,16 @@ Describe "Invoke-DbaDbClone" { $CommandUnderTest | Should -HaveParameter CloneDatabase -Type String[] -Not -Mandatory } It "Should have ExcludeStatistics parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeStatistics -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeStatistics -Type Switch -Not -Mandatory } It "Should have ExcludeQueryStore parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeQueryStore -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeQueryStore -Type Switch -Not -Mandatory } It "Should have UpdateStatistics parameter" { - $CommandUnderTest | Should -HaveParameter UpdateStatistics -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter UpdateStatistics -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -46,7 +46,7 @@ Describe "Invoke-DbaDbClone" { $clonedb = "dbatoolsci_clonetest_CLONE" $clonedb2 = "dbatoolsci_clonetest_CLONE2" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE $dbname") } @@ -56,24 +56,24 @@ Describe "Invoke-DbaDbClone" { It "warns if SQL instance version is not supported" { $versionwarn = $null - $results = Invoke-DbaDbClone -SqlInstance $script:instance1 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable versionwarn + $results = Invoke-DbaDbClone -SqlInstance $env:instance1 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable versionwarn $versionwarn | Should -Match "required" } It "warns if destination database already exists" { $dbwarn = $null - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database $dbname -CloneDatabase tempdb -WarningAction SilentlyContinue -WarningVariable dbwarn + $results = Invoke-DbaDbClone -SqlInstance $env:instance2 -Database $dbname -CloneDatabase tempdb -WarningAction SilentlyContinue -WarningVariable dbwarn $dbwarn | Should -Match "exists" } It "warns if a system db is specified to clone" { $systemwarn = $null - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database master -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable systemwarn + $results = Invoke-DbaDbClone -SqlInstance $env:instance2 -Database master -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable systemwarn $systemwarn | Should -Match "user database" } It "returns 1 result with the correct name" { - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue + $results = Invoke-DbaDbClone -SqlInstance $env:instance2 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue $results | Should -HaveCount 1 $results.Name | Should -BeIn @($clonedb, $clonedb2) } diff --git a/tests/Invoke-DbaDbCorruption.Tests.ps1 b/tests/Invoke-DbaDbCorruption.Tests.ps1 index e5aef11ce8..2894915edd 100644 --- a/tests/Invoke-DbaDbCorruption.Tests.ps1 +++ b/tests/Invoke-DbaDbCorruption.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Invoke-DbaDbCorruption" { $CommandUnderTest | Should -HaveParameter Table -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -38,36 +38,36 @@ Describe "Invoke-DbaDbCorruption" { Context "Integration Tests" { BeforeAll { $dbname = "dbatoolsci_InvokeDbaDatabaseCorruptionTest" - $Server = Connect-DbaInstance -SqlInstance $script:instance2 + $Server = Connect-DbaInstance -SqlInstance $env:instance2 $TableName = "Example" # Need a clean empty database $null = $Server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname } AfterAll { # Cleanup - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false } Context "Validating Database Input" { It "Should not allow you to corrupt system databases." { $systemwarn = $null - Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database "master" -WarningAction SilentlyContinue -WarningVariable systemwarn + Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database "master" -WarningAction SilentlyContinue -WarningVariable systemwarn $systemwarn | Should -Match 'may not corrupt system databases' } It "Should fail if more than one database is specified" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database "Database1", "Database2" -EnableException } | Should -Throw + { Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database "Database1", "Database2" -EnableException } | Should -Throw } } It "Require at least a single table in the database specified" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -EnableException } | Should -Throw + { Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database $dbname -EnableException } | Should -Throw } It "Fail if the specified table does not exist" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Table "DoesntExist$(New-Guid)" -EnableException } | Should -Throw + { Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database $dbname -Table "DoesntExist$(New-Guid)" -EnableException } | Should -Throw } It "Corrupt a single database" { @@ -77,7 +77,7 @@ Describe "Invoke-DbaDbCorruption" { SELECT top 1000 1 FROM sys.objects") - $result = Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + $result = Invoke-DbaDbCorruption -SqlInstance $env:instance2 -Database $dbname -Confirm:$false $result.Status | Should -Be "Corrupted" } diff --git a/tests/Invoke-DbaDbDataGenerator.Tests.ps1 b/tests/Invoke-DbaDbDataGenerator.Tests.ps1 index 96c3adcb9b..33d6f1fb68 100644 --- a/tests/Invoke-DbaDbDataGenerator.Tests.ps1 +++ b/tests/Invoke-DbaDbDataGenerator.Tests.ps1 @@ -45,13 +45,13 @@ Describe "Invoke-DbaDbDataGenerator" { $CommandUnderTest | Should -HaveParameter MaxValue -Type Int32 -Not -Mandatory } It "Should have ExactLength parameter" { - $CommandUnderTest | Should -HaveParameter ExactLength -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExactLength -Type Switch -Not -Mandatory } It "Should have ModulusFactor parameter" { $CommandUnderTest | Should -HaveParameter ModulusFactor -Type Int32 -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -63,24 +63,24 @@ Describe "Invoke-DbaDbDataGenerator" { [LastName] [varchar](50) NULL, [City] [varchar](100) NULL ) ON [PRIMARY];" - New-DbaDatabase -SqlInstance $script:instance2 -Name $db - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query $sql + New-DbaDatabase -SqlInstance $env:instance2 -Name $db + Invoke-DbaQuery -SqlInstance $env:instance2 -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $db -Confirm:$false $file | Remove-Item -Confirm:$false -ErrorAction Ignore } It "Starts with the right data" { - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query "select * from people" + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $db -Query "select * from people" $result | Should -BeNullOrEmpty } It "Returns the proper output" { - $file = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance2 -Database $db -Path C:\temp -Rows 10 + $file = New-DbaDbDataGeneratorConfig -SqlInstance $env:instance2 -Database $db -Path C:\temp -Rows 10 - $results = Invoke-DbaDbDataGenerator -SqlInstance $script:instance2 -Database $db -Confirm:$false -FilePath $file.FullName + $results = Invoke-DbaDbDataGenerator -SqlInstance $env:instance2 -Database $db -Confirm:$false -FilePath $file.FullName foreach ($result in $results) { $result.Rows | Should -Be 10 @@ -89,7 +89,7 @@ Describe "Invoke-DbaDbDataGenerator" { } It "Generates the data" { - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query "select * from people" + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $db -Query "select * from people" $result | Should -Not -BeNullOrEmpty } } diff --git a/tests/Invoke-DbaDbDataMasking.Tests.ps1 b/tests/Invoke-DbaDbDataMasking.Tests.ps1 index 6d19a8567e..b294291594 100644 --- a/tests/Invoke-DbaDbDataMasking.Tests.ps1 +++ b/tests/Invoke-DbaDbDataMasking.Tests.ps1 @@ -24,12 +24,12 @@ Describe "Invoke-DbaDbDataMasking" { GO INSERT INTO people2 (fname, lname, dob) VALUES ('Layla','Schmoe','2/2/2000') INSERT INTO people2 (fname, lname, dob) VALUES ('Eric','Schmee','2/2/1950')" - New-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Name $db - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $sql + New-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Name $db + Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Confirm:$false $file | Remove-Item -Confirm:$false -ErrorAction Ignore } @@ -74,7 +74,7 @@ Describe "Invoke-DbaDbDataMasking" { $CommandUnderTest | Should -HaveParameter ModulusFactor -Type Int32 } It "Should have ExactLength as a parameter" { - $CommandUnderTest | Should -HaveParameter ExactLength -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExactLength -Type Switch } It "Should have CommandTimeout as a parameter" { $CommandUnderTest | Should -HaveParameter CommandTimeout -Type Int32 @@ -92,27 +92,27 @@ Describe "Invoke-DbaDbDataMasking" { $CommandUnderTest | Should -HaveParameter DictionaryExportPath -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command works" { It "starts with the right data" { $query = "select * from people where fname = 'Joe'" - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $query + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $query $result | Should -Not -BeNullOrEmpty } It "starts with the right data (lname)" { $query = "select * from people where lname = 'Schmee'" - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $query + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $query $result | Should -Not -BeNullOrEmpty } It "returns the proper output" { - $file = New-DbaDbMaskingConfig -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Path C:\temp + $file = New-DbaDbMaskingConfig -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Path C:\temp - [array]$results = $file | Invoke-DbaDbDataMasking -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Confirm:$false + [array]$results = $file | Invoke-DbaDbDataMasking -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Confirm:$false $results[0].Rows | Should -Be 2 $results[0].Database | Should -Contain $db @@ -123,15 +123,15 @@ Describe "Invoke-DbaDbDataMasking" { It "masks the data and does not delete it" { $query1 = "select * from people" - $result1 = Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $query1 + $result1 = Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $query1 $result1 | Should -Not -BeNullOrEmpty $query2 = "select * from people where fname = 'Joe'" - $result2 = Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $query2 + $result2 = Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $query2 $result2 | Should -BeNullOrEmpty $query3 = "select * from people where lname = 'Schmee'" - $result3 = Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $query3 + $result3 = Invoke-DbaQuery -SqlInstance $env:instance2 -SqlCredential $env:SqlCredential -Database $db -Query $query3 $result3 | Should -BeNullOrEmpty } } diff --git a/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 b/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 index 73e133e2e1..e2e85e2790 100644 --- a/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 @@ -24,23 +24,23 @@ Describe "Invoke-DbaDbDbccCheckConstraint Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Object -Type String -Not -Mandatory } It "Should have AllConstraints parameter" { - $CommandUnderTest | Should -HaveParameter AllConstraints -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllConstraints -Type Switch -Not -Mandatory } It "Should have AllErrorMessages parameter" { - $CommandUnderTest | Should -HaveParameter AllErrorMessages -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllErrorMessages -Type Switch -Not -Mandatory } It "Should have NoInformationalMessages parameter" { - $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Invoke-DbaDbDbccCheckConstraint Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $random = Get-Random $tableName = "dbatools_CheckConstraintTbl1" $check1 = "chkTab1" @@ -53,12 +53,12 @@ Describe "Invoke-DbaDbDbccCheckConstraint Integration Test" -Tag "IntegrationTes } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output" { BeforeAll { - $result = Invoke-DbaDbDbccCheckConstraint -SqlInstance $script:instance2 -Database $dbname -Object $tableName -Confirm:$false + $result = Invoke-DbaDbDbccCheckConstraint -SqlInstance $env:instance2 -Database $dbname -Object $tableName -Confirm:$false } It "Should return correct properties" { diff --git a/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 b/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 index 2f44feedd4..0f3d8b4b03 100644 --- a/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 @@ -21,17 +21,17 @@ Describe "Invoke-DbaDbDbccCleanTable" { $CommandUnderTest | Should -HaveParameter BatchSize -Type Int32 -Not -Mandatory } It "Should have NoInformationalMessages parameter" { - $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . (Join-Path $PSScriptRoot 'constants.ps1') - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolct_example (object_id int, [definition] nvarchar(max),Document varchar(2000)); INSERT INTO dbo.dbatoolct_example([object_id], [definition], Document) Select [object_id], [definition], REPLICATE('ab', 800) from master.sys.sql_modules; ALTER TABLE dbo.dbatoolct_example DROP COLUMN Definition, Document;") @@ -47,7 +47,7 @@ Describe "Invoke-DbaDbDbccCleanTable" { Context "Validate standard output" { BeforeAll { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Cmd', 'Output' - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $env:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -Confirm:$false } It "Should return property: <_>" -ForEach $props { $result[0].PSObject.Properties[$_] | Should -Not -BeNullOrEmpty @@ -61,7 +61,7 @@ Describe "Invoke-DbaDbDbccCleanTable" { Context "Validate BatchSize parameter" { BeforeAll { - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -BatchSize 1000 -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $env:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -BatchSize 1000 -Confirm:$false } It "Returns results for table" { $result.Cmd | Should -Be "DBCC CLEANTABLE('tempdb', 'dbo.dbatoolct_example', 1000)" @@ -71,7 +71,7 @@ Describe "Invoke-DbaDbDbccCleanTable" { Context "Validate NoInformationalMessages parameter" { BeforeAll { - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $env:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -NoInformationalMessages -Confirm:$false } It "Returns results for table" { $result.Cmd | Should -Be "DBCC CLEANTABLE('tempdb', 'dbo.dbatoolct_example') WITH NO_INFOMSGS" diff --git a/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 b/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 index 4e71b57295..70fad1cfff 100644 --- a/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 @@ -6,19 +6,19 @@ Describe "Invoke-DbaDbDbccUpdateUsage" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $random = Get-Random $tableName = "dbatools_getdbtbl1" $dbname = "dbatoolsci_getdbUsage$random" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname $null = $db.Query("CREATE TABLE $tableName (id int)", $dbname) $null = $db.Query("CREATE CLUSTERED INDEX [PK_Id] ON $tableName ([id] ASC)", $dbname) $null = $db.Query("INSERT $tableName(id) SELECT object_id FROM sys.objects", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate parameters" { @@ -53,7 +53,7 @@ Describe "Invoke-DbaDbDbccUpdateUsage" { Context "Validate standard output" { BeforeAll { - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $env:instance1 -Confirm:$false } It "returns results" { @@ -68,12 +68,12 @@ Describe "Invoke-DbaDbDbccUpdateUsage" { Context "Validate returns results" { It "returns results for table" { - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Database $dbname -Table $tableName -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $env:instance1 -Database $dbname -Table $tableName -Confirm:$false $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' } It "returns results for index by id" { - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Database $dbname -Table $tableName -Index 1 -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $env:instance1 -Database $dbname -Table $tableName -Index 1 -Confirm:$false $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' } } diff --git a/tests/Invoke-DbaDbDecryptObject.Tests.ps1 b/tests/Invoke-DbaDbDecryptObject.Tests.ps1 index 9dc5190ca7..eb2a962e8e 100644 --- a/tests/Invoke-DbaDbDecryptObject.Tests.ps1 +++ b/tests/Invoke-DbaDbDecryptObject.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Invoke-DbaDbDecryptObject Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter ExportDestination -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -44,18 +44,18 @@ Describe "Invoke-DbaDbDecryptObject Integration Tests" -Tag "IntegrationTests" { } # Remove the database if it exists - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false # Create the database - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname - if ($null -ne $script:instance2SQLUserName) { - $instance2SecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $instance2SqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $instance2SecurePassword + if ($null -ne $env:instance2SQLUserName) { + $instance2SecurePassword = ConvertTo-SecureString -String $env:instance2SQLPassword -AsPlainText -Force + $instance2SqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:instance2SQLUserName, $instance2SecurePassword } - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false - $instance2Db = New-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Name $dbname + Remove-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false + $instance2Db = New-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -Name $dbname # test object for usage with sql credential $remoteDacSampleEncryptedView = "CREATE VIEW dbo.dbatoolsci_test_remote_dac_vw WITH ENCRYPTION AS SELECT 'remoteDac' as TestFeature;" @@ -212,93 +212,93 @@ SELECT 'áéíñóú¡¿' as SampleUTF8; $db.Query($setupViewWithUTF8) # Check if DAC is enabled - $config = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled + $config = Get-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteDacConnectionsEnabled if ($config.ConfiguredValue -ne 1) { - Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $true + Set-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $true } - $instance2Config = Get-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled + $instance2Config = Get-DbaSpConfigure -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled if ($instance2Config.ConfiguredValue -ne 1) { - Set-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $true + Set-DbaSpConfigure -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $true } } AfterAll { # Remove the database if it exists - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false # Set the original configuration - Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $config.ConfiguredValue -WarningAction SilentlyContinue - Set-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $instance2Config.ConfiguredValue -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $config.ConfiguredValue -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $instance2Config.ConfiguredValue -WarningAction SilentlyContinue } Context "DAC enabled" { It "Should throw error" { - Set-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteDacConnectionsEnabled -Value $false - { Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure -WarningAction SilentlyContinue -ErrorAction Stop } | Should -Throw -ExpectedMessage "*DAC is not enabled for instance*" - Set-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteDacConnectionsEnabled -Value $true -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $env:instance1 -Name RemoteDacConnectionsEnabled -Value $false + { Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure -WarningAction SilentlyContinue -ErrorAction Stop } | Should -Throw -ExpectedMessage "*DAC is not enabled for instance*" + Set-DbaSpConfigure -SqlInstance $env:instance1 -Name RemoteDacConnectionsEnabled -Value $true -WarningAction SilentlyContinue } } Context "Decrypt Scalar Function" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedScalarFunction + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName DummyEncryptedScalarFunction $result.Script | Should -Be $queryScalarFunction } } Context "Decrypt Inline TVF" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedInlineTVF + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName DummyEncryptedInlineTVF $result.Script | Should -Be $queryInlineTVF } } Context "Decrypt TVF" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedTableValuedFunction + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName DummyEncryptedTableValuedFunction $result.Script | Should -Be $queryTableValuedFunction } } Context "Decrypt Stored Procedure" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure $result.Script | Should -Be $queryStoredProcedure } } Context "Decrypt view" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw $result.Script | Should -Be $setupView } } Context "Decrypt trigger in a schema other than dbo" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_trigger + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName dbatoolsci_test_trigger $result.Script | Should -Be $setupTrigger } } Context "Decrypt objects with the same name but in different schemas" { It "Should be successful" { - @(Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_schema_vw).Count | Should -Be 2 + @(Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName dbatoolsci_test_schema_vw).Count | Should -Be 2 } } Context "Decrypt view with UTF8" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_UTF8_vw -EncodingType UTF8 + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName dbatoolsci_test_UTF8_vw -EncodingType UTF8 $result.Script | Should -Not -BeNullOrEmpty } } Context "Decrypt view and use a destination folder" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw -ExportDestination . (Get-Content $result.OutputFile | Out-String).Trim() | Should -Be $setupView.Trim() Remove-Item $result.OutputFile } @@ -306,7 +306,7 @@ SELECT 'áéíñóú¡¿' as SampleUTF8; Context "Decrypt all encrypted objects and use a destination folder" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance1 -Database $dbname -ExportDestination . @($result | Where-Object { $_.Type -eq 'StoredProcedure' }).Count | Should -Be 1 @($result | Where-Object { $_.Type -eq 'Trigger' }).Count | Should -Be 1 @($result | Where-Object { $_.Type -eq 'UserDefinedFunction' }).Count | Should -Be 3 @@ -316,7 +316,7 @@ SELECT 'áéíñóú¡¿' as SampleUTF8; Context "Connect to an instance (ideally a remote instance) using a SqlCredential and decrypt an object" { It "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -ObjectName dbatoolsci_test_remote_dac_vw -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $env:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -ObjectName dbatoolsci_test_remote_dac_vw -ExportDestination . (Get-Content $result.OutputFile | Out-String).Trim() | Should -Be $remoteDacSampleEncryptedView.Trim() Remove-Item $result.OutputFile } diff --git a/tests/Invoke-DbaDbLogShipping.Tests.ps1 b/tests/Invoke-DbaDbLogShipping.Tests.ps1 index 89edda383f..835796c00c 100644 --- a/tests/Invoke-DbaDbLogShipping.Tests.ps1 +++ b/tests/Invoke-DbaDbLogShipping.Tests.ps1 @@ -49,7 +49,7 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter BackupSchedule -Type String } It "Should have BackupScheduleDisabled as a parameter" { - $CommandUnderTest | Should -HaveParameter BackupScheduleDisabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter BackupScheduleDisabled -Type Switch } It "Should have BackupScheduleFrequencyType as a parameter" { $CommandUnderTest | Should -HaveParameter BackupScheduleFrequencyType -Type Object @@ -85,7 +85,7 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter BackupThreshold -Type Int32 } It "Should have CompressBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter CompressBackup -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CompressBackup -Type Switch } It "Should have CopyDestinationFolder as a parameter" { $CommandUnderTest | Should -HaveParameter CopyDestinationFolder -Type String @@ -100,7 +100,7 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter CopySchedule -Type String } It "Should have CopyScheduleDisabled as a parameter" { - $CommandUnderTest | Should -HaveParameter CopyScheduleDisabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CopyScheduleDisabled -Type Switch } It "Should have CopyScheduleFrequencyType as a parameter" { $CommandUnderTest | Should -HaveParameter CopyScheduleFrequencyType -Type Object @@ -133,22 +133,22 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter CopyScheduleEndTime -Type String } It "Should have DisconnectUsers as a parameter" { - $CommandUnderTest | Should -HaveParameter DisconnectUsers -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter DisconnectUsers -Type Switch } It "Should have FullBackupPath as a parameter" { $CommandUnderTest | Should -HaveParameter FullBackupPath -Type String } It "Should have GenerateFullBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter GenerateFullBackup -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter GenerateFullBackup -Type Switch } It "Should have HistoryRetention as a parameter" { $CommandUnderTest | Should -HaveParameter HistoryRetention -Type Int32 } It "Should have NoRecovery as a parameter" { - $CommandUnderTest | Should -HaveParameter NoRecovery -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoRecovery -Type Switch } It "Should have NoInitialization as a parameter" { - $CommandUnderTest | Should -HaveParameter NoInitialization -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoInitialization -Type Switch } It "Should have PrimaryMonitorServer as a parameter" { $CommandUnderTest | Should -HaveParameter PrimaryMonitorServer -Type String @@ -160,7 +160,7 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter PrimaryMonitorServerSecurityMode -Type Object } It "Should have PrimaryThresholdAlertEnabled as a parameter" { - $CommandUnderTest | Should -HaveParameter PrimaryThresholdAlertEnabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter PrimaryThresholdAlertEnabled -Type Switch } It "Should have RestoreDataFolder as a parameter" { $CommandUnderTest | Should -HaveParameter RestoreDataFolder -Type String @@ -184,7 +184,7 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter RestoreSchedule -Type String } It "Should have RestoreScheduleDisabled as a parameter" { - $CommandUnderTest | Should -HaveParameter RestoreScheduleDisabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter RestoreScheduleDisabled -Type Switch } It "Should have RestoreScheduleFrequencyType as a parameter" { $CommandUnderTest | Should -HaveParameter RestoreScheduleFrequencyType -Type Object @@ -235,35 +235,35 @@ Describe "Invoke-DbaDbLogShipping" { $CommandUnderTest | Should -HaveParameter SecondaryMonitorServerSecurityMode -Type Object } It "Should have SecondaryThresholdAlertEnabled as a parameter" { - $CommandUnderTest | Should -HaveParameter SecondaryThresholdAlertEnabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SecondaryThresholdAlertEnabled -Type Switch } It "Should have Standby as a parameter" { - $CommandUnderTest | Should -HaveParameter Standby -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Standby -Type Switch } It "Should have StandbyDirectory as a parameter" { $CommandUnderTest | Should -HaveParameter StandbyDirectory -Type String } It "Should have UseExistingFullBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter UseExistingFullBackup -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseExistingFullBackup -Type Switch } It "Should have UseBackupFolder as a parameter" { $CommandUnderTest | Should -HaveParameter UseBackupFolder -Type String } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeDiscovery { - $script:skipIntegrationTests = [Environment]::GetEnvironmentVariable('appveyor') -ne $true + $env:skipIntegrationTests = [Environment]::GetEnvironmentVariable('appveyor') -ne $true } It "returns success" -Skip:$skipIntegrationTests { - $results = Invoke-DbaDbLogShipping -SourceSqlInstance $script:instance2 -DestinationSqlInstance $script:instance -Database $dbname -BackupNetworkPath C:\temp -BackupLocalPath "C:\temp\logshipping\backup" -GenerateFullBackup -CompressBackup -SecondaryDatabaseSuffix "_LS" -Force + $results = Invoke-DbaDbLogShipping -SourceSqlInstance $env:instance2 -DestinationSqlInstance $env:instance -Database $dbname -BackupNetworkPath C:\temp -BackupLocalPath "C:\temp\logshipping\backup" -GenerateFullBackup -CompressBackup -SecondaryDatabaseSuffix "_LS" -Force $results.Status | Should -Be 'Success' } } diff --git a/tests/Invoke-DbaDbMirroring.Tests.ps1 b/tests/Invoke-DbaDbMirroring.Tests.ps1 index e1e4fe83aa..2e42435fbd 100644 --- a/tests/Invoke-DbaDbMirroring.Tests.ps1 +++ b/tests/Invoke-DbaDbMirroring.Tests.ps1 @@ -45,40 +45,40 @@ Describe "Invoke-DbaDbMirroring" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have UseLastBackup parameter" { - $CommandUnderTest | Should -HaveParameter UseLastBackup -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseLastBackup -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $env:instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_mirroring" - Remove-DbaDbMirror -SqlInstance $script:instance2 -Database $db1 -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db1 -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbMirror -SqlInstance $env:instance2 -Database $db1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $db1 -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false $null = $server.Query("CREATE DATABASE $db1") - Get-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa - Get-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa + Get-DbaEndpoint -SqlInstance $env:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $env:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $env:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $env:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa } AfterAll { - $null = Remove-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db1 -Confirm:$false - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $db1 -ErrorAction SilentlyContinue + $null = Remove-DbaDbMirror -SqlInstance $env:instance2, $env:instance3 -Database $db1 -Confirm:$false + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2, $env:instance3 -Database $db1 -ErrorAction SilentlyContinue } It "returns success" { - $results = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp -WarningVariable warn + $results = Invoke-DbaDbMirroring -Primary $env:instance2 -Mirror $env:instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp -WarningVariable warn $warn | Should -BeNullOrEmpty $results.Status | Should -Be 'Success' } diff --git a/tests/Invoke-DbaDbPiiScan.Tests.ps1 b/tests/Invoke-DbaDbPiiScan.Tests.ps1 index ba7c52912b..08f6f6acf7 100644 --- a/tests/Invoke-DbaDbPiiScan.Tests.ps1 +++ b/tests/Invoke-DbaDbPiiScan.Tests.ps1 @@ -48,13 +48,13 @@ Describe "Invoke-DbaDbPiiScan Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter PatternFilePath -Type String -Not -Mandatory } It "Should have ExcludeDefaultKnownName as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeDefaultKnownName -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeDefaultKnownName -Type Switch -Not -Mandatory } It "Should have ExcludeDefaultPattern as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeDefaultPattern -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeDefaultPattern -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -123,24 +123,24 @@ INSERT INTO dbo.TestTable2 VALUES (1, 'Firstname1') INSERT INTO dbo.TestTable2 VALUES (2, 'Firstname2') "@ - New-DbaDatabase -SqlInstance $script:instance1 -Name $db - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query $sql + New-DbaDatabase -SqlInstance $env:instance1 -Name $db + Invoke-DbaQuery -SqlInstance $env:instance1 -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $db -Confirm:$false } Context "Command works" { It "starts with the right data" { - $result = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query "SELECT * FROM Customer WHERE FirstName = 'Delores'" + $result = Invoke-DbaQuery -SqlInstance $env:instance1 -Database $db -Query "SELECT * FROM Customer WHERE FirstName = 'Delores'" $result | Should -Not -BeNullOrEmpty - $result = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query "SELECT * FROM Customer WHERE RandomText = '6011295760226704'" + $result = Invoke-DbaQuery -SqlInstance $env:instance1 -Database $db -Query "SELECT * FROM Customer WHERE RandomText = '6011295760226704'" $result | Should -Not -BeNullOrEmpty } It "returns the proper output" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -SampleCount 500 + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -SampleCount 500 $results.Count | Should -Be 29 $results."PII-Name" | Should -Contain "Creditcard Discover" $results."PII-Name" | Should -Contain "First name" @@ -148,36 +148,36 @@ INSERT INTO dbo.TestTable2 VALUES (2, 'Firstname2') } It "ExcludeColumn param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn @('CustomerID', 'Firstname', 'Lastname', 'FullName', 'Address', 'Zip', 'City', 'Randomtext') + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -ExcludeColumn @('CustomerID', 'Firstname', 'Lastname', 'FullName', 'Address', 'Zip', 'City', 'Randomtext') $results.Count | Should -Be 2 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' } It "Table param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer $results.Count | Should -Be 27 $results.Table | Should -Not -Contain TestTable $results.Table | Should -Not -Contain TestTable2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer, TestTable + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer, TestTable $results.Count | Should -Be 28 $results.Table | Should -Not -Contain TestTable2 } It "Column param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Column UnknownColumn + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -Column UnknownColumn $results.Count | Should -Be 2 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Column UnknownColumn, Firstname + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -Column UnknownColumn, Firstname $results.Count | Should -Be 3 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' $results."PII-Name" | Should -Contain 'First name' - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer, TestTable -Column UnknownColumn, Firstname + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer, TestTable -Column UnknownColumn, Firstname $results.Count | Should -Be 4 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' @@ -185,29 +185,29 @@ INSERT INTO dbo.TestTable2 VALUES (2, 'Firstname2') } It "Country param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Country Austria + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -Country Austria $results.Count | Should -Be 9 (($results | Where-Object { $_.Country -eq "Austria" })."PII-Name" -eq "National ID") | Should -Be $true - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Country Austria, Slovakia + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -Country Austria, Slovakia $results.Count | Should -Be 10 (($results | Where-Object { $_.Country -eq "Austria" })."PII-Name" -eq "National ID") | Should -Be $true (($results | Where-Object { $_.Country -eq "Slovakia" })."PII-Name" -eq "National ID") | Should -Be $true } It "CountryCode param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -CountryCode SK + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -CountryCode SK $results.Count | Should -Be 9 (($results | Where-Object { $_.CountryCode -eq "SK" })."PII-Name" -eq "National ID") | Should -Be $true - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -CountryCode AT, SK + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -Table Customer -CountryCode AT, SK $results.Count | Should -Be 10 (($results | Where-Object { $_.CountryCode -eq "SK" })."PII-Name" -eq "National ID") | Should -Be $true (($results | Where-Object { $_.CountryCode -eq "AT" })."PII-Name" -eq "National ID") | Should -Be $true } It "Custom scan definitions" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -KnownNameFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-knownnames.json" -PatternFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-patterns.json" -ExcludeDefaultKnownName -ExcludeDefaultPattern + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -KnownNameFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-knownnames.json" -PatternFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-patterns.json" -ExcludeDefaultKnownName -ExcludeDefaultPattern $results.Count | Should -Be 6 ($results | Where-Object { $_."PII-Name" -eq "First name" }).Count | Should -Be 3 ($results | Where-Object { $_."PII-Name" -eq "IPv4 Address" }).Count | Should -Be 2 @@ -215,18 +215,18 @@ INSERT INTO dbo.TestTable2 VALUES (2, 'Firstname2') } It "ExcludeColumn and ExcludeTable params" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeTable Customer + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -ExcludeTable Customer $results.Count | Should -Be 2 ($results | Where-Object { $_."PII-Name" -eq "First name" }).Count | Should -Be 2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeTable Customer, TestTable + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -ExcludeTable Customer, TestTable $results.Table | Should -Be TestTable2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn UnknownColumn + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -ExcludeColumn UnknownColumn $results.Count | Should -Be 27 $results.Column | Should -Not -Contain UnknownColumn - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn UnknownColumn, FirstName + $results = Invoke-DbaDbPiiScan -SqlInstance $env:instance1 -Database $db -ExcludeColumn UnknownColumn, FirstName $results.Count | Should -Be 24 $results.Column | Should -Not -Contain UnknownColumn $results.Column | Should -Not -Contain FirstName diff --git a/tests/Invoke-DbaDbShrink.Tests.ps1 b/tests/Invoke-DbaDbShrink.Tests.ps1 index 0cc6aab7b1..ba83e980d2 100644 --- a/tests/Invoke-DbaDbShrink.Tests.ps1 +++ b/tests/Invoke-DbaDbShrink.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Invoke-DbaDbShrink Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have AllUserDatabases parameter" { - $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type Switch -Not -Mandatory } It "Should have PercentFreeSpace parameter" { $CommandUnderTest | Should -HaveParameter PercentFreeSpace -Type Int32 -Not -Mandatory @@ -42,20 +42,20 @@ Describe "Invoke-DbaDbShrink Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter StatementTimeout -Type Int32 -Not -Mandatory } It "Should have ExcludeIndexStats parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeIndexStats -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeIndexStats -Type Switch -Not -Mandatory } It "Should have ExcludeUpdateUsage parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeUpdateUsage -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeUpdateUsage -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Invoke-DbaDbShrink Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $defaultPath = $server | Get-DbaDefaultPath } diff --git a/tests/Invoke-DbaDbTransfer.Tests.ps1 b/tests/Invoke-DbaDbTransfer.Tests.ps1 index 970f226b7c..d0a0316e67 100644 --- a/tests/Invoke-DbaDbTransfer.Tests.ps1 +++ b/tests/Invoke-DbaDbTransfer.Tests.ps1 @@ -7,11 +7,11 @@ Describe "Invoke-DbaDbTransfer" { . "$PSScriptRoot\constants.ps1" $dbName = 'dbatools_transfer' - $source = Connect-DbaInstance -SqlInstance $script:instance2 - $destination = Connect-DbaInstance -SqlInstance $script:instance3 - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + $source = Connect-DbaInstance -SqlInstance $env:instance2 + $destination = Connect-DbaInstance -SqlInstance $env:instance3 + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbName -Confirm:$false $source.Query("CREATE DATABASE $dbName") - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbName + $db = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbName $null = $db.Query("CREATE TABLE dbo.transfer_test (id int); INSERT dbo.transfer_test SELECT top 10 1 @@ -35,7 +35,7 @@ Describe "Invoke-DbaDbTransfer" { } catch { $null = 1 } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbName -Confirm:$false } Context "Validate parameters" { @@ -94,7 +94,7 @@ Describe "Invoke-DbaDbTransfer" { Context "Testing scripting invocation" { It "Should script all objects" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance2 -Database $dbName -CopyAllObjects + $transfer = New-DbaDbTransfer -SqlInstance $env:instance2 -Database $dbName -CopyAllObjects $scripts = $transfer | Invoke-DbaDbTransfer -ScriptOnly $script = $scripts -join "`n" $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' @@ -103,7 +103,7 @@ Describe "Invoke-DbaDbTransfer" { $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test4`]*' } It "Should script all tables with schema only" { - $scripts = Invoke-DbaDbTransfer -SqlInstance $script:instance2 -Database $dbName -CopyAll Tables -SchemaOnly -ScriptOnly + $scripts = Invoke-DbaDbTransfer -SqlInstance $env:instance2 -Database $dbName -CopyAll Tables -SchemaOnly -ScriptOnly $script = $scripts -join "`n" $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test2`]*' @@ -114,40 +114,40 @@ Describe "Invoke-DbaDbTransfer" { Context "Testing object transfer" { BeforeEach { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $dbName -Confirm:$false $destination.Query("CREATE DATABASE $dbname") - $db2 = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbName + $db2 = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbName } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance3 -Database $dbName -Confirm:$false } It "Should transfer all tables" { - $result = Invoke-DbaDbTransfer -SqlInstance $script:instance2 -DestinationSqlInstance $script:instance3 -Database $dbName -CopyAll Tables - $tables = Get-DbaDbTable -SqlInstance $script:instance3 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 + $result = Invoke-DbaDbTransfer -SqlInstance $env:instance2 -DestinationSqlInstance $env:instance3 -Database $dbName -CopyAll Tables + $tables = Get-DbaDbTable -SqlInstance $env:instance3 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 $tables.Count | Should -Be 4 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test4").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id $db.Query("select id from dbo.transfer_test4").id | Should -BeIn $db2.Query("select id from dbo.transfer_test4").id - $result.SourceInstance | Should -Be $script:instance2 + $result.SourceInstance | Should -Be $env:instance2 $result.SourceDatabase | Should -Be $dbName - $result.DestinationInstance | Should -Be $script:instance3 + $result.DestinationInstance | Should -Be $env:instance3 $result.DestinationDatabase | Should -Be $dbName $result.Elapsed.TotalMilliseconds | Should -BeGreaterThan 0 $result.Status | Should -Be 'Success' $result.Log -join "`n" | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' } It "Should transfer select tables piping the transfer object" { - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance2 -DestinationSqlInstance $script:instance3 -Database $dbName + $sourceTables = Get-DbaDbTable -SqlInstance $env:instance2 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $env:instance2 -DestinationSqlInstance $env:instance3 -Database $dbName $result = $transfer | Invoke-DbaDbTransfer - $tables = Get-DbaDbTable -SqlInstance $script:instance3 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $env:instance3 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id - $result.SourceInstance | Should -Be $script:instance2 + $result.SourceInstance | Should -Be $env:instance2 $result.SourceDatabase | Should -Be $dbName - $result.DestinationInstance | Should -Be $script:instance3 + $result.DestinationInstance | Should -Be $env:instance3 $result.DestinationDatabase | Should -Be $dbName $result.Elapsed.TotalMilliseconds | Should -BeGreaterThan 0 $result.Status | Should -Be 'Success' diff --git a/tests/Invoke-DbaDbUpgrade.Tests.ps1 b/tests/Invoke-DbaDbUpgrade.Tests.ps1 index cadeaa7a37..452525cebc 100644 --- a/tests/Invoke-DbaDbUpgrade.Tests.ps1 +++ b/tests/Invoke-DbaDbUpgrade.Tests.ps1 @@ -22,28 +22,28 @@ Describe "Invoke-DbaDbUpgrade" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have NoCheckDb parameter" { - $CommandUnderTest | Should -HaveParameter NoCheckDb -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoCheckDb -Type Switch -Not -Mandatory } It "Should have NoUpdateUsage parameter" { - $CommandUnderTest | Should -HaveParameter NoUpdateUsage -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoUpdateUsage -Type Switch -Not -Mandatory } It "Should have NoUpdateStats parameter" { - $CommandUnderTest | Should -HaveParameter NoUpdateStats -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoUpdateStats -Type Switch -Not -Mandatory } It "Should have NoRefreshView parameter" { - $CommandUnderTest | Should -HaveParameter NoRefreshView -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoRefreshView -Type Switch -Not -Mandatory } It "Should have AllUserDatabases parameter" { - $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 b/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 index ade46a67fb..8215ce26b9 100644 --- a/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 +++ b/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 @@ -26,7 +26,7 @@ Describe "Invoke-DbaDbccDropCleanBuffer" { Context "Validate standard output" { BeforeAll { - $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $script:instance1 -Confirm:$false + $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $env:instance1 -Confirm:$false } It "Should return property: ComputerName" { @@ -48,12 +48,12 @@ Describe "Invoke-DbaDbccDropCleanBuffer" { Context "Works correctly" { It "returns results" { - $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $script:instance1 -Confirm:$false + $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $env:instance1 -Confirm:$false $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' } It "returns the right results for -NoInformationalMessages" { - $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $script:instance1 -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $env:instance1 -NoInformationalMessages -Confirm:$false $result.Cmd | Should -Match 'DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS' $result.Output | Should -BeNullOrEmpty } diff --git a/tests/Invoke-DbaDbccFreeCache.Tests.ps1 b/tests/Invoke-DbaDbccFreeCache.Tests.ps1 index 445a687bb2..65c37c3c2e 100644 --- a/tests/Invoke-DbaDbccFreeCache.Tests.ps1 +++ b/tests/Invoke-DbaDbccFreeCache.Tests.ps1 @@ -23,13 +23,13 @@ Describe "Invoke-DbaDbccFreeCache" { $CommandUnderTest | Should -HaveParameter InputValue -Type String } It "Should have NoInformationalMessages as a parameter" { - $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoInformationalMessages -Type Switch } It "Should have MarkInUseForRemoval as a parameter" { - $CommandUnderTest | Should -HaveParameter MarkInUseForRemoval -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter MarkInUseForRemoval -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -39,7 +39,7 @@ Describe "Invoke-DbaDbccFreeCache" { } It "returns the right results for FREESYSTEMCACHE" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSystemCache -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $env:instance2 -Operation FreeSystemCache -Confirm:$false $result.Operation | Should -Match 'FREESYSTEMCACHE' $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' foreach ($prop in $props) { @@ -48,19 +48,19 @@ Describe "Invoke-DbaDbccFreeCache" { } It "returns the right results for FREESESSIONCACHE" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSessionCache -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $env:instance2 -Operation FreeSessionCache -Confirm:$false $result.Operation | Should -Match 'FREESESSIONCACHE' $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' } It "returns the right results for FREEPROCCACHE" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FREEPROCCACHE -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $env:instance2 -Operation FREEPROCCACHE -Confirm:$false $result.Operation | Should -Match 'FREEPROCCACHE' $result.Output | Should -Match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' } It "returns the right results for FREESESSIONCACHE and using NoInformationalMessages" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSessionCache -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $env:instance2 -Operation FreeSessionCache -NoInformationalMessages -Confirm:$false $result.Operation | Should -Match 'FREESESSIONCACHE' $result.Output | Should -BeNullOrEmpty } diff --git a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 index bd573889c8..a5d770c979 100644 --- a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 +++ b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 @@ -6,11 +6,11 @@ Describe "Invoke-DbaDiagnosticQuery" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $script:PesterOutputPath = "TestDrive:$commandName" + $env:PesterOutputPath = "TestDrive:$commandName" $database = "dbatoolsci_frk_$(Get-Random)" $database2 = "dbatoolsci_frk_$(Get-Random)" $database3 = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE [$database]") $server.Query("CREATE DATABASE [$database2]") $server.Query("CREATE DATABASE [$database3]") @@ -27,11 +27,11 @@ Describe "Invoke-DbaDiagnosticQuery" { end") } - Remove-Item $script:PesterOutputPath -Recurse -ErrorAction SilentlyContinue + Remove-Item $env:PesterOutputPath -Recurse -ErrorAction SilentlyContinue } AfterEach { - Remove-Item $script:PesterOutputPath -Recurse -ErrorAction SilentlyContinue + Remove-Item $env:PesterOutputPath -Recurse -ErrorAction SilentlyContinue } Context "Validate parameters" { @@ -90,30 +90,30 @@ Describe "Invoke-DbaDiagnosticQuery" { Context "verifying output when running queries" { It "runs a specific query" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -QueryName 'Memory Clerk Usage' @($results).Count | Should -Be 1 } It "works with DatabaseSpecific" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -DatabaseSpecific @($results).Count | Should -BeGreaterThan 10 } It "works with specific database provided" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'File Sizes and Space', 'Log Space Usage' -Database $database2, $database3 + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -QueryName 'File Sizes and Space', 'Log Space Usage' -Database $database2, $database3 @($results | Where-Object {$_.Database -eq $Database}).Count | Should -Be 0 @($results | Where-Object {$_.Database -eq $Database2}).Count | Should -Be 2 @($results | Where-Object {$_.Database -eq $Database3}).Count | Should -Be 2 } It "works with Exclude Databases provided" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -ExcludeDatabase $database2 + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -DatabaseSpecific -ExcludeDatabase $database2 @($results | Where-Object {$_.Database -eq $Database}).Count | Should -BeGreaterThan 1 @($results | Where-Object {$_.Database -eq $Database2}).Count | Should -Be 0 } It "Correctly excludes queries when QueryName and ExcludeQuery parameters are used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' @($results).Count | Should -Be 2 } It "Correctly excludes queries when only ExcludeQuery parameter is used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" @($results).Count | Should -BeGreaterThan 0 @($results | Where-Object Name -eq "Missing Index Warnings").Count | Should -Be 0 @($results | Where-Object Name -eq "Buffer Usage").Count | Should -Be 0 @@ -121,7 +121,7 @@ Describe "Invoke-DbaDiagnosticQuery" { BeforeAll { $columnnames = 'Item', 'RowError', 'RowState', 'Table', 'ItemArray', 'HasErrors' - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -QueryName 'Memory Clerk Usage' } It "correctly excludes default column name <_>" -ForEach $columnnames { @($results.Result | Get-Member | Where-Object Name -eq $_).Count | Should -Be 0 @@ -130,34 +130,34 @@ Describe "Invoke-DbaDiagnosticQuery" { Context "verifying output when exporting queries as files instead of running" { It "exports queries to sql files without running" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -QueryName 'Memory Clerk Usage' -OutputPath $script:PesterOutputPath - @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql).Count | Should -Be 1 + $null = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -ExportQueries -QueryName 'Memory Clerk Usage' -OutputPath $env:PesterOutputPath + @(Get-ChildItem -path $env:PesterOutputPath -filter *.sql).Count | Should -Be 1 } It "exports single database specific query against single database" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database -OutputPath $script:PesterOutputPath - @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)"}).Count | Should -Be 1 + $null = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database -OutputPath $env:PesterOutputPath + @(Get-ChildItem -path $env:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)"}).Count | Should -Be 1 } It "exports a database specific query foreach specific database provided" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath - @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 + $null = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $env:PesterOutputPath + @(Get-ChildItem -path $env:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 } It "exports database specific query when multiple specific databases are referenced" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath - @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 + $null = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $env:PesterOutputPath + @(Get-ChildItem -path $env:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 } } Context "verifying output when running database specific queries" { It "runs database specific queries against single database only when providing database name" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database @($results).Count | Should -Be 1 } It "runs database specific queries against set of databases when provided with multiple database names" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) + $results = Invoke-DbaDiagnosticQuery -SqlInstance $env:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) @($results).Count | Should -Be 2 } } diff --git a/tests/Invoke-DbaPfRelog.Tests.ps1 b/tests/Invoke-DbaPfRelog.Tests.ps1 index 8664f7e78f..7e9986a491 100644 --- a/tests/Invoke-DbaPfRelog.Tests.ps1 +++ b/tests/Invoke-DbaPfRelog.Tests.ps1 @@ -20,11 +20,11 @@ Describe "Invoke-DbaPfRelog Unit Tests" -Tag 'UnitTests' { It "Should have Type as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Type -Type String -Not -Mandatory } - It "Should have Append as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Append -Type SwitchParameter -Not -Mandatory + It "Should have Append as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Append -Type Switch -Not -Mandatory } - It "Should have AllowClobber as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter AllowClobber -Type SwitchParameter -Not -Mandatory + It "Should have AllowClobber as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter AllowClobber -Type Switch -Not -Mandatory } It "Should have PerformanceCounter as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter PerformanceCounter -Type String[] -Not -Mandatory @@ -44,23 +44,23 @@ Describe "Invoke-DbaPfRelog Unit Tests" -Tag 'UnitTests' { It "Should have ConfigPath as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter ConfigPath -Type String -Not -Mandatory } - It "Should have Summary as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Summary -Type SwitchParameter -Not -Mandatory + It "Should have Summary as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Summary -Type Switch -Not -Mandatory } It "Should have InputObject as a non-mandatory Object[] parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have Multithread as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Multithread -Type SwitchParameter -Not -Mandatory + It "Should have Multithread as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Multithread -Type Switch -Not -Mandatory } - It "Should have AllTime as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter AllTime -Type SwitchParameter -Not -Mandatory + It "Should have AllTime as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter AllTime -Type Switch -Not -Mandatory } - It "Should have Raw as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Raw -Type SwitchParameter -Not -Mandatory + It "Should have Raw as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Raw -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Invoke-DbaQuery.Tests.ps1 b/tests/Invoke-DbaQuery.Tests.ps1 index 7b93d6e1c6..7d2b4c35dd 100644 --- a/tests/Invoke-DbaQuery.Tests.ps1 +++ b/tests/Invoke-DbaQuery.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Invoke-DbaQuery" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $env:instance2 -Database tempdb $null = $db.Query("CREATE PROCEDURE dbo.dbatoolsci_procedure_example @p1 [INT] = 0 AS BEGIN SET NOCOUNT OFF; SELECT TestColumn = @p1; END") } @@ -55,22 +55,22 @@ Describe "Invoke-DbaQuery" { $CommandUnderTest | Should -HaveParameter CommandType -Type CommandType -Not -Mandatory } It "Should have AppendServerInstance parameter" { - $CommandUnderTest | Should -HaveParameter AppendServerInstance -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AppendServerInstance -Type Switch -Not -Mandatory } It "Should have MessagesToOutput parameter" { - $CommandUnderTest | Should -HaveParameter MessagesToOutput -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter MessagesToOutput -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have ReadOnly parameter" { - $CommandUnderTest | Should -HaveParameter ReadOnly -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ReadOnly -Type Switch -Not -Mandatory } It "Should have NoExec parameter" { - $CommandUnderTest | Should -HaveParameter NoExec -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoExec -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -87,7 +87,7 @@ Describe "Invoke-DbaQuery" { } It "supports pipable instances" { - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" + $results = $env:instance2, $env:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } @@ -95,17 +95,17 @@ Describe "Invoke-DbaQuery" { It "supports parameters" { $sqlParams = @{ testvalue = 'hello' } - $results = $script:instance2 | Invoke-DbaQuery -Database tempdb -Query "Select @testvalue as TestColumn" -SqlParameters $sqlParams + $results = $env:instance2 | Invoke-DbaQuery -Database tempdb -Query "Select @testvalue as TestColumn" -SqlParameters $sqlParams foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } } It "supports AppendServerInstance" { - $conn1 = Connect-DbaInstance $script:instance2 - $conn2 = Connect-DbaInstance $script:instance3 + $conn1 = Connect-DbaInstance $env:instance2 + $conn2 = Connect-DbaInstance $env:instance3 $serverInstances = $conn1.Name, $conn2.Name - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" -AppendServerInstance + $results = $env:instance2, $env:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" -AppendServerInstance foreach ($result in $results) { $result.ServerInstance | Should -Not -BeNullOrEmpty $result.ServerInstance | Should -BeIn $serverInstances @@ -113,7 +113,7 @@ Describe "Invoke-DbaQuery" { } It "supports pipable databases" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 + $dbs = Get-DbaDatabase -SqlInstance $env:instance2, $env:instance3 $results = $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' @@ -122,14 +122,14 @@ Describe "Invoke-DbaQuery" { } It "stops when piped databases and -Database" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 + $dbs = Get-DbaDatabase -SqlInstance $env:instance2, $env:instance3 { $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" -Database tempdb -EnableException } | Should -Throw "You can't" } It "supports reading files" { $testPath = "TestDrive:\dbasqlquerytest.txt" Set-Content $testPath -Value "Select 'hello' as TestColumn, DB_NAME() as dbname" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $testPath + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -File $testPath foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } @@ -142,7 +142,7 @@ Describe "Invoke-DbaQuery" { Set-Content "$testPath\dbasqlquerytest2.sql" -Value "Select 'hello2' as TestColumn, DB_NAME() as dbname" Set-Content "$testPath\dbasqlquerytest2.txt" -Value "Select 'hello3' as TestColumn, DB_NAME() as dbname" $pathinfo = Get-Item $testpath - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $pathinfo + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -File $pathinfo 'hello' | Should -BeIn $results.TestColumn 'hello2' | Should -BeIn $results.TestColumn 'hello3' | Should -Not -BeIn $results.TestColumn @@ -151,26 +151,26 @@ Describe "Invoke-DbaQuery" { It "supports http files" { $cleanup = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')) DROP TABLE [dbo].[CommandLog]" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $cleanup $CloudQuery = 'https://raw.githubusercontent.com/dataplat/appveyor-lab/master/sql2016-startup/ola/CommandLog.sql' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $CloudQuery + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -File $CloudQuery $check = "SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $check + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $check $results.Name | Should -Be 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $cleanup } It "supports smo objects" { $cleanup = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')) DROP TABLE [dbo].[CommandLog]" - $null = Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $env:instance2, $env:instance3 -Database tempdb -Query $cleanup $CloudQuery = 'https://raw.githubusercontent.com/dataplat/appveyor-lab/master/sql2016-startup/ola/CommandLog.sql' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $CloudQuery - $smoobj = Get-DbaDbTable -SqlInstance $script:instance2 -Database tempdb | Where-Object Name -EQ 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -SqlObject $smoobj + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -File $CloudQuery + $smoobj = Get-DbaDbTable -SqlInstance $env:instance2 -Database tempdb | Where-Object Name -EQ 'CommandLog' + $null = Invoke-DbaQuery -SqlInstance $env:instance3 -Database tempdb -SqlObject $smoobj $check = "SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')" - $results = Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -Query $check + $results = Invoke-DbaQuery -SqlInstance $env:instance3 -Database tempdb -Query $check $results.Name | Should -Be 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $env:instance2, $env:instance3 -Database tempdb -Query $cleanup } It "supports queries with GO statements" { @@ -179,7 +179,7 @@ SELECT DB_NAME() as dbname GO SELECT @@servername as dbname '@ - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query $Query + $results = $env:instance2, $env:instance3 | Invoke-DbaQuery -Database tempdb -Query $Query $results.dbname -contains 'tempdb' | Should -Be $true } @@ -200,7 +200,7 @@ SELECT @@servername as dbname PRINT 'stmt_6|PRINT end|' + CONVERT(VARCHAR(19), GETUTCDATE(), 126) '@ $results = @() - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $query -Verbose 4>&1 | ForEach-Object { + Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $query -Verbose 4>&1 | ForEach-Object { $results += [pscustomobject]@{ FiredAt = (Get-Date).ToUniversalTime() Out = $_ @@ -227,7 +227,7 @@ SELECT @@servername as dbname PRINT 'stmt_6|PRINT end|' + CONVERT(VARCHAR(19), GETUTCDATE(), 126) '@ $results = @() - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $query -MessagesToOutput | ForEach-Object { + Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $query -MessagesToOutput | ForEach-Object { $results += [pscustomobject]@{ FiredAt = (Get-Date).ToUniversalTime() Out = $_ @@ -238,13 +238,13 @@ SELECT @@servername as dbname } It "Executes stored procedures with parameters" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "dbatoolsci_procedure_example" -SqlParameters @{p1 = 1 } -CommandType StoredProcedure + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "dbatoolsci_procedure_example" -SqlParameters @{p1 = 1 } -CommandType StoredProcedure $results.TestColumn | Should -Be 1 } It "Executes script file with a relative path (see #6184)" { Set-Content -Path ".\hellorelative.sql" -Value "Select 'hello' as TestColumn, DB_NAME() as dbname" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File ".\hellorelative.sql" + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -File ".\hellorelative.sql" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } @@ -252,7 +252,7 @@ SELECT @@servername as dbname } It "supports multiple datatables also as array of PSObjects (see #6921)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObjectArray + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObjectArray $results.Count | Should -Be 2 $results[0].Count | Should -Be 3 $results[0][0].a | Should -Be 1 @@ -262,7 +262,7 @@ SELECT @@servername as dbname } It "supports multiple datatables also as PSObjects (see #6921)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObject + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObject $results.Count | Should -Be 5 $results[0].a | Should -Be 1 $results[3].b | Should -Be 4 @@ -270,7 +270,7 @@ SELECT @@servername as dbname } It "supports using SqlParameters as Microsoft.Data.SqlClient.SqlParameter (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] @json_result nvarchar(max) output AS BEGIN @@ -280,12 +280,12 @@ SELECT @@servername as dbname ); END" $output = New-DbaSqlParameter -ParameterName json_result -SqlDbType NVarChar -Size -1 -Direction Output - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output + Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output $output.Value | Should -Be '{"example":"sample"}' } It "supports using multiple and mixed params, even with different names (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething @somevalue varchar(10), @newid varchar(50) OUTPUT AS @@ -298,14 +298,14 @@ SELECT @@servername as dbname 'newid' = $outparam 'somevalue' = 'asd' } - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result.'input param' | Should -Be 'asd' $result.somevalue | Should -Be 'fixedval' } It "supports using the same parameters multiple times (#9217)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething @somevalue varchar(10), @newid varchar(50) OUTPUT AS @@ -319,19 +319,19 @@ SELECT @@servername as dbname 'newid' = $outparam 'somevalue' = $inparam } - $result1 = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result1 = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result1.'input param' | Should -Be 'example' $result1.somevalue | Should -Be 'fixedval' - $result2 = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result2 = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result2.'input param' | Should -Be 'example' $result2.somevalue | Should -Be 'fixedval' } It "supports complex types, such as datatables (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query " + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query " IF NOT EXISTS (SELECT * FROM sys.types WHERE name = N'dbatools_tabletype') CREATE TYPE dbatools_tabletype AS TABLE( somestring varchar(50), @@ -360,7 +360,7 @@ END" 'newid' = $outparam 'sometable' = New-DbaSqlParameter -SqlDbType structured -Value (ConvertTo-DbaDataTable -InputObject $inparam) -TypeName 'dbatools_tabletype' } - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @sometable, @newid output" -SqlParameters $sqlparams + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @sometable, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result.Count | Should -Be 2 $result[0].somestring | Should -Be 'string1' @@ -368,7 +368,7 @@ END" } It "support NOEXEC mode" { - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "SELECT 1" -NoExec + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "SELECT 1" -NoExec $result | Should -BeNullOrEmpty #for multiple batches, too $q = @' @@ -376,10 +376,10 @@ SELECT 1 GO SELECT 2 '@ - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $q -NoExec + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $q -NoExec $result | Should -BeNullOrEmpty - { Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'selec'" + { Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'selec'" } It "supports dropping temp objects (#8472)" { @@ -389,15 +389,15 @@ SELECT 2 GO drop procedure #DropStatistics go" - { Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $sql -EnableException } | Should -Not -Throw + { Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query $sql -EnableException } | Should -Not -Throw } It "supports geography types (#8541)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as geometry)" + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Query "select cast(null as geometry)" $results.Column1 | Should -Be "Null" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as geography)" + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Query "select cast(null as geography)" $results.Column1 | Should -Be "Null" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as hierarchyid)" + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Query "select cast(null as hierarchyid)" $results.Column1 | Should -Be "NULL" } } diff --git a/tests/Invoke-DbaWhoisActive.Tests.ps1 b/tests/Invoke-DbaWhoisActive.Tests.ps1 index 2d9a9223e1..f4baad7565 100644 --- a/tests/Invoke-DbaWhoisActive.Tests.ps1 +++ b/tests/Invoke-DbaWhoisActive.Tests.ps1 @@ -6,14 +6,14 @@ Describe "Invoke-DbaWhoIsActive" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $testzippath = "$script:appveyorlabrepo\CommunitySoftware\sp_whoisactive-12.00.zip" - $resultInstallMaster = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database master -WarningVariable warnInstallMaster - $resultInstallTempdb = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database tempdb -WarningVariable warnInstallTempdb + $testzippath = "$env:appveyorlabrepo\CommunitySoftware\sp_whoisactive-12.00.zip" + $resultInstallMaster = Install-DbaWhoIsActive -SqlInstance $env:instance1 -LocalFile $testzippath -Database master -WarningVariable warnInstallMaster + $resultInstallTempdb = Install-DbaWhoIsActive -SqlInstance $env:instance1 -LocalFile $testzippath -Database tempdb -WarningVariable warnInstallTempdb } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' - Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Database master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $env:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } Context "Validate parameters" { @@ -122,33 +122,33 @@ Describe "Invoke-DbaWhoIsActive" { Context "Should Execute SPWhoisActive" { It "Should execute and return Help" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -Help -WarningVariable warn + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -Help -WarningVariable warn $warn | Should -BeNullOrEmpty $results | Should -Not -BeNullOrEmpty } It "Should execute with ShowSleepingSpids" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowSleepingSpids 2 + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -ShowSleepingSpids 2 $results | Should -Not -BeNullOrEmpty } It "Should execute with ShowOwnSpid" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowOwnSpid + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -ShowOwnSpid $results | Should -Not -BeNullOrEmpty } It "Should execute with ShowSystemSpids" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowSystemSpids + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -ShowSystemSpids $results | Should -Not -BeNullOrEmpty } It "Should execute with GetOuterCommand and FindBlockLeaders" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -GetOuterCommand -FindBlockLeaders + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -GetOuterCommand -FindBlockLeaders $results | Should -Not -BeNullOrEmpty } It "Should execute with NotFilter and NotFilterType" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -NotFilter 0 -NotFilterType Program + $results = Invoke-DbaWhoIsActive -SqlInstance $env:instance1 -NotFilter 0 -NotFilterType Program $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Invoke-DbaXEReplay.Tests.ps1 b/tests/Invoke-DbaXEReplay.Tests.ps1 index d6dc651fdf..2af659ea13 100644 --- a/tests/Invoke-DbaXEReplay.Tests.ps1 +++ b/tests/Invoke-DbaXEReplay.Tests.ps1 @@ -25,10 +25,10 @@ Describe "Invoke-DbaXEReplay" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object } It "Should have Raw parameter" { - $CommandUnderTest | Should -HaveParameter Raw -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Raw -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Join-DbaAvailabilityGroup.Tests.ps1 b/tests/Join-DbaAvailabilityGroup.Tests.ps1 index 640b9f56bf..0a12c6596f 100644 --- a/tests/Join-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Join-DbaAvailabilityGroup.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Join-DbaAvailabilityGroup" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Join-DbaPath.Tests.ps1 b/tests/Join-DbaPath.Tests.ps1 index ca14eac268..d2496a37a4 100644 --- a/tests/Join-DbaPath.Tests.ps1 +++ b/tests/Join-DbaPath.Tests.ps1 @@ -18,11 +18,11 @@ Describe "Join-DbaPath" { It "Should have Child as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Child -Type String[] -Not -Mandatory } - It "Should have Verbose as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + It "Should have Verbose as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } - It "Should have Debug as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + It "Should have Debug as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a non-mandatory ActionPreference parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Measure-DbaBackupThroughput.Tests.ps1 b/tests/Measure-DbaBackupThroughput.Tests.ps1 index 6def46dab7..b87cd1d62d 100644 --- a/tests/Measure-DbaBackupThroughput.Tests.ps1 +++ b/tests/Measure-DbaBackupThroughput.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Measure-DbaBackupThroughput" { $CommandUnderTest | Should -HaveParameter Since -Type DateTime -Not -Mandatory } It "Should have Last parameter" { - $CommandUnderTest | Should -HaveParameter Last -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Last -Type Switch -Not -Mandatory } It "Should have Type parameter" { $CommandUnderTest | Should -HaveParameter Type -Type String -Not -Mandatory @@ -36,23 +36,23 @@ Describe "Measure-DbaBackupThroughput" { $CommandUnderTest | Should -HaveParameter DeviceType -Type String[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Returns output for single database" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $null = Get-DbaProcess -SqlInstance $env:instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue $random = Get-Random $db = "dbatoolsci_measurethruput$random" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Database $db | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $env:instance2 -Database $db | Backup-DbaDatabase } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $db } It "Should return results" { - $results = Measure-DbaBackupThroughput -SqlInstance $script:instance2 -Database $db + $results = Measure-DbaBackupThroughput -SqlInstance $env:instance2 -Database $db $results.Database | Should -Be $db $results.BackupCount | Should -Be 1 } diff --git a/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 b/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 index 17be07bb4d..81438036aa 100644 --- a/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 +++ b/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 @@ -32,29 +32,29 @@ Describe "Measure-DbaDbVirtualLogFile" { Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_testvlf" $server.Query("CREATE DATABASE $db1") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1 } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1 } It "Should have correct properties" { - $results = Measure-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Measure-DbaDbVirtualLogFile -SqlInstance $env:instance2 -Database $db1 $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Total', 'TotalCount', 'Inactive', 'Active', 'LogFileName', 'LogFileGrowth', 'LogFileGrowthType' $results[0].PSObject.Properties.Name | Should -Be $ExpectedProps } It "Should have database name of $db1" { - $results = Measure-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Measure-DbaDbVirtualLogFile -SqlInstance $env:instance2 -Database $db1 $results.Database | Should -Be $db1 } It "Should have values for Total property" { - $results = Measure-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Measure-DbaDbVirtualLogFile -SqlInstance $env:instance2 -Database $db1 $results.Total | Should -Not -BeNullOrEmpty $results.Total | Should -BeGreaterThan 0 } diff --git a/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 b/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 index c08e750615..c0fb51c332 100644 --- a/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 +++ b/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 @@ -32,17 +32,17 @@ Describe "Measure-DbaDiskSpaceRequirement" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Should Measure Disk Space Required" { BeforeAll { - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $Options = @{ - Source = $script:instance1 - Destination = $script:instance2 + Source = $env:instance1 + Destination = $env:instance2 Database = "master" DestinationDatabase = "Dbatoolsci_DestinationDB" } @@ -57,7 +57,7 @@ Describe "Measure-DbaDiskSpaceRequirement" { $results.SourceDatabase | Should -Be $Options.Database } - It "Should be sourced from the instance $($script:instance1)" { + It "Should be sourced from the instance $($env:instance1)" { $results.SourceSqlInstance | Should -Be $server1.SqlInstance } @@ -65,7 +65,7 @@ Describe "Measure-DbaDiskSpaceRequirement" { $results.DestinationDatabase | Should -Be $Options.DestinationDatabase } - It "Should be destined for the instance $($script:instance2)" { + It "Should be destined for the instance $($env:instance2)" { $results.DestinationSqlInstance | Should -Be $server2.SqlInstance } diff --git a/tests/Mount-DbaDatabase.Tests.ps1 b/tests/Mount-DbaDatabase.Tests.ps1 index 252ac31e87..041dd34813 100644 --- a/tests/Mount-DbaDatabase.Tests.ps1 +++ b/tests/Mount-DbaDatabase.Tests.ps1 @@ -24,23 +24,23 @@ Describe "Mount-DbaDatabase" { $CommandUnderTest | Should -HaveParameter AttachOption -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - + # Setup: remove, restore and backup on the local drive - Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false - Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\detachattach\detachattach.bak -WithReplace - Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Backup-DbaDatabase -Type Full - Detach-DbaDatabase -SqlInstance $script:instance1 -Database detachattach -Force + Get-DbaDatabase -SqlInstance $env:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false + Restore-DbaDatabase -SqlInstance $env:instance1 -Path $env:appveyorlabrepo\detachattach\detachattach.bak -WithReplace + Get-DbaDatabase -SqlInstance $env:instance1 -Database detachattach | Backup-DbaDatabase -Type Full + Detach-DbaDatabase -SqlInstance $env:instance1 -Database detachattach -Force } It "Attaches a single database and ensures the alias still exists" { - $results = Attach-DbaDatabase -SqlInstance $script:instance1 -Database detachattach + $results = Attach-DbaDatabase -SqlInstance $env:instance1 -Database detachattach $results.AttachResult | Should -Be "Success" $results.Database | Should -Be "detachattach" @@ -48,7 +48,7 @@ Describe "Mount-DbaDatabase" { } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false } } } diff --git a/tests/Move-DbaDbFile.Tests.ps1 b/tests/Move-DbaDbFile.Tests.ps1 index bf73add88d..c8edc7c0c4 100644 --- a/tests/Move-DbaDbFile.Tests.ps1 +++ b/tests/Move-DbaDbFile.Tests.ps1 @@ -7,10 +7,10 @@ Describe "Move-DbaDbFile" { . "$PSScriptRoot\constants.ps1" # Setup code - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_MoveDbFile' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_MoveDbFile_2DataFiles' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_MoveDbFile' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_MoveDbFile_2DataFiles' - $dbFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object TypeDescription -eq 'ROWS' + $dbFiles = Get-DbaDbFile -SqlInstance $env:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object TypeDescription -eq 'ROWS' $physicalPathFolder = Split-Path -Path $dbFiles[0].PhysicalName -Parent $physicalPathNewFolder = "$physicalPathFolder\moveFile" $null = New-Item -Path $physicalPathNewFolder -Type Directory @@ -22,11 +22,11 @@ Describe "Move-DbaDbFile" { TO FILEGROUP [PRIMARY] GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $addNewDataFile + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Query $addNewDataFile } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_MoveDbFile", "dbatoolsci_MoveDbFile_2DataFiles" -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database "dbatoolsci_MoveDbFile", "dbatoolsci_MoveDbFile_2DataFiles" -Confirm:$false Get-Item -Path "$physicalPathFolder\moveFile" | Remove-Item -Recurse Get-Item -Path "$physicalPathFolder\New" | Remove-Item -Recurse Get-Item -Path "$physicalPathFolder\dbatoolsci_MoveDbFile.mdf" | Remove-Item @@ -71,7 +71,7 @@ Describe "Move-DbaDbFile" { Context "Should output current database structure" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_MoveDbFile' FileStructureOnly = $true } @@ -92,10 +92,10 @@ Describe "Move-DbaDbFile" { Context "Should move all database data files" { BeforeAll { - $dbDataFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'ROWS' + $dbDataFiles = Get-DbaDbFile -SqlInstance $env:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'ROWS' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_MoveDbFile' FileType = 'Data' FileDestination = $physicalPathNewFolder @@ -119,16 +119,16 @@ Describe "Move-DbaDbFile" { Test-Path -Path $dbDataFiles.PhysicalName | Should -Be $true } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should -Be 'ONLINE' + (Get-DbaDbState -SqlInstance $env:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should -Be 'ONLINE' } } Context "Should move all database log files and delete source" { BeforeAll { - $dbLogFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'LOG' + $dbLogFiles = Get-DbaDbFile -SqlInstance $env:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'LOG' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_MoveDbFile' FileType = 'Log' FileDestination = $physicalPathNewFolder @@ -153,16 +153,16 @@ Describe "Move-DbaDbFile" { Test-Path -Path $dbLogFiles.PhysicalName | Should -Be $false } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should -Be 'ONLINE' + (Get-DbaDbState -SqlInstance $env:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should -Be 'ONLINE' } } Context "Should move only one database file and delete source" { BeforeAll { - $dbNDFFile = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object LogicalName -eq 'dbatoolsci_MoveDbFile_2DataFiles_2' + $dbNDFFile = Get-DbaDbFile -SqlInstance $env:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object LogicalName -eq 'dbatoolsci_MoveDbFile_2DataFiles_2' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_MoveDbFile_2DataFiles' FileToMove = @{ 'dbatoolsci_MoveDbFile_2DataFiles_2' = $physicalPathNewFolder @@ -188,19 +188,19 @@ Describe "Move-DbaDbFile" { Test-Path -Path $dbNDFFile.PhysicalName | Should -Be $false } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should -Be 'ONLINE' + (Get-DbaDbState -SqlInstance $env:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should -Be 'ONLINE' } } Context "Should move all files and delete source" { BeforeAll { - $dbAllFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles + $dbAllFiles = Get-DbaDbFile -SqlInstance $env:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles $destinationFolder = "$physicalPathFolder\New" $null = New-Item -Path $destinationFolder -Type Directory $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_MoveDbFile_2DataFiles' FileType = 'Both' FileDestination = $destinationFolder @@ -231,7 +231,7 @@ Describe "Move-DbaDbFile" { } } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should -Be 'ONLINE' + (Get-DbaDbState -SqlInstance $env:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should -Be 'ONLINE' } } } diff --git a/tests/Move-DbaRegServer.Tests.ps1 b/tests/Move-DbaRegServer.Tests.ps1 index 76b3195e43..8a636ea91b 100644 --- a/tests/Move-DbaRegServer.Tests.ps1 +++ b/tests/Move-DbaRegServer.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Move-DbaRegServer" { $CommandUnderTest | Should -HaveParameter InputObject -Type RegisteredServer[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -36,37 +36,37 @@ Describe "Move-DbaRegServer" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group1a" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 $testGroupHR = "dbatoolsci-HR-$random" $testGroupFinance = "dbatoolsci-Finance-$random" $regSrvNameHR = "dbatoolsci-HR-$random" $regSrvNameFinance = "dbatoolsci-Finance-$random" - $newTestGroupHR = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $testGroupHR - $newTestGroup5 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $testGroupFinance - $newServerHR = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvNameHR -Group $testGroupHR - $newServerFinance = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvNameFinance -Group $testGroupHR + $newTestGroupHR = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $testGroupHR + $newTestGroup5 = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $testGroupFinance + $newServerHR = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName -Name $regSrvNameHR -Group $testGroupHR + $newServerFinance = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName -Name $regSrvNameFinance -Group $testGroupHR } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3, $regSrvNameHR, $regSrvNameFinance | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group, $group2, $testGroupHR, $testGroupFinance | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3, $regSrvNameHR, $regSrvNameFinance | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group $group, $group2, $testGroupHR, $testGroupFinance | Remove-DbaRegServerGroup -Confirm:$false } It "moves a piped server" { @@ -76,13 +76,13 @@ Describe "Move-DbaRegServer" { } It "moves a manually specified server" { - $results = Move-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName3 -NewGroup $newGroup2.Name + $results = Move-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName3 -NewGroup $newGroup2.Name $results.Parent.Name | Should -Be $newGroup2.Name $results.Description | Should -Be $regSrvDesc3 } It "moves a piped server to a target group" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $testGroupHR | Move-DbaRegServer -Group $testGroupFinance + $results = Get-DbaRegServer -SqlInstance $env:instance1 -Group $testGroupHR | Move-DbaRegServer -Group $testGroupFinance $results.Count | Should -Be 2 } } diff --git a/tests/Move-DbaRegServerGroup.Tests.ps1 b/tests/Move-DbaRegServerGroup.Tests.ps1 index a1b236b08e..2d8f602744 100644 --- a/tests/Move-DbaRegServerGroup.Tests.ps1 +++ b/tests/Move-DbaRegServerGroup.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Move-DbaRegServerGroup" { $CommandUnderTest | Should -HaveParameter InputObject -Type ServerGroup[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -37,19 +37,19 @@ Describe "Move-DbaRegServerGroup" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $group2 = "dbatoolsci-group1a" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group2 $group3 = "dbatoolsci-group1b" - $newGroup3 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group3 + $newGroup3 = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group3 } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group, $group2, $group3 | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 -Name $regSrvName | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group $group, $group2, $group3 | Remove-DbaRegServerGroup -Confirm:$false } It "moves a piped group" { @@ -58,7 +58,7 @@ Describe "Move-DbaRegServerGroup" { } It "moves a manually specified group" { - $results = Move-DbaRegServerGroup -SqlInstance $script:instance1 -Group "$group\$group3" -NewGroup Default + $results = Move-DbaRegServerGroup -SqlInstance $env:instance1 -Group "$group\$group3" -NewGroup Default $results.Parent.Name | Should -Be 'DatabaseEngineServerGroup' } } diff --git a/tests/New-DbaAgentAlert.Tests.ps1 b/tests/New-DbaAgentAlert.Tests.ps1 index bedabe2b16..e531c56be4 100644 --- a/tests/New-DbaAgentAlert.Tests.ps1 +++ b/tests/New-DbaAgentAlert.Tests.ps1 @@ -31,7 +31,7 @@ Describe "New-DbaAgentAlert" { $CommandUnderTest | Should -HaveParameter DelayBetweenResponses -Type Int32 -Not -Mandatory } It "Should have Disabled parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch -Not -Mandatory } It "Should have EventDescriptionKeyword parameter" { $CommandUnderTest | Should -HaveParameter EventDescriptionKeyword -Type String -Not -Mandatory @@ -64,14 +64,14 @@ Describe "New-DbaAgentAlert" { $CommandUnderTest | Should -HaveParameter NotifyMethod -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Creating a new SQL Server Agent alert" { BeforeAll { - $script:instance2 = "instance2" - $script:instance3 = "instance3" + $env:instance2 = "instance2" + $env:instance3 = "instance3" } BeforeEach { @@ -104,7 +104,7 @@ Describe "New-DbaAgentAlert" { It 'Should create a new alert' { $parms = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Alert = "Test Alert" DelayBetweenResponses = 60 Disabled = $false @@ -131,13 +131,13 @@ Describe "New-DbaAgentAlert" { $alert.Severity | Should -Be 17 Should -Invoke Get-DbaAgentAlert -Times 1 -Exactly -ParameterFilter { - $SqlInstance -eq $script:instance2 -and $Alert -eq $parms.Alert + $SqlInstance -eq $env:instance2 -and $Alert -eq $parms.Alert } } It 'Should create another new alert' { $parms = @{ - SqlInstance = $script:instance3 + SqlInstance = $env:instance3 Alert = "Another Alert" DelayBetweenResponses = 60 NotifyMethod = "NotifyEmail" @@ -165,7 +165,7 @@ Describe "New-DbaAgentAlert" { $alert.Severity | Should -Be 0 Should -Invoke Get-DbaAgentAlert -Times 1 -Exactly -ParameterFilter { - $SqlInstance -eq $script:instance3 -and $Alert -eq $parms.Alert + $SqlInstance -eq $env:instance3 -and $Alert -eq $parms.Alert } } } diff --git a/tests/New-DbaAgentAlertCategory.Tests.ps1 b/tests/New-DbaAgentAlertCategory.Tests.ps1 index 06d0d67c78..a3ab7acbe4 100644 --- a/tests/New-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/New-DbaAgentAlertCategory.Tests.ps1 @@ -28,33 +28,33 @@ Describe "New-DbaAgentAlertCategory" { Context "New Agent Alert Category is added properly" { BeforeAll { - $script:instance2 = "localhost" + $env:instance2 = "localhost" } AfterAll { # Cleanup and ignore all output - $null = Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false + $null = Remove-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false } It "Should have the right name and category type" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1 $results.Name | Should -Be "CategoryTest1" } It "Should have the right name and category type" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest2 + $results = New-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest2 $results.Name | Should -Be "CategoryTest2" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 + $newresults = Get-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2 $newresults[0].Name | Should -Be "CategoryTest1" $newresults[1].Name | Should -Be "CategoryTest2" } It "Should not write over existing job categories" { $warn = $null - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Match "already exists" } } diff --git a/tests/New-DbaAgentJob.Tests.ps1 b/tests/New-DbaAgentJob.Tests.ps1 index eea8a27b46..73630cc6c3 100644 --- a/tests/New-DbaAgentJob.Tests.ps1 +++ b/tests/New-DbaAgentJob.Tests.ps1 @@ -25,7 +25,7 @@ Describe "New-DbaAgentJob" { $CommandUnderTest | Should -HaveParameter ScheduleId -Type Int32[] -Not -Mandatory } It "Should have Disabled parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch -Not -Mandatory } It "Should have Description parameter" { $CommandUnderTest | Should -HaveParameter Description -Type String -Not -Mandatory @@ -61,10 +61,10 @@ Describe "New-DbaAgentJob" { $CommandUnderTest | Should -HaveParameter DeleteLevel -Type Object -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -76,24 +76,24 @@ Describe "New-DbaAgentJob" { AfterAll { # Cleanup and ignore all output - Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Confirm:$false *> $null + Remove-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName -Confirm:$false *> $null } It "Should create a new job with the right name and description" { - $results = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Description $jobDescription + $results = New-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName -Description $jobDescription $results.Name | Should -Be $jobName $results.Description | Should -Be $jobDescription } It "Should verify the job exists" { - $newResults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName + $newResults = Get-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName $newResults.Name | Should -Be $jobName $newResults.Description | Should -Be $jobDescription } It "Should not overwrite existing jobs" { $warn = $null - $results = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Description $jobDescription -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName -Description $jobDescription -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Match "already exists" } } diff --git a/tests/New-DbaAgentJobCategory.Tests.ps1 b/tests/New-DbaAgentJobCategory.Tests.ps1 index ca8af1b5d0..7c237bde1c 100644 --- a/tests/New-DbaAgentJobCategory.Tests.ps1 +++ b/tests/New-DbaAgentJobCategory.Tests.ps1 @@ -22,32 +22,32 @@ Describe "New-DbaAgentJobCategory" { $CommandUnderTest | Should -HaveParameter CategoryType -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "New Agent Job Category is added properly" { BeforeAll { - $script:instance2 = "localhost" + $env:instance2 = "localhost" } It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1 $results.Name | Should -Be "CategoryTest1" $results.CategoryType | Should -Be "LocalJob" } It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest2 -CategoryType MultiServerJob + $results = New-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest2 -CategoryType MultiServerJob $results.Name | Should -Be "CategoryTest2" $results.CategoryType | Should -Be "MultiServerJob" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 + $newresults = Get-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2 $newresults[0].Name | Should -Be "CategoryTest1" $newresults[0].CategoryType | Should -Be "LocalJob" $newresults[1].Name | Should -Be "CategoryTest2" @@ -56,13 +56,13 @@ Describe "New-DbaAgentJobCategory" { It "Should not write over existing job categories" { $warn = $null - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Match "already exists" } AfterAll { # Cleanup and ignore all output - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false *> $null + Remove-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false *> $null } } } diff --git a/tests/New-DbaAgentJobStep.Tests.ps1 b/tests/New-DbaAgentJobStep.Tests.ps1 index 7e66d43d1c..d382019014 100644 --- a/tests/New-DbaAgentJobStep.Tests.ps1 +++ b/tests/New-DbaAgentJobStep.Tests.ps1 @@ -64,7 +64,7 @@ Describe "New-DbaAgentJobStep" { $CommandUnderTest | Should -HaveParameter OutputFileName -Type String } It "Should have Insert parameter" { - $CommandUnderTest | Should -HaveParameter Insert -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Insert -Type Switch } It "Should have Flag parameter" { $CommandUnderTest | Should -HaveParameter Flag -Type String[] @@ -73,33 +73,33 @@ Describe "New-DbaAgentJobStep" { $CommandUnderTest | Should -HaveParameter ProxyName -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "New Agent Job Step is added properly" { BeforeAll { $random = Get-Random - $job = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -Description "Just another job" - $jobTwo = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_2_$random" -Description "Just another job" - $jobThree = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_3_$random" -Description "Just another job" + $job = New-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" -Description "Just another job" + $jobTwo = New-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_2_$random" -Description "Just another job" + $jobThree = New-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_3_$random" -Description "Just another job" } AfterAll { - Remove-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random", "dbatoolsci_job_2_$random", "dbatoolsci_job_3_$random" -Confirm:$false + Remove-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random", "dbatoolsci_job_2_$random", "dbatoolsci_job_3_$random" -Confirm:$false } It "Should have the right name and description" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "Step One" + $results = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $job -StepName "Step One" $results.Name | Should -Be "Step One" } It "Should have the right properties" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Job = $jobTwo StepName = "Step X" Subsystem = "TransactSql" @@ -120,40 +120,40 @@ Describe "New-DbaAgentJobStep" { } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps.Name | Should -Be "Step One" } It "Should not write over existing job steps" { $warn = $null - New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "Step One" -WarningAction SilentlyContinue -WarningVariable warn + New-DbaAgentJobStep -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" -StepName "Step One" -WarningAction SilentlyContinue -WarningVariable warn $warn -match "already exists" | Should -Be $true - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps.Name | Should -Be "Step One" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Step One" } It "Force should replace the job step" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step One" -StepId 1 -Force + $results = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step One" -StepId 1 -Force $results.Name | Should -Be "New Step One" - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "New Step One" } It "Insert should insert jobstep and update IDs" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step Three" -StepId 1 -Insert + $results = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step Three" -StepId 1 -Insert $results.Name | Should -Be "New Step Three" - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $env:instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "New Step Three" $newresults.JobSteps | Where-Object Id -eq 2 | Select-Object -ExpandProperty Name | Should -Be "New Step One" } It "Job is refreshed from the server" { - $agentStep1 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Error collection" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithFailure - $agentStep2 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 1" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep3 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 2" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep4 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 3" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep5 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 4" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep1 = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $jobThree -StepName "Error collection" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithFailure + $agentStep2 = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $jobThree -StepName "Step 1" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep3 = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $jobThree -StepName "Step 2" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep4 = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $jobThree -StepName "Step 3" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep5 = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $jobThree -StepName "Step 4" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep $agentStep1.Name | Should -Be "Error collection" $agentStep2.Name | Should -Be "Step 1" @@ -161,7 +161,7 @@ Describe "New-DbaAgentJobStep" { $agentStep4.Name | Should -Be "Step 3" $agentStep5.Name | Should -Be "Step 4" - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $jobThree + $results = Get-DbaAgentJob -SqlInstance $env:instance2 -Job $jobThree $results.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Error collection" $results.JobSteps | Where-Object Id -eq 2 | Select-Object -ExpandProperty Name | Should -Be "Step 1" $results.JobSteps | Where-Object Id -eq 3 | Select-Object -ExpandProperty Name | Should -Be "Step 2" diff --git a/tests/New-DbaAgentOperator.Tests.ps1 b/tests/New-DbaAgentOperator.Tests.ps1 index 759dd90767..fd7802b0f4 100644 --- a/tests/New-DbaAgentOperator.Tests.ps1 +++ b/tests/New-DbaAgentOperator.Tests.ps1 @@ -45,27 +45,27 @@ Describe "New-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter WeekdayEndTime -Type String } It "Should have IsFailsafeOperator parameter" { - $CommandUnderTest | Should -HaveParameter IsFailsafeOperator -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IsFailsafeOperator -Type Switch } It "Should have FailsafeNotificationMethod parameter" { $CommandUnderTest | Should -HaveParameter FailsafeNotificationMethod -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Server[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "New Agent Operator is added properly" { BeforeAll { $random = Get-Random - $script:instance2 = $env:COMPUTERNAME - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $env:instance2 = $env:COMPUTERNAME + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $email1 = "test1$($random)@test.com" $email2 = "test2$($random)@test.com" $email3 = "test3$($random)@test.com" diff --git a/tests/New-DbaAgentProxy.Tests.ps1 b/tests/New-DbaAgentProxy.Tests.ps1 index 8f608d7e3f..24b705867e 100644 --- a/tests/New-DbaAgentProxy.Tests.ps1 +++ b/tests/New-DbaAgentProxy.Tests.ps1 @@ -51,7 +51,7 @@ Describe "New-DbaAgentProxy" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $login = "db$random" $plaintext = "BigOlPassword!" diff --git a/tests/New-DbaAgentSchedule.Tests.ps1 b/tests/New-DbaAgentSchedule.Tests.ps1 index f0719b5539..941caa4deb 100644 --- a/tests/New-DbaAgentSchedule.Tests.ps1 +++ b/tests/New-DbaAgentSchedule.Tests.ps1 @@ -22,7 +22,7 @@ Describe "New-DbaAgentSchedule Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Schedule -Type Object -Not -Mandatory } It "Should have Disabled as a parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch -Not -Mandatory } It "Should have FrequencyType as a parameter" { $CommandUnderTest | Should -HaveParameter FrequencyType -Type Object -Not -Mandatory @@ -58,24 +58,24 @@ Describe "New-DbaAgentSchedule Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Owner -Type String -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -StepId 1 -StepName 'dbatoolsci Test Select' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command "SELECT * FROM master.sys.all_columns;" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa + $null = New-DbaAgentJob -SqlInstance $env:instance2 -Job 'dbatoolsci_newschedule' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job 'dbatoolsci_newschedule' -StepId 1 -StepName 'dbatoolsci Test Select' -Subsystem TransactSql -SubsystemServer $env:instance2 -Command "SELECT * FROM master.sys.all_columns;" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa $start = (Get-Date).AddDays(2).ToString('yyyyMMdd') $end = (Get-Date).AddDays(4).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $env:instance2 -Job 'dbatoolsci_newschedule' -Confirm:$false } Context "Should create schedules based on frequency type" { @@ -86,7 +86,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { foreach ($frequency in $scheduleOptions) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_newschedule' FrequencyType = $frequency @@ -103,7 +103,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } @@ -113,7 +113,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } It "Should be a schedule on an existing job and have the correct frequency type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $env:instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencyTypes | Should -BeIn $scheduleOptions @@ -146,7 +146,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequencyinterval" Job = 'dbatoolsci_newschedule' FrequencyType = $frequencyType @@ -162,7 +162,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } @@ -172,7 +172,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } It "Should be a schedule on an existing job and have the correct interval for the frequency type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $env:instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId @@ -204,7 +204,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { foreach ($frequencySubdayType in $scheduleOptions) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequencySubdayType" Job = 'dbatoolsci_newschedule' FrequencyType = 'Daily' @@ -222,7 +222,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } @@ -232,7 +232,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } It "Should be a schedule on an existing job and have a valid frequency subday type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $env:instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencySubdayTypes | Should -BeIn $scheduleOptions @@ -260,7 +260,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { foreach ($frequencyRelativeInterval in $scheduleOptions) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequencyRelativeInterval" Job = 'dbatoolsci_newschedule' FrequencyType = 'MonthlyRelative' @@ -279,7 +279,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } @@ -289,7 +289,7 @@ Describe "New-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { } It "Should be a schedule on an existing job and have a valid frequency relative interval" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $env:instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencyRelativeIntervals | Should -BeIn $scheduleOptions diff --git a/tests/New-DbaAvailabilityGroup.Tests.ps1 b/tests/New-DbaAvailabilityGroup.Tests.ps1 index be356a9793..0654324813 100644 --- a/tests/New-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/New-DbaAvailabilityGroup.Tests.ps1 @@ -111,25 +111,25 @@ Describe "New-DbaAvailabilityGroup" { Context "Command usage" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $null = Get-DbaProcess -SqlInstance $env:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $dbname = "dbatoolsci_addag_agroupdb" $agname = "dbatoolsci_addag_agroup" - $null = New-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase } AfterEach { - $result = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $result = Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance3 -Database $dbname -Confirm:$false } It "returns an ag with a db named" { - $results = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert + $results = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert $results.AvailabilityDatabases.Name | Should -Be $dbname $results.AvailabilityDatabases.Count | Should -Be 1 -Because "There should be only the named database in the group" } It "returns an ag with no database if one was not named" { - $results = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $results = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert $results.AvailabilityDatabases.Count | Should -Be 0 -Because "No database was named" } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/New-DbaAzAccessToken.Tests.ps1 b/tests/New-DbaAzAccessToken.Tests.ps1 index 1bac27ce0c..66afb7397e 100644 --- a/tests/New-DbaAzAccessToken.Tests.ps1 +++ b/tests/New-DbaAzAccessToken.Tests.ps1 @@ -30,7 +30,7 @@ Describe "New-DbaAzAccessToken" { It "Should have Store as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Store -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/New-DbaClientAlias.Tests.ps1 b/tests/New-DbaClientAlias.Tests.ps1 index 8e34ac333e..5143251154 100644 --- a/tests/New-DbaClientAlias.Tests.ps1 +++ b/tests/New-DbaClientAlias.Tests.ps1 @@ -27,7 +27,7 @@ Describe "New-DbaClientAlias" { $CommandUnderTest | Should -HaveParameter Protocol -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaComputerCertificate.Tests.ps1 b/tests/New-DbaComputerCertificate.Tests.ps1 index 16940a386b..636a25aeec 100644 --- a/tests/New-DbaComputerCertificate.Tests.ps1 +++ b/tests/New-DbaComputerCertificate.Tests.ps1 @@ -44,11 +44,11 @@ Describe "New-DbaComputerCertificate" { It "Should have Dns as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Dns -Type String[] -Not -Mandatory } - It "Should have SelfSigned as a non-mandatory SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter SelfSigned -Type SwitchParameter -Not -Mandatory + It "Should have SelfSigned as a non-mandatory Switch parameter" { + $CommandUnderTest | Should -HaveParameter SelfSigned -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch parameter" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have HashAlgorithm as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter HashAlgorithm -Type String -Not -Mandatory @@ -61,10 +61,10 @@ Describe "New-DbaComputerCertificate" { Describe "New-DbaComputerCertificate Integration Tests" -Tag "IntegrationTests" { BeforeDiscovery { - $script:skipIntegrationTests = $env:appveyor -eq $true + $env:skipIntegrationTests = $env:appveyor -eq $true } - Context "Can generate a new certificate" -Skip:$script:skipIntegrationTests { + Context "Can generate a new certificate" -Skip:$env:skipIntegrationTests { BeforeAll { $cert = New-DbaComputerCertificate -SelfSigned -EnableException } @@ -86,7 +86,7 @@ Describe "New-DbaComputerCertificate Integration Tests" -Tag "IntegrationTests" } } - Context "Can generate a new certificate with correct settings" -Skip:$script:skipIntegrationTests { + Context "Can generate a new certificate with correct settings" -Skip:$env:skipIntegrationTests { BeforeAll { $cert = New-DbaComputerCertificate -SelfSigned -HashAlgorithm "Sha256" -MonthsValid 60 -EnableException } diff --git a/tests/New-DbaConnectionString.Tests.ps1 b/tests/New-DbaConnectionString.Tests.ps1 index 92e883229d..e52c28e7cc 100644 --- a/tests/New-DbaConnectionString.Tests.ps1 +++ b/tests/New-DbaConnectionString.Tests.ps1 @@ -92,42 +92,42 @@ Describe "New-DbaConnectionString" { } It "Creates a valid connection string" { - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -Database 'master' - $connectionString | Should -Match "Data Source=$([regex]::Escape($script:instance1))" + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -Database 'master' + $connectionString | Should -Match "Data Source=$([regex]::Escape($env:instance1))" $connectionString | Should -Match "Initial Catalog=master" } It "Appends custom string when using AppendConnectionString" { $customString = "Application Name=MyApp" - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -AppendConnectionString $customString + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -AppendConnectionString $customString $connectionString | Should -Match $customString } It "Uses provided credentials" { $securePassword = ConvertTo-SecureString 'P@ssw0rd' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ('testuser', $securePassword) - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -Credential $cred + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -Credential $cred $connectionString | Should -Match "User ID=testuser" $connectionString | Should -Match "Password=P@ssw0rd" } It "Sets ApplicationIntent when provided" { - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -ApplicationIntent ReadOnly + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -ApplicationIntent ReadOnly $connectionString | Should -Match "ApplicationIntent=ReadOnly" } It "Sets ConnectTimeout when provided" { - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -ConnectTimeout 30 + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -ConnectTimeout 30 $connectionString | Should -Match "Connect Timeout=30" } It "Sets EncryptConnection when provided" { - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -EncryptConnection + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -EncryptConnection $connectionString | Should -Match "Encrypt=True" } It "Sets MultiSubnetFailover when provided" { - $connectionString = New-DbaConnectionString -SqlInstance $script:instance1 -MultiSubnetFailover + $connectionString = New-DbaConnectionString -SqlInstance $env:instance1 -MultiSubnetFailover $connectionString | Should -Match "MultiSubnetFailover=True" } } diff --git a/tests/New-DbaConnectionStringBuilder.Tests.ps1 b/tests/New-DbaConnectionStringBuilder.Tests.ps1 index 17ba804949..c372b9032f 100644 --- a/tests/New-DbaConnectionStringBuilder.Tests.ps1 +++ b/tests/New-DbaConnectionStringBuilder.Tests.ps1 @@ -20,8 +20,8 @@ Describe "New-DbaConnectionStringBuilder" { It "Should have InitialCatalog as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter InitialCatalog -Type String -Not -Mandatory } - It "Should have IntegratedSecurity as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter IntegratedSecurity -Type SwitchParameter -Not -Mandatory + It "Should have IntegratedSecurity as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter IntegratedSecurity -Type Switch -Not -Mandatory } It "Should have UserName as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter UserName -Type String -Not -Mandatory @@ -29,17 +29,17 @@ Describe "New-DbaConnectionStringBuilder" { It "Should have Password as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Password -Type String -Not -Mandatory } - It "Should have MultipleActiveResultSets as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter MultipleActiveResultSets -Type SwitchParameter -Not -Mandatory + It "Should have MultipleActiveResultSets as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter MultipleActiveResultSets -Type Switch -Not -Mandatory } It "Should have ColumnEncryptionSetting as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter ColumnEncryptionSetting -Type String -Not -Mandatory } - It "Should have Legacy as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Legacy -Type SwitchParameter -Not -Mandatory + It "Should have Legacy as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Legacy -Type Switch -Not -Mandatory } - It "Should have NonPooledConnection as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter NonPooledConnection -Type SwitchParameter -Not -Mandatory + It "Should have NonPooledConnection as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter NonPooledConnection -Type Switch -Not -Mandatory } It "Should have WorkstationId as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter WorkstationId -Type String -Not -Mandatory diff --git a/tests/New-DbaCredential.Tests.ps1 b/tests/New-DbaCredential.Tests.ps1 index fbc54fc62f..06ae77645e 100644 --- a/tests/New-DbaCredential.Tests.ps1 +++ b/tests/New-DbaCredential.Tests.ps1 @@ -35,10 +35,10 @@ Describe 'New-DbaCredential' -Tag 'UnitTests', 'IntegrationTests' { $CommandUnderTest | Should -HaveParameter -Name 'ProviderName' -Type 'String' -Mandatory:$false } It "Accepts Force as a parameter" { - $CommandUnderTest | Should -HaveParameter -Name 'Force' -Type 'SwitchParameter' -Mandatory:$false + $CommandUnderTest | Should -HaveParameter -Name 'Force' -Type 'Switch' -Mandatory:$false } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter -Name 'EnableException' -Type 'SwitchParameter' -Mandatory:$false + $CommandUnderTest | Should -HaveParameter -Name 'EnableException' -Type 'Switch' -Mandatory:$false } } @@ -50,32 +50,32 @@ Describe 'New-DbaCredential' -Tag 'UnitTests', 'IntegrationTests' { # Add users foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $using:login $using:plaintext /add *>&1 } -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $using:login $using:plaintext /add *>&1 } -ComputerName $env:instance2 } } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue) | ForEach-Object { $_.Drop() } - (Get-DbaCredential -SqlInstance $script:instance2 -Name "https://mystorageaccount.blob.core.windows.net/mycontainer" -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $env:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue) | ForEach-Object { $_.Drop() } + (Get-DbaCredential -SqlInstance $env:instance2 -Name "https://mystorageaccount.blob.core.windows.net/mycontainer" -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $using:login /delete *>&1 } -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $using:login /delete *>&1 } -ComputerName $env:instance2 } } Context "Create a new credential" { It "Should create new credentials with the proper properties" { - $results = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password + $results = New-DbaCredential -SqlInstance $env:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password $results.Name | Should -Be "dbatoolsci_thorcred" $results.Identity | Should -Be "dbatoolsci_thor" - $results = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma -Password $password + $results = New-DbaCredential -SqlInstance $env:instance2 -Identity dbatoolsci_thorsmomma -Password $password $results | Should -Not -Be $null } It "Gets the newly created credential" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $env:instance2 -Identity dbatoolsci_thorsmomma $results.Name | Should -Be "dbatoolsci_thorsmomma" $results.Identity | Should -Be "dbatoolsci_thorsmomma" } @@ -84,7 +84,7 @@ Describe 'New-DbaCredential' -Tag 'UnitTests', 'IntegrationTests' { Context "Create a new credential without password" { It "Should create new credentials with the proper properties but without password" { $credentialParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Name = "https://mystorageaccount.blob.core.windows.net/mycontainer" Identity = 'Managed Identity' } @@ -93,7 +93,7 @@ Describe 'New-DbaCredential' -Tag 'UnitTests', 'IntegrationTests' { $results.Identity | Should -Be "Managed Identity" } It "Gets the newly created credential that doesn't have password" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity "Managed Identity" + $results = Get-DbaCredential -SqlInstance $env:instance2 -Identity "Managed Identity" $results.Name | Should -Be "https://mystorageaccount.blob.core.windows.net/mycontainer" $results.Identity | Should -Be "Managed Identity" } diff --git a/tests/New-DbaCustomError.Tests.ps1 b/tests/New-DbaCustomError.Tests.ps1 index 00e1b1d8b8..fbcd3b0935 100644 --- a/tests/New-DbaCustomError.Tests.ps1 +++ b/tests/New-DbaCustomError.Tests.ps1 @@ -37,8 +37,8 @@ Describe "New-DbaCustomError" { Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 } AfterAll { $server.Query("IF EXISTS (SELECT 1 FROM master.sys.messages WHERE message_id = 70000) BEGIN EXEC msdb.dbo.sp_dropmessage @msgnum = 70000, @lang = 'all'; END") diff --git a/tests/New-DbaDacOption.Tests.ps1 b/tests/New-DbaDacOption.Tests.ps1 index bf77140cd3..d8f33dab14 100644 --- a/tests/New-DbaDacOption.Tests.ps1 +++ b/tests/New-DbaDacOption.Tests.ps1 @@ -17,15 +17,15 @@ Describe "New-DbaDacOption" { It "Should have Property as a non-mandatory Hashtable parameter" { $CommandUnderTest | Should -HaveParameter Property -Type Hashtable -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database whatever -Path C:\temp + $publishprofile = New-DbaDacProfile -SqlInstance $env:instance1 -Database whatever -Path C:\temp } AfterAll { Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue diff --git a/tests/New-DbaDacProfile.Tests.ps1 b/tests/New-DbaDacProfile.Tests.ps1 index 3a231a6be1..9f139d9e0b 100644 --- a/tests/New-DbaDacProfile.Tests.ps1 +++ b/tests/New-DbaDacProfile.Tests.ps1 @@ -24,25 +24,25 @@ Describe "New-DbaDacProfile" { $CommandUnderTest | Should -HaveParameter PublishOptions -Type Hashtable } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { $dbname = "dbatoolsci_publishprofile" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname $null = $db.Query("CREATE TABLE dbo.example (id int); INSERT dbo.example SELECT top 100 1 FROM sys.objects") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "returns the right results" { - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database $dbname + $publishprofile = New-DbaDacProfile -SqlInstance $env:instance1 -Database $dbname $publishprofile.FileName | Should -Match 'publish.xml' Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue } diff --git a/tests/New-DbaDatabase.Tests.ps1 b/tests/New-DbaDatabase.Tests.ps1 index 860b568ae5..5beb4bedb6 100644 --- a/tests/New-DbaDatabase.Tests.ps1 +++ b/tests/New-DbaDatabase.Tests.ps1 @@ -7,8 +7,8 @@ Describe "New-DbaDatabase" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 + $instance3 = Connect-DbaInstance -SqlInstance $env:instance3 $null = Get-DbaProcess -SqlInstance $instance2, $instance3 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $randomDb = New-DbaDatabase -SqlInstance $instance2 $newDbName = "dbatoolsci_newdb_$random" @@ -101,7 +101,7 @@ Describe "New-DbaDatabase" { $CommandUnderTest | Should -HaveParameter SecondaryDataFileSuffix -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/New-DbaDbAsymmetricKey.Tests.ps1 b/tests/New-DbaDbAsymmetricKey.Tests.ps1 index f26ba6e7a2..f080145493 100644 --- a/tests/New-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/New-DbaDbAsymmetricKey.Tests.ps1 @@ -40,26 +40,26 @@ Describe "New-DbaDbAsymmetricKey" { $CommandUnderTest | Should -HaveParameter Algorithm -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - if (!(Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master)) { - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database master -SecurePassword $tPassword -Confirm:$false + if (!(Get-DbaDbMasterKey -SqlInstance $env:instance2 -Database master)) { + New-DbaDbMasterKey -SqlInstance $env:instance2 -Database master -SecurePassword $tPassword -Confirm:$false } } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database enctest -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database enctest -Confirm:$false } It "Should create new key in master" { $keyname = 'test1' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database master $results.database | Should -Be 'master' $results.name | Should -Be $keyname $results.KeyLength | Should -Be '2048' @@ -67,20 +67,20 @@ Describe "New-DbaDbAsymmetricKey" { It "Should warn when key already exists" { $keyname = 'test1' - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -WarningVariable warnvar 3> $null - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -Confirm:$false + $null = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database master -WarningVariable warnvar 3> $null + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database master -Confirm:$false $warnvar | Should -BeLike '*already exists in master on*' } It "Should handle algorithm changes" { $keyname = 'test2' $algorithm = 'Rsa4096' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Algorithm $algorithm - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Algorithm $algorithm + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database master $results.database | Should -Be 'master' $results.name | Should -Be $keyname $results.KeyLength | Should -Be 4096 - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -Confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database master -Confirm:$false } It "Should create key in non-master database" { @@ -88,17 +88,17 @@ Describe "New-DbaDbAsymmetricKey" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'enctest' - New-DbaDatabase -SqlInstance $script:instance2 -Name $database + New-DbaDatabase -SqlInstance $env:instance2 -Name $database $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false - New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner $dbuser -Algorithm $algorithm - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + New-DbaDbMasterKey -SqlInstance $env:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false + New-DbaDbUser -SqlInstance $env:instance2 -Database $database -UserName $dbuser + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database -Name $keyname -Owner $dbuser -Algorithm $algorithm + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $results.database | Should -Be $database $results.name | Should -Be $keyname $results.KeyLength | Should -Be 4096 $results.Owner | Should -Be $dbuser - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false } It "Should set owner correctly" { @@ -106,38 +106,38 @@ Describe "New-DbaDbAsymmetricKey" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'enctest' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Owner $dbuser -Database $database -Algorithm $algorithm - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Owner $dbuser -Database $database -Algorithm $algorithm + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $results.database | Should -Be $database $results.name | Should -Be $keyname $results.KeyLength | Should -Be 4096 $results.Owner | Should -Be $dbuser - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false } - It "Should create new key loaded from a keyfile" -Skip:(-not (Test-Path -Path "$($script:appveyorlabrepo)\keytests\keypair.snk")) { + It "Should create new key loaded from a keyfile" -Skip:(-not (Test-Path -Path "$($env:appveyorlabrepo)\keytests\keypair.snk")) { $keyname = 'filekey' $dbuser = 'keyowner' $database = 'enctest' - $path = "$($script:appveyorlabrepo)\keytests\keypair.snk" - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner $dbuser -KeySourceType File -KeySource $path - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $path = "$($env:appveyorlabrepo)\keytests\keypair.snk" + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database -Name $keyname -Owner $dbuser -KeySourceType File -KeySource $path + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $results.database | Should -Be $database $results.name | Should -Be $keyname $results.Owner | Should -Be $dbuser - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false } It "Should fail key creation from a missing keyfile" { $keyname = 'filekeybad' $dbuser = 'keyowner' $database = 'enctest' - $path = "$($script:appveyorlabrepo)\keytests\keypair.bad" - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner $dbuser -KeySourceType File -KeySource $path -WarningVariable warnvar 3> $null - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $path = "$($env:appveyorlabrepo)\keytests\keypair.bad" + $null = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database -Name $keyname -Owner $dbuser -KeySourceType File -KeySource $path -WarningVariable warnvar 3> $null + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $warnvar | Should -Not -BeNullOrEmpty $results | Should -BeNullOrEmpty - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false } } } diff --git a/tests/New-DbaDbCertificate.Tests.ps1 b/tests/New-DbaDbCertificate.Tests.ps1 index fb2362cbeb..b561ca211f 100644 --- a/tests/New-DbaDbCertificate.Tests.ps1 +++ b/tests/New-DbaDbCertificate.Tests.ps1 @@ -33,7 +33,7 @@ Describe "New-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter ExpirationDate -Type DateTime } It "Should have ActiveForServiceBrokerDialog as a parameter" { - $CommandUnderTest | Should -HaveParameter ActiveForServiceBrokerDialog -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ActiveForServiceBrokerDialog -Type Switch } It "Should have SecurePassword as a parameter" { $CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString @@ -42,19 +42,19 @@ Describe "New-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Can create a database certificate" { BeforeAll { - $script:instance1 = $script:instance1 # Assuming this is defined in constants.ps1 + $env:instance1 = $env:instance1 # Assuming this is defined in constants.ps1 - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $env:instance1 -Database master)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $env:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } - $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $env:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $certificateName1 = "Cert_$(Get-random)" $certificateName2 = "Cert_$(Get-random)" } @@ -65,13 +65,13 @@ Describe "New-DbaDbCertificate" { } It "Successfully creates a new database certificate in default, master database" { - $cert1 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName1 -Confirm:$false + $cert1 = New-DbaDbCertificate -SqlInstance $env:instance1 -Name $certificateName1 -Confirm:$false $cert1.Name | Should -Match $certificateName1 $cert1 | Remove-DbaDbCertificate -Confirm:$false } It "Successfully creates a new database certificate in the tempdb database" { - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName2 -Database tempdb -Confirm:$false + $cert2 = New-DbaDbCertificate -SqlInstance $env:instance1 -Name $certificateName2 -Database tempdb -Confirm:$false $cert2.Database | Should -Match "tempdb" $cert2 | Remove-DbaDbCertificate -Confirm:$false } diff --git a/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 b/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 index 58e363326a..545de6e2dc 100644 --- a/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 +++ b/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 @@ -12,12 +12,12 @@ Describe "New-DbaDbDataGeneratorConfig" { [LastName] [varchar](50) NULL, [City] [datetime] NULL ) ON [PRIMARY]" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname $db.Query($sql) } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false $results | Remove-Item -Confirm:$false -ErrorAction Ignore } @@ -59,7 +59,7 @@ Describe "New-DbaDbDataGeneratorConfig" { Context "Command works" { It "Should output a file with specific content" { - $results = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $results = New-DbaDbDataGeneratorConfig -SqlInstance $env:instance1 -Database $dbname -Path C:\temp $results.Directory.Name | Should -Be 'temp' $results.FullName | Should -FileContentMatch $dbname $results.FullName | Should -FileContentMatch 'FirstName' diff --git a/tests/New-DbaDbEncryptionKey.Tests.ps1 b/tests/New-DbaDbEncryptionKey.Tests.ps1 index beb50dd8d9..9cbf4b8bd8 100644 --- a/tests/New-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/New-DbaDbEncryptionKey.Tests.ps1 @@ -27,10 +27,10 @@ Describe "New-DbaDbEncryptionKey Unit Tests" -Tag "UnitTests" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -41,18 +41,18 @@ Describe "New-DbaDbEncryptionKey Integration Tests" -Tag "IntegrationTests" { $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential "sqladmin", $passwd - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $env:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $env:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $env:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $env:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $env:instance2 } AfterAll { @@ -73,8 +73,8 @@ Describe "New-DbaDbEncryptionKey Integration Tests" -Tag "IntegrationTests" { $results.EncryptionAlgorithm | Should -Be "Aes256" } It "should create a new encryption key" { - $null = Get-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name | Remove-DbaDbEncryptionKey - $results = New-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name -Force -EncryptorName $mastercert.Name + $null = Get-DbaDbEncryptionKey -SqlInstance $env:instance2 -Database $db.Name | Remove-DbaDbEncryptionKey + $results = New-DbaDbEncryptionKey -SqlInstance $env:instance2 -Database $db.Name -Force -EncryptorName $mastercert.Name $results.EncryptionAlgorithm | Should -Be "Aes256" } } @@ -84,20 +84,20 @@ Describe "New-DbaDbEncryptionKey Integration Tests for Async" -Tag "IntegrationT BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $env:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $env:instance2 -SecurePassword $passwd } - $masterasym = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database master + $masterasym = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database master if (-not $masterasym) { $delmasterasym = $true - $masterasym = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database master + $masterasym = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database master } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $env:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbAsymmetricKey } diff --git a/tests/New-DbaDbFileGroup.Tests.ps1 b/tests/New-DbaDbFileGroup.Tests.ps1 index 3bc25797b1..4b25ca822b 100644 --- a/tests/New-DbaDbFileGroup.Tests.ps1 +++ b/tests/New-DbaDbFileGroup.Tests.ps1 @@ -10,14 +10,14 @@ Describe "New-DbaDbFileGroup" { $db1name = "dbatoolsci_filegroup_test_$random" $db2name = "dbatoolsci_filegroup_test2_$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name - $newDb2 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db2name + $server = Connect-DbaInstance -SqlInstance $env:instance2 + $newDb1 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db1name + $newDb2 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db2name - $fileStreamStatus = Get-DbaFilestream -SqlInstance $script:instance2 + $fileStreamStatus = Get-DbaFilestream -SqlInstance $env:instance2 if ($fileStreamStatus.InstanceAccessLevel -eq 0) { - Enable-DbaFilestream -SqlInstance $script:instance2 -Confirm:$false -Force + Enable-DbaFilestream -SqlInstance $env:instance2 -Confirm:$false -Force $resetFileStream = $true } else { $resetFileStream = $false @@ -28,7 +28,7 @@ Describe "New-DbaDbFileGroup" { $newDb1, $newDb2 | Remove-DbaDatabase -Confirm:$false if ($resetFileStream) { - Disable-DbaFilestream -SqlInstance $script:instance2 -Confirm:$false -Force + Disable-DbaFilestream -SqlInstance $env:instance2 -Confirm:$false -Force } } @@ -55,33 +55,33 @@ Describe "New-DbaDbFileGroup" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command functionality" { It "Creates a filegroup" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_$random" + $results = New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup "filegroup_$random" $results.Parent.Name | Should -Be $db1name $results.Name | Should -Be "filegroup_$random" $results.FileGroupType | Should -Be RowsFileGroup } It "Check the validation for duplicate filegroup names" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_$random" + $results = New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup "filegroup_$random" $results | Should -BeNullOrEmpty } It "Creates a filegroup of each FileGroupType" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_rows_$random" -FileGroupType RowsFileGroup + $results = New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup "filegroup_rows_$random" -FileGroupType RowsFileGroup $results.Name | Should -Be "filegroup_rows_$random" $results.FileGroupType | Should -Be RowsFileGroup - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_filestream_$random" -FileGroupType FileStreamDataFileGroup + $results = New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup "filegroup_filestream_$random" -FileGroupType FileStreamDataFileGroup $results.Name | Should -Be "filegroup_filestream_$random" $results.FileGroupType | Should -Be FileStreamDataFileGroup - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_memory_optimized_$random" -FileGroupType MemoryOptimizedDataFileGroup + $results = New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup "filegroup_memory_optimized_$random" -FileGroupType MemoryOptimizedDataFileGroup $results.Name | Should -Be "filegroup_memory_optimized_$random" $results.FileGroupType | Should -Be MemoryOptimizedDataFileGroup } @@ -91,7 +91,7 @@ Describe "New-DbaDbFileGroup" { $results.Name | Should -Be "filegroup_pipeline_$random" $results.Parent.Name | Should -Be $db1name - $results = $newDb1 | New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup "filegroup_pipeline2_$random" + $results = $newDb1 | New-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db2name -FileGroup "filegroup_pipeline2_$random" $results.Name | Should -Be "filegroup_pipeline2_$random", "filegroup_pipeline2_$random" $results.Parent.Name | Should -Be $db1name, $db2name } diff --git a/tests/New-DbaDbMailAccount.Tests.ps1 b/tests/New-DbaDbMailAccount.Tests.ps1 index b60a18546e..50828a655b 100644 --- a/tests/New-DbaDbMailAccount.Tests.ps1 +++ b/tests/New-DbaDbMailAccount.Tests.ps1 @@ -44,7 +44,7 @@ Describe "New-DbaDbMailAccount" { BeforeAll { $accountName = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $description = 'Mail account for email alerts' $email_address = 'dbatoolssci@dbatools.net' $display_name = 'dbatoolsci mail alerts' @@ -57,14 +57,14 @@ Describe "New-DbaDbMailAccount" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountName';" $server.Query($mailAccountSettings) } It "Creates a new DbMail Account" { $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Account = $accountName Description = $description EmailAddress = $email_address diff --git a/tests/New-DbaDbMailProfile.Tests.ps1 b/tests/New-DbaDbMailProfile.Tests.ps1 index f1154ba7d2..f5cd65569e 100644 --- a/tests/New-DbaDbMailProfile.Tests.ps1 +++ b/tests/New-DbaDbMailProfile.Tests.ps1 @@ -23,8 +23,8 @@ Describe "New-DbaDbMailProfile" { It "Should have MailAccountPriority as a non-mandatory parameter of type Int32" { $CommandUnderTest | Should -HaveParameter MailAccountPriority -Type Int32 -Not -Mandatory } - It "Should have EnableException as a non-mandatory parameter of type SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory parameter of type Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -32,7 +32,7 @@ Describe "New-DbaDbMailProfile" { BeforeAll { . "$PSScriptRoot\constants.ps1" $profilename = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $description = 'Mail account for email alerts' $mailaccountname = 'dbatoolssci@dbatools.io' $mailaccountpriority = 1 @@ -47,7 +47,7 @@ Describe "New-DbaDbMailProfile" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_profile_sp @profile_name = '$profilename';" $server.Query($mailAccountSettings) $regularaccountsettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$mailaccountname';" @@ -56,7 +56,7 @@ Describe "New-DbaDbMailProfile" { It "Sets DbMail Profile" { $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Profile = $profilename Description = $description MailAccountName = $mailaccountname diff --git a/tests/New-DbaDbMaskingConfig.Tests.ps1 b/tests/New-DbaDbMaskingConfig.Tests.ps1 index 437471729f..9b31935966 100644 --- a/tests/New-DbaDbMaskingConfig.Tests.ps1 +++ b/tests/New-DbaDbMaskingConfig.Tests.ps1 @@ -64,7 +64,7 @@ Describe "New-DbaDbMaskingConfig" { [lname] [varchar](50) NULL, [dob] [datetime] NULL ) ON [PRIMARY]" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname $db.Query($sql) $sql = "INSERT INTO people (fname, lname, dob) VALUES ('Joe','Schmoe','2/2/2000') INSERT INTO people (fname, lname, dob) VALUES ('Jane','Schmee','2/2/1950')" @@ -88,19 +88,19 @@ Describe "New-DbaDbMaskingConfig" { } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false $results | Remove-Item -Confirm:$false -ErrorAction Ignore } It "Should output a file with specific content" { - $results = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $results = New-DbaDbMaskingConfig -SqlInstance $env:instance1 -Database $dbname -Path C:\temp $results.Directory.Name | Should -Be temp $results.FullName | Should -FileContentMatch $dbname $results.FullName | Should -FileContentMatch fname } It "Bug 6934: matching IPAddress, Address, and StreetAddress on known names" { - $results = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Table DbConfigTest -Path C:\temp + $results = New-DbaDbMaskingConfig -SqlInstance $env:instance1 -Database $dbname -Table DbConfigTest -Path C:\temp $jsonOutput = Get-Content $results.FullName | ConvertFrom-Json $jsonOutput.Tables.Columns[1].Name | Should -Be "IPAddress" diff --git a/tests/New-DbaDbMasterKey.Tests.ps1 b/tests/New-DbaDbMasterKey.Tests.ps1 index 56a032e638..ee75512a96 100644 --- a/tests/New-DbaDbMasterKey.Tests.ps1 +++ b/tests/New-DbaDbMasterKey.Tests.ps1 @@ -24,7 +24,7 @@ Describe "New-DbaDbMasterKey" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,18 +32,18 @@ Describe "New-DbaDbMasterKey" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $env:instance1 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance1 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $env:instance1 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $env:instance1 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance1 + $mastercert = New-DbaDbCertificate -SqlInstance $env:instance1 } - $db = New-DbaDatabase -SqlInstance $script:instance1 - $db1 = New-DbaDatabase -SqlInstance $script:instance1 + $db = New-DbaDatabase -SqlInstance $env:instance1 + $db1 = New-DbaDatabase -SqlInstance $env:instance1 } AfterAll { @@ -69,7 +69,7 @@ Describe "New-DbaDbMasterKey" { } It "should create master key on a database" { - $results = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1.Name -SecurePassword $passwd + $results = New-DbaDbMasterKey -SqlInstance $env:instance1 -Database $db1.Name -SecurePassword $passwd $results.IsEncryptedByServer | Should -Be $true } } diff --git a/tests/New-DbaDbRole.Tests.ps1 b/tests/New-DbaDbRole.Tests.ps1 index 48b9978b48..dd82c85f04 100644 --- a/tests/New-DbaDbRole.Tests.ps1 +++ b/tests/New-DbaDbRole.Tests.ps1 @@ -6,7 +6,7 @@ Describe "New-DbaDbRole" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $env:instance2 $dbname = "dbatoolsci_adddb_newrole" $instance.Query("create database $dbname") $roleExecutor = "dbExecuter" @@ -44,7 +44,7 @@ Describe "New-DbaDbRole" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaDbSchema.Tests.ps1 b/tests/New-DbaDbSchema.Tests.ps1 index 84d043ab9e..6de46dd163 100644 --- a/tests/New-DbaDbSchema.Tests.ps1 +++ b/tests/New-DbaDbSchema.Tests.ps1 @@ -24,7 +24,7 @@ Describe "New-DbaDbSchema" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -32,8 +32,8 @@ Describe "New-DbaDbSchema" { Describe "New-DbaDbSchema Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName diff --git a/tests/New-DbaDbSequence.Tests.ps1 b/tests/New-DbaDbSequence.Tests.ps1 index aa09b685ed..ddf06478c8 100644 --- a/tests/New-DbaDbSequence.Tests.ps1 +++ b/tests/New-DbaDbSequence.Tests.ps1 @@ -7,7 +7,7 @@ Describe "New-DbaDbSequence" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName @@ -55,7 +55,7 @@ Describe "New-DbaDbSequence" { $CommandUnderTest | Should -HaveParameter MaxValue -Type Int64 } It "Should have Cycle parameter" { - $CommandUnderTest | Should -HaveParameter Cycle -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Cycle -Type Switch } It "Should have CacheSize parameter" { $CommandUnderTest | Should -HaveParameter CacheSize -Type Int32 @@ -64,7 +64,7 @@ Describe "New-DbaDbSequence" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaDbSnapshot.Tests.ps1 b/tests/New-DbaDbSnapshot.Tests.ps1 index d8da21bbfd..33ee612db3 100644 --- a/tests/New-DbaDbSnapshot.Tests.ps1 +++ b/tests/New-DbaDbSnapshot.Tests.ps1 @@ -47,8 +47,8 @@ Describe "New-DbaDbSnapshot" { Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance2 + Get-DbaProcess -SqlInstance $env:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue $db1 = "dbatoolsci_SnapMe" $db2 = "dbatoolsci_SnapMe2" $db3 = "dbatoolsci_SnapMe3_Offline" @@ -60,40 +60,40 @@ Describe "New-DbaDbSnapshot" { } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4 -Confirm:$false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4 + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2, $db3, $db4 -Confirm:$false + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1, $db2, $db3, $db4 } It "Stops if no Database or AllDatabases" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -WarningAction SilentlyContinue } | Should -Throw "You must specify" + { New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -WarningAction SilentlyContinue } | Should -Throw "You must specify" } It "Is nice by default" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 *> $null -WarningAction SilentlyContinue } | Should -Not -Throw + { New-DbaDbSnapshot -SqlInstance $env:instance2 *> $null -WarningAction SilentlyContinue } | Should -Not -Throw } It "Doesn't support model, master or tempdb" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database model, master, tempdb -WarningAction SilentlyContinue + $result = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database model, master, tempdb -WarningAction SilentlyContinue $result | Should -BeNullOrEmpty } It "Skips over offline databases nicely" { $server.Query("ALTER DATABASE $db3 SET OFFLINE WITH ROLLBACK IMMEDIATE") - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db3 + $result = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db3 $result | Should -BeNullOrEmpty $server.Query("ALTER DATABASE $db3 SET ONLINE WITH ROLLBACK IMMEDIATE") } It "Refuses to accept multiple source databases with a single name target" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1, $db2 -Name "dbatools_Snapped" -WarningAction SilentlyContinue } | Should -Throw + { New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db1, $db2 -Name "dbatools_Snapped" -WarningAction SilentlyContinue } | Should -Throw } It "Halts when path is not accessible" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Path B:\Funnydbatoolspath -EnableException -WarningAction SilentlyContinue } | Should -Throw + { New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Path B:\Funnydbatoolspath -EnableException -WarningAction SilentlyContinue } | Should -Throw } It "Creates snaps for multiple dbs by default" { - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1, $db2 + $results = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db1, $db2 $results | Should -Not -BeNullOrEmpty foreach ($result in $results) { $result.SnapshotOf | Should -BeIn @($db1, $db2) @@ -101,33 +101,33 @@ Describe "New-DbaDbSnapshot" { } It "Creates snap with the correct name" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1 -Name "dbatools_SnapMe_right" + $result = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db1 -Name "dbatools_SnapMe_right" $result | Should -Not -BeNullOrEmpty $result.SnapshotOf | Should -Be $db1 $result.Name | Should -Be "dbatools_SnapMe_right" } It "Creates snap with the correct name template" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db2 -NameSuffix "dbatools_SnapMe_{0}_funny" + $result = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db2 -NameSuffix "dbatools_SnapMe_{0}_funny" $result | Should -Not -BeNullOrEmpty $result.SnapshotOf | Should -Be $db2 $result.Name | Should -Be ("dbatools_SnapMe_{0}_funny" -f $db2) } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 | Select-Object -First 1 + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 | Select-Object -First 1 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } It "Creates multiple snaps for db with dot in the name (see #8829)" { - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db4 + $results = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db4 $results | Should -Not -BeNullOrEmpty foreach ($result in $results) { $result.SnapshotOf | Should -Be $db4 } Start-Sleep -Seconds 2 - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db4 + $results = New-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException -Database $db4 $results | Should -Not -BeNullOrEmpty foreach ($result in $results) { $result.SnapshotOf | Should -Be $db4 diff --git a/tests/New-DbaDbSynonym.Tests.ps1 b/tests/New-DbaDbSynonym.Tests.ps1 index 4f78b45c57..80da8b5d9f 100644 --- a/tests/New-DbaDbSynonym.Tests.ps1 +++ b/tests/New-DbaDbSynonym.Tests.ps1 @@ -8,13 +8,13 @@ Describe "New-DbaDbSynonym" { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname2 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $env:instance2 -Confirm:$false } Context "Validate parameters" { @@ -55,17 +55,17 @@ Describe "New-DbaDbSynonym" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Functionality" { BeforeEach { - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $env:instance2 -Confirm:$false } It 'Add new synonym and returns results' { - $result1 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' + $result1 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' $result1.Count | Should -Be 1 $result1.Name | Should -Be syn1 @@ -74,7 +74,7 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym with default schema' { - $result2a = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2a' -BaseObject 'obj2a' + $result2a = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn2a' -BaseObject 'obj2a' $result2a.Count | Should -Be 1 $result2a.Name | Should -Be 'syn2a' @@ -84,8 +84,8 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym with specified schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch2' - $result2 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' -Schema 'sch2' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch2' + $result2 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' -Schema 'sch2' $result2.Count | Should -Be 1 $result2.Name | Should -Be 'syn2' @@ -95,7 +95,7 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym to list of databases' { - $result3 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Synonym 'syn3' -BaseObject 'obj3' + $result3 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname, $dbname2 -Synonym 'syn3' -BaseObject 'obj3' $result3.Count | Should -Be 2 $result3.Name | Select-Object -Unique | Should -Be 'syn3' @@ -105,8 +105,8 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym to different schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch4' - $result4 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch4' -Synonym 'syn4' -BaseObject 'obj4' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch4' + $result4 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Schema 'sch4' -Synonym 'syn4' -BaseObject 'obj4' $result4.Count | Should -Be 1 $result4.Name | Select-Object -Unique | Should -Be 'syn4' @@ -119,8 +119,8 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym to with a base schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch5' - $result5 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch5' -Synonym 'syn5' -BaseObject 'obj5' -BaseSchema 'bsch5' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch5' + $result5 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Schema 'sch5' -Synonym 'syn5' -BaseObject 'obj5' -BaseSchema 'bsch5' $result5.Count | Should -Be 1 $result5.Name | Select-Object -Unique | Should -Be 'syn5' @@ -133,8 +133,8 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym to with a base database' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch6' - $result6 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch6' -Synonym 'syn6' -BaseObject 'obj6' -BaseSchema 'bsch6' -BaseDatabase 'bdb6' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch6' + $result6 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Schema 'sch6' -Synonym 'syn6' -BaseObject 'obj6' -BaseSchema 'bsch6' -BaseDatabase 'bdb6' $result6.Count | Should -Be 1 $result6.Name | Select-Object -Unique | Should -Be 'syn6' @@ -147,8 +147,8 @@ Describe "New-DbaDbSynonym" { } It 'Add new synonym to with a base server' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch7' - $result7 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch7' -Synonym 'syn7' -BaseObject 'obj7' -BaseSchema 'bsch7' -BaseDatabase 'bdb7' -BaseServer 'bsrv7' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch7' + $result7 = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Schema 'sch7' -Synonym 'syn7' -BaseObject 'obj7' -BaseSchema 'bsch7' -BaseDatabase 'bdb7' -BaseServer 'bsrv7' $result7.Count | Should -Be 1 $result7.Name | Select-Object -Unique | Should -Be 'syn7' diff --git a/tests/New-DbaDbTable.Tests.ps1 b/tests/New-DbaDbTable.Tests.ps1 index 4cc99bc7b0..b0348eff68 100644 --- a/tests/New-DbaDbTable.Tests.ps1 +++ b/tests/New-DbaDbTable.Tests.ps1 @@ -7,7 +7,7 @@ Describe "New-DbaDbTable" { . "$PSScriptRoot\constants.ps1" $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $null = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname $tablename = "dbatoolssci_$(Get-Random)" $tablename2 = "dbatoolssci2_$(Get-Random)" $tablename3 = "dbatoolssci3_$(Get-Random)" @@ -16,8 +16,8 @@ Describe "New-DbaDbTable" { } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "drop table if exists $tablename, $tablename2, $tablename3, $tablename4, $tablename5" - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Invoke-DbaQuery -SqlInstance $env:instance1 -Database $dbname -Query "drop table if exists $tablename, $tablename2, $tablename3, $tablename4, $tablename5" + $null = Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } Context "Validate parameters" { @@ -58,11 +58,11 @@ Describe "New-DbaDbTable" { } } It "Creates the table" { - $result = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename -ColumnMap $map + $result = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tablename -ColumnMap $map $result.Name | Should -Contain $tablename } It "Really created it" { - $tables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname + $tables = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbname $tables.Name | Should -Contain $tablename } } @@ -79,11 +79,11 @@ Describe "New-DbaDbTable" { } } It "Creates the table" { - $result = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename2 -ColumnMap $map + $result = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tablename2 -ColumnMap $map $result.Name | Should -Contain $tablename2 } It "Has a default constraint" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename2 + $table = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Table $tablename2 $table.Name | Should -Be $tablename2 $table.Columns.DefaultConstraint.Name | Should -Contain "DF_MyTest" } @@ -100,11 +100,11 @@ Describe "New-DbaDbTable" { } } It "Creates the table" { - $result = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename3 -ColumnMap $map + $result = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tablename3 -ColumnMap $map $result.Name | Should -Contain $tablename3 } It "Has an identity column" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename3 + $table = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Table $tablename3 $table.Name | Should -Be $tablename3 $table.Columns.Identity | Should -BeTrue $table.Columns.IdentitySeed | Should -Be $map.IdentitySeed @@ -129,7 +129,7 @@ Describe "New-DbaDbTable" { ) } It "Creates the table" { - { New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename4 -ColumnMap $map -EnableException } | Should -Not -Throw + { New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tablename4 -ColumnMap $map -EnableException } | Should -Not -Throw } } @@ -142,11 +142,11 @@ Describe "New-DbaDbTable" { } } It "Creates the table" { - $result = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename5 -ColumnMap $map + $result = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tablename5 -ColumnMap $map $result.Name | Should -Contain $tablename5 } It "Has the correct column datatype" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename5 + $table = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Table $tablename5 $table.Columns['test'].DataType.SqlDataType | Should -Be "NVarCharMax" } } @@ -161,7 +161,7 @@ Describe "New-DbaDbTable" { Type = 'int' } - $tableWithSchema = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName + $tableWithSchema = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName $tableWithSchema.Count | Should -Be 1 $tableWithSchema.Database | Should -Be $dbname $tableWithSchema.Name | Should -Be "table_$random" @@ -177,7 +177,7 @@ Describe "New-DbaDbTable" { Type = 'int' } - $tableWithSchema = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName -Passthru + $tableWithSchema = New-DbaDbTable -SqlInstance $env:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName -Passthru $tableWithSchema[0] | Should -Be "CREATE SCHEMA [$schemaName]" $tableWithSchema[2] | Should -Match "$schemaName" $tableWithSchema[2] | Should -Match "$tableName" diff --git a/tests/New-DbaDbTransfer.Tests.ps1 b/tests/New-DbaDbTransfer.Tests.ps1 index ffe9325b2e..c85dcf0122 100644 --- a/tests/New-DbaDbTransfer.Tests.ps1 +++ b/tests/New-DbaDbTransfer.Tests.ps1 @@ -7,10 +7,10 @@ Describe "New-DbaDbTransfer" { . "$PSScriptRoot\constants.ps1" $dbName = 'dbatools_transfer' - $source = Connect-DbaInstance -SqlInstance $script:instance1 - $destination = Connect-DbaInstance -SqlInstance $script:instance2 + $source = Connect-DbaInstance -SqlInstance $env:instance1 + $destination = Connect-DbaInstance -SqlInstance $env:instance2 $source.Query("CREATE DATABASE $dbName") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbName + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbName $null = $db.Query("CREATE TABLE dbo.transfer_test (id int); INSERT dbo.transfer_test SELECT top 10 1 @@ -66,7 +66,7 @@ Describe "New-DbaDbTransfer" { } catch { $null = 1 } - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbName -Confirm:$false } Context "Validate parameters" { @@ -104,25 +104,25 @@ Describe "New-DbaDbTransfer" { $CommandUnderTest | Should -HaveParameter InputObject -Type NamedSmoObject[] } It "Should have CopyAllObjects as a switch parameter" { - $CommandUnderTest | Should -HaveParameter CopyAllObjects -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CopyAllObjects -Type Switch } It "Should have CopyAll as a parameter" { $CommandUnderTest | Should -HaveParameter CopyAll -Type String[] } It "Should have SchemaOnly as a switch parameter" { - $CommandUnderTest | Should -HaveParameter SchemaOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SchemaOnly -Type Switch } It "Should have DataOnly as a switch parameter" { - $CommandUnderTest | Should -HaveParameter DataOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter DataOnly -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Testing connection parameters" { It "Should create a transfer object" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName $transfer | Should -BeOfType Microsoft.SqlServer.Management.Smo.Transfer $transfer.BatchSize | Should -Be 50000 $transfer.BulkCopyTimeout | Should -Be 5000 @@ -137,7 +137,7 @@ Describe "New-DbaDbTransfer" { } It "Should properly assign dest server parameters from full connstring" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;User=bar;password=foobar;Initial Catalog=hog' + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;User=bar;password=foobar;Initial Catalog=hog' $transfer.DestinationDatabase | Should -Be 'hog' $transfer.DestinationLoginSecure | Should -BeFalse $transfer.DestinationLogin | Should -Be 'bar' @@ -146,7 +146,7 @@ Describe "New-DbaDbTransfer" { } It "Should properly assign dest server parameters from trusted connstring" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;Integrated Security=True' + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;Integrated Security=True' $transfer.DestinationDatabase | Should -Be $dbName $transfer.DestinationLoginSecure | Should -BeTrue $transfer.DestinationLogin | Should -BeNullOrEmpty @@ -155,9 +155,9 @@ Describe "New-DbaDbTransfer" { } It "Should properly assign dest server parameters from server object" { - $dest = Connect-DbaInstance -SqlInstance $script:instance2 -Database msdb + $dest = Connect-DbaInstance -SqlInstance $env:instance2 -Database msdb $connStringBuilder = New-Object Microsoft.Data.SqlClient.SqlConnectionStringBuilder $dest.ConnectionContext.ConnectionString - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance $dest + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -DestinationSqlInstance $dest $transfer.DestinationDatabase | Should -Be $connStringBuilder['Initial Catalog'] $transfer.DestinationLoginSecure | Should -Be $connStringBuilder['Integrated Security'] $transfer.DestinationLogin | Should -Be $connStringBuilder['User ID'] @@ -166,7 +166,7 @@ Describe "New-DbaDbTransfer" { } It "Should properly assign dest server parameters from plaintext params" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance foo -DestinationDatabase bar -DestinationSqlCredential $creds + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -DestinationSqlInstance foo -DestinationDatabase bar -DestinationSqlCredential $creds $transfer.DestinationDatabase | Should -Be 'bar' $transfer.DestinationLoginSecure | Should -BeFalse $transfer.DestinationLogin | Should -Be $creds.UserName @@ -177,7 +177,7 @@ Describe "New-DbaDbTransfer" { Context "Testing function parameters" { It "Should script all objects" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAllObjects + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -CopyAllObjects $transfer.CopyData | Should -BeTrue $transfer.CopySchema | Should -BeTrue $script = $transfer.ScriptTransfer() -join "`n" @@ -188,7 +188,7 @@ Describe "New-DbaDbTransfer" { } It "Should script all tables with just schemas" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAll Tables -SchemaOnly + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -CopyAll Tables -SchemaOnly $transfer.CopyData | Should -BeFalse $transfer.CopySchema | Should -BeTrue $script = $transfer.ScriptTransfer() -join "`n" @@ -199,8 +199,8 @@ Describe "New-DbaDbTransfer" { } It "Should script one table with just data" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -InputObject $table -DataOnly + $table = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbName -Table transfer_test + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -InputObject $table -DataOnly $transfer.ObjectList.Count | Should -Be 1 $transfer.CopyData | Should -BeTrue $transfer.CopySchema | Should -BeFalse @@ -209,8 +209,8 @@ Describe "New-DbaDbTransfer" { } It "Should script two tables from pipeline" { - $tables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test2, transfer_test4 - $transfer = $tables | New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName + $tables = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbName -Table transfer_test2, transfer_test4 + $transfer = $tables | New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName $transfer.ObjectList.Count | Should -Be 2 $script = $transfer.ScriptTransfer() -join "`n" $script | Should -Not -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' @@ -222,7 +222,7 @@ Describe "New-DbaDbTransfer" { It "Should accept script options object" { $options = New-DbaScriptingOption $options.ScriptDrops = $true - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAll Tables -ScriptingOption $options + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -Database $dbName -CopyAll Tables -ScriptingOption $options $transfer.Options.ScriptDrops | Should -BeTrue $script = $transfer.ScriptTransfer() -join "`n" $script | Should -BeLike '*DROP TABLE `[dbo`].`[transfer_test`]*' @@ -232,17 +232,17 @@ Describe "New-DbaDbTransfer" { Context "Testing object transfer" { BeforeEach { $destination.Query("CREATE DATABASE $dbname") - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbName + $db2 = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbName } AfterEach { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbName -Confirm:$false } It "Should transfer all tables" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -CopyAll Tables + $transfer = New-DbaDbTransfer -SqlInstance $env:instance1 -DestinationSqlInstance $env:instance2 -Database $dbName -CopyAll Tables $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 + $tables = Get-DbaDbTable -SqlInstance $env:instance2 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 $tables.Count | Should -Be 4 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test4").id | Should -Not -BeNullOrEmpty @@ -251,10 +251,10 @@ Describe "New-DbaDbTransfer" { } It "Should transfer two tables with just schemas" { - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -SchemaOnly + $sourceTables = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $env:instance1 -DestinationSqlInstance $env:instance2 -Database $dbName -SchemaOnly $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $env:instance2 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db2.Query("select id from dbo.transfer_test").id | Should -BeNullOrEmpty } @@ -262,10 +262,10 @@ Describe "New-DbaDbTransfer" { It "Should transfer two tables without copying schema" { $null = $db2.Query("CREATE TABLE dbo.transfer_test (id int)") $null = $db2.Query("CREATE TABLE dbo.transfer_test2 (id int)") - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -DataOnly + $sourceTables = Get-DbaDbTable -SqlInstance $env:instance1 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $env:instance1 -DestinationSqlInstance $env:instance2 -Database $dbName -DataOnly $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $env:instance2 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id diff --git a/tests/New-DbaDbUser.Tests.ps1 b/tests/New-DbaDbUser.Tests.ps1 index bde578e781..0027a61092 100644 --- a/tests/New-DbaDbUser.Tests.ps1 +++ b/tests/New-DbaDbUser.Tests.ps1 @@ -13,17 +13,17 @@ Describe "New-DbaDbUser" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $userName -Password $securePassword -Force - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $dbContainmentSpValue = (Get-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled).ConfiguredValue - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled -Value 1 - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER DATABASE [$dbname] SET CONTAINMENT = PARTIAL WITH NO_WAIT" + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $userName -Password $securePassword -Force + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname + $dbContainmentSpValue = (Get-DbaSpConfigure -SqlInstance $env:instance2 -Name ContainmentEnabled).ConfiguredValue + $null = Set-DbaSpConfigure -SqlInstance $env:instance2 -Name ContainmentEnabled -Value 1 + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Query "ALTER DATABASE [$dbname] SET CONTAINMENT = PARTIAL WITH NO_WAIT" } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $userName -Confirm:$false - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled -Value $dbContainmentSpValue + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $userName -Confirm:$false + $null = Set-DbaSpConfigure -SqlInstance $env:instance2 -Name ContainmentEnabled -Value $dbContainmentSpValue } Context "Validate parameters" { @@ -43,7 +43,7 @@ Describe "New-DbaDbUser" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type String[] -Not -Mandatory } It "Should have IncludeSystem as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSystem -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeSystem -Type Switch -Not -Mandatory } It "Should have User as a parameter" { $CommandUnderTest | Should -HaveParameter User -Type String -Not -Mandatory @@ -55,23 +55,23 @@ Describe "New-DbaDbUser" { $CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString -Not -Mandatory } It "Should have ExternalProvider as a parameter" { - $CommandUnderTest | Should -HaveParameter ExternalProvider -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExternalProvider -Type Switch -Not -Mandatory } It "Should have DefaultSchema as a parameter" { $CommandUnderTest | Should -HaveParameter DefaultSchema -Type String -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Test error handling" { It "Tries to create the user with an invalid default schema" { $warningMessage = $null - $results = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $userName -DefaultSchema invalidSchemaName -WarningVariable warningMessage + $results = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $userName -DefaultSchema invalidSchemaName -WarningVariable warningMessage $results | Should -BeNullOrEmpty $warningMessage | Should -BeLike "*Schema * does not exist in database*" } @@ -79,8 +79,8 @@ Describe "New-DbaDbUser" { Context "Should create the user with login" { It "Creates the user and get it" { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $userName -DefaultSchema guest - $newDbUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userName + New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $userName -DefaultSchema guest + $newDbUser = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname | Where-Object Name -eq $userName $newDbUser.Name | Should -Be $userName $newDbUser.DefaultSchema | Should -Be 'guest' } @@ -88,8 +88,8 @@ Describe "New-DbaDbUser" { Context "Should create the user with password" { It "Creates the contained sql user and get it." { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Username $userNameWithPassword -Password $securePassword -DefaultSchema guest - $newDbUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userNameWithPassword + New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Username $userNameWithPassword -Password $securePassword -DefaultSchema guest + $newDbUser = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname | Where-Object Name -eq $userNameWithPassword $newDbUser.Name | Should -Be $userNameWithPassword $newDbUser.DefaultSchema | Should -Be 'guest' } @@ -97,8 +97,8 @@ Describe "New-DbaDbUser" { Context "Should create the user without login" { It "Creates the user and get it. Login property is empty" { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -User $userNameWithoutLogin -DefaultSchema guest - $results = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userNameWithoutLogin + New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -User $userNameWithoutLogin -DefaultSchema guest + $results = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname | Where-Object Name -eq $userNameWithoutLogin $results.Name | Should -Be $userNameWithoutLogin $results.DefaultSchema | Should -Be 'guest' $results.Login | Should -BeNullOrEmpty @@ -112,25 +112,25 @@ Describe "New-DbaDbUser" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $loginName -Password $securePassword -Force - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbs - $accessibleDbCount = (Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem -OnlyAccessible).count + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $loginName -Password $securePassword -Force + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbs + $accessibleDbCount = (Get-DbaDatabase -SqlInstance $env:instance2 -ExcludeSystem -OnlyAccessible).count } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbs -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $loginName -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbs -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $loginName -Confirm:$false } It "Should add login to all databases provided" { - $results = New-DbaDbUser -SqlInstance $script:instance2 -Login $loginName -Database $dbs -Force -EnableException + $results = New-DbaDbUser -SqlInstance $env:instance2 -Login $loginName -Database $dbs -Force -EnableException $results.Count | Should -Be 3 $results.Name | Should -Be $loginName, $loginName, $loginName $results.DefaultSchema | Should -Be dbo, dbo, dbo } It "Should add user to all user databases" { - $results = New-DbaDbUser -SqlInstance $script:instance2 -Login $loginName -Force -EnableException + $results = New-DbaDbUser -SqlInstance $env:instance2 -Login $loginName -Force -EnableException $results.Count | Should -Be $accessibleDbCount $results.Name | Get-Unique | Should -Be $loginName } diff --git a/tests/New-DbaEndpoint.Tests.ps1 b/tests/New-DbaEndpoint.Tests.ps1 index 809bbfdd98..6fc7be6394 100644 --- a/tests/New-DbaEndpoint.Tests.ps1 +++ b/tests/New-DbaEndpoint.Tests.ps1 @@ -54,31 +54,31 @@ Describe "New-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Owner -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring + $endpoint = Get-DbaEndpoint -SqlInstance $env:instance2 | Where-Object EndpointType -eq DatabaseMirroring $create = $endpoint | Export-DbaScript -Passthru - Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $env:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false } AfterAll { - Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $env:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false if ($create) { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "$create" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query "$create" } } It "creates an endpoint of the db mirroring type" { - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false + $results = New-DbaEndpoint -SqlInstance $env:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false $results.EndpointType | Should -Be 'DatabaseMirroring' } It "creates it with the right owner" { - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false - $sa = Get-SaLoginName -SqlInstance $script:instance2 + $results = New-DbaEndpoint -SqlInstance $env:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false + $sa = Get-SaLoginName -SqlInstance $env:instance2 $results.Owner | Should -Be $sa } } diff --git a/tests/New-DbaFirewallRule.Tests.ps1 b/tests/New-DbaFirewallRule.Tests.ps1 index 035d35385d..c39c94126f 100644 --- a/tests/New-DbaFirewallRule.Tests.ps1 +++ b/tests/New-DbaFirewallRule.Tests.ps1 @@ -18,31 +18,31 @@ Describe "New-DbaFirewallRule" { $CommandUnderTest | Should -HaveParameter Configuration -Type Hashtable -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaFirewallRule -SqlInstance $env:instance2 -Confirm:$false } AfterAll { - $null = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaFirewallRule -SqlInstance $env:instance2 -Confirm:$false } It "creates two firewall rules" { - $resultsNew = New-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $resultsNew = New-DbaFirewallRule -SqlInstance $env:instance2 -Confirm:$false $resultsNew.Count | Should -Be 2 } It "creates first firewall rule for SQL Server instance" { - $resultsNew = New-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false - $instanceName = ([DbaInstanceParameter]$script:instance2).InstanceName + $resultsNew = New-DbaFirewallRule -SqlInstance $env:instance2 -Confirm:$false + $instanceName = ([DbaInstanceParameter]$env:instance2).InstanceName $resultsNew[0].Successful | Should -Be $true $resultsNew[0].Type | Should -Be 'Engine' $resultsNew[0].DisplayName | Should -Be "SQL Server instance $instanceName" @@ -50,7 +50,7 @@ Describe "New-DbaFirewallRule" { } It "creates second firewall rule for SQL Server Browser" { - $resultsNew = New-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $resultsNew = New-DbaFirewallRule -SqlInstance $env:instance2 -Confirm:$false $resultsNew[1].Successful | Should -Be $true $resultsNew[1].Type | Should -Be 'Browser' $resultsNew[1].DisplayName | Should -Be 'SQL Server Browser' @@ -58,25 +58,25 @@ Describe "New-DbaFirewallRule" { } It "returns two firewall rules" { - $resultsGet = Get-DbaFirewallRule -SqlInstance $script:instance2 + $resultsGet = Get-DbaFirewallRule -SqlInstance $env:instance2 $resultsGet.Count | Should -Be 2 } It "returns one firewall rule for SQL Server instance" { - $resultsGet = Get-DbaFirewallRule -SqlInstance $script:instance2 + $resultsGet = Get-DbaFirewallRule -SqlInstance $env:instance2 $resultInstance = $resultsGet | Where-Object Type -eq 'Engine' $resultInstance.Protocol | Should -Be "TCP" } It "returns one firewall rule for SQL Server Browser" { - $resultsGet = Get-DbaFirewallRule -SqlInstance $script:instance2 + $resultsGet = Get-DbaFirewallRule -SqlInstance $env:instance2 $resultBrowser = $resultsGet | Where-Object Type -eq 'Browser' $resultBrowser.Protocol | Should -Be 'UDP' $resultBrowser.LocalPort | Should -Be '1434' } It "removes firewall rule for Browser" { - $resultsGet = Get-DbaFirewallRule -SqlInstance $script:instance2 + $resultsGet = Get-DbaFirewallRule -SqlInstance $env:instance2 $resultsRemoveBrowser = $resultsGet | Where-Object { $_.Type -eq "Browser" } | Remove-DbaFirewallRule -Confirm:$false $resultsRemoveBrowser.Type | Should -Be 'Browser' $resultsRemoveBrowser.IsRemoved | Should -Be $true @@ -84,7 +84,7 @@ Describe "New-DbaFirewallRule" { } It "removes other firewall rule" { - $resultsRemove = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Type AllInstance -Confirm:$false + $resultsRemove = Remove-DbaFirewallRule -SqlInstance $env:instance2 -Type AllInstance -Confirm:$false $resultsRemove.Type | Should -Be 'Engine' $resultsRemove.IsRemoved | Should -Be $true $resultsRemove.Status | Should -Be 'The rule was successfully removed.' diff --git a/tests/New-DbaLinkedServer.Tests.ps1 b/tests/New-DbaLinkedServer.Tests.ps1 index 0fb2533589..37f666afe6 100644 --- a/tests/New-DbaLinkedServer.Tests.ps1 +++ b/tests/New-DbaLinkedServer.Tests.ps1 @@ -7,8 +7,8 @@ Describe "New-DbaLinkedServer" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 + $instance3 = Connect-DbaInstance -SqlInstance $env:instance3 $securePassword = ConvertTo-SecureString -String 'securePassword!' -AsPlainText -Force $loginName = "dbatoolscli_test_$random" @@ -70,7 +70,7 @@ Describe "New-DbaLinkedServer" { $CommandUnderTest | Should -HaveParameter InputObject -Type Server[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaLinkedServerLogin.Tests.ps1 b/tests/New-DbaLinkedServerLogin.Tests.ps1 index 64703a4504..784761e888 100644 --- a/tests/New-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/New-DbaLinkedServerLogin.Tests.ps1 @@ -24,13 +24,13 @@ Describe "New-DbaLinkedServerLogin" { $CommandUnderTest | Should -HaveParameter RemoteUserPassword -Type SecureString -Not -Mandatory } It "Should have Impersonate parameter" { - $CommandUnderTest | Should -HaveParameter Impersonate -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Impersonate -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type LinkedServer[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -38,8 +38,8 @@ Describe "New-DbaLinkedServerLogin" { Describe "New-DbaLinkedServerLogin Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 + $instance3 = Connect-DbaInstance -SqlInstance $env:instance3 $securePassword = ConvertTo-SecureString -String 'securePassword' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" diff --git a/tests/New-DbaLogin.Tests.ps1 b/tests/New-DbaLogin.Tests.ps1 index 8a5cbc33f4..05cb98dcd2 100644 --- a/tests/New-DbaLogin.Tests.ps1 +++ b/tests/New-DbaLogin.Tests.ps1 @@ -9,8 +9,8 @@ Describe "New-DbaLogin" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $sid = '0xDBA700131337C0D30123456789ABCDEF' - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $servers = @($server1, $server2) $computerName = $server1.NetName $credLogin = 'credologino' @@ -109,31 +109,31 @@ Describe "New-DbaLogin" { $Command | Should -HaveParameter Language -Type String -Not -Mandatory } It "Should have PasswordExpirationEnabled parameter" { - $Command | Should -HaveParameter PasswordExpirationEnabled -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter PasswordExpirationEnabled -Type Switch -Not -Mandatory } It "Should have PasswordPolicyEnforced parameter" { - $Command | Should -HaveParameter PasswordPolicyEnforced -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter PasswordPolicyEnforced -Type Switch -Not -Mandatory } It "Should have PasswordMustChange parameter" { - $Command | Should -HaveParameter PasswordMustChange -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter PasswordMustChange -Type Switch -Not -Mandatory } It "Should have Disabled parameter" { - $Command | Should -HaveParameter Disabled -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter Disabled -Type Switch -Not -Mandatory } It "Should have DenyWindowsLogin parameter" { - $Command | Should -HaveParameter DenyWindowsLogin -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter DenyWindowsLogin -Type Switch -Not -Mandatory } It "Should have NewSid parameter" { - $Command | Should -HaveParameter NewSid -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter NewSid -Type Switch -Not -Mandatory } It "Should have ExternalProvider parameter" { - $Command | Should -HaveParameter ExternalProvider -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter ExternalProvider -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $Command | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $Command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $Command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -232,8 +232,8 @@ Describe "New-DbaLogin" { } It "Should retain its same properties" { - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login tester - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login tester + $login1 = Get-DbaLogin -SqlInstance $env:instance1 -login tester + $login2 = Get-DbaLogin -SqlInstance $env:instance2 -login tester $login2 | Should -Not -BeNullOrEmpty @@ -250,8 +250,8 @@ Describe "New-DbaLogin" { } It "Should not have same properties because of the overrides" { - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login claudio - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login withMustChange + $login1 = Get-DbaLogin -SqlInstance $env:instance1 -login claudio + $login2 = Get-DbaLogin -SqlInstance $env:instance2 -login withMustChange $login2 | Should -Not -BeNullOrEmpty @@ -276,12 +276,12 @@ Describe "New-DbaLogin" { } } - Context "Connect with a new login" -Skip:((Connect-DbaInstance -SqlInstance $script:instance1).LoginMode -ne "Mixed") { + Context "Connect with a new login" -Skip:((Connect-DbaInstance -SqlInstance $env:instance1).LoginMode -ne "Mixed") { It "Should login with newly created Sql Login, get instance name and kill the process" { $cred = New-Object System.Management.Automation.PSCredential ("tester", $securePassword) - $s = Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $cred - $s.Name | Should -Be $script:instance1 - Stop-DbaProcess -SqlInstance $script:instance1 -Login tester + $s = Connect-DbaInstance -SqlInstance $env:instance1 -SqlCredential $cred + $s.Name | Should -Be $env:instance1 + Stop-DbaProcess -SqlInstance $env:instance1 -Login tester } } @@ -314,7 +314,7 @@ Describe "New-DbaLogin" { $server1.Credentials[$credLogin].Drop() $server1.Databases['master'].Certificates[$certificateName].Drop() if (!$mkey) { - $null = Remove-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Confirm:$false + $null = Remove-DbaDbMasterKey -SqlInstance $env:instance1 -Database master -Confirm:$false } } } diff --git a/tests/New-DbaReplPublication.Tests.ps1 b/tests/New-DbaReplPublication.Tests.ps1 index 3f44152e2f..0d709c4cc7 100644 --- a/tests/New-DbaReplPublication.Tests.ps1 +++ b/tests/New-DbaReplPublication.Tests.ps1 @@ -29,7 +29,7 @@ Describe "New-DbaReplPublication" { $CommandUnderTest | Should -HaveParameter LogReaderAgentCredential -Type PSCredential } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/New-DbaReplSubscription.Tests.ps1 b/tests/New-DbaReplSubscription.Tests.ps1 index e80e43ce51..0fed7671b7 100644 --- a/tests/New-DbaReplSubscription.Tests.ps1 +++ b/tests/New-DbaReplSubscription.Tests.ps1 @@ -38,13 +38,13 @@ Describe "New-DbaReplSubscription" { $CommandUnderTest | Should -HaveParameter Type -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -77,10 +77,10 @@ Describe "New-DbaReplSubscription" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } diff --git a/tests/New-DbaRgResourcePool.Tests.ps1 b/tests/New-DbaRgResourcePool.Tests.ps1 index 643d05a3ac..e9fe77f399 100644 --- a/tests/New-DbaRgResourcePool.Tests.ps1 +++ b/tests/New-DbaRgResourcePool.Tests.ps1 @@ -46,25 +46,25 @@ Describe "New-DbaRgResourcePool" { $CommandUnderTest | Should -HaveParameter MaximumProcesses -Type Int32 -Not -Mandatory } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Creates a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -72,9 +72,9 @@ Describe "New-DbaRgResourcePool" { CapCpuPercentage = 100 Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -84,7 +84,7 @@ Describe "New-DbaRgResourcePool" { It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -96,9 +96,9 @@ Describe "New-DbaRgResourcePool" { Type = "Internal" Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type Internal $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type Internal $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -114,7 +114,7 @@ Describe "New-DbaRgResourcePool" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -122,9 +122,9 @@ Describe "New-DbaRgResourcePool" { Type = "External" Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type External $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type External $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -136,7 +136,7 @@ Describe "New-DbaRgResourcePool" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -147,7 +147,7 @@ Describe "New-DbaRgResourcePool" { } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result.ReconfigurePending | Should -BeTrue } @@ -155,8 +155,8 @@ Describe "New-DbaRgResourcePool" { AfterEach { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External } } } diff --git a/tests/New-DbaRgWorkloadGroup.Tests.ps1 b/tests/New-DbaRgWorkloadGroup.Tests.ps1 index 8eb5ebcf5c..176b0cff98 100644 --- a/tests/New-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/New-DbaRgWorkloadGroup.Tests.ps1 @@ -45,31 +45,31 @@ Describe "New-DbaRgWorkloadGroup" { $CommandUnderTest | Should -HaveParameter GroupMaximumRequests -Type Int32 } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Creates a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName Force = $true } - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result2 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result2 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -BeNullOrEmpty $result2.Count | Should -BeGreaterThan $result.Count @@ -79,7 +79,7 @@ Describe "New-DbaRgWorkloadGroup" { It "Does nothing without -Force if workload group exists" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName } $result1 = New-DbaRgWorkloadGroup @splatNewWorkloadGroup @@ -94,13 +94,13 @@ Describe "New-DbaRgWorkloadGroup" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -115,8 +115,8 @@ Describe "New-DbaRgWorkloadGroup" { $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup.Parent.Name | Should -Be $resourcePoolName $newWorkloadGroup.Parent.GetType().Name | Should -Be "ResourcePool" @@ -132,12 +132,12 @@ Describe "New-DbaRgWorkloadGroup" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Force = $true } - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup -WorkloadGroup $wklGroupName, $wklGroupName2 - $result2 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result2 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups | Should -Not -BeNullOrEmpty $result2.Count | Should -Be 2 @@ -147,14 +147,14 @@ Describe "New-DbaRgWorkloadGroup" { It "Skips Resource Governor reconfiguration" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName SkipReconfigure = $true Force = $true } $null = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result.ReconfigurePending | Should -BeTrue } @@ -162,7 +162,7 @@ Describe "New-DbaRgWorkloadGroup" { AfterEach { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $null = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 } } } diff --git a/tests/New-DbaServerRole.Tests.ps1 b/tests/New-DbaServerRole.Tests.ps1 index d975c3bdfb..21d8991e7e 100644 --- a/tests/New-DbaServerRole.Tests.ps1 +++ b/tests/New-DbaServerRole.Tests.ps1 @@ -22,13 +22,13 @@ Describe "New-DbaServerRole" { $CommandUnderTest | Should -HaveParameter Owner -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $env:instance2 $roleExecutor = "serverExecuter" $roleMaster = "serverMaster" $owner = "sa" diff --git a/tests/New-DbaServiceMasterKey.Tests.ps1 b/tests/New-DbaServiceMasterKey.Tests.ps1 index 39357f803a..37deb94fc5 100644 --- a/tests/New-DbaServiceMasterKey.Tests.ps1 +++ b/tests/New-DbaServiceMasterKey.Tests.ps1 @@ -18,11 +18,11 @@ Describe "New-DbaServiceMasterKey" { $CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have common parameters" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch + $CommandUnderTest | Should -HaveParameter Debug -Type Switch $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference $CommandUnderTest | Should -HaveParameter WarningAction -Type ActionPreference $CommandUnderTest | Should -HaveParameter InformationAction -Type ActionPreference @@ -33,8 +33,8 @@ Describe "New-DbaServiceMasterKey" { $CommandUnderTest | Should -HaveParameter OutVariable -Type String $CommandUnderTest | Should -HaveParameter OutBuffer -Type Int32 $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } diff --git a/tests/New-DbaSqlParameter.Tests.ps1 b/tests/New-DbaSqlParameter.Tests.ps1 index 83b7e59d52..e374b3cdc4 100644 --- a/tests/New-DbaSqlParameter.Tests.ps1 +++ b/tests/New-DbaSqlParameter.Tests.ps1 @@ -14,11 +14,11 @@ Describe "New-DbaSqlParameter" { It "Should have Direction as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Direction -Type String -Not -Mandatory } - It "Should have ForceColumnEncryption as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter ForceColumnEncryption -Type SwitchParameter -Not -Mandatory + It "Should have ForceColumnEncryption as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter ForceColumnEncryption -Type Switch -Not -Mandatory } - It "Should have IsNullable as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter IsNullable -Type SwitchParameter -Not -Mandatory + It "Should have IsNullable as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter IsNullable -Type Switch -Not -Mandatory } It "Should have LocaleId as a non-mandatory Int32 parameter" { $CommandUnderTest | Should -HaveParameter LocaleId -Type Int32 -Not -Mandatory @@ -41,8 +41,8 @@ Describe "New-DbaSqlParameter" { It "Should have SourceColumn as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter SourceColumn -Type String -Not -Mandatory } - It "Should have SourceColumnNullMapping as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter SourceColumnNullMapping -Type SwitchParameter -Not -Mandatory + It "Should have SourceColumnNullMapping as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter SourceColumnNullMapping -Type Switch -Not -Mandatory } It "Should have SourceVersion as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter SourceVersion -Type String -Not -Mandatory @@ -62,8 +62,8 @@ Describe "New-DbaSqlParameter" { It "Should have Value as a non-mandatory Object parameter" { $CommandUnderTest | Should -HaveParameter Value -Type Object -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -74,7 +74,7 @@ Describe "New-DbaSqlParameter Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] @json_result nvarchar(max) output AS BEGIN @@ -87,7 +87,7 @@ Describe "New-DbaSqlParameter Integration Tests" -Tag "IntegrationTests" { AfterAll { try { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "DROP PROCEDURE dbo.my_proc" + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -Query "DROP PROCEDURE dbo.my_proc" } catch { $null = 1 } @@ -95,7 +95,7 @@ Describe "New-DbaSqlParameter Integration Tests" -Tag "IntegrationTests" { It "creates a usable sql parameter" { $output = New-DbaSqlParameter -ParameterName json_result -SqlDbType NVarChar -Size -1 -Direction Output - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output + Invoke-DbaQuery -SqlInstance $env:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output $output.Value | Should -Be '{"example":"sample"}' } } diff --git a/tests/New-DbaSsisCatalog.Tests.ps1 b/tests/New-DbaSsisCatalog.Tests.ps1 index b28206953c..b1b5de00a5 100644 --- a/tests/New-DbaSsisCatalog.Tests.ps1 +++ b/tests/New-DbaSsisCatalog.Tests.ps1 @@ -21,7 +21,7 @@ Describe "New-DbaSsisCatalog" { $CommandUnderTest | Should -HaveParameter SsisCatalog -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaXESmartCsvWriter.Tests.ps1 b/tests/New-DbaXESmartCsvWriter.Tests.ps1 index 2dd14a3b0a..04ad9d2ead 100644 --- a/tests/New-DbaXESmartCsvWriter.Tests.ps1 +++ b/tests/New-DbaXESmartCsvWriter.Tests.ps1 @@ -14,7 +14,7 @@ Describe "New-DbaXESmartCsvWriter" { It "Should have OutputFile as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter OutputFile -Type String -Not -Mandatory } - It "Should have Overwrite as a non-mandatory SwitchParameter" { + It "Should have Overwrite as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter Overwrite -Type Switch -Not -Mandatory } It "Should have Event as a non-mandatory String[] parameter" { @@ -26,7 +26,7 @@ Describe "New-DbaXESmartCsvWriter" { It "Should have Filter as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Filter -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/New-DbaXESmartEmail.Tests.ps1 b/tests/New-DbaXESmartEmail.Tests.ps1 index 9cde564e42..5903a536dc 100644 --- a/tests/New-DbaXESmartEmail.Tests.ps1 +++ b/tests/New-DbaXESmartEmail.Tests.ps1 @@ -51,7 +51,7 @@ Describe "New-DbaXESmartEmail" { $CommandUnderTest | Should -HaveParameter Filter -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/New-DbaXESmartQueryExec.Tests.ps1 b/tests/New-DbaXESmartQueryExec.Tests.ps1 index 62fee6050e..b2dba111df 100644 --- a/tests/New-DbaXESmartQueryExec.Tests.ps1 +++ b/tests/New-DbaXESmartQueryExec.Tests.ps1 @@ -24,7 +24,7 @@ Describe "New-DbaXESmartQueryExec" { $CommandUnderTest | Should -HaveParameter Query -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Event as a parameter" { $CommandUnderTest | Should -HaveParameter Event -Type String[] @@ -36,11 +36,11 @@ Describe "New-DbaXESmartQueryExec" { Context "Creates a smart object" { BeforeAll { - $results = New-DbaXESmartQueryExec -SqlInstance $script:instance2 -Database dbadb -Query "update table set whatever = 1" + $results = New-DbaXESmartQueryExec -SqlInstance $env:instance2 -Database dbadb -Query "update table set whatever = 1" } It "returns the object with all of the correct properties" { $results.TSQL | Should -Be 'update table set whatever = 1' - $results.ServerName | Should -Be $script:instance2 + $results.ServerName | Should -Be $env:instance2 $results.DatabaseName | Should -Be 'dbadb' $results.Password | Should -BeNullOrEmpty } diff --git a/tests/New-DbaXESmartReplay.Tests.ps1 b/tests/New-DbaXESmartReplay.Tests.ps1 index dbc2d2d2f5..12b224d9cc 100644 --- a/tests/New-DbaXESmartReplay.Tests.ps1 +++ b/tests/New-DbaXESmartReplay.Tests.ps1 @@ -30,27 +30,27 @@ Describe "New-DbaXESmartReplay" { $CommandUnderTest | Should -HaveParameter DelaySeconds -Type Int32 -Not -Mandatory } It "Should have StopOnError parameter" { - $CommandUnderTest | Should -HaveParameter StopOnError -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter StopOnError -Type Switch -Not -Mandatory } It "Should have ReplayIntervalSeconds parameter" { $CommandUnderTest | Should -HaveParameter ReplayIntervalSeconds -Type Int32 -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "New-DbaXESmartReplay Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance2 = [Environment]::GetEnvironmentVariable("instance2") + $env:instance2 = [Environment]::GetEnvironmentVariable("instance2") } Context "Creates a smart object" { It "returns the object with all of the correct properties" { $columns = "cpu_time", "duration", "physical_reads", "logical_reads", "writes", "row_count", "batch_text" - $results = New-DbaXESmartTableWriter -SqlInstance $script:instance2 -Database dbadb -Table deadlocktracker -OutputColumn $columns -Filter "duration > 10000" - $results.ServerName | Should -Be $script:instance2 + $results = New-DbaXESmartTableWriter -SqlInstance $env:instance2 -Database dbadb -Table deadlocktracker -OutputColumn $columns -Filter "duration > 10000" + $results.ServerName | Should -Be $env:instance2 $results.DatabaseName | Should -Be 'dbadb' $results.Password | Should -BeNullOrEmpty $results.TableName | Should -Be 'deadlocktracker' diff --git a/tests/New-DbaXESmartTableWriter.Tests.ps1 b/tests/New-DbaXESmartTableWriter.Tests.ps1 index a56d409a65..19cc52ef92 100644 --- a/tests/New-DbaXESmartTableWriter.Tests.ps1 +++ b/tests/New-DbaXESmartTableWriter.Tests.ps1 @@ -45,10 +45,10 @@ Describe "New-DbaXESmartTableWriter" { Context "Creates a smart object" { BeforeAll { - $results = New-DbaXESmartReplay -SqlInstance $script:instance2 -Database planning + $results = New-DbaXESmartReplay -SqlInstance $env:instance2 -Database planning } It "returns the object with all of the correct properties" { - $results.ServerName | Should -Be $script:instance2 + $results.ServerName | Should -Be $env:instance2 $results.DatabaseName | Should -Be 'planning' $results.Password | Should -BeNullOrEmpty $results.DelaySeconds | Should -Be 0 diff --git a/tests/New-DbatoolsSupportPackage.Tests.ps1 b/tests/New-DbatoolsSupportPackage.Tests.ps1 index 9fffd83f0e..b6186f6cf9 100644 --- a/tests/New-DbatoolsSupportPackage.Tests.ps1 +++ b/tests/New-DbatoolsSupportPackage.Tests.ps1 @@ -16,17 +16,17 @@ Describe "New-DbatoolsSupportPackage" { It "Should have Variables as a non-mandatory String[] parameter" { $CommandUnderTest | Should -HaveParameter Variables -Type String[] -Not -Mandatory } - It "Should have PassThru as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter PassThru -Type SwitchParameter -Not -Mandatory + It "Should have PassThru as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter PassThru -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } - It "Should have Verbose as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + It "Should have Verbose as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } - It "Should have Debug as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + It "Should have Debug as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a non-mandatory ActionPreference parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -58,11 +58,11 @@ Describe "New-DbatoolsSupportPackage" { It "Should have PipelineVariable as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } - It "Should have WhatIf as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + It "Should have WhatIf as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } - It "Should have Confirm as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + It "Should have Confirm as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } diff --git a/tests/Publish-DbaDacPackage.Tests.ps1 b/tests/Publish-DbaDacPackage.Tests.ps1 index d44a18bf11..c86b70a6b2 100644 --- a/tests/Publish-DbaDacPackage.Tests.ps1 +++ b/tests/Publish-DbaDacPackage.Tests.ps1 @@ -24,10 +24,10 @@ Describe "Publish-DbaDacPackage" { $CommandUnderTest | Should -HaveParameter ConnectionString -Type String[] } It "Should have GenerateDeploymentReport parameter" { - $CommandUnderTest | Should -HaveParameter GenerateDeploymentReport -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter GenerateDeploymentReport -Type Switch } It "Should have ScriptOnly parameter" { - $CommandUnderTest | Should -HaveParameter ScriptOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ScriptOnly -Type Switch } It "Should have Type parameter" { $CommandUnderTest | Should -HaveParameter Type -Type String @@ -36,13 +36,13 @@ Describe "Publish-DbaDacPackage" { $CommandUnderTest | Should -HaveParameter OutputPath -Type String } It "Should have IncludeSqlCmdVars parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSqlCmdVars -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IncludeSqlCmdVars -Type Switch } It "Should have DacOption parameter" { $CommandUnderTest | Should -HaveParameter DacOption -Type Object } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have DacFxPath parameter" { $CommandUnderTest | Should -HaveParameter DacFxPath -Type String @@ -56,30 +56,30 @@ Describe "Publish-DbaDacPackage" { BeforeAll { $dbname = "dbatoolsci_publishdacpac" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $null = $server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbname $null = $db.Query("CREATE TABLE dbo.example (id int, PRIMARY KEY (id)); INSERT dbo.example SELECT top 100 object_id FROM sys.objects") - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $publishprofile = New-DbaDacProfile -SqlInstance $env:instance1 -Database $dbname -Path C:\temp } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1, $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1, $env:instance2 -Database $dbname -Confirm:$false Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false } Context "Dacpac tests" { BeforeAll { $extractOptions = New-DbaDacOption -Action Export $extractOptions.ExtractAllTableData = $true - $dacpac = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -DacOption $extractOptions + $dacpac = Export-DbaDacPackage -SqlInstance $env:instance1 -Database $dbname -DacOption $extractOptions } AfterAll { @@ -87,48 +87,48 @@ Describe "Publish-DbaDacPackage" { } It "Performs an xml-based deployment" { - $results = $dacpac | Publish-DbaDacPackage -PublishXml $publishprofile.FileName -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -PublishXml $publishprofile.FileName -Database $dbname -SqlInstance $env:instance2 -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $env:instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs an SMO-based deployment" { $options = New-DbaDacOption -Action Publish - $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $env:instance2 -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $env:instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs an SMO-based deployment and generates a deployment report" { $options = New-DbaDacOption -Action Publish - $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -GenerateDeploymentReport -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $env:instance2 -GenerateDeploymentReport -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' $results.DeploymentReport | Should -Not -BeNullOrEmpty $deploymentReportContent = Get-Content -Path $results.DeploymentReport $deploymentReportContent | Should -BeLike '*DeploymentReport*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $env:instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs a script generation without deployment" { - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -ScriptOnly -PublishXml $publishprofile.FileName -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $env:instance2 -ScriptOnly -PublishXml $publishprofile.FileName -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Not -BeNullOrEmpty Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } It "Performs a script generation without deployment and using an input options object" { $opts = New-DbaDacOption -Action Publish $opts.GenerateDeploymentScript = $true - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -DacOption $opts -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $env:instance2 -DacOption $opts -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Not -BeNullOrEmpty Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } @@ -137,11 +137,11 @@ Describe "Publish-DbaDacPackage" { GenerateDeploymentScript = $true DatabaseScriptPath = 'C:\Temp\testdb.sql' } - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -DacOption $opts -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $env:instance2 -DacOption $opts -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Be 'C:\Temp\testdb.sql' Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } } @@ -149,7 +149,7 @@ Describe "Publish-DbaDacPackage" { Context "Bacpac tests" { BeforeAll { $extractOptions = New-DbaDacOption -Action Export -Type Bacpac - $bacpac = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -DacOption $extractOptions -Type Bacpac + $bacpac = Export-DbaDacPackage -SqlInstance $env:instance1 -Database $dbname -DacOption $extractOptions -Type Bacpac } AfterAll { @@ -158,22 +158,22 @@ Describe "Publish-DbaDacPackage" { It "Performs an SMO-based deployment" { $options = New-DbaDacOption -Action Publish -Type Bacpac - $results = $bacpac | Publish-DbaDacPackage -Type Bacpac -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $bacpac | Publish-DbaDacPackage -Type Bacpac -DacOption $options -Database $dbname -SqlInstance $env:instance2 -Confirm:$false $results.Result | Should -BeLike '*Updating database (Complete)*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $env:instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Auto detects that a .bacpac is being used and sets the Type to Bacpac" { $options = New-DbaDacOption -Action Publish -Type Bacpac - $results = $bacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $bacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $env:instance2 -Confirm:$false $results.Result | Should -BeLike '*Updating database (Complete)*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $env:instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Should throw when ScriptOnly is used" { - { $bacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -ScriptOnly -Type Bacpac -EnableException -Confirm:$false } | Should -Throw + { $bacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $env:instance2 -ScriptOnly -Type Bacpac -EnableException -Confirm:$false } | Should -Throw } } } diff --git a/tests/Read-DbaAuditFile.Tests.ps1 b/tests/Read-DbaAuditFile.Tests.ps1 index a032ac43dc..667fc74933 100644 --- a/tests/Read-DbaAuditFile.Tests.ps1 +++ b/tests/Read-DbaAuditFile.Tests.ps1 @@ -9,10 +9,10 @@ Describe "Read-DbaAuditFile" { $CommandUnderTest | Should -HaveParameter Path -Type Object[] -Not -Mandatory } It "Should have Raw as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Raw -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Raw -Type Switch -Not -Mandatory } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -22,7 +22,7 @@ Describe "Read-DbaAuditFile" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $path = $server.ErrorLogPath $sql = @" CREATE SERVER AUDIT LoginAudit @@ -36,8 +36,8 @@ ALTER SERVER AUDIT LoginAudit WITH (STATE = ON) "@ $server.Query($sql) # generate a login - $null = Get-DbaDatabase -SqlInstance $script:instance2 - $null = Get-DbaDbFile -SqlInstance $script:instance2 + $null = Get-DbaDatabase -SqlInstance $env:instance2 + $null = Get-DbaDbFile -SqlInstance $env:instance2 # Give it a chance to write Start-Sleep 2 } @@ -53,12 +53,12 @@ DROP SERVER AUDIT LoginAudit } It "returns some results when using -Raw parameter" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit | Read-DbaAuditFile -Raw -WarningAction SilentlyContinue + $results = Get-DbaInstanceAudit -SqlInstance $env:instance2 -Audit LoginAudit | Read-DbaAuditFile -Raw -WarningAction SilentlyContinue $results.Count | Should -BeGreaterThan 1 } It "returns results with server_principal_name" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit | Read-DbaAuditFile | Select-Object -First 1 + $results = Get-DbaInstanceAudit -SqlInstance $env:instance2 -Audit LoginAudit | Read-DbaAuditFile | Select-Object -First 1 $results.server_principal_name | Should -Not -BeNullOrEmpty } } diff --git a/tests/Read-DbaBackupHeader.Tests.ps1 b/tests/Read-DbaBackupHeader.Tests.ps1 index 840b8e0daf..2f2386ad22 100644 --- a/tests/Read-DbaBackupHeader.Tests.ps1 +++ b/tests/Read-DbaBackupHeader.Tests.ps1 @@ -15,16 +15,16 @@ Describe "Read-DbaBackupHeader" { $CommandUnderTest | Should -HaveParameter Path -Type Object[] } It "Should have Simple parameter" { - $CommandUnderTest | Should -HaveParameter Simple -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Simple -Type Switch } It "Should have FileList parameter" { - $CommandUnderTest | Should -HaveParameter FileList -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter FileList -Type Switch } It "Should have AzureCredential parameter" { $CommandUnderTest | Should -HaveParameter AzureCredential -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -46,7 +46,7 @@ Describe "Read-DbaBackupHeader" { # Add more specific assertions based on expected output } - It "Should read backup header from SQL Server" -ForEach @($script:instance1, $script:instance2) { + It "Should read backup header from SQL Server" -ForEach @($env:instance1, $env:instance2) { $result = Read-DbaBackupHeader -SqlInstance $_ -Path $backupFile $result | Should -Not -BeNullOrEmpty # Add more specific assertions based on expected output diff --git a/tests/Read-DbaTraceFile.Tests.ps1 b/tests/Read-DbaTraceFile.Tests.ps1 index f756e8e70f..840326dba7 100644 --- a/tests/Read-DbaTraceFile.Tests.ps1 +++ b/tests/Read-DbaTraceFile.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Read-DbaTraceFile" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $configs = $script:instance1, $script:instance2 | Get-DbaSpConfigure -Name DefaultTraceEnabled + $configs = $env:instance1, $env:instance2 | Get-DbaSpConfigure -Name DefaultTraceEnabled $configs | Set-DbaSpConfigure -Value $true -WarningAction SilentlyContinue } @@ -65,13 +65,13 @@ Describe "Read-DbaTraceFile" { $CommandUnderTest | Should -HaveParameter Where -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Verifying command output" { It "returns results" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile + $results = Get-DbaTrace -SqlInstance $env:instance2 -Id 1 | Read-DbaTraceFile $results.DatabaseName.Count | Should -BeGreaterThan 0 } @@ -86,7 +86,7 @@ Describe "Read-DbaTraceFile" { # Collect the results into a variable so that the bulk import is super fast $warn = $null - Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -Where $where -WarningAction SilentlyContinue -WarningVariable warn > $null + Get-DbaTrace -SqlInstance $env:instance2 -Id 1 | Read-DbaTraceFile -Where $where -WarningAction SilentlyContinue -WarningVariable warn > $null $warn | Should -BeNullOrEmpty } } @@ -94,17 +94,17 @@ Describe "Read-DbaTraceFile" { Context "Verify Parameter Use" { It "Should execute using parameters Database, Login, Spid" { $warn = $null - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -Database Master -Login sa -Spid 7 -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $env:instance2 -Id 1 | Read-DbaTraceFile -Database Master -Login sa -Spid 7 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -BeNullOrEmpty } It "Should execute using parameters EventClass, ObjectType, ErrorId" { $warn = $null - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -EventClass 4 -ObjectType 4 -ErrorId 4 -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $env:instance2 -Id 1 | Read-DbaTraceFile -EventClass 4 -ObjectType 4 -ErrorId 4 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -BeNullOrEmpty } It "Should execute using parameters EventSequence, TextData, ApplicationName, ObjectName" { $warn = $null - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -EventSequence 4 -TextData "Text" -ApplicationName "Application" -ObjectName "Name" -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $env:instance2 -Id 1 | Read-DbaTraceFile -EventSequence 4 -TextData "Text" -ApplicationName "Application" -ObjectName "Name" -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -BeNullOrEmpty } } diff --git a/tests/Read-DbaTransactionLog.Tests.ps1 b/tests/Read-DbaTransactionLog.Tests.ps1 index 804aeae413..2a4913a308 100644 --- a/tests/Read-DbaTransactionLog.Tests.ps1 +++ b/tests/Read-DbaTransactionLog.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Read-DbaTransactionLog" { $CommandUnderTest | Should -HaveParameter Database -Type Object } It "Should have IgnoreLimit parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreLimit -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IgnoreLimit -Type Switch } It "Should have RowLimit parameter" { $CommandUnderTest | Should -HaveParameter RowLimit -Type Int32 } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Read-DbaXEFile.Tests.ps1 b/tests/Read-DbaXEFile.Tests.ps1 index 678c2017a3..009a39e9d8 100644 --- a/tests/Read-DbaXEFile.Tests.ps1 +++ b/tests/Read-DbaXEFile.Tests.ps1 @@ -25,16 +25,16 @@ Describe "Read-DbaXEFile" { Context "Verifying command output" { BeforeDiscovery { - $script:skipIntegrationTests = [Environment]::GetEnvironmentVariable('DBA_TOOLS_SKIP_INTEGRATION_TESTS') -eq $true + $env:skipIntegrationTests = [Environment]::GetEnvironmentVariable('DBA_TOOLS_SKIP_INTEGRATION_TESTS') -eq $true } It "returns some results using Raw parameter" -Skip:$skipIntegrationTests { - $results = Get-DbaXESession -SqlInstance $script:instance2 | Read-DbaXEFile -Raw -WarningAction SilentlyContinue + $results = Get-DbaXESession -SqlInstance $env:instance2 | Read-DbaXEFile -Raw -WarningAction SilentlyContinue [System.Linq.Enumerable]::Count($results) | Should -BeGreaterThan 1 } It "returns some results without Raw parameter" -Skip:$skipIntegrationTests { - $results = Get-DbaXESession -SqlInstance $script:instance2 | Read-DbaXEFile -WarningAction SilentlyContinue + $results = Get-DbaXESession -SqlInstance $env:instance2 | Read-DbaXEFile -WarningAction SilentlyContinue $results.Count | Should -BeGreaterThan 1 } } diff --git a/tests/Register-DbatoolsConfig.Tests.ps1 b/tests/Register-DbatoolsConfig.Tests.ps1 index 46d3552b06..12204bc15c 100644 --- a/tests/Register-DbatoolsConfig.Tests.ps1 +++ b/tests/Register-DbatoolsConfig.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Register-DbatoolsConfig" { $CommandUnderTest | Should -HaveParameter Scope -Type ConfigScope } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Remove-DbaAgDatabase.Tests.ps1 b/tests/Remove-DbaAgDatabase.Tests.ps1 index 2412cfdc96..e1dc42aca5 100644 --- a/tests/Remove-DbaAgDatabase.Tests.ps1 +++ b/tests/Remove-DbaAgDatabase.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Remove-DbaAgDatabase" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -29,14 +29,14 @@ Describe "Remove-DbaAgDatabase" { Describe "Remove-DbaAgDatabase Integration Tests" -Tag "IntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $env:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance3 $agname = "dbatoolsci_removeagdb_agroup" $dbname = "dbatoolsci_removeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -44,16 +44,16 @@ Describe "Remove-DbaAgDatabase Integration Tests" -Tag "IntegrationTests" { } Context "removes ag db" { It "returns removed results" { - $results = Remove-DbaAgDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Remove-DbaAgDatabase -SqlInstance $env:instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Database | Should -Be $dbname $results.Status | Should -Be 'Removed' } It "really removed the db from the ag" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.AvailabilityDatabases.Name | Should -Not -Contain $dbname } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Remove-DbaAgListener.Tests.ps1 b/tests/Remove-DbaAgListener.Tests.ps1 index de80cfbbd0..df326681a6 100644 --- a/tests/Remove-DbaAgListener.Tests.ps1 +++ b/tests/Remove-DbaAgListener.Tests.ps1 @@ -20,7 +20,7 @@ Describe "Remove-DbaAgListener" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroupListener[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,17 +31,17 @@ Describe "Remove-DbaAgListener" { BeforeAll { $agname = "dbatoolsci_ag_removelistener" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert $aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } It "removes a listener" { - $results = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $aglistener.Name -Confirm:$false + $results = Remove-DbaAgListener -SqlInstance $env:instance3 -Listener $aglistener.Name -Confirm:$false $results.Status | Should -Be 'Removed' } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Remove-DbaAgReplica.Tests.ps1 b/tests/Remove-DbaAgReplica.Tests.ps1 index 55537d4100..2db474b7c2 100644 --- a/tests/Remove-DbaAgReplica.Tests.ps1 +++ b/tests/Remove-DbaAgReplica.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Remove-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityReplica[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -60,10 +60,10 @@ Describe "Remove-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } diff --git a/tests/Remove-DbaAgentAlert.Tests.ps1 b/tests/Remove-DbaAgentAlert.Tests.ps1 index ad03b5b665..5aa7895713 100644 --- a/tests/Remove-DbaAgentAlert.Tests.ps1 +++ b/tests/Remove-DbaAgentAlert.Tests.ps1 @@ -25,18 +25,18 @@ Describe "Remove-DbaAgentAlert Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Alert[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Remove-DbaAgentAlert Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance2 = "localhost" + $env:instance2 = "localhost" } BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $alertName = "dbatoolsci_test_$(Get-Random)" $alertName2 = "dbatoolsci_test_$(Get-Random)" diff --git a/tests/Remove-DbaAgentAlertCategory.Tests.ps1 b/tests/Remove-DbaAgentAlertCategory.Tests.ps1 index 69c4521dd7..aabaa32ace 100644 --- a/tests/Remove-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/Remove-DbaAgentAlertCategory.Tests.ps1 @@ -28,30 +28,30 @@ Describe "Remove-DbaAgentAlertCategory" { } It "Should remove newly created Agent Alert Categories" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $results = New-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $results.Count | Should -Be 3 $results[0].Name | Should -Be "CategoryTest1" $results[1].Name | Should -Be "CategoryTest2" $results[2].Name | Should -Be "CategoryTest3" - $newResults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newResults = Get-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newResults.Count | Should -Be 3 - Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 -Confirm:$false + Remove-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 -Confirm:$false - $finalResults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $finalResults = Get-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $finalResults.Count | Should -Be 0 } It "Should support piping SQL Agent alert category" { $categoryName = "dbatoolsci_test_$(Get-Random)" - $null = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName - $category = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName + $null = New-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category $categoryName + $category = Get-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category $categoryName $category | Should -Not -BeNullOrEmpty $category | Remove-DbaAgentAlertCategory -Confirm:$false - $removedCategory = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName + $removedCategory = Get-DbaAgentAlertCategory -SqlInstance $env:instance2 -Category $categoryName $removedCategory | Should -BeNullOrEmpty } } diff --git a/tests/Remove-DbaAgentJob.Tests.ps1 b/tests/Remove-DbaAgentJob.Tests.ps1 index 6d9772e0cb..e08754f409 100644 --- a/tests/Remove-DbaAgentJob.Tests.ps1 +++ b/tests/Remove-DbaAgentJob.Tests.ps1 @@ -36,58 +36,58 @@ Describe "Remove-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { Context "Command removes jobs" { BeforeAll { - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily -FrequencyType Daily -FrequencyInterval Everyday -Force - $null = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob -Schedule dbatoolsci_daily - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' - $null = Start-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob + $null = New-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_daily -FrequencyType Daily -FrequencyInterval Everyday -Force + $null = New-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob -Schedule dbatoolsci_daily + $null = New-DbaAgentJobStep -SqlInstance $env:instance3 -Job dbatoolsci_testjob -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = Start-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob } AfterAll { - if (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily) { - Remove-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily -Confirm:$false + if (Get-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_daily) { + Remove-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_daily -Confirm:$false } } It "Should have deleted job: dbatoolsci_testjob" { - Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob -Confirm:$false - Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob | Should -BeNullOrEmpty + Remove-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob -Confirm:$false + Get-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob | Should -BeNullOrEmpty } It "Should have deleted schedule: dbatoolsci_daily" { - Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily | Should -BeNullOrEmpty + Get-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_daily | Should -BeNullOrEmpty } It "Should have deleted history: dbatoolsci_daily" { - Get-DbaAgentJobHistory -SqlInstance $script:instance3 -Job dbatoolsci_testjob | Should -BeNullOrEmpty + Get-DbaAgentJobHistory -SqlInstance $env:instance3 -Job dbatoolsci_testjob | Should -BeNullOrEmpty } } Context "Command removes job but not schedule" { BeforeAll { - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly -FrequencyType Weekly -FrequencyInterval Everyday -Force - $null = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -Schedule dbatoolsci_weekly - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = New-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_weekly -FrequencyType Weekly -FrequencyInterval Everyday -Force + $null = New-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_schedule -Schedule dbatoolsci_weekly + $null = New-DbaAgentJobStep -SqlInstance $env:instance3 -Job dbatoolsci_testjob_schedule -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' } AfterAll { - if (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly) { - Remove-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly -Confirm:$false + if (Get-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_weekly) { + Remove-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_weekly -Confirm:$false } } It "Should have deleted job: dbatoolsci_testjob_schedule" { - Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -KeepUnusedSchedule -Confirm:$false - Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule | Should -BeNullOrEmpty + Remove-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_schedule -KeepUnusedSchedule -Confirm:$false + Get-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_schedule | Should -BeNullOrEmpty } It "Should not have deleted schedule: dbatoolsci_weekly" { - Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly | Should -Not -BeNullOrEmpty + Get-DbaAgentSchedule -SqlInstance $env:instance3 -Schedule dbatoolsci_weekly | Should -Not -BeNullOrEmpty } } Context "Command removes job but not history and supports piping" { BeforeAll { - $jobId = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history | Select-Object -ExpandProperty JobId - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' - $null = Start-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $jobId = New-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_history | Select-Object -ExpandProperty JobId + $null = New-DbaAgentJobStep -SqlInstance $env:instance3 -Job dbatoolsci_testjob_history -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = Start-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_history + $server = Connect-DbaInstance -SqlInstance $env:instance3 } It "Should have deleted job: dbatoolsci_testjob_history" { - Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history | Remove-DbaAgentJob -KeepHistory -Confirm:$false - Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history | Should -BeNullOrEmpty + Get-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_history | Remove-DbaAgentJob -KeepHistory -Confirm:$false + Get-DbaAgentJob -SqlInstance $env:instance3 -Job dbatoolsci_testjob_history | Should -BeNullOrEmpty } It "Should not have deleted history: dbatoolsci_testjob_history" -Skip { $server.Query("select 1 from sysjobhistory where job_id = '$jobId'", "msdb") | Should -Not -BeNullOrEmpty @@ -96,4 +96,4 @@ Describe "Remove-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { $server.Query("delete from sysjobhistory where job_id = '$jobId'", "msdb") } } -} # $script:instance2 for appveyor +} # $env:instance2 for appveyor diff --git a/tests/Remove-DbaAgentJobCategory.Tests.ps1 b/tests/Remove-DbaAgentJobCategory.Tests.ps1 index 6343bdb87c..796c1d0a69 100644 --- a/tests/Remove-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Remove-DbaAgentJobCategory.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Remove-DbaAgentJobCategory Integration Tests" -Tag "IntegrationTests" Context "New Agent Job Category is changed properly" { BeforeAll { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $results = New-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 } It "Should have the right name and category type" { @@ -46,21 +46,21 @@ Describe "Remove-DbaAgentJobCategory Integration Tests" -Tag "IntegrationTests" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should -Be 3 } It "Remove the job categories" { - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false + Remove-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should -Be 0 } AfterAll { # Cleanup any remaining test categories - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 -Confirm:$false -ErrorAction SilentlyContinue } } } diff --git a/tests/Remove-DbaAgentJobStep.Tests.ps1 b/tests/Remove-DbaAgentJobStep.Tests.ps1 index 672d24d927..b1a5681126 100644 --- a/tests/Remove-DbaAgentJobStep.Tests.ps1 +++ b/tests/Remove-DbaAgentJobStep.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Remove-DbaAgentJobStep" { $CommandUnderTest | Should -HaveParameter StepName -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -57,10 +57,10 @@ Describe "Remove-DbaAgentJobStep" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } diff --git a/tests/Remove-DbaAgentOperator.Tests.ps1 b/tests/Remove-DbaAgentOperator.Tests.ps1 index e63a457bdf..f429a83f38 100644 --- a/tests/Remove-DbaAgentOperator.Tests.ps1 +++ b/tests/Remove-DbaAgentOperator.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Remove-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter InputObject -Type Operator[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -60,10 +60,10 @@ Describe "Remove-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } @@ -71,7 +71,7 @@ Describe "Remove-DbaAgentOperator" { Describe "Remove-DbaAgentOperator Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $email1 = "test1$($random)@test.com" $email2 = "test2$($random)@test.com" } diff --git a/tests/Remove-DbaAgentProxy.Tests.ps1 b/tests/Remove-DbaAgentProxy.Tests.ps1 index ba610bf1d8..062d0f5117 100644 --- a/tests/Remove-DbaAgentProxy.Tests.ps1 +++ b/tests/Remove-DbaAgentProxy.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Remove-DbaAgentProxy" { $CommandUnderTest | Should -HaveParameter InputObject -Type ProxyAccount[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $null = Invoke-DbaQuery -SqlInstance $server -Query "CREATE CREDENTIAL proxyCred WITH IDENTITY = 'NT AUTHORITY\SYSTEM', SECRET = 'G31o)lkJ8HNd!';" } @@ -36,7 +36,7 @@ Describe "Remove-DbaAgentProxy" { } BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $proxyName = "dbatoolsci_test_$(Get-Random)" $proxyName2 = "dbatoolsci_test_$(Get-Random)" diff --git a/tests/Remove-DbaAgentSchedule.Tests.ps1 b/tests/Remove-DbaAgentSchedule.Tests.ps1 index 62bfa763cc..825f30a03a 100644 --- a/tests/Remove-DbaAgentSchedule.Tests.ps1 +++ b/tests/Remove-DbaAgentSchedule.Tests.ps1 @@ -30,10 +30,10 @@ Describe "Remove-DbaAgentSchedule Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type ScheduleBase[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } } } @@ -45,7 +45,7 @@ Describe "Remove-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { foreach ($FrequencySubdayType in ('Time', 'Seconds', 'Minutes', 'Hours')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$FrequencySubdayType" FrequencyRecurrenceFactor = '1' FrequencySubdayInterval = '1' @@ -61,19 +61,19 @@ Describe "Remove-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" { Context "Should remove schedules" { It "Should find all created schedules" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty } It "Should remove dbatoolsci_Minutes schedule" { - Remove-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_Minutes -Confirm:$false - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_Minutes + Remove-DbaAgentSchedule -SqlInstance $env:instance2 -Schedule dbatoolsci_Minutes -Confirm:$false + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 -Schedule dbatoolsci_Minutes $results | Should -BeNullOrEmpty } It "Should remove all remaining created schedules" { - Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -BeNullOrEmpty } } diff --git a/tests/Remove-DbaAvailabilityGroup.Tests.ps1 b/tests/Remove-DbaAvailabilityGroup.Tests.ps1 index ec5bfa35a4..00bef18619 100644 --- a/tests/Remove-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Remove-DbaAvailabilityGroup.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Remove-DbaAvailabilityGroup" { $CommandUnderTest | Should -HaveParameter AvailabilityGroup -Type String[] } It "Should have AllAvailabilityGroups as a switch parameter" { - $CommandUnderTest | Should -HaveParameter AllAvailabilityGroups -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllAvailabilityGroups -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,18 +32,18 @@ Describe "Remove-DbaAvailabilityGroup" { BeforeAll { $agname = "dbatoolsci_removewholegroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false + $null = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false } It "removes the newly created ag" { - $results = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $results = Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false $results.Status | Should -Be 'Removed' $results.AvailabilityGroup | Should -Be $agname } It "really removed the ag" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname $results | Should -BeNullOrEmpty } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Remove-DbaClientAlias.Tests.ps1 b/tests/Remove-DbaClientAlias.Tests.ps1 index c953306ffd..d447f9128e 100644 --- a/tests/Remove-DbaClientAlias.Tests.ps1 +++ b/tests/Remove-DbaClientAlias.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Remove-DbaClientAlias" { $CommandUnderTest | Should -HaveParameter Alias -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Remove-DbaComputerCertificate.Tests.ps1 b/tests/Remove-DbaComputerCertificate.Tests.ps1 index 09f2338ef8..b58f44f9c7 100644 --- a/tests/Remove-DbaComputerCertificate.Tests.ps1 +++ b/tests/Remove-DbaComputerCertificate.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Remove-DbaComputerCertificate" { $CommandUnderTest | Should -HaveParameter Folder -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Can remove a certificate" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path $env:appveyorlabrepo\certificates\localhost.crt -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" } diff --git a/tests/Remove-DbaCredential.Tests.ps1 b/tests/Remove-DbaCredential.Tests.ps1 index 36c42e0ec2..d24e6c9f95 100644 --- a/tests/Remove-DbaCredential.Tests.ps1 +++ b/tests/Remove-DbaCredential.Tests.ps1 @@ -27,14 +27,14 @@ Describe "Remove-DbaCredential" { $CommandUnderTest | Should -HaveParameter InputObject -Type Credential[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $credentialName = "dbatoolsci_test_$(Get-Random)" $credentialName2 = "dbatoolsci_test_$(Get-Random)" diff --git a/tests/Remove-DbaCustomError.Tests.ps1 b/tests/Remove-DbaCustomError.Tests.ps1 index 17202cf65f..1e3fefa3d2 100644 --- a/tests/Remove-DbaCustomError.Tests.ps1 +++ b/tests/Remove-DbaCustomError.Tests.ps1 @@ -5,8 +5,8 @@ Describe "Remove-DbaCustomError" { $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $results = New-DbaCustomError -SqlInstance $server -MessageID 70000 -Severity 1 -MessageText "test_70000" $results = New-DbaCustomError -SqlInstance $server, $server2 -MessageID 70001 -Severity 1 -MessageText "test_70001" @@ -54,7 +54,7 @@ Describe "Remove-DbaCustomError" { $CommandUnderTest | Should -HaveParameter Language -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -93,10 +93,10 @@ Describe "Remove-DbaCustomError" { } It "Multiple servers via -SqlInstance" { - $results = Remove-DbaCustomError -SqlInstance $script:instance1, $script:instance2 -MessageID 70002 + $results = Remove-DbaCustomError -SqlInstance $env:instance1, $env:instance2 -MessageID 70002 # even the SMO server.Refresh() doesn't pick up the changes to the user defined messages - $server1Reconnected = Connect-DbaInstance -SqlInstance $script:instance1 - $server2Reconnected = Connect-DbaInstance -SqlInstance $script:instance2 + $server1Reconnected = Connect-DbaInstance -SqlInstance $env:instance1 + $server2Reconnected = Connect-DbaInstance -SqlInstance $env:instance2 ($server1Reconnected.UserDefinedMessages | Where-Object ID -eq 70002).Count | Should -Be 0 ($server2Reconnected.UserDefinedMessages | Where-Object ID -eq 70002).Count | Should -Be 0 } diff --git a/tests/Remove-DbaDatabase.Tests.ps1 b/tests/Remove-DbaDatabase.Tests.ps1 index a947b08fb8..c1b9cde5a1 100644 --- a/tests/Remove-DbaDatabase.Tests.ps1 +++ b/tests/Remove-DbaDatabase.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Remove-DbaDatabase" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -33,18 +33,18 @@ Describe "Remove-DbaDatabase" { It "Should not attempt to remove system databases" { foreach ($db in $dbs) { - $db1 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db + $db1 = Get-DbaDatabase -SqlInstance $env:instance1 -Database $db + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database $db + $db2 = Get-DbaDatabase -SqlInstance $env:instance1 -Database $db $db2.Name | Should -Be $db1.Name } } It "Should not take system databases offline or change their status" { foreach ($db in $dbs) { - $db1 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db + $db1 = Get-DbaDatabase -SqlInstance $env:instance1 -Database $db + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database $db + $db2 = Get-DbaDatabase -SqlInstance $env:instance1 -Database $db $db2.Status | Should -Be $db1.Status $db2.IsAccessible | Should -Be $db1.IsAccessible } @@ -54,28 +54,28 @@ Describe "Remove-DbaDatabase" { Context "Should remove user databases and return useful errors if it cannot" { It "Should remove a non system database" { BeforeAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaProcess -SqlInstance $script:instance1 -Database singlerestore | Stop-DbaProcess - Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database singlerestore + Get-DbaProcess -SqlInstance $env:instance1 -Database singlerestore | Stop-DbaProcess + Restore-DbaDatabase -SqlInstance $env:instance1 -Path $env:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace } - (Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore).IsAccessible | Should -Be $true - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore | Should -BeNullOrEmpty + (Get-DbaDatabase -SqlInstance $env:instance1 -Database singlerestore).IsAccessible | Should -Be $true + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database singlerestore + Get-DbaDatabase -SqlInstance $env:instance1 -Database singlerestore | Should -BeNullOrEmpty } } Context "Should remove restoring database and return useful errors if it cannot" { It "Should remove a non system database" { BeforeAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaProcess -SqlInstance $script:instance1 -Database singlerestore | Stop-DbaProcess - Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace -NoRecovery + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database singlerestore + Get-DbaProcess -SqlInstance $env:instance1 -Database singlerestore | Stop-DbaProcess + Restore-DbaDatabase -SqlInstance $env:instance1 -Path $env:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace -NoRecovery } - (Connect-DbaInstance -SqlInstance $script:instance1).Databases['singlerestore'].IsAccessible | Should -Be $false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore | Should -BeNullOrEmpty + (Connect-DbaInstance -SqlInstance $env:instance1).Databases['singlerestore'].IsAccessible | Should -Be $false + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database singlerestore + Get-DbaDatabase -SqlInstance $env:instance1 -Database singlerestore | Should -BeNullOrEmpty } } } diff --git a/tests/Remove-DbaDatabaseSafely.Tests.ps1 b/tests/Remove-DbaDatabaseSafely.Tests.ps1 index a222c495bd..9389a5f8be 100644 --- a/tests/Remove-DbaDatabaseSafely.Tests.ps1 +++ b/tests/Remove-DbaDatabaseSafely.Tests.ps1 @@ -59,36 +59,36 @@ Describe "Remove-DbaDatabaseSafely" { BeforeAll { $db1 = "dbatoolsci_safely" $db2 = "dbatoolsci_safely_otherInstance" - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server3 = Connect-DbaInstance -SqlInstance $env:instance3 $server3.Query("CREATE DATABASE $db1") - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $server2.Query("CREATE DATABASE $db1") $server2.Query("CREATE DATABASE $db2") - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 } AfterAll { - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $db1 - $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $script:instance2 -Job 'Rationalised Database Restore Script for dbatoolsci_safely' - $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $script:instance3 -Job 'Rationalised Database Restore Script for dbatoolsci_safely_otherInstance' + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1, $db2 + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance3 -Database $db1 + $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $env:instance2 -Job 'Rationalised Database Restore Script for dbatoolsci_safely' + $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $env:instance3 -Job 'Rationalised Database Restore Script for dbatoolsci_safely_otherInstance' } It "Should have database name of $db1" { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance2 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb + $results = Remove-DbaDatabaseSafely -SqlInstance $env:instance2 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb foreach ($result in $results) { $result.DatabaseName | Should -Be $db1 } } It "Should warn and quit on Express Edition" -Skip:($server1.EngineEdition -notmatch "Express") { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance1 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb -WarningAction SilentlyContinue -WarningVariable warn + $results = Remove-DbaDatabaseSafely -SqlInstance $env:instance1 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb -WarningAction SilentlyContinue -WarningVariable warn $results | Should -BeNullOrEmpty $warn | Should -Match 'Express Edition' } It "Should restore to another server" { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance2 -Database $db2 -BackupFolder c:\temp -NoDbccCheckDb -Destination $script:instance3 + $results = Remove-DbaDatabaseSafely -SqlInstance $env:instance2 -Database $db2 -BackupFolder c:\temp -NoDbccCheckDb -Destination $env:instance3 foreach ($result in $results) { $result.SqlInstance | Should -Be $server2.SqlInstance $result.TestingInstance | Should -Be $server3.SqlInstance diff --git a/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 b/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 index 8c3e3db639..3938d7b60d 100644 --- a/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 @@ -21,33 +21,33 @@ Describe "Remove-DbaDbAsymmetricKey" { $CommandUnderTest | Should -HaveParameter InputObject -Type AsymmetricKey[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Remove a certificate" { BeforeAll { $database = 'RemAsy' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $database + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $database $keyname = 'test1' $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + New-DbaDbMasterKey -SqlInstance $env:instance2 -Database $database -SecurePassword $tPassword -Confirm:$false + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Should create new key in $database called $keyname" { - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $results.Database | Should -Be $database $results.Name | Should -Be $keyname $results.KeyLength | Should -Be '2048' } It "Should Remove a certificate" { - $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false - $getResults = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false + $getResults = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database $getResults | Should -HaveCount 0 $removeResults.Status | Should -Be 'Success' } @@ -58,22 +58,22 @@ Describe "Remove-DbaDbAsymmetricKey" { $database = 'RemAsy' $keyname = 'test1' $keyname2 = 'test2' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $database - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database - $key2 = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname2 -Database $database + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $database + $key = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database + $key2 = New-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname2 -Database $database } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Should create new keys in $database" { - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database + $results = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database $results | Should -HaveCount 2 } It "Should Remove a specific certificate" { - $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -Confirm:$false - $getResults = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database + $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname -Database $database -Confirm:$false + $getResults = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database $getResults | Should -HaveCount 1 $getResults[0].Name | Should -Be $keyname2 $removeResults.Status | Should -Be 'Success' @@ -81,8 +81,8 @@ Describe "Remove-DbaDbAsymmetricKey" { } It "Should remove the remaining certificate" { - $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname2 -Database $database -Confirm:$false - $getResults = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database + $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Name $keyname2 -Database $database -Confirm:$false + $getResults = Get-DbaDbAsymmetricKey -SqlInstance $env:instance2 -Database $database $getResults | Should -HaveCount 0 $removeResults.Status | Should -Be 'Success' $removeResults.Name | Should -Be $keyname2 diff --git a/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 b/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 index da9d7375f7..db33d7c7e0 100644 --- a/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 +++ b/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Remove-DbaDbBackupRestoreHistory" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -33,7 +33,7 @@ Describe "Remove-DbaDbBackupRestoreHistory" { BeforeAll { # Setup code for all tests in this context - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $randomDb = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $randomDb } diff --git a/tests/Remove-DbaDbCertificate.Tests.ps1 b/tests/Remove-DbaDbCertificate.Tests.ps1 index 235160c2f0..6855b78546 100644 --- a/tests/Remove-DbaDbCertificate.Tests.ps1 +++ b/tests/Remove-DbaDbCertificate.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Remove-DbaDbCertificate Unit Tests" -Tag 'UnitTests' { } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -45,7 +45,7 @@ Describe "Remove-DbaDbCertificate Integration Tests" -Tag "IntegrationTests" { Context "Can remove a database certificate" -Skip:$SkipTests { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 if (-not (Get-DbaDbMasterKey -SqlInstance $server -Database master)) { $masterkey = New-DbaDbMasterKey -SqlInstance $server -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } @@ -53,8 +53,8 @@ Describe "Remove-DbaDbCertificate Integration Tests" -Tag "IntegrationTests" { } AfterAll { - if ($masterKey) { - $masterkey | Remove-DbaDbMasterKey -Confirm:$false + if ($masterKey) { + $masterkey | Remove-DbaDbMasterKey -Confirm:$false } } diff --git a/tests/Remove-DbaDbCheckConstraint.Tests.ps1 b/tests/Remove-DbaDbCheckConstraint.Tests.ps1 index 2467df5469..845fc93d64 100644 --- a/tests/Remove-DbaDbCheckConstraint.Tests.ps1 +++ b/tests/Remove-DbaDbCheckConstraint.Tests.ps1 @@ -18,20 +18,20 @@ Describe "Remove-DbaDbCheckConstraint" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have ExcludeSystemTable as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeSystemTable -Type Switch -Not -Mandatory } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Check[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . (Join-Path $PSScriptRoot 'constants.ps1') - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 diff --git a/tests/Remove-DbaDbData.Tests.ps1 b/tests/Remove-DbaDbData.Tests.ps1 index 88b7cac239..994738efec 100644 --- a/tests/Remove-DbaDbData.Tests.ps1 +++ b/tests/Remove-DbaDbData.Tests.ps1 @@ -24,16 +24,16 @@ Describe "Remove-DbaDbData" { $CommandUnderTest | Should -HaveParameter Path -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname1 = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname1 -Owner sa - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname1 -Owner sa + Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query " create table dept ( deptid int identity(1,1) primary key, deptname varchar(10) @@ -52,92 +52,92 @@ Describe "Remove-DbaDbData" { " } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname1 -Confirm:$false } Context "Functionality" { BeforeEach { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Remove-DbaDbData -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' + Remove-DbaDbData -SqlInstance $env:instance2 -Database $dbname1 -Confirm:$false + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' $result.rwCnt | Should -Be 0 } It 'Foreign Keys are recreated' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.Name | Should -Be 'FK_dept' } It 'Foreign Keys are trusted' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.IsChecked | Should -Be $true } It 'Views are recreated' { - $views = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView + $views = Get-DbaDbView -SqlInstance $env:instance2 -Database $dbname1 -ExcludeSystemView $views.Name | Should -Be 'vw_emp' } } Context "Functionality - Pipe database" { BeforeEach { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 | Remove-DbaDbData -Confirm:$false - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' + Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname1 | Remove-DbaDbData -Confirm:$false + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' $result.rwCnt | Should -Be 0 } It 'Foreign Keys are recreated' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.Name | Should -Be 'FK_dept' } It 'Foreign Keys are trusted' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.IsChecked | Should -Be $true } It 'Views are recreated' { - $views = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView + $views = Get-DbaDbView -SqlInstance $env:instance2 -Database $dbname1 -ExcludeSystemView $views.Name | Should -Be 'vw_emp' } } Context "Functionality - Pipe server" { BeforeEach { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Connect-DbaInstance -SqlInstance $script:instance2 | Remove-DbaDbData -Database $dbname1 -Confirm:$false - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' + Connect-DbaInstance -SqlInstance $env:instance2 | Remove-DbaDbData -Database $dbname1 -Confirm:$false + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept' $result.rwCnt | Should -Be 0 } It 'Foreign Keys are recreated' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.Name | Should -Be 'FK_dept' } It 'Foreign Keys are trusted' { - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $env:instance2 -Database $dbname1 $fkeys.IsChecked | Should -Be $true } It 'Views are recreated' { - $views = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView + $views = Get-DbaDbView -SqlInstance $env:instance2 -Database $dbname1 -ExcludeSystemView $views.Name | Should -Be 'vw_emp' } } diff --git a/tests/Remove-DbaDbEncryptionKey.Tests.ps1 b/tests/Remove-DbaDbEncryptionKey.Tests.ps1 index 504c73e820..0985de7476 100644 --- a/tests/Remove-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/Remove-DbaDbEncryptionKey.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Remove-DbaDbEncryptionKey" { $CommandUnderTest | Should -HaveParameter InputObject -Type DatabaseEncryptionKey[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -26,18 +26,18 @@ Describe "Remove-DbaDbEncryptionKey" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $env:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $env:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $env:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $env:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $env:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $dbkey = $db | New-DbaDbEncryptionKey -Force @@ -64,7 +64,7 @@ Describe "Remove-DbaDbEncryptionKey" { It "should remove encryption key on a database" { $null = $db | New-DbaDbEncryptionKey -Force - $results = Remove-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name + $results = Remove-DbaDbEncryptionKey -SqlInstance $env:instance2 -Database $db.Name $results.Status | Should -Be "Success" $db.Refresh() $db | Get-DbaDbEncryptionKey | Should -BeNullOrEmpty diff --git a/tests/Remove-DbaDbFileGroup.Tests.ps1 b/tests/Remove-DbaDbFileGroup.Tests.ps1 index 26eeddc07e..73b774aca5 100644 --- a/tests/Remove-DbaDbFileGroup.Tests.ps1 +++ b/tests/Remove-DbaDbFileGroup.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Remove-DbaDbFileGroup Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -39,10 +39,10 @@ Describe "Remove-DbaDbFileGroup Integration Tests" -Tag "IntegrationTests" { $fileGroup5Name = "FG5" $fileGroup6Name = "FG6" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name - $newDb2 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db2name - $newDb3 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db3name + $server = Connect-DbaInstance -SqlInstance $env:instance2 + $newDb1 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db1name + $newDb2 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db2name + $newDb3 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db3name $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup1Name;") $server.Query("ALTER DATABASE $db2name ADD FILEGROUP $fileGroup1Name;") @@ -61,40 +61,40 @@ Describe "Remove-DbaDbFileGroup Integration Tests" -Tag "IntegrationTests" { Context "Command works" { It "Removes filegroups" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name $results.Length | Should -Be 3 - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name + Remove-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name -Confirm:$false + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name $results | Should -BeNullOrEmpty } It "Tries to remove a non-existent filegroup" { - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup invalidFileGroupName -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $script:instance2" + Remove-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup invalidFileGroupName -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $env:instance2" } It "Tries to remove a filegroup that still has files" { - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup2Name -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup $fileGroup2Name is not empty. Before the filegroup can be dropped the files must be removed in $fileGroup2Name on $db1name on $script:instance2" + Remove-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup2Name -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup $fileGroup2Name is not empty. Before the filegroup can be dropped the files must be removed in $fileGroup2Name on $db1name on $env:instance2" } It "Removes a filegroup using a database from a pipeline and a filegroup from a pipeline" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup $fileGroup1Name + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db2name -FileGroup $fileGroup1Name $results.Length | Should -Be 1 $newDb2 | Remove-DbaDbFileGroup -FileGroup $fileGroup1Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup $fileGroup1Name + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db2name -FileGroup $fileGroup1Name $results | Should -BeNullOrEmpty - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name $results.Length | Should -Be 2 $results[0], $newDb1 | Remove-DbaDbFileGroup -FileGroup $fileGroup5Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name $results | Should -BeNullOrEmpty - $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup6Name + $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup6Name $fileGroup6 | Should -Not -BeNullOrEmpty $fileGroup6 | Remove-DbaDbFileGroup -Confirm:$false - $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup6Name + $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup6Name $fileGroup6 | Should -BeNullOrEmpty } } diff --git a/tests/Remove-DbaDbLogShipping.Tests.ps1 b/tests/Remove-DbaDbLogShipping.Tests.ps1 index 78d869e4af..538ef6b4ba 100644 --- a/tests/Remove-DbaDbLogShipping.Tests.ps1 +++ b/tests/Remove-DbaDbLogShipping.Tests.ps1 @@ -23,11 +23,11 @@ Describe "Remove-DbaDbLogShipping Unit Tests" -Tag "UnitTests" { It "Should have Database as a non-mandatory Object[]" { $CommandUnderTest | Should -HaveParameter Database -Type Object[] -Not -Mandatory } - It "Should have RemoveSecondaryDatabase as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter RemoveSecondaryDatabase -Type SwitchParameter -Not -Mandatory + It "Should have RemoveSecondaryDatabase as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter RemoveSecondaryDatabase -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -43,13 +43,13 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { $localPath = 'C:\temp\logshipping' $networkPath = '\\localhost\c$\temp\logshipping' - $primaryServer = Connect-DbaInstance -SqlInstance $script:instance2 - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $primaryServer = Connect-DbaInstance -SqlInstance $env:instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $env:instance2 # Create the database if ($primaryServer.Databases.Name -notcontains $dbname) { $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $env:instance2 -Database master -Query $query } if (-not (Test-Path -Path $localPath)) { @@ -60,8 +60,8 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { Context "Remove database from log shipping without removing secondary database" { BeforeAll { $params = @{ - SourceSqlInstance = $script:instance2 - DestinationSqlInstance = $script:instance2 + SourceSqlInstance = $env:instance2 + DestinationSqlInstance = $env:instance2 Database = $dbname BackupNetworkPath = $networkPath BackupLocalPath = $localPath @@ -84,21 +84,21 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $dbname } It "Should remove log shipping without removing secondary database" { $params = @{ - PrimarySqlInstance = $script:instance2 - SecondarySqlInstance = $script:instance2 + PrimarySqlInstance = $env:instance2 + SecondarySqlInstance = $env:instance2 Database = $dbname } Remove-DbaDbLogShipping @params $primaryServer.Databases.Refresh() - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $env:instance2 "$($dbname)_LS" | Should -BeIn $secondaryserver.Databases.Name @@ -110,7 +110,7 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database master -Query $query $results.PrimaryDatabase | Should -BeNullOrEmpty } } @@ -118,8 +118,8 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { Context "Remove database from log shipping with removing secondary database" { BeforeAll { $params = @{ - SourceSqlInstance = $script:instance2 - DestinationSqlInstance = $script:instance2 + SourceSqlInstance = $env:instance2 + DestinationSqlInstance = $env:instance2 Database = $dbname BackupNetworkPath = $networkPath BackupLocalPath = $localPath @@ -141,14 +141,14 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $dbname } It "Should remove log shipping and secondary database" { $params = @{ - PrimarySqlInstance = $script:instance2 - SecondarySqlInstance = $script:instance2 + PrimarySqlInstance = $env:instance2 + SecondarySqlInstance = $env:instance2 Database = $dbname RemoveSecondaryDatabase = $true } @@ -156,7 +156,7 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { Remove-DbaDbLogShipping @params $primaryServer.Databases.Refresh() - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $env:instance2 "$($dbname)_LS" | Should -Not -BeIn $secondaryserver.Databases.Name @@ -168,7 +168,7 @@ Describe "Remove-DbaDbLogShipping Integration Tests" -Tag "IntegrationTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $env:instance2 -Database master -Query $query $results.PrimaryDatabase | Should -BeNullOrEmpty } } diff --git a/tests/Remove-DbaDbMailAccount.Tests.ps1 b/tests/Remove-DbaDbMailAccount.Tests.ps1 index 94dcaa1731..11897f75bd 100644 --- a/tests/Remove-DbaDbMailAccount.Tests.ps1 +++ b/tests/Remove-DbaDbMailAccount.Tests.ps1 @@ -27,13 +27,13 @@ Describe "Remove-DbaDbMailAccount" { $CommandUnderTest | Should -HaveParameter InputObject -Type MailAccount[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $accountname = "dbatoolsci_test_$(Get-Random)" $accountname2 = "dbatoolsci_test_$(Get-Random)" diff --git a/tests/Remove-DbaDbMailProfile.Tests.ps1 b/tests/Remove-DbaDbMailProfile.Tests.ps1 index 4f410c0b2a..333e808bbc 100644 --- a/tests/Remove-DbaDbMailProfile.Tests.ps1 +++ b/tests/Remove-DbaDbMailProfile.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Remove-DbaDbMailProfile" { $CommandUnderTest | Should -HaveParameter InputObject -Type MailProfile[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $profilename = "dbatoolsci_test_$(Get-Random)" $profilename2 = "dbatoolsci_test_$(Get-Random)" diff --git a/tests/Remove-DbaDbMasterKey.Tests.ps1 b/tests/Remove-DbaDbMasterKey.Tests.ps1 index dbd44f6c4d..7807fbc37f 100644 --- a/tests/Remove-DbaDbMasterKey.Tests.ps1 +++ b/tests/Remove-DbaDbMasterKey.Tests.ps1 @@ -29,7 +29,7 @@ Describe "Remove-DbaDbMasterKey Unit Tests" -Tag 'UnitTests' { } It "Should have All parameter" { - $command | Should -HaveParameter All -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter All -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { @@ -37,12 +37,12 @@ Describe "Remove-DbaDbMasterKey Unit Tests" -Tag 'UnitTests' { } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have common parameters" { - $command | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Verbose -Type Switch -Not -Mandatory + $command | Should -HaveParameter Debug -Type Switch -Not -Mandatory $command | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory $command | Should -HaveParameter WarningAction -Type ActionPreference -Not -Mandatory $command | Should -HaveParameter InformationAction -Type ActionPreference -Not -Mandatory @@ -53,8 +53,8 @@ Describe "Remove-DbaDbMasterKey Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter OutVariable -Type String -Not -Mandatory $command | Should -HaveParameter OutBuffer -Type Int32 -Not -Mandatory $command | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory - $command | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory + $command | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } } diff --git a/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 b/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 index 512e5f76ba..fcdf56d140 100644 --- a/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Remove-DbaDbMirrorMonitor" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -22,23 +22,23 @@ Describe "Remove-DbaDbMirrorMonitor" { } BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database msdb + $db = Get-DbaDatabase -SqlInstance $env:instance2 -Database msdb if (($db.Tables['dbm_monitor_data'].Name)) { - $script:putback = $true + $env:putback = $true } else { - $null = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Add-DbaDbMirrorMonitor -SqlInstance $env:instance2 -WarningAction SilentlyContinue } } AfterAll { - if ($script:putback) { + if ($env:putback) { # add it back - $results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Add-DbaDbMirrorMonitor -SqlInstance $env:instance2 -WarningAction SilentlyContinue } } It "removes the mirror monitor" { - $results = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Remove-DbaDbMirrorMonitor -SqlInstance $env:instance2 -WarningAction SilentlyContinue $results.MonitorStatus | Should -Be 'Removed' } } diff --git a/tests/Remove-DbaDbOrphanUser.Tests.ps1 b/tests/Remove-DbaDbOrphanUser.Tests.ps1 index 87e3a723f9..9f529a9790 100644 --- a/tests/Remove-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Remove-DbaDbOrphanUser.Tests.ps1 @@ -31,7 +31,7 @@ Describe "Remove-DbaDbOrphanUser Unit Tests" -Tag 'UnitTests' { Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $random = Get-Random $dbname = "dbatoolsci_$random" $login1 = "dbatoolssci_user1_$random" @@ -44,44 +44,44 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { $loginWindows = "db$random" - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $loginWindows, $plaintext -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $loginWindows, $plaintext -ComputerName $env:instance2 } BeforeEach { - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login "$($script:instance2)\$loginWindows" -Force - - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $login1 -Username $login1 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $login2 -Username $login2 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login "$($script:instance2)\$loginWindows" -Username "$($script:instance2)\$loginWindows" - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $login1 -Username $login1 -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $login2 -Username $login2 -IncludeSystem - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login "$($script:instance2)\$loginWindows" -Confirm:$false + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login1 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login2 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $env:instance2 -Login "$($env:instance2)\$loginWindows" -Force + + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $login1 -Username $login1 + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $login2 -Username $login2 + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login "$($env:instance2)\$loginWindows" -Username "$($env:instance2)\$loginWindows" + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database msdb -Login $login1 -Username $login1 -IncludeSystem + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database msdb -Login $login2 -Username $login2 -IncludeSystem + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $login1 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $login2 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login "$($env:instance2)\$loginWindows" -Confirm:$false } AfterEach { - $users = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $users = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb if ($users.Name -contains $login1) { - $null = Remove-DbaDbUser $script:instance2 -Database $dbname, msdb -User $login1 + $null = Remove-DbaDbUser $env:instance2 -Database $dbname, msdb -User $login1 } if ($users.Name -contains $login2) { - $null = Remove-DbaDbUser $script:instance2 -Database $dbname, msdb -User $login2 + $null = Remove-DbaDbUser $env:instance2 -Database $dbname, msdb -User $login2 } } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $loginWindows -ComputerName $script:instance2 + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $loginWindows -ComputerName $env:instance2 } It "Removes Orphan Users" { - $results0 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $results0 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results0.Name | Should -Contain $login1 $results0.Name | Should -Contain $login2 @@ -89,10 +89,10 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { } It "Removes selected Orphan Users" { - $results0 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $results0 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login1 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -User $login1 + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results0.Count | Should -BeGreaterThan $results1.Count $results1.Name | Should -Not -Contain $login1 @@ -100,8 +100,8 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { } It "Removes Orphan Users for Database" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database msdb -User $login1, $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -Database msdb -User $login1, $login2 + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results1 = $results1 | Where-Object { $_.Name -eq $login1 -or $_.Name -eq $login2 } $results1.Name | Should -Contain $login1 @@ -111,8 +111,8 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { } It "Removes Orphan Users except for excluded databases" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -ExcludeDatabase msdb -User $login1, $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -ExcludeDatabase msdb -User $login1, $login2 + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results1 = $results1 | Where-Object { $_.Name -eq $login1 -or $_.Name -eq $login2 } $results1.Name | Should -Contain $login1 @@ -122,26 +122,26 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { } It "Removes Orphan Users with unmapped logins if force specified" { - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login1 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login2 -Password $securePassword -Force - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login1 -Force - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -User $login1 -Force + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -User $login2 + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results1.Name | Should -Not -Contain $login1 $results1.Name | Should -Contain $login2 - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $login1 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $login2 -Confirm:$false } It "Removes Orphan Logins that own Schemas without objects" { $sql = "CREATE SCHEMA $schema AUTHORIZATION $login2" $server.Query($sql, $dbname) - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname, msdb -User $login1, $login2 -Force - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -Database $dbname, msdb -User $login1, $login2 -Force + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname, msdb $results1.Name | Should -Not -Contain $login1 $results1.Name | Should -Not -Contain $login2 @@ -160,9 +160,9 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { $sql = "CREATE TABLE [$login2].test2(Id int NULL)" $server.Query($sql, $dbname) - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User $login1 - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User $login2 -Force - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -Database $dbname -User $login1 + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -Database $dbname -User $login2 -Force + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname $results1.Name | Should -Contain $login1 $results1.Name | Should -Not -Contain $login2 @@ -172,8 +172,8 @@ Describe "Remove-DbaDbOrphanUser Integration Tests" -Tag "IntegrationTests" { } It "Removes the orphaned windows login" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User "$($script:instance2)\$loginWindows" - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname + $null = Remove-DbaDbOrphanUser -SqlInstance $env:instance2 -Database $dbname -User "$($env:instance2)\$loginWindows" + $results1 = Get-DbaDbUser -SqlInstance $env:instance2 -Database $dbname $results1.Name | Should -Not -Contain $loginWindows } } diff --git a/tests/Remove-DbaDbPartitionFunction.Tests.ps1 b/tests/Remove-DbaDbPartitionFunction.Tests.ps1 index 2dcf482376..afa9e7fa39 100644 --- a/tests/Remove-DbaDbPartitionFunction.Tests.ps1 +++ b/tests/Remove-DbaDbPartitionFunction.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Remove-DbaDbPartitionFunction" { $CommandUnderTest | Should -HaveParameter InputObject -Type PartitionFunction[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 diff --git a/tests/Remove-DbaDbPartitionScheme.Tests.ps1 b/tests/Remove-DbaDbPartitionScheme.Tests.ps1 index 51d8469391..37bb18dff8 100644 --- a/tests/Remove-DbaDbPartitionScheme.Tests.ps1 +++ b/tests/Remove-DbaDbPartitionScheme.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Remove-DbaDbPartitionScheme" { $CommandUnderTest | Should -HaveParameter InputObject -Type PartitionScheme[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -60,17 +60,17 @@ Describe "Remove-DbaDbPartitionScheme" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } It "Should have WhatIf parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } It "Should have Confirm parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } } Describe "Remove-DbaDbPartitionScheme Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 diff --git a/tests/Remove-DbaDbRole.Tests.ps1 b/tests/Remove-DbaDbRole.Tests.ps1 index 30e428c2f5..685bcef73b 100644 --- a/tests/Remove-DbaDbRole.Tests.ps1 +++ b/tests/Remove-DbaDbRole.Tests.ps1 @@ -24,36 +24,36 @@ Describe "Remove-DbaDbRole Unit Tests" -Tag "UnitTests" { $CommandUnderTest | Should -HaveParameter ExcludeRole -Type String[] -Not -Mandatory } It "Should have IncludeSystemDbs parameter" { - $CommandUnderTest | Should -HaveParameter IncludeSystemDbs -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeSystemDbs -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Remove-DbaDbRole Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $role1 = "dbatoolssci_role1_$(Get-Random)" $role2 = "dbatoolssci_role2_$(Get-Random)" $dbname1 = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname1 -Owner sa + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname1 -Owner sa } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname1 -Confirm:$false } Context "Functionality" { It 'Removes Non Fixed Roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) $null = $server.Query("CREATE ROLE $role2", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 -Confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 $result0.Count | Should -BeGreaterThan $result1.Count $result1.Name | Should -Not -Contain $role1 @@ -63,9 +63,9 @@ Describe "Remove-DbaDbRole Integration Tests" -Tag "IntegrationTests" { It 'Accepts a list of roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) $null = $server.Query("CREATE ROLE $role2", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $role1 -Confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 -Role $role1 -Confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 $result0.Count | Should -BeGreaterThan $result1.Count $result1.Name | Should -Not -Contain $role1 @@ -74,9 +74,9 @@ Describe "Remove-DbaDbRole Integration Tests" -Tag "IntegrationTests" { It 'Excludes databases Roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -ExcludeRole $role1 -Confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 -ExcludeRole $role1 -Confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 $result0.Count | Should -BeGreaterThan $result1.Count $result1.Name | Should -Contain $role1 @@ -84,18 +84,18 @@ Describe "Remove-DbaDbRole Integration Tests" -Tag "IntegrationTests" { } It 'Accepts input from Get-DbaDbRole' { - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $role2 + $result0 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 -Role $role2 $result0 | Remove-DbaDbRole -Confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result1 = Get-DbaDbRole -SqlInstance $env:instance2 -Database $dbname1 $result1.Name | Should -Not -Contain $role2 } It 'Removes roles in System DB' { $null = $server.Query("CREATE ROLE $role1", 'msdb') - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database msdb - Remove-DbaDbRole -SqlInstance $script:instance2 -Database msdb -Role $role1 -IncludeSystemDbs -Confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database msdb + $result0 = Get-DbaDbRole -SqlInstance $env:instance2 -Database msdb + Remove-DbaDbRole -SqlInstance $env:instance2 -Database msdb -Role $role1 -IncludeSystemDbs -Confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $env:instance2 -Database msdb $result0.Count | Should -BeGreaterThan $result1.Count $result1.Name | Should -Not -Contain $role1 diff --git a/tests/Remove-DbaDbRoleMember.Tests.ps1 b/tests/Remove-DbaDbRoleMember.Tests.ps1 index e62fb20ba7..f7e8ea0822 100644 --- a/tests/Remove-DbaDbRoleMember.Tests.ps1 +++ b/tests/Remove-DbaDbRoleMember.Tests.ps1 @@ -6,18 +6,18 @@ Describe "Remove-DbaDbRoleMember" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $user1 = "dbatoolssci_user1_$(Get-Random)" $user2 = "dbatoolssci_user2_$(Get-Random)" $role = "dbatoolssci_role_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname -Owner sa - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user1 -Username 'User1' - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user2 -Username 'User2' - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user1 -Username 'User1' -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user2 -Username 'User2' -IncludeSystem + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname -Owner sa + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $user1 -Username 'User1' + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database $dbname -Login $user2 -Username 'User2' + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database msdb -Login $user1 -Username 'User1' -IncludeSystem + $null = New-DbaDbUser -SqlInstance $env:instance2 -Database msdb -Login $user2 -Username 'User2' -IncludeSystem $null = $server.Query("CREATE ROLE $role", $dbname) $null = $server.Query("ALTER ROLE $role ADD MEMBER User1", $dbname) @@ -28,11 +28,11 @@ Describe "Remove-DbaDbRoleMember" { } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $null = $server.Query("DROP USER User1", 'msdb') $null = $server.Query("DROP USER User2", 'msdb') - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $user1, $user2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $user1, $user2 -Confirm:$false } Context "Validate parameters" { @@ -58,18 +58,18 @@ Describe "Remove-DbaDbRoleMember" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Functionality" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 } It 'Removes Role for User' { - $roleDB = Get-DbaDbRoleMember -SqlInstance $script:instance2 -Database $dbname -Role $role - Remove-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -User 'User1' -Database $dbname -Confirm:$false + $roleDB = Get-DbaDbRoleMember -SqlInstance $env:instance2 -Database $dbname -Role $role + Remove-DbaDbRoleMember -SqlInstance $env:instance2 -Role $role -User 'User1' -Database $dbname -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role $roleDB.UserName | Should -Be 'User1' diff --git a/tests/Remove-DbaDbSchema.Tests.ps1 b/tests/Remove-DbaDbSchema.Tests.ps1 index 7171d1428a..bdea587947 100644 --- a/tests/Remove-DbaDbSchema.Tests.ps1 +++ b/tests/Remove-DbaDbSchema.Tests.ps1 @@ -21,15 +21,15 @@ Describe "Remove-DbaDbSchema" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName diff --git a/tests/Remove-DbaDbSequence.Tests.ps1 b/tests/Remove-DbaDbSequence.Tests.ps1 index 77b77836da..4731344198 100644 --- a/tests/Remove-DbaDbSequence.Tests.ps1 +++ b/tests/Remove-DbaDbSequence.Tests.ps1 @@ -24,14 +24,14 @@ Describe "Remove-DbaDbSequence" { $CommandUnderTest | Should -HaveParameter InputObject -Type Sequence[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $newDbName = "dbatoolsci_newdb_$random" $null = New-DbaDatabase -SqlInstance $server -Name $newDbName diff --git a/tests/Remove-DbaDbSnapshot.Tests.ps1 b/tests/Remove-DbaDbSnapshot.Tests.ps1 index 0e6faf9a42..051f112213 100644 --- a/tests/Remove-DbaDbSnapshot.Tests.ps1 +++ b/tests/Remove-DbaDbSnapshot.Tests.ps1 @@ -30,83 +30,83 @@ Describe "Remove-DbaDbSnapshot" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have AllSnapshots parameter" { - $CommandUnderTest | Should -HaveParameter AllSnapshots -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllSnapshots -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_RemoveSnap" $db1_snap1 = "dbatoolsci_RemoveSnap_snapshotted1" $db1_snap2 = "dbatoolsci_RemoveSnap_snapshotted2" $db2 = "dbatoolsci_RemoveSnap2" $db2_snap1 = "dbatoolsci_RemoveSnap2_snapshotted" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } Context "Parameters validation" { It "Stops if no Database or AllDatabases" { - { Remove-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException } | Should -Throw "You must pipe" + { Remove-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException } | Should -Throw "You must pipe" } It "Is nice by default" { - { Remove-DbaDbSnapshot -SqlInstance $script:instance2 *> $null } | Should -Not -Throw + { Remove-DbaDbSnapshot -SqlInstance $env:instance2 *> $null } | Should -Not -Throw } } Context "Operations on snapshots" { BeforeEach { - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue } It "Honors the Database parameter, dropping only snapshots of that database" { - $results = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Confirm:$false + $results = Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Confirm:$false $results.Count | Should -Be 2 - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 -Confirm:$false $result.Name | Should -Be $db2_snap1 } It "Honors the ExcludeDatabase parameter, returning relevant snapshots" { - $alldbs = (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name - $results = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeDatabase $alldbs -Confirm:$false + $alldbs = (Get-DbaDatabase -SqlInstance $env:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name + $results = Remove-DbaDbSnapshot -SqlInstance $env:instance2 -ExcludeDatabase $alldbs -Confirm:$false $results.Count | Should -Be 3 } It "Honors the Snapshot parameter" { - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Snapshot $db1_snap1 -Confirm:$false $result.Name | Should -Be $db1_snap1 } It "Works with piped snapshots" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 | Remove-DbaDbSnapshot -Confirm:$false + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Snapshot $db1_snap1 | Remove-DbaDbSnapshot -Confirm:$false $result.Name | Should -Be $db1_snap1 - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Snapshot $db1_snap1 $result | Should -BeNullOrEmpty } It "Has the correct default properties" { - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 -Confirm:$false $ExpectedPropsDefault = 'ComputerName', 'Name', 'InstanceName', 'SqlInstance', 'Status' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } diff --git a/tests/Remove-DbaDbSynonym.Tests.ps1 b/tests/Remove-DbaDbSynonym.Tests.ps1 index c97ad5b28b..59cab72efa 100644 --- a/tests/Remove-DbaDbSynonym.Tests.ps1 +++ b/tests/Remove-DbaDbSynonym.Tests.ps1 @@ -8,13 +8,13 @@ Describe "Remove-DbaDbSynonym" { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name $dbname2 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $env:instance2 -Confirm:$false } Context "Validate parameters" { @@ -49,17 +49,17 @@ Describe "Remove-DbaDbSynonym" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Functionality" { It 'Removes Synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' - $result1 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -Confirm:$false - $result2 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' + $result1 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn1' -Confirm:$false + $result2 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result1.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain 'syn1' @@ -67,11 +67,11 @@ Describe "Remove-DbaDbSynonym" { } It 'Accepts a list of synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn3' -BaseObject 'obj3' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn4' -BaseObject 'obj4' - $result3 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn3','syn4' - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn3','syn4' -Confirm:$false - $result4 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn3' -BaseObject 'obj3' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn4' -BaseObject 'obj4' + $result3 = Get-DbaDbSynonym -SqlInstance $env:instance2 -Synonym 'syn3','syn4' + Remove-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn3','syn4' -Confirm:$false + $result4 = Get-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname $result3.Count | Should -BeGreaterThan $result4.Count $result4.Name | Should -Not -Contain 'syn3' @@ -79,11 +79,11 @@ Describe "Remove-DbaDbSynonym" { } It 'Excludes Synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn5' -BaseObject 'obj5' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn6' -BaseObject 'obj6' - $result5 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSynonym 'syn5' -Confirm:$false - $result6 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn5' -BaseObject 'obj5' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn6' -BaseObject 'obj6' + $result5 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -ExcludeSynonym 'syn5' -Confirm:$false + $result6 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result5.Count | Should -BeGreaterThan $result6.Count $result6.Name | Should -Not -Contain 'syn6' @@ -91,10 +91,10 @@ Describe "Remove-DbaDbSynonym" { } It 'Accepts input from Get-DbaDbSynonym' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn7' -BaseObject 'obj7' - $result7 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn5','syn7' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn7' -BaseObject 'obj7' + $result7 = Get-DbaDbSynonym -SqlInstance $env:instance2 -Synonym 'syn5','syn7' $result7 | Remove-DbaDbSynonym -Confirm:$false - $result8 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result8 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result7.Name | Should -Contain 'syn5' $result7.Name | Should -Contain 'syn7' @@ -103,11 +103,11 @@ Describe "Remove-DbaDbSynonym" { } It 'Excludes Synonyms in a specified database' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn10' -BaseObject 'obj10' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn11' -BaseObject 'obj11' - $result11 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeDatabase $dbname2 -Confirm:$false - $result12 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn10' -BaseObject 'obj10' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname2 -Synonym 'syn11' -BaseObject 'obj11' + $result11 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -ExcludeDatabase $dbname2 -Confirm:$false + $result12 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result11.Count | Should -BeGreaterThan $result12.Count $result12.Database | Should -Not -Contain $dbname @@ -115,12 +115,12 @@ Describe "Remove-DbaDbSynonym" { } It 'Excludes Synonyms in a specified schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema 'sch2' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn12' -BaseObject 'obj12' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn13' -BaseObject 'obj13' -Schema 'sch2' - $result13 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSchema 'sch2' -Confirm:$false - $result14 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname2 -Schema 'sch2' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn12' -BaseObject 'obj12' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname2 -Synonym 'syn13' -BaseObject 'obj13' -Schema 'sch2' + $result13 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -ExcludeSchema 'sch2' -Confirm:$false + $result14 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result13.Count | Should -BeGreaterThan $result14.Count $result13.Schema | Should -Contain 'dbo' @@ -129,14 +129,14 @@ Describe "Remove-DbaDbSynonym" { } It 'Accepts a list of schemas' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch3' - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema 'sch4' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn14' -BaseObject 'obj14' -Schema 'sch3' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn15' -BaseObject 'obj15' -Schema 'sch4' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn16' -BaseObject 'obj15' -Schema 'dbo' - $result15 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'sch3', 'dbo' -Confirm:$false - $result16 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname -Schema 'sch3' + $null = New-DbaDbSchema -SqlInstance $env:instance2 -Database $dbname2 -Schema 'sch4' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn14' -BaseObject 'obj14' -Schema 'sch3' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname2 -Synonym 'syn15' -BaseObject 'obj15' -Schema 'sch4' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname2 -Synonym 'syn16' -BaseObject 'obj15' -Schema 'dbo' + $result15 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -Schema 'sch3', 'dbo' -Confirm:$false + $result16 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result15.Count | Should -BeGreaterThan $result16.Count $result16.Schema | Should -Not -Contain 'sch3' @@ -145,11 +145,11 @@ Describe "Remove-DbaDbSynonym" { } It 'Accepts a list of databases' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn17' -BaseObject 'obj17' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn18' -BaseObject 'obj18' - $result17 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $result18 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname -Synonym 'syn17' -BaseObject 'obj17' + $null = New-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname2 -Synonym 'syn18' -BaseObject 'obj18' + $result17 = Get-DbaDbSynonym -SqlInstance $env:instance2 + Remove-DbaDbSynonym -SqlInstance $env:instance2 -Database $dbname, $dbname2 -Confirm:$false + $result18 = Get-DbaDbSynonym -SqlInstance $env:instance2 $result17.Count | Should -BeGreaterThan $result18.Count $result18.Database | Should -Not -Contain $dbname diff --git a/tests/Remove-DbaDbTable.Tests.ps1 b/tests/Remove-DbaDbTable.Tests.ps1 index 82470efafb..2e27f5f2e1 100644 --- a/tests/Remove-DbaDbTable.Tests.ps1 +++ b/tests/Remove-DbaDbTable.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Remove-DbaDbTable" { Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $instance2 -Name $dbname1 diff --git a/tests/Remove-DbaDbTableData.Tests.ps1 b/tests/Remove-DbaDbTableData.Tests.ps1 index eafc771b33..8a50103f03 100644 --- a/tests/Remove-DbaDbTableData.Tests.ps1 +++ b/tests/Remove-DbaDbTableData.Tests.ps1 @@ -5,8 +5,8 @@ Describe "Remove-DbaDbTableData" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance2 + $server2 = Connect-DbaInstance -SqlInstance $env:instance3 # scenario for testing with a db in the simple recovery model $dbnameSimpleModel = "dbatoolsci_$(Get-Random)" @@ -86,8 +86,8 @@ Describe "Remove-DbaDbTableData" { It "Should have InputObject as an Object[] parameter that is not mandatory" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have EnableException as a SwitchParameter that is not mandatory" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a Switch that is not mandatory" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -180,11 +180,11 @@ Describe "Remove-DbaDbTableData" { Context "Functionality with bulk_logged recovery model" { BeforeEach { - $addRowsToBulkLoggedDb = Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbnameBulkLoggedModel -Query $sqlAddRows + $addRowsToBulkLoggedDb = Invoke-DbaQuery -SqlInstance $env:instance2 -Database $dbnameBulkLoggedModel -Query $sqlAddRows } It 'Removes Data for a specified database' { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database $dbnameBulkLoggedModel -NonPooledConnection + $server = Connect-DbaInstance -SqlInstance $env:instance2 -Database $dbnameBulkLoggedModel -NonPooledConnection $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameBulkLoggedModel -Table dbo.Test -BatchSize 10 -LogBackupPath $logBackupPath -Confirm:$false $result.TotalIterations | Should -Be 10 $result.TotalRowsDeleted | Should -Be 100 diff --git a/tests/Remove-DbaDbUdf.Tests.ps1 b/tests/Remove-DbaDbUdf.Tests.ps1 index 05369af093..295ff100e7 100644 --- a/tests/Remove-DbaDbUdf.Tests.ps1 +++ b/tests/Remove-DbaDbUdf.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Remove-DbaDbUdf" { Context "Command usage" { BeforeAll { . (Join-Path $PSScriptRoot 'constants.ps1') - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 diff --git a/tests/Remove-DbaDbUser.Tests.ps1 b/tests/Remove-DbaDbUser.Tests.ps1 index a4dc610438..2e10cfc2bd 100644 --- a/tests/Remove-DbaDbUser.Tests.ps1 +++ b/tests/Remove-DbaDbUser.Tests.ps1 @@ -30,21 +30,21 @@ Describe "Remove-DbaDbUser Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter InputObject -Type User[] -Not -Mandatory } It "Should have Force parameter" { - $command | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Remove-DbaDbUser Integration Tests" -Tag "IntegrationTests" { BeforeDiscovery { - $script:instance1 = "localhost" + $env:instance1 = "localhost" } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $db = Get-DbaDatabase $server -Database tempdb $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force $loginTest = New-DbaLogin $server -Login dbatoolsci_remove_dba_db_user -Password $securePassword -Force diff --git a/tests/Remove-DbaDbView.Tests.ps1 b/tests/Remove-DbaDbView.Tests.ps1 index f495b057e3..3a3561ce3d 100644 --- a/tests/Remove-DbaDbView.Tests.ps1 +++ b/tests/Remove-DbaDbView.Tests.ps1 @@ -21,14 +21,14 @@ Describe "Remove-DbaDbView" { $CommandUnderTest | Should -HaveParameter InputObject -Type View[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $instance2 -Name $dbname1 diff --git a/tests/Remove-DbaEndpoint.Tests.ps1 b/tests/Remove-DbaEndpoint.Tests.ps1 index 4943ead604..58f9cd8213 100644 --- a/tests/Remove-DbaEndpoint.Tests.ps1 +++ b/tests/Remove-DbaEndpoint.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Remove-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Endpoint -Type String[] } It "Should have AllEndpoints as a switch parameter" { - $CommandUnderTest | Should -HaveParameter AllEndpoints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllEndpoints -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Endpoint[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,20 +31,20 @@ Describe "Remove-DbaEndpoint" { } BeforeAll { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring + $endpoint = Get-DbaEndpoint -SqlInstance $env:instance2 | Where-Object EndpointType -eq DatabaseMirroring $create = $endpoint | Export-DbaScript -Passthru $null = $endpoint | Remove-DbaEndpoint -Confirm:$false - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false + $results = New-DbaEndpoint -SqlInstance $env:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false } AfterAll { if ($create) { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "$create" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query "$create" } } It "removes an endpoint" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + $results = Get-DbaEndpoint -SqlInstance $env:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false $results.Status | Should -Be 'Removed' } } diff --git a/tests/Remove-DbaExtendedProperty.Tests.ps1 b/tests/Remove-DbaExtendedProperty.Tests.ps1 index 6543f0a395..75710e60f4 100644 --- a/tests/Remove-DbaExtendedProperty.Tests.ps1 +++ b/tests/Remove-DbaExtendedProperty.Tests.ps1 @@ -9,13 +9,13 @@ Describe "Remove-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter InputObject -Type ExtendedProperty[] } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Accepts Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Accepts Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Accepts ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -48,17 +48,17 @@ Describe "Remove-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Accepts WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Accepts Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } Context "Command usage" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName diff --git a/tests/Remove-DbaFirewallRule.Tests.ps1 b/tests/Remove-DbaFirewallRule.Tests.ps1 index 10dc62a2ac..890621bded 100644 --- a/tests/Remove-DbaFirewallRule.Tests.ps1 +++ b/tests/Remove-DbaFirewallRule.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Remove-DbaFirewallRule" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -30,8 +30,8 @@ Describe "Remove-DbaFirewallRule Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { BeforeAll { - $script:instance1 = $script:instance1 - $script:instance2 = $script:instance2 + $env:instance1 = $env:instance1 + $env:instance2 = $env:instance2 } It "Removes firewall rules" { diff --git a/tests/Remove-DbaLinkedServer.Tests.ps1 b/tests/Remove-DbaLinkedServer.Tests.ps1 index 575c2e099e..9bfe374ba1 100644 --- a/tests/Remove-DbaLinkedServer.Tests.ps1 +++ b/tests/Remove-DbaLinkedServer.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Remove-DbaLinkedServer" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,8 +29,8 @@ Describe "Remove-DbaLinkedServer" { BeforeAll { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 + $instance3 = Connect-DbaInstance -SqlInstance $env:instance3 $linkedServerName1 = "dbatoolscli_LS1_$random" $linkedServerName2 = "dbatoolscli_LS2_$random" @@ -77,18 +77,18 @@ Describe "Remove-DbaLinkedServer" { It "Removes a linked server" { $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName1 $results.Length | Should -Be 1 - Remove-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName1 -Confirm:$false + Remove-DbaLinkedServer -SqlInstance $env:instance2 -LinkedServer $linkedServerName1 -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName1 $results | Should -BeNullOrEmpty } It "Tries to remove a non-existent linked server" { - Remove-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName1 -Confirm:$false -WarningVariable warnings + Remove-DbaLinkedServer -SqlInstance $env:instance2 -LinkedServer $linkedServerName1 -Confirm:$false -WarningVariable warnings $warnings | Should -BeLike "*Linked server $linkedServerName1 does not exist on $($instance2.Name)" } It "Removes a linked server passed in via pipeline" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName2 + $results = Get-DbaLinkedServer -SqlInstance $env:instance2 -LinkedServer $linkedServerName2 $results.Length | Should -Be 1 Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2 | Remove-DbaLinkedServer -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2 @@ -96,7 +96,7 @@ Describe "Remove-DbaLinkedServer" { } It "Removes a linked server using a server passed in via pipeline" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName3 + $results = Get-DbaLinkedServer -SqlInstance $env:instance2 -LinkedServer $linkedServerName3 $results.Length | Should -Be 1 $instance2 | Remove-DbaLinkedServer -LinkedServer $linkedServerName3 -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName3 diff --git a/tests/Remove-DbaLinkedServerLogin.Tests.ps1 b/tests/Remove-DbaLinkedServerLogin.Tests.ps1 index dd48a7175a..4f9af78549 100644 --- a/tests/Remove-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Remove-DbaLinkedServerLogin.Tests.ps1 @@ -7,8 +7,8 @@ Describe "Remove-DbaLinkedServerLogin" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 + $instance3 = Connect-DbaInstance -SqlInstance $env:instance3 $securePassword = ConvertTo-SecureString -String 'securePassword' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -64,7 +64,7 @@ Describe "Remove-DbaLinkedServerLogin" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Remove-DbaLogin.Tests.ps1 b/tests/Remove-DbaLogin.Tests.ps1 index 4507c3ad40..4b7232107a 100644 --- a/tests/Remove-DbaLogin.Tests.ps1 +++ b/tests/Remove-DbaLogin.Tests.ps1 @@ -24,10 +24,10 @@ Describe "Remove-DbaLogin" { $CommandUnderTest | Should -HaveParameter InputObject -Type Login[] -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -36,13 +36,13 @@ Describe "Remove-DbaLogin" { $login = "dbatoolsci_removelogin" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword + $newlogin = New-DbaLogin -SqlInstance $env:instance1 -Login $login -Password $securePassword } It "removes the login" { - $results = Remove-DbaLogin -SqlInstance $script:instance1 -Login $login -Confirm:$false + $results = Remove-DbaLogin -SqlInstance $env:instance1 -Login $login -Confirm:$false $results.Status | Should -Be "Dropped" - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login $login + $login1 = Get-DbaLogin -SqlInstance $env:instance1 -login $login $login1 | Should -BeNullOrEmpty } } diff --git a/tests/Remove-DbaNetworkCertificate.Tests.ps1 b/tests/Remove-DbaNetworkCertificate.Tests.ps1 index 548e0c3e60..8e6b180a4e 100644 --- a/tests/Remove-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Remove-DbaNetworkCertificate.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Remove-DbaNetworkCertificate" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory @@ -51,10 +51,10 @@ Describe "Remove-DbaNetworkCertificate" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String -Not -Mandatory } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch -Not -Mandatory } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch -Not -Mandatory } } } diff --git a/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 index 799932d933..ac40008f7e 100644 --- a/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 @@ -23,7 +23,7 @@ Describe "Remove-DbaPfDataCollectorCounter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 b/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 index fbda793105..ffeff769bd 100644 --- a/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Remove-DbaPfDataCollectorSet" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Remove-DbaRegServer.Tests.ps1 b/tests/Remove-DbaRegServer.Tests.ps1 index 16d0a5c0b1..968c017766 100644 --- a/tests/Remove-DbaRegServer.Tests.ps1 +++ b/tests/Remove-DbaRegServer.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Remove-DbaRegServer" { $CommandUnderTest | Should -HaveParameter InputObject -Type RegisteredServer[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -35,15 +35,15 @@ Describe "Remove-DbaRegServer" { $srvName = "dbatoolsci-server1" $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc + $newServer = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc $srvName2 = "dbatoolsci-server2" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newServer2 = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3 | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3 | Remove-DbaRegServer -Confirm:$false } It "supports dropping via the pipeline" { @@ -53,7 +53,7 @@ Describe "Remove-DbaRegServer" { } It "supports dropping manually" { - $results = Remove-DbaRegServer -Confirm:$false -SqlInstance $script:instance1 -Name $regSrvName2 + $results = Remove-DbaRegServer -Confirm:$false -SqlInstance $env:instance1 -Name $regSrvName2 $results.Name | Should -Be $regSrvName2 $results.Status | Should -Be 'Dropped' } diff --git a/tests/Remove-DbaRegServerGroup.Tests.ps1 b/tests/Remove-DbaRegServerGroup.Tests.ps1 index b90b2a9e07..fa57d6a544 100644 --- a/tests/Remove-DbaRegServerGroup.Tests.ps1 +++ b/tests/Remove-DbaRegServerGroup.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Remove-DbaRegServerGroup" { $CommandUnderTest | Should -HaveParameter InputObject -Type ServerGroup[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,21 +29,21 @@ Describe "Remove-DbaRegServerGroup" { BeforeAll { $group = "dbatoolsci-group1" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $newGroup = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group $group2 = "dbatoolsci-group1a" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $env:instance1 -Name $group2 - $hellagroup = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | - Add-DbaRegServerGroup -Name dbatoolsci-first | - Add-DbaRegServerGroup -Name dbatoolsci-second | - Add-DbaRegServerGroup -Name dbatoolsci-third | + $hellagroup = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Id 1 | + Add-DbaRegServerGroup -Name dbatoolsci-first | + Add-DbaRegServerGroup -Name dbatoolsci-second | + Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous } AfterAll { - Get-DbaRegServerGroup -SqlInstance $script:instance1 | - Where-Object Name -match dbatoolsci | + Get-DbaRegServerGroup -SqlInstance $env:instance1 | + Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } @@ -54,13 +54,13 @@ Describe "Remove-DbaRegServerGroup" { } It "supports dropping manually" { - $results = Remove-DbaRegServerGroup -Confirm:$false -SqlInstance $script:instance1 -Name $group2 + $results = Remove-DbaRegServerGroup -Confirm:$false -SqlInstance $env:instance1 -Name $group2 $results.Name | Should -Be $group2 $results.Status | Should -Be 'Dropped' } It "supports hella long group name" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $hellagroup.Group + $results = Get-DbaRegServerGroup -SqlInstance $env:instance1 -Group $hellagroup.Group $results.Name | Should -Be 'dbatoolsci-third' } } diff --git a/tests/Remove-DbaReplSubscription.Tests.ps1 b/tests/Remove-DbaReplSubscription.Tests.ps1 index 5ef749905e..6e8ca49a73 100644 --- a/tests/Remove-DbaReplSubscription.Tests.ps1 +++ b/tests/Remove-DbaReplSubscription.Tests.ps1 @@ -32,13 +32,13 @@ Describe "Remove-DbaReplSubscription" { $CommandUnderTest | Should -HaveParameter SubscriptionDatabase -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -71,10 +71,10 @@ Describe "Remove-DbaReplSubscription" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } diff --git a/tests/Remove-DbaRgResourcePool.Tests.ps1 b/tests/Remove-DbaRgResourcePool.Tests.ps1 index 74331ea783..ae845a8439 100644 --- a/tests/Remove-DbaRgResourcePool.Tests.ps1 +++ b/tests/Remove-DbaRgResourcePool.Tests.ps1 @@ -22,25 +22,25 @@ Describe "Remove-DbaRgResourcePool" { $CommandUnderTest | Should -HaveParameter Type -Type String -Not -Mandatory } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Removes a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -49,9 +49,9 @@ Describe "Remove-DbaRgResourcePool" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 + Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -60,7 +60,7 @@ Describe "Remove-DbaRgResourcePool" { It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -70,9 +70,9 @@ Describe "Remove-DbaRgResourcePool" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type Internal - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type Internal + Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -Type Internal + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -81,7 +81,7 @@ Describe "Remove-DbaRgResourcePool" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -91,9 +91,9 @@ Describe "Remove-DbaRgResourcePool" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type External - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type External + Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -Type External + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 -Type External $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -103,7 +103,7 @@ Describe "Remove-DbaRgResourcePool" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -112,9 +112,9 @@ Describe "Remove-DbaRgResourcePool" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 + Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -125,7 +125,7 @@ Describe "Remove-DbaRgResourcePool" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -134,9 +134,9 @@ Describe "Remove-DbaRgResourcePool" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) | Remove-DbaRgResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result2 = Get-DbaRgResourcePool -SqlInstance $env:instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -146,7 +146,7 @@ Describe "Remove-DbaRgResourcePool" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -155,8 +155,8 @@ Describe "Remove-DbaRgResourcePool" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -SkipReconfigure - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -SkipReconfigure + $result = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result.ReconfigurePending | Should -Be $true } diff --git a/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 b/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 index d9c3614ad2..c1c8680d79 100644 --- a/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 @@ -25,32 +25,32 @@ Describe "Remove-DbaRgWorkloadGroup" { $CommandUnderTest | Should -HaveParameter ResourcePoolType -Type String -Not -Mandatory } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type WorkloadGroup[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Removes a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName Force = $true } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -BeNullOrEmpty $result.Count | Should -BeGreaterThan $result3.Count @@ -64,13 +64,13 @@ Describe "Remove-DbaRgWorkloadGroup" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -78,11 +78,11 @@ Describe "Remove-DbaRgWorkloadGroup" { } $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName -ResourcePoolType $resourcePoolType - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName -ResourcePoolType $resourcePoolType + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup | Should -Not -BeNullOrEmpty $result.Count | Should -BeGreaterThan $result3.Count @@ -95,15 +95,15 @@ Describe "Remove-DbaRgWorkloadGroup" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) Force = $true } $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups | Should -Not -BeNullOrEmpty $result.Count | Should -BeGreaterThan $result3.Count @@ -115,14 +115,14 @@ Describe "Remove-DbaRgWorkloadGroup" { It "Removes a piped workload group" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName Force = $true } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName $result2 = $newWorkloadGroup | Remove-DbaRgWorkloadGroup - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $env:instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -BeNullOrEmpty $result.Count | Should -BeGreaterThan $result3.Count diff --git a/tests/Remove-DbaServerRole.Tests.ps1 b/tests/Remove-DbaServerRole.Tests.ps1 index b5c6c9b3d5..82fbe2b9ba 100644 --- a/tests/Remove-DbaServerRole.Tests.ps1 +++ b/tests/Remove-DbaServerRole.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Remove-DbaServerRole Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type ServerRole[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -29,7 +29,7 @@ Describe "Remove-DbaServerRole Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $env:instance2 $roleExecutor = "serverExecuter" $null = New-DbaServerRole -SqlInstance $instance -ServerRole $roleExecutor } diff --git a/tests/Remove-DbaServerRoleMember.Tests.ps1 b/tests/Remove-DbaServerRoleMember.Tests.ps1 index 25bce6be44..b62043b144 100644 --- a/tests/Remove-DbaServerRoleMember.Tests.ps1 +++ b/tests/Remove-DbaServerRoleMember.Tests.ps1 @@ -6,20 +6,20 @@ Describe "Remove-DbaServerRoleMember" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $login1 = "dbatoolsci_login1_$(Get-Random)" $login2 = "dbatoolsci_login2_$(Get-Random)" $customServerRole = "dbatoolsci_customrole_$(Get-Random)" $fixedServerRoles = 'dbcreator','processadmin' - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $env:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaServerRole -SqlInstance $env:instance2 -ServerRole $customServerRole -Owner sa Add-DbaServerRoleMember -SqlInstance $server -ServerRole $fixedServerRoles[0] -Login $login1, $login2 -Confirm:$false } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $env:instance2 + $null = Remove-DbaLogin -SqlInstance $env:instance2 -Login $login1, $login2 -Confirm:$false } Context "Validate parameters" { @@ -45,13 +45,13 @@ Describe "Remove-DbaServerRoleMember" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Functionality" { It 'Removes Login from Role' { - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $env:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] $roleAfter.Role | Should -Be $fixedServerRoles[0] @@ -61,7 +61,7 @@ Describe "Remove-DbaServerRoleMember" { It 'Removes Login from Multiple Roles' { $serverRoles = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $env:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false $roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles $roleDBAfter.Count | Should -Be $serverRoles.Count @@ -70,7 +70,7 @@ Describe "Remove-DbaServerRoleMember" { } It 'Removes Custom Server-Level Role Membership' { - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $env:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[-1] $roleAfter.Role | Should -Be $fixedServerRoles[-1] diff --git a/tests/Remove-DbaTrace.Tests.ps1 b/tests/Remove-DbaTrace.Tests.ps1 index e17de54ca9..34c6622b9b 100644 --- a/tests/Remove-DbaTrace.Tests.ps1 +++ b/tests/Remove-DbaTrace.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Remove-DbaTrace" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Accepts EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -102,7 +102,7 @@ exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references select TraceID=@TraceID "@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $traceid = ($server.Query($sql)).TraceID } @@ -111,13 +111,13 @@ select TraceID=@TraceID } It "Removes the trace" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Remove-DbaTrace + $results = Get-DbaTrace -SqlInstance $env:instance1 -Id $traceid | Remove-DbaTrace $results.Id | Should -Be $traceid $results.Status | Should -Be "Stopped, closed and deleted" } It "Doesn't return any result for removed trace file id" { - Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Should -BeNullOrEmpty + Get-DbaTrace -SqlInstance $env:instance1 -Id $traceid | Should -BeNullOrEmpty } } } diff --git a/tests/Remove-DbaXESession.Tests.ps1 b/tests/Remove-DbaXESession.Tests.ps1 index d30b5a8a0f..c083eb28c7 100644 --- a/tests/Remove-DbaXESession.Tests.ps1 +++ b/tests/Remove-DbaXESession.Tests.ps1 @@ -28,18 +28,18 @@ Describe "Remove-DbaXESession" { Context "Integration Tests" -Tag "IntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $env:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $env:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } It "Imports and removes a session template" { - $results = Import-DbaXESessionTemplate -SqlInstance $script:instance2 -Template 'Profiler TSQL Duration' + $results = Import-DbaXESessionTemplate -SqlInstance $env:instance2 -Template 'Profiler TSQL Duration' $results.Name | Should -Be 'Profiler TSQL Duration' - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' + $null = Get-DbaXESession -SqlInstance $env:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $results = Get-DbaXESession -SqlInstance $env:instance2 -Session 'Profiler TSQL Duration' $results.Name | Should -BeNullOrEmpty $results.Status | Should -BeNullOrEmpty diff --git a/tests/Rename-DbaDatabase.Tests.ps1 b/tests/Rename-DbaDatabase.Tests.ps1 index c64f8ead68..9e26c84be5 100644 --- a/tests/Rename-DbaDatabase.Tests.ps1 +++ b/tests/Rename-DbaDatabase.Tests.ps1 @@ -6,20 +6,20 @@ Describe "Rename-DbaDatabase" { $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_rename1' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_filemove' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_logicname' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_filegroupname' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_rename1' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_filemove' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_logicname' + $null = New-DbaDatabase -SqlInstance $env:instance2 -Name 'dbatoolsci_filegroupname' $FileGroupName = @" ALTER DATABASE dbatoolsci_filegroupname ADD FILEGROUP Dbatoolsci_filegroupname "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $FileGroupName + $null = Invoke-DbaQuery -SqlInstance $env:instance2 -Query $FileGroupName $date = (Get-Date).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database "test_dbatoolsci_rename2_$($date)", "Dbatoolsci_filemove", "dbatoolsci_logicname", "dbatoolsci_filegroupname" -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database "test_dbatoolsci_rename2_$($date)", "Dbatoolsci_filemove", "dbatoolsci_logicname", "dbatoolsci_filegroupname" -Confirm:$false } Context "Validate parameters" { @@ -79,7 +79,7 @@ Describe "Rename-DbaDatabase" { Context "Should preview a rename of a database" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_rename1' DatabaseName = 'dbatoolsci_rename2' Preview = $true @@ -98,7 +98,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename a database" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_rename1' DatabaseName = 'dbatoolsci_rename2' } @@ -122,7 +122,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename a database with a prefix" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'dbatoolsci_rename2' DatabaseName = 'test_' } @@ -146,7 +146,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename a database with a date" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = 'test_dbatoolsci_rename2' DatabaseName = '_' } @@ -170,7 +170,7 @@ Describe "Rename-DbaDatabase" { Context "Should preview renaming database files" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_filemove" FileName = "__" Preview = $true @@ -195,7 +195,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename database files and move them" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_filemove" FileName = "__" Move = $true @@ -220,7 +220,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename database files and forces the move" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_filemove" FileName = "_" ReplaceBefore = $true @@ -246,7 +246,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename database files and set the database offline" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_filemove" FileName = "__" SetOffline = $true @@ -274,7 +274,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename the logical name" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_logicname" LogicalName = "__" } @@ -298,7 +298,7 @@ Describe "Rename-DbaDatabase" { Context "Should rename the filegroupname name" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = "dbatoolsci_filegroupname" FileGroupName = "__" } diff --git a/tests/Rename-DbaLogin.Tests.ps1 b/tests/Rename-DbaLogin.Tests.ps1 index 3f18f9eab6..baa015741d 100644 --- a/tests/Rename-DbaLogin.Tests.ps1 +++ b/tests/Rename-DbaLogin.Tests.ps1 @@ -18,10 +18,10 @@ Describe "Rename-DbaLogin" { $CommandUnderTest | Should -HaveParameter NewLogin -Type String } It "Should have Force as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,19 +32,19 @@ Describe "Rename-DbaLogin" { $renamed = "dbatoolsci_renamelogin2" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword + $newlogin = New-DbaLogin -SqlInstance $env:instance1 -Login $login -Password $securePassword } AfterAll { - $null = Stop-DbaProcess -SqlInstance $script:instance1 -Login $renamed - $null = Remove-DbaLogin -SqlInstance $script:instance1 -Login $renamed -Confirm:$false + $null = Stop-DbaProcess -SqlInstance $env:instance1 -Login $renamed + $null = Remove-DbaLogin -SqlInstance $env:instance1 -Login $renamed -Confirm:$false } It "renames the login" { - $results = Rename-DbaLogin -SqlInstance $script:instance1 -Login $login -NewLogin $renamed + $results = Rename-DbaLogin -SqlInstance $env:instance1 -Login $login -NewLogin $renamed $results.Status | Should -Be "Successful" $results.PreviousLogin | Should -Be $login $results.NewLogin | Should -Be $renamed - Get-DbaLogin -SqlInstance $script:instance1 -login $renamed | Should -Not -BeNullOrEmpty + Get-DbaLogin -SqlInstance $env:instance1 -login $renamed | Should -Not -BeNullOrEmpty } } } diff --git a/tests/Repair-DbaDbOrphanUser.Tests.ps1 b/tests/Repair-DbaDbOrphanUser.Tests.ps1 index d6136f0971..9b2052f709 100644 --- a/tests/Repair-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Repair-DbaDbOrphanUser.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Repair-DbaDbOrphanUser" { $CommandUnderTest | Should -HaveParameter Users -Type Object[] } It "Should have RemoveNotExisting parameter" { - $CommandUnderTest | Should -HaveParameter RemoveNotExisting -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter RemoveNotExisting -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -39,7 +39,7 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION CREATE LOGIN [dbatoolsci_orphan3] WITH PASSWORD = N'password3', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF; CREATE DATABASE dbatoolsci_orphan; '@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false $null = Invoke-DbaQuery -SqlInstance $server -Query $loginsq @@ -59,13 +59,13 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false } It "Finds two orphans" { - $results = Repair-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Repair-DbaDbOrphanUser -SqlInstance $env:instance1 -Database dbatoolsci_orphan $results.Count | Should -Be 2 foreach ($user in $results) { $user.User | Should -BeIn @('dbatoolsci_orphan1', 'dbatoolsci_orphan2') @@ -75,14 +75,14 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION } It "Has the correct properties" { - $results = Repair-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Repair-DbaDbOrphanUser -SqlInstance $env:instance1 -Database dbatoolsci_orphan $result = $results[0] $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'DatabaseName', 'User', 'Status' $result.PSObject.Properties.Name | Should -Be $ExpectedProps } It "Does not find any other orphan" { - $results = Repair-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Repair-DbaDbOrphanUser -SqlInstance $env:instance1 -Database dbatoolsci_orphan $results | Should -BeNullOrEmpty } } diff --git a/tests/Repair-DbaInstanceName.Tests.ps1 b/tests/Repair-DbaInstanceName.Tests.ps1 index 1fd8f6eb12..ad6e75660e 100644 --- a/tests/Repair-DbaInstanceName.Tests.ps1 +++ b/tests/Repair-DbaInstanceName.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Repair-DbaInstanceName" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have AutoFix parameter" { - $CommandUnderTest | Should -HaveParameter AutoFix -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AutoFix -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Reset-DbaAdmin.Tests.ps1 b/tests/Reset-DbaAdmin.Tests.ps1 index f6ea549a81..974bd99274 100644 --- a/tests/Reset-DbaAdmin.Tests.ps1 +++ b/tests/Reset-DbaAdmin.Tests.ps1 @@ -24,10 +24,10 @@ Describe "Reset-DbaAdmin" { $CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -38,12 +38,12 @@ Describe "Reset-DbaAdmin" { } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaLogin -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin | Remove-DbaLogin -Confirm:$false + Get-DbaProcess -SqlInstance $env:instance2 -Login dbatoolsci_resetadmin | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaLogin -SqlInstance $env:instance2 -Login dbatoolsci_resetadmin | Remove-DbaLogin -Confirm:$false } It "adds the login as sysadmin" { - $results = Reset-DbaAdmin -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin -SecurePassword $password -Confirm:$false + $results = Reset-DbaAdmin -SqlInstance $env:instance2 -Login dbatoolsci_resetadmin -SecurePassword $password -Confirm:$false $results.Name | Should -Be 'dbatoolsci_resetadmin' $results.IsMember("sysadmin") | Should -Be $true } diff --git a/tests/Restart-DbaService.Tests.ps1 b/tests/Restart-DbaService.Tests.ps1 index 2bc3ebe847..9d5f024a77 100644 --- a/tests/Restart-DbaService.Tests.ps1 +++ b/tests/Restart-DbaService.Tests.ps1 @@ -30,21 +30,21 @@ Describe "Restart-DbaService" { It "Should have Credential as a non-mandatory parameter of type PSCredential" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } - It "Should have Force as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + It "Should have Force as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $instanceName = (Connect-DbaInstance -SqlInstance $script:instance2).ServiceName + $instanceName = (Connect-DbaInstance -SqlInstance $env:instance2).ServiceName } It "restarts some services" { - $services = Restart-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent + $services = Restart-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Running' @@ -53,7 +53,7 @@ Describe "Restart-DbaService" { } It "restarts some services through pipeline" { - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Restart-DbaService + $services = Get-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent, Engine | Restart-DbaService $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Running' diff --git a/tests/Restore-DbaDatabase.Tests.ps1 b/tests/Restore-DbaDatabase.Tests.ps1 index d10906dc49..3885471d47 100644 --- a/tests/Restore-DbaDatabase.Tests.ps1 +++ b/tests/Restore-DbaDatabase.Tests.ps1 @@ -36,43 +36,43 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter RestoreTime -Type DateTime -Not -Mandatory } It "Should have NoRecovery parameter" { - $command | Should -HaveParameter NoRecovery -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter NoRecovery -Type Switch -Not -Mandatory } It "Should have WithReplace parameter" { - $command | Should -HaveParameter WithReplace -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter WithReplace -Type Switch -Not -Mandatory } It "Should have KeepReplication parameter" { - $command | Should -HaveParameter KeepReplication -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter KeepReplication -Type Switch -Not -Mandatory } It "Should have XpDirTree parameter" { - $command | Should -HaveParameter XpDirTree -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter XpDirTree -Type Switch -Not -Mandatory } It "Should have NoXpDirRecurse parameter" { - $command | Should -HaveParameter NoXpDirRecurse -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter NoXpDirRecurse -Type Switch -Not -Mandatory } It "Should have OutputScriptOnly parameter" { - $command | Should -HaveParameter OutputScriptOnly -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter OutputScriptOnly -Type Switch -Not -Mandatory } It "Should have VerifyOnly parameter" { - $command | Should -HaveParameter VerifyOnly -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter VerifyOnly -Type Switch -Not -Mandatory } It "Should have MaintenanceSolutionBackup parameter" { - $command | Should -HaveParameter MaintenanceSolutionBackup -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter MaintenanceSolutionBackup -Type Switch -Not -Mandatory } It "Should have FileMapping parameter" { $command | Should -HaveParameter FileMapping -Type Hashtable -Not -Mandatory } It "Should have IgnoreLogBackup parameter" { - $command | Should -HaveParameter IgnoreLogBackup -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter IgnoreLogBackup -Type Switch -Not -Mandatory } It "Should have IgnoreDiffBackup parameter" { - $command | Should -HaveParameter IgnoreDiffBackup -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter IgnoreDiffBackup -Type Switch -Not -Mandatory } It "Should have UseDestinationDefaultDirectories parameter" { - $command | Should -HaveParameter UseDestinationDefaultDirectories -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter UseDestinationDefaultDirectories -Type Switch -Not -Mandatory } It "Should have ReuseSourceFolderStructure parameter" { - $command | Should -HaveParameter ReuseSourceFolderStructure -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter ReuseSourceFolderStructure -Type Switch -Not -Mandatory } It "Should have DestinationFilePrefix parameter" { $command | Should -HaveParameter DestinationFilePrefix -Type String -Not -Mandatory @@ -81,7 +81,7 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter RestoredDatabaseNamePrefix -Type String -Not -Mandatory } It "Should have TrustDbBackupHistory parameter" { - $command | Should -HaveParameter TrustDbBackupHistory -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter TrustDbBackupHistory -Type Switch -Not -Mandatory } It "Should have MaxTransferSize parameter" { $command | Should -HaveParameter MaxTransferSize -Type Int32 -Not -Mandatory @@ -93,16 +93,16 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter BufferCount -Type Int32 -Not -Mandatory } It "Should have DirectoryRecurse parameter" { - $command | Should -HaveParameter DirectoryRecurse -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter DirectoryRecurse -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have StandbyDirectory parameter" { $command | Should -HaveParameter StandbyDirectory -Type String -Not -Mandatory } It "Should have Continue parameter" { - $command | Should -HaveParameter Continue -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Continue -Type Switch -Not -Mandatory } It "Should have ExecuteAs parameter" { $command | Should -HaveParameter ExecuteAs -Type String -Not -Mandatory @@ -111,40 +111,40 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter AzureCredential -Type String -Not -Mandatory } It "Should have ReplaceDbNameInFile parameter" { - $command | Should -HaveParameter ReplaceDbNameInFile -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter ReplaceDbNameInFile -Type Switch -Not -Mandatory } It "Should have DestinationFileSuffix parameter" { $command | Should -HaveParameter DestinationFileSuffix -Type String -Not -Mandatory } It "Should have Recover parameter" { - $command | Should -HaveParameter Recover -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Recover -Type Switch -Not -Mandatory } It "Should have KeepCDC parameter" { - $command | Should -HaveParameter KeepCDC -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter KeepCDC -Type Switch -Not -Mandatory } It "Should have GetBackupInformation parameter" { $command | Should -HaveParameter GetBackupInformation -Type String -Not -Mandatory } It "Should have StopAfterGetBackupInformation parameter" { - $command | Should -HaveParameter StopAfterGetBackupInformation -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter StopAfterGetBackupInformation -Type Switch -Not -Mandatory } It "Should have SelectBackupInformation parameter" { $command | Should -HaveParameter SelectBackupInformation -Type String -Not -Mandatory } It "Should have StopAfterSelectBackupInformation parameter" { - $command | Should -HaveParameter StopAfterSelectBackupInformation -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter StopAfterSelectBackupInformation -Type Switch -Not -Mandatory } It "Should have FormatBackupInformation parameter" { $command | Should -HaveParameter FormatBackupInformation -Type String -Not -Mandatory } It "Should have StopAfterFormatBackupInformation parameter" { - $command | Should -HaveParameter StopAfterFormatBackupInformation -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter StopAfterFormatBackupInformation -Type Switch -Not -Mandatory } It "Should have TestBackupInformation parameter" { $command | Should -HaveParameter TestBackupInformation -Type String -Not -Mandatory } It "Should have StopAfterTestBackupInformation parameter" { - $command | Should -HaveParameter StopAfterTestBackupInformation -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter StopAfterTestBackupInformation -Type Switch -Not -Mandatory } It "Should have PageRestore parameter" { $command | Should -HaveParameter PageRestore -Type Object -Not -Mandatory @@ -153,7 +153,7 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { $command | Should -HaveParameter PageRestoreTailFolder -Type String -Not -Mandatory } It "Should have StopBefore parameter" { - $command | Should -HaveParameter StopBefore -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter StopBefore -Type Switch -Not -Mandatory } It "Should have StopMark parameter" { $command | Should -HaveParameter StopMark -Type String -Not -Mandatory @@ -169,8 +169,8 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' { Describe "Restore-DbaDatabase Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance2 = "localhost" - $script:appveyorlabrepo = "C:\github\appveyor-lab" + $env:instance2 = "localhost" + $env:appveyorlabrepo = "C:\github\appveyor-lab" $DataFolder = 'C:\temp\datafiles' $LogFolder = 'C:\temp\logfiles' New-Item -ItemType Directory -Force -Path $DataFolder @@ -179,11 +179,11 @@ Describe "Restore-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Properly restores a database on the local drive using Path" { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path "$script:appveyorlabrepo\singlerestore\singlerestore.bak" + Get-DbaDatabase -SqlInstance $env:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Restore-DbaDatabase -SqlInstance $env:instance2 -Path "$env:appveyorlabrepo\singlerestore\singlerestore.bak" } It "Should return the proper backup file location" { - $results.BackupFile | Should -Be "$script:appveyorlabrepo\singlerestore\singlerestore.bak" + $results.BackupFile | Should -Be "$env:appveyorlabrepo\singlerestore\singlerestore.bak" } It "Should return successful restore" { $results.RestoreComplete | Should -Be $true @@ -192,7 +192,7 @@ Describe "Restore-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Ensuring warning is thrown if database already exists" { BeforeAll { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path "$script:appveyorlabrepo\singlerestore\singlerestore.bak" -WarningVariable warning -WarningAction SilentlyContinue + $results = Restore-DbaDatabase -SqlInstance $env:instance2 -Path "$env:appveyorlabrepo\singlerestore\singlerestore.bak" -WarningVariable warning -WarningAction SilentlyContinue } It "Should warn" { $warning | Where-Object { $_ -like '*Test-DbaBackupInformation*Database*' } | Should -Match "exists, so WithReplace must be specified" @@ -204,8 +204,8 @@ Describe "Restore-DbaDatabase Integration Tests" -Tag "IntegrationTests" { Context "Database is properly removed again after withreplace test" { BeforeAll { - Get-DbaProcess $script:instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + Get-DbaProcess $env:instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database singlerestore } It "Should say the status was dropped" { $results.Status -eq "Dropped" -or $results.Status -eq $null | Should -Be $true diff --git a/tests/Restore-DbaDbCertificate.Tests.ps1 b/tests/Restore-DbaDbCertificate.Tests.ps1 index fdf7c15611..dff7da965b 100644 --- a/tests/Restore-DbaDbCertificate.Tests.ps1 +++ b/tests/Restore-DbaDbCertificate.Tests.ps1 @@ -30,22 +30,22 @@ Describe "Restore-DbaDbCertificate" { $CommandUnderTest | Should -HaveParameter DecryptionPassword -Type SecureString } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Can create a database certificate" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $masterkey = New-DbaDbMasterKey -SqlInstance $env:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $password = ConvertTo-SecureString -AsPlainText "GoodPass1234!!" -Force - $cert = New-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb -Confirm:$false - $backup = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database tempdb -EncryptionPassword $password -Confirm:$false + $cert = New-DbaDbCertificate -SqlInstance $env:instance1 -Database tempdb -Confirm:$false + $backup = Backup-DbaDbCertificate -SqlInstance $env:instance1 -Certificate $cert.Name -Database tempdb -EncryptionPassword $password -Confirm:$false $cert | Remove-DbaDbCertificate -Confirm:$false } AfterEach { - $null = Remove-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database tempdb -Confirm:$false + $null = Remove-DbaDbCertificate -SqlInstance $env:instance1 -Certificate $cert.Name -Database tempdb -Confirm:$false } AfterAll { @@ -54,7 +54,7 @@ Describe "Restore-DbaDbCertificate" { } It "restores the db cert when passing in a .cer file" { - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $backup.ExportPath -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $env:instance1 -Path $backup.ExportPath -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false $results.Parent.Name | Should -Be 'tempdb' $results.Name | Should -Not -BeNullOrEmpty $results.PrivateKeyEncryptionType | Should -Be "Password" @@ -63,7 +63,7 @@ Describe "Restore-DbaDbCertificate" { It "restores the db cert when passing in a folder" { $folder = Split-Path $backup.ExportPath -Parent - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $folder -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $env:instance1 -Path $folder -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false $results.Parent.Name | Should -Be 'tempdb' $results.Name | Should -Not -BeNullOrEmpty $results.PrivateKeyEncryptionType | Should -Be "Password" @@ -72,7 +72,7 @@ Describe "Restore-DbaDbCertificate" { It "restores the db cert and encrypts with master key" { $folder = Split-Path $backup.ExportPath -Parent - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $folder -Password $password -Database tempdb -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $env:instance1 -Path $folder -Password $password -Database tempdb -Confirm:$false $results.Parent.Name | Should -Be 'tempdb' $results.Name | Should -Not -BeNullOrEmpty $results.PrivateKeyEncryptionType | Should -Be "MasterKey" diff --git a/tests/Restore-DbaDbSnapshot.Tests.ps1 b/tests/Restore-DbaDbSnapshot.Tests.ps1 index 8364b1fef6..415551ce8e 100644 --- a/tests/Restore-DbaDbSnapshot.Tests.ps1 +++ b/tests/Restore-DbaDbSnapshot.Tests.ps1 @@ -40,17 +40,17 @@ Describe "Restore-DbaDbSnapshot Unit Tests" -Tag 'UnitTests' { Describe "Restore-DbaDbSnapshot Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance2 = $script:instance2 + $env:instance2 = $env:instance2 - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $env:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_RestoreSnap1" $db1_snap1 = "dbatoolsci_RestoreSnap1_snapshotted1" $db1_snap2 = "dbatoolsci_RestoreSnap1_snapshotted2" $db2 = "dbatoolsci_RestoreSnap2" $db2_snap1 = "dbatoolsci_RestoreSnap2_snapshotted1" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("ALTER DATABASE $db1 MODIFY FILE ( NAME = N'$($db1)_log', SIZE = 13312KB )") $server.Query("CREATE DATABASE $db2") @@ -61,56 +61,56 @@ Describe "Restore-DbaDbSnapshot Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } Context "Parameters validation" { It "Stops if no Database or Snapshot" { - { Restore-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException } | Should -Throw "You must specify" + { Restore-DbaDbSnapshot -SqlInstance $env:instance2 -EnableException } | Should -Throw "You must specify" } It "Is nice by default" { - { Restore-DbaDbSnapshot -SqlInstance $script:instance2 *> $null } | Should -Not -Throw + { Restore-DbaDbSnapshot -SqlInstance $env:instance2 *> $null } | Should -Not -Throw } } Context "Operations on snapshots" { BeforeEach { - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue } It "Honors the Database parameter, restoring only snapshots of that database" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false -EnableException -Force + $result = Restore-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 -Confirm:$false -EnableException -Force $result.Status | Should -Be "Normal" $result.Name | Should -Be $db2 $server.Query("INSERT INTO [$db1].[dbo].[Example] values ('sample2')") - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Confirm:$false -Force + $result = Restore-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 -Confirm:$false -Force $result.Name | Should -Be $db1 # the other snapshot has been dropped - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 $result.Count | Should -Be 1 # the query doesn't return records inserted before the restore - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "SELECT * FROM [$db1].[dbo].[Example]" -QueryTimeout 10 + $result = Invoke-DbaQuery -SqlInstance $env:instance2 -Query "SELECT * FROM [$db1].[dbo].[Example]" -QueryTimeout 10 $result.id | Should -Be 1 } It "Honors the Snapshot parameter" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 -Confirm:$false -EnableException -Force + $result = Restore-DbaDbSnapshot -SqlInstance $env:instance2 -Snapshot $db1_snap1 -Confirm:$false -EnableException -Force $result.Name | Should -Be $db1 $result.Status | Should -Be "Normal" # the other snapshot has been dropped - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db1 $result.SnapshotOf | Should -Be $db1 $result.Database.Name | Should -Be $db1_snap1 @@ -119,12 +119,12 @@ Describe "Restore-DbaDbSnapshot Integration Tests" -Tag "IntegrationTests" { } It "Stops if multiple snapshot for the same db are passed" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1, $db1_snap2 -Confirm:$false *> $null + $result = Restore-DbaDbSnapshot -SqlInstance $env:instance2 -Snapshot $db1_snap1, $db1_snap2 -Confirm:$false *> $null $result | Should -Be $null } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $env:instance2 -Database $db2 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } diff --git a/tests/Resume-DbaAgDbDataMovement.Tests.ps1 b/tests/Resume-DbaAgDbDataMovement.Tests.ps1 index 85babb3470..b88ad65610 100644 --- a/tests/Resume-DbaAgDbDataMovement.Tests.ps1 +++ b/tests/Resume-DbaAgDbDataMovement.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Resume-DbaAgDbDataMovement" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityDatabase[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -31,15 +31,15 @@ Describe "Resume-DbaAgDbDataMovement" { } BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $env:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance3 $agname = "dbatoolsci_resumeagdb_agroup" $dbname = "dbatoolsci_resumeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup - $null = Get-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname | Suspend-DbaAgDbDataMovement -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaAgDatabase -SqlInstance $env:instance3 -AvailabilityGroup $agname | Suspend-DbaAgDbDataMovement -Confirm:$false } AfterAll { @@ -48,10 +48,10 @@ Describe "Resume-DbaAgDbDataMovement" { } It "resumes data movement" { - $results = Resume-DbaAgDbDataMovement -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Resume-DbaAgDbDataMovement -SqlInstance $env:instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.SynchronizationState | Should -Be 'Synchronized' } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Revoke-DbaAgPermission.Tests.ps1 b/tests/Revoke-DbaAgPermission.Tests.ps1 index b9b0f302e8..89f868361d 100644 --- a/tests/Revoke-DbaAgPermission.Tests.ps1 +++ b/tests/Revoke-DbaAgPermission.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Revoke-DbaAgPermission" { $CommandUnderTest | Should -HaveParameter InputObject -Type Login[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -37,18 +37,18 @@ Describe "Revoke-DbaAgPermission" { } BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue + $null = Invoke-DbaQuery -SqlInstance $env:instance3 -InputFile $env:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue $agname = "dbatoolsci_ag_revoke" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } It "returns results with proper data" { - $results = Get-DbaLogin -SqlInstance $script:instance3 -Login tester | Revoke-DbaAgPermission -Type EndPoint + $results = Get-DbaLogin -SqlInstance $env:instance3 -Login tester | Revoke-DbaAgPermission -Type EndPoint $results.Status | Should -Be 'Success' } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Save-DbaCommunitySoftware.Tests.ps1 b/tests/Save-DbaCommunitySoftware.Tests.ps1 index 955487948e..f18c8da6ed 100644 --- a/tests/Save-DbaCommunitySoftware.Tests.ps1 +++ b/tests/Save-DbaCommunitySoftware.Tests.ps1 @@ -26,7 +26,7 @@ Describe "Save-DbaCommunitySoftware" { It "Should have LocalDirectory as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter LocalDirectory -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Save-DbaKbUpdate.Tests.ps1 b/tests/Save-DbaKbUpdate.Tests.ps1 index 36aa06884c..6e302c5c50 100644 --- a/tests/Save-DbaKbUpdate.Tests.ps1 +++ b/tests/Save-DbaKbUpdate.Tests.ps1 @@ -28,8 +28,8 @@ Describe "Save-DbaKbUpdate" { It "Should have InputObject as a non-mandatory Object[] parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Select-DbaDbSequenceNextValue.Tests.ps1 b/tests/Select-DbaDbSequenceNextValue.Tests.ps1 index 18efe4dddd..76a8704456 100644 --- a/tests/Select-DbaDbSequenceNextValue.Tests.ps1 +++ b/tests/Select-DbaDbSequenceNextValue.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Select-DbaDbSequenceNextValue" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -32,7 +32,7 @@ Describe "Select-DbaDbSequenceNextValue" { Describe "Select-DbaDbSequenceNextValue Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName diff --git a/tests/Set-DbaAgListener.Tests.ps1 b/tests/Set-DbaAgListener.Tests.ps1 index 267bdbe2b4..dc9d2af9c9 100644 --- a/tests/Set-DbaAgListener.Tests.ps1 +++ b/tests/Set-DbaAgListener.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Set-DbaAgListener" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroupListener[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -63,10 +63,10 @@ Describe "Set-DbaAgListener" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } diff --git a/tests/Set-DbaAgReplica.Tests.ps1 b/tests/Set-DbaAgReplica.Tests.ps1 index 678568a5b6..592349d995 100644 --- a/tests/Set-DbaAgReplica.Tests.ps1 +++ b/tests/Set-DbaAgReplica.Tests.ps1 @@ -56,34 +56,34 @@ Describe "Set-DbaAgReplica" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityReplica } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { $agname = "dbatoolsci_arepgroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } It "returns modified results for BackupPriority" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false + $results = Set-DbaAgReplica -SqlInstance $env:instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.BackupPriority | Should -Be 100 } It "returns modified results for SeedingMode" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false + $results = Set-DbaAgReplica -SqlInstance $env:instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.SeedingMode | Should -Be Automatic } It "attempts to add a ReadOnlyRoutingList" { - $null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | - Select-Object -First 1 | + $null = Get-DbaAgReplica -SqlInstance $env:instance3 -AvailabilityGroup $agname | + Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false $warn | Should -Match "does not exist. Only availability" } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Set-DbaAgentAlert.Tests.ps1 b/tests/Set-DbaAgentAlert.Tests.ps1 index cd195fce38..d5e5baa81f 100644 --- a/tests/Set-DbaAgentAlert.Tests.ps1 +++ b/tests/Set-DbaAgentAlert.Tests.ps1 @@ -18,39 +18,39 @@ Describe "Set-DbaAgentAlert" { $CommandUnderTest | Should -HaveParameter NewName -Type String } It "Should have Enabled parameter" { - $CommandUnderTest | Should -HaveParameter Enabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Enabled -Type Switch } It "Should have Disabled parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Alert[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $env:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'dbatoolsci test alert',@message_id=0,@severity=6,@enabled=1,@delay_between_responses=0,@include_event_description_in=0,@category_name=N'[Uncategorized]',@job_id=N'00000000-0000-0000-0000-000000000000'") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $env:instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'dbatoolsci test alert NEW'") } It "changes new alert to disabled" { - $results = Set-DbaAgentAlert -SqlInstance $script:instance2 -Alert 'dbatoolsci test alert' -Disabled + $results = Set-DbaAgentAlert -SqlInstance $env:instance2 -Alert 'dbatoolsci test alert' -Disabled $results.IsEnabled | Should -Be 'False' } It "changes new alert name to dbatoolsci test alert NEW" { - $results = Set-DbaAgentAlert -SqlInstance $script:instance2 -Alert 'dbatoolsci test alert' -NewName 'dbatoolsci test alert NEW' + $results = Set-DbaAgentAlert -SqlInstance $env:instance2 -Alert 'dbatoolsci test alert' -NewName 'dbatoolsci test alert NEW' $results.Name | Should -Be 'dbatoolsci test alert NEW' } } diff --git a/tests/Set-DbaAgentJob.Tests.ps1 b/tests/Set-DbaAgentJob.Tests.ps1 index 604fa4fd78..5bbc266426 100644 --- a/tests/Set-DbaAgentJob.Tests.ps1 +++ b/tests/Set-DbaAgentJob.Tests.ps1 @@ -87,7 +87,7 @@ Describe "Set-DbaAgentJob Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $jobName = "dbatoolsci_test_job" $newJobName = "dbatoolsci_test_job_renamed" $null = New-DbaAgentJob -SqlInstance $server -Job $jobName diff --git a/tests/Set-DbaAgentJobCategory.Tests.ps1 b/tests/Set-DbaAgentJobCategory.Tests.ps1 index 4bea63820c..70621ce6d5 100644 --- a/tests/Set-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Set-DbaAgentJobCategory.Tests.ps1 @@ -30,27 +30,27 @@ Describe "Set-DbaAgentJobCategory" { Context "New Agent Job Category is changed properly" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 } AfterAll { - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest2 -Confirm:$false + Remove-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest2 -Confirm:$false } It "Should create a new job category with the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1 $results.Name | Should -Be "CategoryTest1" $results.CategoryType | Should -Be "LocalJob" } It "Should verify the newly created job category exists" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $newresults = Get-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1 $newresults.Name | Should -Be "CategoryTest1" $newresults.CategoryType | Should -Be "LocalJob" } It "Should change the name of the job category" { - $results = Set-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 -NewName CategoryTest2 + $results = Set-DbaAgentJobCategory -SqlInstance $env:instance2 -Category CategoryTest1 -NewName CategoryTest2 $results.Name | Should -Be "CategoryTest2" } } diff --git a/tests/Set-DbaAgentJobOutputFile.Tests.ps1 b/tests/Set-DbaAgentJobOutputFile.Tests.ps1 index b03b860b3d..1866119f22 100644 --- a/tests/Set-DbaAgentJobOutputFile.Tests.ps1 +++ b/tests/Set-DbaAgentJobOutputFile.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Set-DbaAgentJobOutputFile" { $CommandUnderTest | Should -HaveParameter OutputFile -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Set-DbaAgentJobOwner.Tests.ps1 b/tests/Set-DbaAgentJobOwner.Tests.ps1 index 061156f09c..f2334beabc 100644 --- a/tests/Set-DbaAgentJobOwner.Tests.ps1 +++ b/tests/Set-DbaAgentJobOwner.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Set-DbaAgentJobOwner" { $CommandUnderTest | Should -HaveParameter Login -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Set-DbaAgentJobStep.Tests.ps1 b/tests/Set-DbaAgentJobStep.Tests.ps1 index e29ca120a2..f69d7bffc1 100644 --- a/tests/Set-DbaAgentJobStep.Tests.ps1 +++ b/tests/Set-DbaAgentJobStep.Tests.ps1 @@ -41,8 +41,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance1 = Connect-DbaInstance -SqlInstance $env:instance1 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $job1Instance1 = New-DbaAgentJob -SqlInstance $instance1 -Job "dbatoolsci_job_1_$random" $job1Instance2 = New-DbaAgentJob -SqlInstance $instance2 -Job "dbatoolsci_job_1_$random" diff --git a/tests/Set-DbaAgentOperator.Tests.ps1 b/tests/Set-DbaAgentOperator.Tests.ps1 index fd89a6ff6b..cc242287a6 100644 --- a/tests/Set-DbaAgentOperator.Tests.ps1 +++ b/tests/Set-DbaAgentOperator.Tests.ps1 @@ -54,7 +54,7 @@ Describe "Set-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter WeekdayEndTime -Type String } It "Should have IsFailsafeOperator as a parameter" { - $CommandUnderTest | Should -HaveParameter IsFailsafeOperator -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter IsFailsafeOperator -Type Switch } It "Should have FailsafeNotificationMethod as a parameter" { $CommandUnderTest | Should -HaveParameter FailsafeNotificationMethod -Type String[] @@ -63,13 +63,13 @@ Describe "Set-DbaAgentOperator" { $CommandUnderTest | Should -HaveParameter InputObject -Type Operator[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 -Database msdb + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 -Database msdb $instance2.Invoke("EXEC msdb.dbo.sp_add_operator @name=N'dbatools dba', @enabled=1, @pager_days=0") } diff --git a/tests/Set-DbaAgentSchedule.Tests.ps1 b/tests/Set-DbaAgentSchedule.Tests.ps1 index 3df418bc9b..39e6d68dfb 100644 --- a/tests/Set-DbaAgentSchedule.Tests.ps1 +++ b/tests/Set-DbaAgentSchedule.Tests.ps1 @@ -25,10 +25,10 @@ Describe "Set-DbaAgentSchedule" { $CommandUnderTest | Should -HaveParameter NewName -Type String -Not -Mandatory } It "Should have Enabled parameter" { - $CommandUnderTest | Should -HaveParameter Enabled -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Enabled -Type Switch -Not -Mandatory } It "Should have Disabled parameter" { - $CommandUnderTest | Should -HaveParameter Disabled -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Disabled -Type Switch -Not -Mandatory } It "Should have FrequencyType parameter" { $CommandUnderTest | Should -HaveParameter FrequencyType -Type Object -Not -Mandatory @@ -61,30 +61,30 @@ Describe "Set-DbaAgentSchedule" { $CommandUnderTest | Should -HaveParameter EndTime -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule1' -OwnerLogin 'sa' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule2' -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $env:instance2 -Job 'dbatoolsci_setschedule1' -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $env:instance2 -Job 'dbatoolsci_setschedule2' -OwnerLogin 'sa' $start = (Get-Date).AddDays(2).ToString('yyyyMMdd') $end = (Get-Date).AddDays(4).ToString('yyyyMMdd') $altstart = (Get-Date).AddDays(3).ToString('yyyyMMdd') $altend = (Get-Date).AddDays(5).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule1', 'dbatoolsci_setschedule2' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $env:instance2 -Job 'dbatoolsci_setschedule1', 'dbatoolsci_setschedule2' -Confirm:$false } Context "Should rename schedule" { BeforeAll { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = 'dbatoolsci_oldname' Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '1' @@ -99,15 +99,15 @@ Describe "Set-DbaAgentSchedule" { $null = New-DbaAgentSchedule @variables } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } It "Should rename the schedule" { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $schedules = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_oldname" NewName = "dbatoolsci_newname" Job = 'dbatoolsci_setschedule1' @@ -120,7 +120,7 @@ Describe "Set-DbaAgentSchedule" { } $null = Set-DbaAgentSchedule @variables - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { @@ -133,7 +133,7 @@ Describe "Set-DbaAgentSchedule" { BeforeAll { foreach ($frequency in ('Once', 'AgentStart', 'IdleComputer')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_setschedule1' FrequencyType = $frequency @@ -148,17 +148,17 @@ Describe "Set-DbaAgentSchedule" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } It "Should set schedules to OnIdle and Enabled" { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $schedules = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } foreach ($schedule in $schedules) { foreach ($frequency in ('Once', '1' , 'AgentStart', '64', 'IdleComputer', '128')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "$($schedule.name)" Job = 'dbatoolsci_setschedule1' FrequencyType = $frequency @@ -172,7 +172,7 @@ Describe "Set-DbaAgentSchedule" { } } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { @@ -186,7 +186,7 @@ Describe "Set-DbaAgentSchedule" { BeforeAll { foreach ($frequency in ('Daily', 'Weekly', 'Monthly', 'MonthlyRelative')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_setschedule2' FrequencyType = $frequency @@ -203,17 +203,17 @@ Describe "Set-DbaAgentSchedule" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } It "Should set schedules to MonthlyRelative with updated times" { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $schedules = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } foreach ($schedule in $schedules) { foreach ($frequency in ('Daily', '4', 'Weekly', '8', 'Monthly', '16', 'MonthlyRelative', '32')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "$($schedule.name)" Job = 'dbatoolsci_setschedule2' FrequencyType = $frequency @@ -229,7 +229,7 @@ Describe "Set-DbaAgentSchedule" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { @@ -243,7 +243,7 @@ Describe "Set-DbaAgentSchedule" { BeforeAll { foreach ($FrequencySubdayType in ('Once', 'Time', 'Seconds', 'Second', 'Minutes', 'Minute', 'Hours', 'Hour')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$FrequencySubdayType" Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '1' @@ -259,17 +259,17 @@ Describe "Set-DbaAgentSchedule" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } It "Should set schedules with updated EndDate" { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $schedules = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } foreach ($schedule in $schedules) { foreach ($FrequencySubdayType in ('Once', 'Time', 'Seconds', 'Second', 'Minutes', 'Minute', 'Hours', 'Hour')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "$schedule" Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '6' @@ -284,7 +284,7 @@ Describe "Set-DbaAgentSchedule" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { @@ -297,7 +297,7 @@ Describe "Set-DbaAgentSchedule" { BeforeAll { foreach ($FrequencyRelativeInterval in ('Unused', 'First', 'Second', 'Third', 'Fourth', 'Last')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "dbatoolsci_$FrequencyRelativeInterval" Job = 'dbatoolsci_setschedule2' FrequencyRecurrenceFactor = '1' @@ -312,17 +312,17 @@ Describe "Set-DbaAgentSchedule" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force } It "Should set schedules with updated EndTime" { - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $schedules = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } foreach ($schedule in $schedules) { foreach ($FrequencyRelativeInterval in ('Unused', 'First', 'Second', 'Third', 'Fourth', 'Last')) { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Schedule = "$schedule" Job = 'dbatoolsci_setschedule2' FrequencyRecurrenceFactor = '4' @@ -336,7 +336,7 @@ Describe "Set-DbaAgentSchedule" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $env:instance2 | Where-Object { $_.name -like 'dbatools*' } $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { diff --git a/tests/Set-DbaAgentServer.Tests.ps1 b/tests/Set-DbaAgentServer.Tests.ps1 index 291c6ec070..4e5f9de858 100644 --- a/tests/Set-DbaAgentServer.Tests.ps1 +++ b/tests/Set-DbaAgentServer.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Set-DbaAgentServer" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $testServer = $script:instance2 + $testServer = $env:instance2 $random = Get-Random $mailProfileName = "dbatoolsci_$random" $mailProfile = New-DbaDbMailProfile -SqlInstance $testServer -Name $mailProfileName @@ -91,7 +91,7 @@ Describe "Set-DbaAgentServer" { $CommandUnderTest | Should -HaveParameter WriteOemErrorLog -Type String -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Set-DbaAvailabilityGroup.Tests.ps1 b/tests/Set-DbaAvailabilityGroup.Tests.ps1 index 632e41edb0..07f46d5798 100644 --- a/tests/Set-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Set-DbaAvailabilityGroup.Tests.ps1 @@ -57,24 +57,24 @@ Describe "Set-DbaAvailabilityGroup Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "Sets AG properties" { It "Returns modified results" { - $results = Set-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled:$false + $results = Set-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled:$false $results.AvailabilityGroup | Should -Be $agname $results.DtcSupportEnabled | Should -Be $false } It "Returns newly modified results" { - $results = Set-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled + $results = Set-DbaAvailabilityGroup -SqlInstance $env:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled $results.AvailabilityGroup | Should -Be $agname $results.DtcSupportEnabled | Should -Be $true } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Set-DbaCmConnection.Tests.ps1 b/tests/Set-DbaCmConnection.Tests.ps1 index 92cc8785d9..eade8a01d4 100644 --- a/tests/Set-DbaCmConnection.Tests.ps1 +++ b/tests/Set-DbaCmConnection.Tests.ps1 @@ -12,31 +12,31 @@ Describe "Set-DbaCmConnection" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have UseWindowsCredentials parameter" { - $CommandUnderTest | Should -HaveParameter UseWindowsCredentials -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter UseWindowsCredentials -Type Switch -Not -Mandatory } It "Should have OverrideExplicitCredential parameter" { - $CommandUnderTest | Should -HaveParameter OverrideExplicitCredential -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter OverrideExplicitCredential -Type Switch -Not -Mandatory } It "Should have OverrideConnectionPolicy parameter" { - $CommandUnderTest | Should -HaveParameter OverrideConnectionPolicy -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter OverrideConnectionPolicy -Type Switch -Not -Mandatory } It "Should have DisabledConnectionTypes parameter" { $CommandUnderTest | Should -HaveParameter DisabledConnectionTypes -Type ManagementConnectionType -Not -Mandatory } It "Should have DisableBadCredentialCache parameter" { - $CommandUnderTest | Should -HaveParameter DisableBadCredentialCache -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DisableBadCredentialCache -Type Switch -Not -Mandatory } It "Should have DisableCimPersistence parameter" { - $CommandUnderTest | Should -HaveParameter DisableCimPersistence -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DisableCimPersistence -Type Switch -Not -Mandatory } It "Should have DisableCredentialAutoRegister parameter" { - $CommandUnderTest | Should -HaveParameter DisableCredentialAutoRegister -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter DisableCredentialAutoRegister -Type Switch -Not -Mandatory } It "Should have EnableCredentialFailover parameter" { - $CommandUnderTest | Should -HaveParameter EnableCredentialFailover -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableCredentialFailover -Type Switch -Not -Mandatory } It "Should have WindowsCredentialsAreBad parameter" { - $CommandUnderTest | Should -HaveParameter WindowsCredentialsAreBad -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter WindowsCredentialsAreBad -Type Switch -Not -Mandatory } It "Should have CimWinRMOptions parameter" { $CommandUnderTest | Should -HaveParameter CimWinRMOptions -Type WSManSessionOptions -Not -Mandatory @@ -51,22 +51,22 @@ Describe "Set-DbaCmConnection" { $CommandUnderTest | Should -HaveParameter RemoveBadCredential -Type PSCredential[] -Not -Mandatory } It "Should have ClearBadCredential parameter" { - $CommandUnderTest | Should -HaveParameter ClearBadCredential -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ClearBadCredential -Type Switch -Not -Mandatory } It "Should have ClearCredential parameter" { - $CommandUnderTest | Should -HaveParameter ClearCredential -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ClearCredential -Type Switch -Not -Mandatory } It "Should have ResetCredential parameter" { - $CommandUnderTest | Should -HaveParameter ResetCredential -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ResetCredential -Type Switch -Not -Mandatory } It "Should have ResetConnectionStatus parameter" { - $CommandUnderTest | Should -HaveParameter ResetConnectionStatus -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ResetConnectionStatus -Type Switch -Not -Mandatory } It "Should have ResetConfiguration parameter" { - $CommandUnderTest | Should -HaveParameter ResetConfiguration -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ResetConfiguration -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Set-DbaDbCompatibility.Tests.ps1 b/tests/Set-DbaDbCompatibility.Tests.ps1 index be0a0d32a3..72c0adb30f 100644 --- a/tests/Set-DbaDbCompatibility.Tests.ps1 +++ b/tests/Set-DbaDbCompatibility.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Set-DbaDbCompatibility" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,12 +31,12 @@ Describe "Set-DbaDbCompatibility" { } BeforeAll { - $sqlCn = Connect-DbaInstance -SqlInstance $script:instance2 + $sqlCn = Connect-DbaInstance -SqlInstance $env:instance2 $sqlCn.Refresh() $dbNameNotMatches = "dbatoolscliCompatibilityLevelNotMatch_$(Get-Random -Minimum 600 -Maximum 1100)" $instanceLevel = $sqlCn.Databases['master'].CompatibilityLevel $previousCompatLevel = [int]($instanceLevel.ToString().Trim('Version')) - 10 - Get-DbaProcess -SqlInstance $script:instance2 -Database model | Stop-DbaProcess -Confirm:$false + Get-DbaProcess -SqlInstance $env:instance2 -Database model | Stop-DbaProcess -Confirm:$false $queryNot = "CREATE DATABASE $dbNameNotMatches" $sqlCn.Query($queryNot) Start-Sleep 5 @@ -48,7 +48,7 @@ Describe "Set-DbaDbCompatibility" { } AfterAll { - $sqlCn = Connect-DbaInstance -SqlInstance $script:instance2 + $sqlCn = Connect-DbaInstance -SqlInstance $env:instance2 Remove-DbaDatabase -SqlInstance $sqlCn -Database $dbNameNotMatches -Confirm:$false $sqlCn.ConnectionContext.Disconnect() } diff --git a/tests/Set-DbaDbCompression.Tests.ps1 b/tests/Set-DbaDbCompression.Tests.ps1 index a41a7b95b1..c7ad1a52b1 100644 --- a/tests/Set-DbaDbCompression.Tests.ps1 +++ b/tests/Set-DbaDbCompression.Tests.ps1 @@ -7,7 +7,7 @@ Describe "Set-DbaDbCompression" { . "$PSScriptRoot\constants.ps1" $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("select * into syscols from sys.all_columns select * into sysallparams from sys.all_parameters @@ -16,8 +16,8 @@ Describe "Set-DbaDbCompression" { } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $env:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false } Context "Validate parameters" { @@ -49,20 +49,20 @@ Describe "Set-DbaDbCompression" { $CommandUnderTest | Should -HaveParameter PercentCompression -Type Int32 } It "Should have ForceOfflineRebuilds as a parameter" { - $CommandUnderTest | Should -HaveParameter ForceOfflineRebuilds -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ForceOfflineRebuilds -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command gets results" { BeforeAll { - $InputObject = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname - $results = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 + $InputObject = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname + $results = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 } It "Should contain objects" { $results | Should -Not -BeNullOrEmpty @@ -71,7 +71,7 @@ Describe "Set-DbaDbCompression" { Context "Command handles heaps and clustered indexes" { BeforeAll { - $results = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 + $results = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 } It "Should process object <_.TableName>" -ForEach ($results | Where-Object {$_.IndexId -le 1}) { $_.AlreadyProcessed | Should -BeTrue @@ -80,7 +80,7 @@ Describe "Set-DbaDbCompression" { Context "Command handles nonclustered indexes" { BeforeAll { - $results = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 + $results = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 } It "Should process nonclustered index <_.IndexName>" -ForEach ($results | Where-Object {$_.IndexId -gt 1}) { $_.AlreadyProcessed | Should -BeTrue @@ -93,15 +93,15 @@ Describe "Set-DbaDbCompression" { $server.Databases[$dbname].Tables['syscols'].Rebuild() } It "Shouldn't get any results for $dbname" { - $result = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname -MaxRunTime 5 -PercentCompression 0 + $result = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -ExcludeDatabase $dbname -MaxRunTime 5 -PercentCompression 0 $result.Database | Should -Not -Contain $dbname } } Context "Command can accept InputObject from Test-DbaDbCompression" { BeforeAll { - $InputObject = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname - $results = @(Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 -InputObject $InputObject) + $InputObject = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname + $results = @(Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 -InputObject $InputObject) } It "Should get results" { $results | Should -Not -BeNullOrEmpty @@ -113,8 +113,8 @@ Describe "Set-DbaDbCompression" { Context "Command sets compression to Row for all objects" { BeforeAll { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType Row - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -CompressionType Row + $results = Get-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname } It "The <_.IndexType> for <_.schema>.<_.TableName> is row compressed" -ForEach $results { $_.DataCompression | Should -Be "Row" @@ -123,8 +123,8 @@ Describe "Set-DbaDbCompression" { Context "Command sets compression to Page for all objects" { BeforeAll { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType Page - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -CompressionType Page + $results = Get-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname } It "The <_.IndexType> for <_.schema>.<_.TableName> is page compressed" -ForEach $results { $_.DataCompression | Should -Be "Page" @@ -133,8 +133,8 @@ Describe "Set-DbaDbCompression" { Context "Command sets compression to None for all objects" { BeforeAll { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType None - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -CompressionType None + $results = Get-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname } It "The <_.IndexType> for <_.schema>.<_.TableName> is not compressed" -ForEach $results { $_.DataCompression | Should -Be "None" diff --git a/tests/Set-DbaDbFileGroup.Tests.ps1 b/tests/Set-DbaDbFileGroup.Tests.ps1 index 88e6c0bf26..6da3d3281e 100644 --- a/tests/Set-DbaDbFileGroup.Tests.ps1 +++ b/tests/Set-DbaDbFileGroup.Tests.ps1 @@ -12,8 +12,8 @@ Describe "Set-DbaDbFileGroup" { $fileGroup2Name = "FG2" $fileGroupROName = "FG1RO" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name + $server = Connect-DbaInstance -SqlInstance $env:instance2 + $newDb1 = New-DbaDatabase -SqlInstance $env:instance2 -Name $db1name $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup1Name") $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup2Name") @@ -43,52 +43,52 @@ Describe "Set-DbaDbFileGroup" { $CommandUnderTest | Should -HaveParameter FileGroup -Type String[] -Not -Mandatory } It "Should have Default as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Default -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Default -Type Switch -Not -Mandatory } It "Should have ReadOnly as a switch parameter" { - $CommandUnderTest | Should -HaveParameter ReadOnly -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ReadOnly -Type Switch -Not -Mandatory } It "Should have AutoGrowAllFiles as a switch parameter" { - $CommandUnderTest | Should -HaveParameter AutoGrowAllFiles -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AutoGrowAllFiles -Type Switch -Not -Mandatory } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { It "Sets the options for default, readonly, readwrite, autogrow all files, and not autogrow all files" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name -Default -AutoGrowAllFiles -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup1Name -Default -AutoGrowAllFiles -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.AutogrowAllFiles | Should -Be $true $results.IsDefault | Should -Be $true - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name -AutoGrowAllFiles:$false -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup1Name -AutoGrowAllFiles:$false -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.AutogrowAllFiles | Should -Be $false - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroupROName -ReadOnly -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroupROName -ReadOnly -Confirm:$false $results.Name | Should -Be $fileGroupROName $results.AutogrowAllFiles | Should -Be $false $results.IsDefault | Should -Be $false $results.ReadOnly | Should -Be $true - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name, $fileGroupROName -ReadOnly:$false -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup1Name, $fileGroupROName -ReadOnly:$false -Confirm:$false $results.Name | Should -Be $fileGroup1Name, $fileGroupROName $results.ReadOnly | Should -Be $false, $false } It "A warning is returned when trying to set the options for a filegroup that doesn't exist" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup invalidFileGroupName -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $($script:instance2)" + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup invalidFileGroupName -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $($env:instance2)" } It "A warning is returned when trying to set the options for an empty filegroup" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup2Name -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup $fileGroup2Name is empty on $db1name on $($script:instance2). Before the options can be set there must be at least one file in the filegroup." + $results = Set-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup2Name -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup $fileGroup2Name is empty on $db1name on $($env:instance2). Before the options can be set there must be at least one file in the filegroup." } It "Sets the filegroup options using a database from a pipeline and a filegroup from a pipeline" { @@ -96,11 +96,11 @@ Describe "Set-DbaDbFileGroup" { $results.Name | Should -Be Primary $results.IsDefault | Should -Be $true - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name | Set-DbaDbFileGroup -Default -Confirm:$false + $results = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup1Name | Set-DbaDbFileGroup -Default -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.IsDefault | Should -Be $true - $fg1 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name + $fg1 = Get-DbaDbFileGroup -SqlInstance $env:instance2 -Database $db1name -FileGroup $fileGroup1Name $results = $fg1, $newDb1 | Set-DbaDbFileGroup -FileGroup Primary -AutoGrowAllFiles -Confirm:$false $results.Name | Should -Be $fileGroup1Name, Primary $results.AutoGrowAllFiles | Should -Be $true, $true diff --git a/tests/Set-DbaDbFileGrowth.Tests.ps1 b/tests/Set-DbaDbFileGrowth.Tests.ps1 index 677a9fcae8..923a43da2f 100644 --- a/tests/Set-DbaDbFileGrowth.Tests.ps1 +++ b/tests/Set-DbaDbFileGrowth.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Set-DbaDbFileGrowth" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -38,7 +38,7 @@ Describe "Set-DbaDbFileGrowth Integration Tests" -Tag "IntegrationTests" { } BeforeAll { - $newdb = New-DbaDatabase -SqlInstance $script:instance2 -Name newdb + $newdb = New-DbaDatabase -SqlInstance $env:instance2 -Name newdb } AfterAll { @@ -47,7 +47,7 @@ Describe "Set-DbaDbFileGrowth Integration Tests" -Tag "IntegrationTests" { Context "Should return file information for only newdb" { It "returns the proper info" { - $result = Set-DbaDbFileGrowth -SqlInstance $script:instance2 -Database newdb | Select-Object -First 1 + $result = Set-DbaDbFileGrowth -SqlInstance $env:instance2 -Database newdb | Select-Object -First 1 $result.Database | Should -Be "newdb" $result.GrowthType | Should -Be "kb" } @@ -55,7 +55,7 @@ Describe "Set-DbaDbFileGrowth Integration Tests" -Tag "IntegrationTests" { Context "Supports piping" { It "returns only newdb files" { - $result = Get-DbaDatabase $script:instance2 -Database newdb | Set-DbaDbFileGrowth | Select-Object -First 1 + $result = Get-DbaDatabase $env:instance2 -Database newdb | Set-DbaDbFileGrowth | Select-Object -First 1 $result.Database | Should -Be "newdb" } } diff --git a/tests/Set-DbaDbIdentity.Tests.ps1 b/tests/Set-DbaDbIdentity.Tests.ps1 index ffda963265..109d9e37c0 100644 --- a/tests/Set-DbaDbIdentity.Tests.ps1 +++ b/tests/Set-DbaDbIdentity.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Set-DbaDbIdentity" { $CommandUnderTest | Should -HaveParameter ReSeedValue -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $random = Get-Random $tableName1 = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -42,12 +42,12 @@ Describe "Set-DbaDbIdentity" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } It "Returns standard output with correct properties" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Table', 'Cmd', 'IdentityValue', 'ColumnValue', 'Output' - $result = Set-DbaDbIdentity -SqlInstance $script:instance2 -Database $dbname -Table $tableName1, $tableName2 -Confirm:$false + $result = Set-DbaDbIdentity -SqlInstance $env:instance2 -Database $dbname -Table $tableName1, $tableName2 -Confirm:$false foreach ($prop in $props) { $result[0].PSObject.Properties[$prop] | Should -Not -BeNullOrEmpty @@ -58,7 +58,7 @@ Describe "Set-DbaDbIdentity" { } It "Reseed option returns correct results" { - $result = Set-DbaDbIdentity -SqlInstance $script:instance2 -Database $dbname -Table $tableName2 -ReSeedValue 400 -Confirm:$false + $result = Set-DbaDbIdentity -SqlInstance $env:instance2 -Database $dbname -Table $tableName2 -ReSeedValue 400 -Confirm:$false $result.cmd | Should -Be "DBCC CHECKIDENT('$tableName2', RESEED, 400)" $result.IdentityValue | Should -Be '5.' diff --git a/tests/Set-DbaDbMirror.Tests.ps1 b/tests/Set-DbaDbMirror.Tests.ps1 index 2955ae7d02..aebad9e9dd 100644 --- a/tests/Set-DbaDbMirror.Tests.ps1 +++ b/tests/Set-DbaDbMirror.Tests.ps1 @@ -36,7 +36,7 @@ Describe "Set-DbaDbMirror" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Set-DbaDbOwner.Tests.ps1 b/tests/Set-DbaDbOwner.Tests.ps1 index da879ee2fd..ba4039431f 100644 --- a/tests/Set-DbaDbOwner.Tests.ps1 +++ b/tests/Set-DbaDbOwner.Tests.ps1 @@ -30,30 +30,30 @@ Describe "Set-DbaDbOwner Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter TargetLogin -Type String -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Set-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $svr = Connect-DbaInstance -SqlInstance $script:instance1 + $svr = Connect-DbaInstance -SqlInstance $env:instance1 $owner = "dbatoolssci_owner_$(Get-Random)" $ownertwo = "dbatoolssci_owner2_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $owner -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $ownertwo -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $env:instance1 -Login $owner -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $env:instance1 -Login $ownertwo -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" $dbnametwo = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbnametwo -Owner sa + $null = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbname -Owner sa + $null = New-DbaDatabase -SqlInstance $env:instance1 -Name $dbnametwo -Owner sa } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnametwo -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance1 -Login $owner, $ownertwo -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname, $dbnametwo -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $env:instance1 -Login $owner, $ownertwo -Confirm:$false } Context "Should set the database owner" { It "Sets the database owner on a specific database" { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -Database $dbName -TargetLogin $owner + $results = Set-DbaDbOwner -SqlInstance $env:instance1 -Database $dbName -TargetLogin $owner $results.Owner | Should -Be $owner } It "Check it actually set the owner" { @@ -64,7 +64,7 @@ Describe "Set-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { Context "Sets multiple database owners" { BeforeAll { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -Database $dbName, $dbnametwo -TargetLogin $ownertwo + $results = Set-DbaDbOwner -SqlInstance $env:instance1 -Database $dbName, $dbnametwo -TargetLogin $ownertwo } It "Sets the database owner on multiple databases" { foreach ($r in $results) { @@ -79,7 +79,7 @@ Describe "Set-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { Context "Excludes databases" { BeforeAll { $svr.Databases[$dbName].refresh() - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -ExcludeDatabase $dbnametwo -TargetLogin $owner + $results = Set-DbaDbOwner -SqlInstance $env:instance1 -ExcludeDatabase $dbnametwo -TargetLogin $owner } It "Excludes specified database" { $results.Database | Should -Not -Contain $dbnametwo @@ -92,7 +92,7 @@ Describe "Set-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { Context "Enables input from Get-DbaDatabase" { BeforeAll { $svr.Databases[$dbnametwo].refresh() - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbnametwo + $db = Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbnametwo $results = Set-DbaDbOwner -InputObject $db -TargetLogin $owner } It "Includes specified database" { @@ -105,7 +105,7 @@ Describe "Set-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { Context "Sets database owner to sa" { BeforeAll { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 + $results = Set-DbaDbOwner -SqlInstance $env:instance1 } It "Sets the database owner on multiple databases" { foreach ($r in $results) { diff --git a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 index 40347bd17a..c39cb5a6ea 100644 --- a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 @@ -24,7 +24,7 @@ Describe "Set-DbaDbQueryStoreOption" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have AllDatabases parameter" { - $CommandUnderTest | Should -HaveParameter AllDatabases -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllDatabases -Type Switch -Not -Mandatory } It "Should have State parameter" { $CommandUnderTest | Should -HaveParameter State -Type String[] -Not -Mandatory @@ -66,25 +66,25 @@ Describe "Set-DbaDbQueryStoreOption" { $CommandUnderTest | Should -HaveParameter CustomCapturePolicyStaleThresholdHours -Type Int64 -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Integration Tests" { BeforeAll { - $script:instances = @($script:instance1, $script:instance2) - Get-DbaDatabase -SqlInstance $script:instances | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false - New-DbaDatabase -SqlInstance $script:instances -Name dbatoolsciqs + $env:instances = @($env:instance1, $env:instance2) + Get-DbaDatabase -SqlInstance $env:instances | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false + New-DbaDatabase -SqlInstance $env:instances -Name dbatoolsciqs } AfterAll { - Get-DbaDatabase -SqlInstance $script:instances | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instances | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false } Context "Get some client protocols" { BeforeDiscovery { - $script:instances = @($script:instance1, $script:instance2) + $env:instances = @($env:instance1, $env:instance2) } - It "Should return valid results for <_>" -ForEach $script:instances { + It "Should return valid results for <_>" -ForEach $env:instances { $server = Connect-DbaInstance -SqlInstance $_ $results = Get-DbaDbQueryStoreOption -SqlInstance $server -WarningVariable warning 3>&1 @@ -101,18 +101,18 @@ Describe "Set-DbaDbQueryStoreOption" { } } - It "Should change the specified param to the new value for <_>" -ForEach $script:instances { + It "Should change the specified param to the new value for <_>" -ForEach $env:instances { $results = Set-DbaDbQueryStoreOption -SqlInstance $_ -Database dbatoolsciqs -FlushInterval 901 -State ReadWrite $results.DataFlushIntervalInSeconds | Should -Be 901 } - It "Should only get one database for <_>" -ForEach $script:instances { + It "Should only get one database for <_>" -ForEach $env:instances { $results = Get-DbaDbQueryStoreOption -SqlInstance $_ -Database dbatoolsciqs $results.Count | Should -Be 1 $results.Database | Should -Be 'dbatoolsciqs' } - It "Should not get this one database for <_>" -ForEach $script:instances { + It "Should not get this one database for <_>" -ForEach $env:instances { $results = Get-DbaDbQueryStoreOption -SqlInstance $_ -ExcludeDatabase dbatoolsciqs $result = $results | Where-Object Database -eq dbatoolsciqs $result.Count | Should -Be 0 diff --git a/tests/Set-DbaDbRecoveryModel.Tests.ps1 b/tests/Set-DbaDbRecoveryModel.Tests.ps1 index 1f637a067d..67d501b8c5 100644 --- a/tests/Set-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Set-DbaDbRecoveryModel.Tests.ps1 @@ -25,10 +25,10 @@ Describe "Set-DbaDbRecoveryModel" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] -Not -Mandatory } It "Should have AllDatabases parameter" { - $CommandUnderTest | Should -HaveParameter AllDatabases -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllDatabases -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory @@ -37,28 +37,28 @@ Describe "Set-DbaDbRecoveryModel" { Context "Recovery model is correctly set" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $dbname = "dbatoolsci_recoverymodel" Get-DbaDatabase -SqlInstance $server -Database $dbname | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $dbname") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } It "sets the proper recovery model" { - $results = Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $dbname -RecoveryModel BulkLogged -Confirm:$false + $results = Set-DbaDbRecoveryModel -SqlInstance $env:instance2 -Database $dbname -RecoveryModel BulkLogged -Confirm:$false $results.RecoveryModel | Should -Be "BulkLogged" } It "supports the pipeline" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Set-DbaDbRecoveryModel -RecoveryModel Simple -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $env:instance2 -Database $dbname | Set-DbaDbRecoveryModel -RecoveryModel Simple -Confirm:$false $results.RecoveryModel | Should -Be "Simple" } It "requires Database, ExcludeDatabase or AllDatabases" { $warn = $null - $results = Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false + $results = Set-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Simple -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false $warn | Should -Match "AllDatabases" } } diff --git a/tests/Set-DbaDbSchema.Tests.ps1 b/tests/Set-DbaDbSchema.Tests.ps1 index da6a49535f..00d762e365 100644 --- a/tests/Set-DbaDbSchema.Tests.ps1 +++ b/tests/Set-DbaDbSchema.Tests.ps1 @@ -7,8 +7,8 @@ Describe "Set-DbaDbSchema" { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName @@ -51,7 +51,7 @@ Describe "Set-DbaDbSchema" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Set-DbaDbSequence.Tests.ps1 b/tests/Set-DbaDbSequence.Tests.ps1 index eef1774227..1e2abe518d 100644 --- a/tests/Set-DbaDbSequence.Tests.ps1 +++ b/tests/Set-DbaDbSequence.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Set-DbaDbSequence" { $CommandUnderTest | Should -HaveParameter MaxValue -Type Int64 } It "Should have Cycle as a parameter" { - $CommandUnderTest | Should -HaveParameter Cycle -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Cycle -Type Switch } It "Should have CacheSize as a parameter" { $CommandUnderTest | Should -HaveParameter CacheSize -Type Int32 @@ -42,7 +42,7 @@ Describe "Set-DbaDbSequence" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -50,7 +50,7 @@ Describe "Set-DbaDbSequence" { BeforeAll { . "$PSScriptRoot\constants.ps1" $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName diff --git a/tests/Set-DbaDbState.Tests.ps1 b/tests/Set-DbaDbState.Tests.ps1 index 0369214768..331c385af0 100644 --- a/tests/Set-DbaDbState.Tests.ps1 +++ b/tests/Set-DbaDbState.Tests.ps1 @@ -66,7 +66,7 @@ Describe "Set-DbaDbState Unit Tests" -Tag 'UnitTests' { Describe "Set-DbaDbState Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_dbsetstate_online" $db2 = "dbatoolsci_dbsetstate_offline" $db3 = "dbatoolsci_dbsetstate_emergency" @@ -75,7 +75,7 @@ Describe "Set-DbaDbState Integration Tests" -Tag "IntegrationTests" { $db6 = "dbatoolsci_dbsetstate_multi" $db7 = "dbatoolsci_dbsetstate_rw" $db8 = "dbatoolsci_dbsetstate_ro" - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") $server.Query("CREATE DATABASE $db3") @@ -93,143 +93,143 @@ Describe "Set-DbaDbState Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Set-DbaDbState -Sqlinstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 + $null = Set-DbaDbState -Sqlinstance $env:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 } Context "Parameters validation" { It "Stops if no Database or AllDatabases" { - { Set-DbaDbState -SqlInstance $script:instance2 -EnableException } | Should -Throw "You must specify" + { Set-DbaDbState -SqlInstance $env:instance2 -EnableException } | Should -Throw "You must specify" } It "Is nice by default" { - { Set-DbaDbState -SqlInstance $script:instance2 *> $null } | Should -Not -Throw + { Set-DbaDbState -SqlInstance $env:instance2 *> $null } | Should -Not -Throw } It "Errors out when multiple 'access' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser -EnableException } | Should -Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -MultiUser -RestrictedUser -EnableException } | Should -Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -SingleUser -RestrictedUser -EnableException } | Should -Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -MultiUser -RestrictedUser -EnableException } | Should -Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" } It "Errors out when multiple 'access' params are passed without EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null } | Should -Not -Throw - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -MultiUser -RestrictedUser *> $null } | Should -Not -Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null } | Should -Not -Throw + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -MultiUser -RestrictedUser *> $null } | Should -Not -Throw + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null $result | Should -BeNullOrEmpty } It "Errors out when multiple 'status' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online -EnableException } | Should -Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Online -EnableException } | Should -Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Offline -Online -EnableException } | Should -Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Emergency -Online -EnableException } | Should -Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" } It "Errors out when multiple 'status' params are passed without EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online *> $null } | Should -Not -Throw - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Online *> $null } | Should -Not -Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online *> $null + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Offline -Online *> $null } | Should -Not -Throw + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Emergency -Online *> $null } | Should -Not -Throw + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Offline -Online *> $null $result | Should -BeNullOrEmpty } It "Errors out when multiple 'rw' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite -EnableException } | Should -Throw "You can only specify one of: -ReadOnly,-ReadWrite" + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -ReadOnly -ReadWrite -EnableException } | Should -Throw "You can only specify one of: -ReadOnly,-ReadWrite" } It "Errors out when multiple 'rw' params are passed without EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null } | Should -Not -Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null + { Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null } | Should -Not -Throw + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null $result | Should -BeNullOrEmpty } } Context "Operations on databases" { It "Honors the Database parameter" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db2 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db2 -Emergency -Force $result.DatabaseName | Should -Be $db2 $result.Status | Should -Be 'EMERGENCY' - $results = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1, $db2 -Emergency -Force + $results = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1, $db2 -Emergency -Force $results.Count | Should -Be 2 } It "Honors the ExcludeDatabase parameter" { $alldbs = ($server.Query("select name from sys.databases") | Where-Object Name -notin @($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)).name - $results = Set-DbaDbState -SqlInstance $script:instance2 -ExcludeDatabase $alldbs -Online -Force + $results = Set-DbaDbState -SqlInstance $env:instance2 -ExcludeDatabase $alldbs -Online -Force $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)) $comparison.Count | Should -Be 0 } It "Sets a database as online" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Online -Force + $null = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Online -Force $result.DatabaseName | Should -Be $db1 $result.Status | Should -Be "ONLINE" } It "Sets a database as offline" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db2 -Offline -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db2 -Offline -Force $result.DatabaseName | Should -Be $db2 $result.Status | Should -Be "OFFLINE" } It "Sets a database as emergency" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db3 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db3 -Emergency -Force $result.DatabaseName | Should -Be $db3 $result.Status | Should -Be "EMERGENCY" } It "Sets a database as single_user" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db4 -SingleUser -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db4 -SingleUser -Force $result.DatabaseName | Should -Be $db4 $result.Access | Should -Be "SINGLE_USER" } It "Sets a database as multi_user" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db6 -RestrictedUser -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db6 -MultiUser -Force + $null = Set-DbaDbState -SqlInstance $env:instance2 -Database $db6 -RestrictedUser -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db6 -MultiUser -Force $result.DatabaseName | Should -Be $db6 $result.Access | Should -Be "MULTI_USER" } It "Sets a database as restricted_user" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db5 -RestrictedUser -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db5 -RestrictedUser -Force $result.DatabaseName | Should -Be $db5 $result.Access | Should -Be "RESTRICTED_USER" } It "Sets a database as read_write" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db7 -ReadOnly -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db7 -ReadWrite -Force + $null = Set-DbaDbState -SqlInstance $env:instance2 -Database $db7 -ReadOnly -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db7 -ReadWrite -Force $result.DatabaseName | Should -Be $db7 $result.RW | Should -Be "READ_WRITE" } It "Sets a database as read_only" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db8 -ReadOnly -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db8 -ReadOnly -Force $result.DatabaseName | Should -Be $db8 $result.RW | Should -Be "READ_ONLY" } It "Works when piped from Get-DbaDbState" { - $results = Get-DbaDbState -SqlInstance $script:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force + $results = Get-DbaDbState -SqlInstance $env:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force $results.Count | Should -Be 2 $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db7, $db8)) $comparison.Count | Should -Be 0 } It "Works when piped from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force + $results = Get-DbaDatabase -SqlInstance $env:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force $results.Count | Should -Be 2 $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db7, $db8)) $comparison.Count | Should -Be 0 } It "Has the correct properties" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Emergency -Force $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'DatabaseName', 'RW', 'Status', 'Access', 'Notes', 'Database' ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } It "Has the correct default properties" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $env:instance2 -Database $db1 -Emergency -Force $ExpectedPropsDefault = 'ComputerName', 'InstanceName', 'SqlInstance', 'DatabaseName', 'RW', 'Status', 'Access', 'Notes' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedPropsDefault | Sort-Object) } diff --git a/tests/Set-DbaDefaultPath.Tests.ps1 b/tests/Set-DbaDefaultPath.Tests.ps1 index c114ef71ba..91940e2c4f 100644 --- a/tests/Set-DbaDefaultPath.Tests.ps1 +++ b/tests/Set-DbaDefaultPath.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Set-DbaDefaultPath" { Context "Integration Tests" { BeforeAll { - $results = Set-DbaDefaultPath -SqlInstance $script:instance1 -Type Backup -Path C:\temp + $results = Set-DbaDefaultPath -SqlInstance $env:instance1 -Type Backup -Path C:\temp } It "Data returns a value that contains :\" { $results.Data | Should -Match "\:\\" diff --git a/tests/Set-DbaEndpoint.Tests.ps1 b/tests/Set-DbaEndpoint.Tests.ps1 index bf98bd78ac..7d0e25aba1 100644 --- a/tests/Set-DbaEndpoint.Tests.ps1 +++ b/tests/Set-DbaEndpoint.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Set-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Type -Type String } It "Should have AllEndpoints parameter" { - $CommandUnderTest | Should -HaveParameter AllEndpoints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllEndpoints -Type Switch } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Endpoint[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } diff --git a/tests/Set-DbaErrorLogConfig.Tests.ps1 b/tests/Set-DbaErrorLogConfig.Tests.ps1 index d9dc34e867..3693b34d3a 100644 --- a/tests/Set-DbaErrorLogConfig.Tests.ps1 +++ b/tests/Set-DbaErrorLogConfig.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Set-DbaErrorLogConfig" { $CommandUnderTest | Should -HaveParameter LogSize -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $logfiles = $server.NumberOfLogFiles $logsize = $server.ErrorLogSizeKb @@ -38,7 +38,7 @@ Describe "Set-DbaErrorLogConfig" { $server.ErrorLogSizeKb = 1024 $server.Alter() - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $logfiles2 = $server.NumberOfLogFiles $logsize2 = $server.ErrorLogSizeKb @@ -46,11 +46,11 @@ Describe "Set-DbaErrorLogConfig" { $server.Alter() } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $server.NumberOfLogFiles = $logfiles2 $server.Alter() - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.NumberOfLogFiles = $logfiles $server.ErrorLogSizeKb = $logsize $server.Alter() @@ -58,7 +58,7 @@ Describe "Set-DbaErrorLogConfig" { Context "Apply LogCount to multiple instances" { BeforeAll { - $results = Set-DbaErrorLogConfig -SqlInstance $script:instance2, $script:instance1 -LogCount 8 + $results = Set-DbaErrorLogConfig -SqlInstance $env:instance2, $env:instance1 -LogCount 8 } It 'Returns LogCount set to 8 for each instance' { foreach ($result in $results) { @@ -68,7 +68,7 @@ Describe "Set-DbaErrorLogConfig" { } Context "Apply LogSize to multiple instances" { BeforeAll { - $results = Set-DbaErrorLogConfig -SqlInstance $script:instance2, $script:instance1 -LogSize 100 -WarningAction SilentlyContinue -WarningVariable warn2 + $results = Set-DbaErrorLogConfig -SqlInstance $env:instance2, $env:instance1 -LogSize 100 -WarningAction SilentlyContinue -WarningVariable warn2 } It 'Returns LogSize set to 100 for each instance' { foreach ($result in $results) { diff --git a/tests/Set-DbaExtendedProperty.Tests.ps1 b/tests/Set-DbaExtendedProperty.Tests.ps1 index dd2cea1873..d3a5868114 100644 --- a/tests/Set-DbaExtendedProperty.Tests.ps1 +++ b/tests/Set-DbaExtendedProperty.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Set-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter Value -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference @@ -51,10 +51,10 @@ Describe "Set-DbaExtendedProperty" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type String } It "Should have WhatIf as a parameter" { - $CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter WhatIf -Type Switch } It "Should have Confirm as a parameter" { - $CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Confirm -Type Switch } } } @@ -62,7 +62,7 @@ Describe "Set-DbaExtendedProperty" { Describe "Set-DbaExtendedProperty Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $env:instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName diff --git a/tests/Set-DbaExtendedProtection.Tests.ps1 b/tests/Set-DbaExtendedProtection.Tests.ps1 index 9436a366d2..966500bfa9 100644 --- a/tests/Set-DbaExtendedProtection.Tests.ps1 +++ b/tests/Set-DbaExtendedProtection.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Set-DbaExtendedProtection" { $CommandUnderTest | Should -HaveParameter Value -Type Object } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { It "Default set and returns '0 - Off'" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -EnableException *>$null + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -EnableException *>$null $results.ExtendedProtection | Should -Be "0 - Off" } } @@ -42,7 +42,7 @@ Describe "Set-DbaExtendedProtection" { $ScriptBlock, $EnableException ) - $server = [DbaInstanceParameter[]]$script:instance1 + $server = [DbaInstanceParameter[]]$env:instance1 @{ DisplayName = "SQL Server ($($instance.InstanceName))" AdvancedProperties = @( @@ -56,32 +56,32 @@ Describe "Set-DbaExtendedProtection" { } It "Set explicitly to '0 - Off' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Off -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value Off -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 0' } It "Set explicitly to '0 - Off' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 0 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value 0 -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 0' } It "Set explicitly to '1 - Allowed' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Allowed -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value Allowed -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 1' } It "Set explicitly to '1 - Allowed' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 1 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value 1 -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 1' } It "Set explicitly to '2 - Required' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Required -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value Required -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 2' } It "Set explicitly to '2 - Required' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 2 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $env:instance1 -Value 2 -EnableException -Verbose 4>&1 $results[-1] | Should -Be 'Value: 2' } } diff --git a/tests/Set-DbaLogin.Tests.ps1 b/tests/Set-DbaLogin.Tests.ps1 index e9d91ef966..7646466cae 100644 --- a/tests/Set-DbaLogin.Tests.ps1 +++ b/tests/Set-DbaLogin.Tests.ps1 @@ -11,16 +11,16 @@ Describe "Set-DbaLogin" { $password2 = ConvertTo-SecureString -String "password2A@" -AsPlainText -Force # Create the login - New-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Password $password1 + New-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Password $password1 - New-DbaDatabase -SqlInstance $script:instance2 -Name "testdb1_$random" -Confirm:$false + New-DbaDatabase -SqlInstance $env:instance2 -Name "testdb1_$random" -Confirm:$false $SkipLocalTest = $true # Change to $false to run the local-only tests on a local instance } AfterAll { - Remove-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force - Remove-DbaDatabase -SqlInstance $script:instance2 -Database "testdb1_$random" -Confirm:$false + Remove-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force + Remove-DbaDatabase -SqlInstance $env:instance2 -Database "testdb1_$random" -Confirm:$false } Context "Validate parameters" { @@ -35,20 +35,20 @@ Describe "Set-DbaLogin" { $command | Should -HaveParameter Login -Type String[] -Not -Mandatory $command | Should -HaveParameter SecurePassword -Type Object -Not -Mandatory $command | Should -HaveParameter DefaultDatabase -Type String -Not -Mandatory - $command | Should -HaveParameter Unlock -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter PasswordMustChange -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Unlock -Type Switch -Not -Mandatory + $command | Should -HaveParameter PasswordMustChange -Type Switch -Not -Mandatory $command | Should -HaveParameter NewName -Type String -Not -Mandatory - $command | Should -HaveParameter Disable -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter Enable -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter DenyLogin -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter GrantLogin -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter PasswordPolicyEnforced -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter PasswordExpirationEnabled -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Disable -Type Switch -Not -Mandatory + $command | Should -HaveParameter Enable -Type Switch -Not -Mandatory + $command | Should -HaveParameter DenyLogin -Type Switch -Not -Mandatory + $command | Should -HaveParameter GrantLogin -Type Switch -Not -Mandatory + $command | Should -HaveParameter PasswordPolicyEnforced -Type Switch -Not -Mandatory + $command | Should -HaveParameter PasswordExpirationEnabled -Type Switch -Not -Mandatory $command | Should -HaveParameter AddRole -Type String[] -Not -Mandatory $command | Should -HaveParameter RemoveRole -Type String[] -Not -Mandatory $command | Should -HaveParameter InputObject -Type Login[] -Not -Mandatory - $command | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory - $command | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $command | Should -HaveParameter Force -Type Switch -Not -Mandatory + $command | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Validates -AddRole contains <_>" -ForEach $systemRoles { @@ -62,117 +62,117 @@ Describe "Set-DbaLogin" { Context "Validate input" { It "Validates -Login and -NewName aren't the same" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -NewName testLogin -EnableException } | Should -Throw 'Login name is the same as the value in -NewName' + { Set-DbaLogin -SqlInstance $env:instance2 -Login testlogin -NewName testLogin -EnableException } | Should -Throw 'Login name is the same as the value in -NewName' } It "Validates -Enable and -Disable aren't used together" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -Enable -Disable -EnableException } | Should -Throw 'You cannot use both -Enable and -Disable together' + { Set-DbaLogin -SqlInstance $env:instance2 -Login testlogin -Enable -Disable -EnableException } | Should -Throw 'You cannot use both -Enable and -Disable together' } It "Validates -GrantLogin and -DenyLogin aren't used together" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -GrantLogin -DenyLogin -EnableException } | Should -Throw 'You cannot use both -GrantLogin and -DenyLogin together' + { Set-DbaLogin -SqlInstance $env:instance2 -Login testlogin -GrantLogin -DenyLogin -EnableException } | Should -Throw 'You cannot use both -GrantLogin and -DenyLogin together' } It "Validates -Login is required when using -SqlInstance" { - { Set-DbaLogin -SqlInstance $script:instance2 -EnableException } | Should -Throw 'You must specify a Login when using SqlInstance' + { Set-DbaLogin -SqlInstance $env:instance2 -EnableException } | Should -Throw 'You must specify a Login when using SqlInstance' } It "Validates -Password is a SecureString or PSCredential" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login 'testLogin' -Password 'password' -EnableException } | Should -Throw 'Password must be a PSCredential or SecureString' + { Set-DbaLogin -SqlInstance $env:instance2 -Login 'testLogin' -Password 'password' -EnableException } | Should -Throw 'Password must be a PSCredential or SecureString' } } Context "Verify command functions" { It "Does test login exist" { - $logins = Get-DbaLogin -SqlInstance $script:instance2 | Where-Object { $_.Name -eq "testlogin1_$random" } | Select-Object Name + $logins = Get-DbaLogin -SqlInstance $env:instance2 | Where-Object { $_.Name -eq "testlogin1_$random" } | Select-Object Name $logins.Name | Should -Be "testlogin1_$random" } It "Verifies -NewName doesn't already exist when renaming a login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -NewName 'sa' -EnableException + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -NewName 'sa' -EnableException $result.Notes | Should -Be 'New login name already exists' } It 'Change the password from a SecureString' { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -SecurePassword $password2 + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -SecurePassword $password2 $result.PasswordChanged | Should -Be $true } It 'Changes the password from a PSCredential' { $cred = New-Object System.Management.Automation.PSCredential ("testlogin1_$random", $password2) - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -SecurePassword $cred + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -SecurePassword $cred $result.PasswordChanged | Should -Be $true } It "Change the password from piped Login" { - $login = Get-DbaLogin -Sqlinstance $script:instance2 -Login "testlogin1_$random" + $login = Get-DbaLogin -Sqlinstance $env:instance2 -Login "testlogin1_$random" $result = $login | Set-DbaLogin -SecurePassword $password2 $result.PasswordChanged | Should -Be $true } It "Change the password from InputObject" { - $login = Get-DbaLogin -Sqlinstance $script:instance2 -Login "testlogin1_$random" + $login = Get-DbaLogin -Sqlinstance $env:instance2 -Login "testlogin1_$random" $result = Set-DbaLogin -InputObject $login -SecurePassword $password2 $result.PasswordChanged | Should -Be $true } It "Disable the login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Disable + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -Disable $result.IsDisabled | Should -Be $true } It "Enable the login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Enable + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -Enable $result.IsDisabled | Should -Be $false } It "Deny access to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -DenyLogin + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -DenyLogin $result.DenyLogin | Should -Be $true } It "Grant access to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -GrantLogin + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -GrantLogin $result.DenyLogin | Should -Be $false } It "Enforces password policy on login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced $result.PasswordPolicyEnforced | Should -Be $true } It "Catches errors when password can't be changed" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $result.PasswordPolicyEnforced | Should -Be $true $invalidPassword = ConvertTo-SecureString -String "password1" -AsPlainText -Force - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -SecurePassword $invalidPassword -WarningAction 'SilentlyContinue' + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -SecurePassword $invalidPassword -WarningAction 'SilentlyContinue' $result | Should -Be $null - { Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -SecurePassword $invalidPassword -EnableException } | Should -Throw + { Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -SecurePassword $invalidPassword -EnableException } | Should -Throw } It "Disables enforcing password policy on login" { - $result = Get-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" + $result = Get-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" $result.PasswordPolicyEnforced | Should -Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false $result.PasswordPolicyEnforced | Should -Be $false } It "Add roles to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -AddRole serveradmin, processadmin + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -AddRole serveradmin, processadmin $result.ServerRole | Should -Be "processadmin, serveradmin" } It "Remove roles from login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -RemoveRole serveradmin + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -RemoveRole serveradmin $result.ServerRole | Should -Be "processadmin" } It "Results include multiple changed objects" { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -DenyLogin + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random", "testlogin2_$random" -DenyLogin $results.Count | Should -Be 2 foreach ($r in $results) { $r.DenyLogin | Should -Be $true @@ -180,40 +180,40 @@ Describe "Set-DbaLogin" { } It "DefaultDatabase" { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -DefaultDatabase "testdb1_$random" + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -DefaultDatabase "testdb1_$random" $results.DefaultDatabase | Should -Be "testdb1_$random" } It "PasswordExpirationEnabled" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced $result.PasswordPolicyEnforced | Should -Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordExpirationEnabled -ErrorVariable error + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordExpirationEnabled -ErrorVariable error $result.Count | Should -Be 1 $result.Name | Should -Be "testlogin2_$random" $result.PasswordExpirationEnabled | Should -Be $true $error.Exception | Should -Match "Couldn't set check_expiration = ON because check_policy = OFF for \[testlogin1_$random\]" - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $result.PasswordExpirationEnabled | Should -Be $true $result.PasswordPolicyEnforced | Should -Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false } It "Ensure both password policy settings can be disabled at the same time" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $result.PasswordExpirationEnabled | Should -Be $true $result.PasswordPolicyEnforced | Should -Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false $result.PasswordPolicyEnforced | Should -Be $false } It "Unlock" -Skip:$SkipLocalTest { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $results.PasswordPolicyEnforced | Should -Be $true $invalidPassword = ConvertTo-SecureString -String 'invalid' -AsPlainText -Force @@ -221,64 +221,64 @@ Describe "Set-DbaLogin" { for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $env:instance2 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 } } - $results = Get-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" + $results = Get-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" $results.IsLocked | Should -Be $true - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -Unlock $results | Should -BeNullOrEmpty - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock -Force + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -Unlock -Force $results.IsLocked | Should -Be $false for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $env:instance2 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 } } - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock -SecurePassword $password1 + $results = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -Unlock -SecurePassword $password1 $results.IsLocked | Should -Be $false } It "PasswordMustChange" { - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordMustChange -ErrorVariable error + $changeResult = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordMustChange -ErrorVariable error $changeResult | Should -BeNullOrEmpty $error.Exception | Should -Match "You must specify a password when using the -PasswordMustChange parameter" - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false $result.PasswordPolicyEnforced | Should -Be $false - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.PasswordPolicyEnforced | Should -Be $true $changeResult.PasswordExpirationEnabled | Should -Be $true - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordMustChange -SecurePassword $password1 -ErrorVariable error + $changeResult = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordMustChange -SecurePassword $password1 -ErrorVariable error $changeResult.Count | Should -Be 1 $changeResult.Name | Should -Be "testlogin2_$random" $error.Exception | Should -Match "Unable to change the password and set the must_change option for \[testlogin1_$random\] because check_policy = False and check_expiration = False" - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordMustChange -SecurePassword $password1 -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin1_$random" -PasswordMustChange -SecurePassword $password1 -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.MustChangePassword | Should -Be $true $changeResult.PasswordChanged | Should -Be $true $changeResult.PasswordPolicyEnforced | Should -Be $true $changeResult.PasswordExpirationEnabled | Should -Be $true - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordMustChange -SecurePassword $password1 + $changeResult = Set-DbaLogin -SqlInstance $env:instance2 -Login "testlogin2_$random" -PasswordMustChange -SecurePassword $password1 $changeResult.MustChangePassword | Should -Be $true $changeResult.PasswordChanged | Should -Be $true - $result = Get-DbaLogin -SqlInstance $script:instance2 -MustChangePassword + $result = Get-DbaLogin -SqlInstance $env:instance2 -MustChangePassword $result.Name | Should -Contain "testlogin1_$random" $result.Name | Should -Contain "testlogin2_$random" } diff --git a/tests/Set-DbaMaxDop.Tests.ps1 b/tests/Set-DbaMaxDop.Tests.ps1 index de11b3484d..6815c7fef7 100644 --- a/tests/Set-DbaMaxDop.Tests.ps1 +++ b/tests/Set-DbaMaxDop.Tests.ps1 @@ -32,10 +32,10 @@ Describe "Set-DbaMaxDop" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject -Not -Mandatory } It "Should have AllDatabases parameter" { - $CommandUnderTest | Should -HaveParameter AllDatabases -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllDatabases -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -44,14 +44,14 @@ Describe "Set-DbaMaxDop" { Mock Stop-Function { } -ModuleName dbatools } It "Should Call Stop-Function when -Database, -AllDatabases and -ExcludeDatabase are used together" { - Set-DbaMaxDop -SqlInstance $script:instance1 -MaxDop 12 -Database $singledb -AllDatabases -ExcludeDatabase "master" + Set-DbaMaxDop -SqlInstance $env:instance1 -MaxDop 12 -Database $singledb -AllDatabases -ExcludeDatabase "master" Should -Invoke Stop-Function -Exactly 1 -Scope It -ModuleName dbatools } } Context "Apply to multiple instances" { BeforeAll { - $results = Set-DbaMaxDop -SqlInstance $script:instance1, $script:instance2 -MaxDop 2 + $results = Set-DbaMaxDop -SqlInstance $env:instance1, $env:instance2 -MaxDop 2 } It 'Returns MaxDop 2 for each instance' { $results | ForEach-Object { @@ -62,7 +62,7 @@ Describe "Set-DbaMaxDop" { Context "Connects to 2016+ instance and apply configuration to single database" { BeforeAll { - $results = Set-DbaMaxDop -SqlInstance $script:instance2 -MaxDop 4 -Database $singledb + $results = Set-DbaMaxDop -SqlInstance $env:instance2 -MaxDop 4 -Database $singledb } It 'Returns 4 for each database' { $results | ForEach-Object { @@ -73,7 +73,7 @@ Describe "Set-DbaMaxDop" { Context "Connects to 2016+ instance and apply configuration to multiple databases" { BeforeAll { - $results = Set-DbaMaxDop -SqlInstance $script:instance2 -MaxDop 8 -Database $dbs + $results = Set-DbaMaxDop -SqlInstance $env:instance2 -MaxDop 8 -Database $dbs } It 'Returns 8 for each database' { $results | ForEach-Object { @@ -84,8 +84,8 @@ Describe "Set-DbaMaxDop" { Context "Piping from Test-DbaMaxDop works" { BeforeAll { - $results = Test-DbaMaxDop -SqlInstance $script:instance2 | Set-DbaMaxDop -MaxDop 4 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $results = Test-DbaMaxDop -SqlInstance $env:instance2 | Set-DbaMaxDop -MaxDop 4 + $server = Connect-DbaInstance -SqlInstance $env:instance2 } It 'Command returns output' { $results.CurrentInstanceMaxDop | Should -Not -BeNullOrEmpty @@ -98,8 +98,8 @@ Describe "Set-DbaMaxDop" { Context "Piping SqlInstance name works" { BeforeAll { - $results = $script:instance2 | Set-DbaMaxDop -MaxDop 2 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $results = $env:instance2 | Set-DbaMaxDop -MaxDop 2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 } It 'Command returns output' { $results.CurrentInstanceMaxDop | Should -Not -BeNullOrEmpty diff --git a/tests/Set-DbaMaxMemory.Tests.ps1 b/tests/Set-DbaMaxMemory.Tests.ps1 index ecbe2345df..b3745d444b 100644 --- a/tests/Set-DbaMaxMemory.Tests.ps1 +++ b/tests/Set-DbaMaxMemory.Tests.ps1 @@ -6,13 +6,13 @@ Describe "Set-DbaMaxMemory" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $inst1CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $script:instance1).MaxValue - $inst2CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $script:instance2).MaxValue + $inst1CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $env:instance1).MaxValue + $inst2CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $env:instance2).MaxValue } AfterAll { - $null = Set-DbaMaxMemory -SqlInstance $script:instance1 -Max $inst1CurrentMaxValue - $null = Set-DbaMaxMemory -SqlInstance $script:instance2 -Max $inst2CurrentMaxValue + $null = Set-DbaMaxMemory -SqlInstance $env:instance1 -Max $inst1CurrentMaxValue + $null = Set-DbaMaxMemory -SqlInstance $env:instance2 -Max $inst2CurrentMaxValue } Context "Validate parameters" { @@ -32,13 +32,13 @@ Describe "Set-DbaMaxMemory" { $CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Connects to multiple instances" { BeforeAll { - $results = Set-DbaMaxMemory -SqlInstance $script:instance1, $script:instance2 -Max 1024 + $results = Set-DbaMaxMemory -SqlInstance $env:instance1, $env:instance2 -Max 1024 } It 'Returns 1024 for each instance' { foreach ($result in $results) { diff --git a/tests/Set-DbaNetworkCertificate.Tests.ps1 b/tests/Set-DbaNetworkCertificate.Tests.ps1 index a635d86edc..271e1a173c 100644 --- a/tests/Set-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Set-DbaNetworkCertificate.Tests.ps1 @@ -22,10 +22,10 @@ Describe "Set-DbaNetworkCertificate" { $CommandUnderTest | Should -HaveParameter Thumbprint -Type String } It "Should have RestartService as a switch parameter" { - $CommandUnderTest | Should -HaveParameter RestartService -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter RestartService -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -35,11 +35,11 @@ Describe "Set-DbaNetworkCertificate" { # BeforeAll { # # Setup code for integration tests # } - # + # # It "Should set network certificate correctly" { # # Test implementation # } - # + # # AfterAll { # # Cleanup code for integration tests # } diff --git a/tests/Set-DbaNetworkConfiguration.Tests.ps1 b/tests/Set-DbaNetworkConfiguration.Tests.ps1 index 1e6f0ed73a..87f5cfc648 100644 --- a/tests/Set-DbaNetworkConfiguration.Tests.ps1 +++ b/tests/Set-DbaNetworkConfiguration.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Set-DbaNetworkConfiguration" { Context "Command works with piped input" { BeforeAll { - $netConf = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 + $netConf = Get-DbaNetworkConfiguration -SqlInstance $env:instance2 $netConf.TcpIpProperties.KeepAlive = 60000 $results = $netConf | Set-DbaNetworkConfiguration -Confirm:$false -WarningAction SilentlyContinue } @@ -57,7 +57,7 @@ Describe "Set-DbaNetworkConfiguration" { } AfterAll { - $netConf = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 + $netConf = Get-DbaNetworkConfiguration -SqlInstance $env:instance2 $netConf.TcpIpProperties.KeepAlive = 30000 $null = $netConf | Set-DbaNetworkConfiguration -Confirm:$false -WarningAction SilentlyContinue } @@ -65,11 +65,11 @@ Describe "Set-DbaNetworkConfiguration" { Context "Command works with commandline input" { BeforeAll { - $netConf = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 + $netConf = Get-DbaNetworkConfiguration -SqlInstance $env:instance2 if ($netConf.NamedPipesEnabled) { - $results = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue + $results = Set-DbaNetworkConfiguration -SqlInstance $env:instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } else { - $results = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue + $results = Set-DbaNetworkConfiguration -SqlInstance $env:instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } } @@ -83,9 +83,9 @@ Describe "Set-DbaNetworkConfiguration" { AfterAll { if ($netConf.NamedPipesEnabled) { - $null = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue + $null = Set-DbaNetworkConfiguration -SqlInstance $env:instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } else { - $null = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue + $null = Set-DbaNetworkConfiguration -SqlInstance $env:instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } } } diff --git a/tests/Set-DbaPowerPlan.Tests.ps1 b/tests/Set-DbaPowerPlan.Tests.ps1 index 9443afc895..b635470eb7 100644 --- a/tests/Set-DbaPowerPlan.Tests.ps1 +++ b/tests/Set-DbaPowerPlan.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Set-DbaPowerPlan" { $CommandUnderTest | Should -HaveParameter PowerPlan -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Set-DbaPrivilege.Tests.ps1 b/tests/Set-DbaPrivilege.Tests.ps1 index 1e29ebf67f..75369801e6 100644 --- a/tests/Set-DbaPrivilege.Tests.ps1 +++ b/tests/Set-DbaPrivilege.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Set-DbaPrivilege" { $CommandUnderTest | Should -HaveParameter Type -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have User as a parameter" { $CommandUnderTest | Should -HaveParameter User -Type String diff --git a/tests/Set-DbaResourceGovernor.Tests.ps1 b/tests/Set-DbaResourceGovernor.Tests.ps1 index 8be06a4640..22e092e927 100644 --- a/tests/Set-DbaResourceGovernor.Tests.ps1 +++ b/tests/Set-DbaResourceGovernor.Tests.ps1 @@ -40,34 +40,34 @@ Describe "Set-DbaResourceGovernor" { BEGIN RETURN DB_NAME(); END;" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $createUDFQuery -Database "master" - Set-DbaResourceGovernor -SqlInstance $script:instance2 -Disabled -Confirm:$false + Invoke-DbaQuery -SqlInstance $env:instance2 -Query $createUDFQuery -Database "master" + Set-DbaResourceGovernor -SqlInstance $env:instance2 -Disabled -Confirm:$false } It "enables resource governor" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled -Confirm:$false $results.Enabled | Should -Be $true } It "disables resource governor" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Disabled -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Disabled -Confirm:$false $results.Enabled | Should -Be $false } It "modifies resource governor classifier function" { $qualifiedClassifierFunction = "[dbo].[$classifierFunction]" - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -ClassifierFunction $classifierFunction -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $env:instance2 -ClassifierFunction $classifierFunction -Confirm:$false $results.ClassifierFunction | Should -Be $qualifiedClassifierFunction } It "removes resource governor classifier function" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -ClassifierFunction 'NULL' -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $env:instance2 -ClassifierFunction 'NULL' -Confirm:$false $results.ClassifierFunction | Should -Be '' } AfterAll { $dropUDFQuery = "DROP FUNCTION [dbo].[$classifierFunction];" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $dropUDFQuery -Database "master" + Invoke-DbaQuery -SqlInstance $env:instance2 -Query $dropUDFQuery -Database "master" } } } diff --git a/tests/Set-DbaRgResourcePool.Tests.ps1 b/tests/Set-DbaRgResourcePool.Tests.ps1 index a0a99d3173..0973cd492b 100644 --- a/tests/Set-DbaRgResourcePool.Tests.ps1 +++ b/tests/Set-DbaRgResourcePool.Tests.ps1 @@ -41,26 +41,26 @@ Describe "Set-DbaRgResourcePool" { $CommandUnderTest | Should -HaveParameter MaximumProcesses -Type Int32 -Not -Mandatory } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Sets a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -68,7 +68,7 @@ Describe "Set-DbaRgResourcePool" { CapCpuPercent = 100 } $null = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Set-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 + $result2 = Set-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 $result2.MaximumCpuPercentage | Should -Be 99 } @@ -76,7 +76,7 @@ Describe "Set-DbaRgResourcePool" { It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -85,7 +85,7 @@ Describe "Set-DbaRgResourcePool" { Type = "Internal" } $splatSetResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 99 MaximumMemoryPercentage = 99 @@ -112,7 +112,7 @@ Describe "Set-DbaRgResourcePool" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -120,7 +120,7 @@ Describe "Set-DbaRgResourcePool" { Type = "External" } $splatSetResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 99 MaximumMemoryPercentage = 99 @@ -140,7 +140,7 @@ Describe "Set-DbaRgResourcePool" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -149,7 +149,7 @@ Describe "Set-DbaRgResourcePool" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) + $result = Get-DbaRgResourcePool -SqlInstance $env:instance2 | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) ($result | Where-Object Name -eq $resourcePoolName).MaximumCpuPercentage = 99 ($result | Where-Object Name -eq $resourcePoolName2).MaximumCpuPercentage = 98 $result2 = $result | Set-DbaRgResourcePool @@ -161,7 +161,7 @@ Describe "Set-DbaRgResourcePool" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -170,8 +170,8 @@ Describe "Set-DbaRgResourcePool" { } $null = New-DbaRgResourcePool @splatNewResourcePool - $null = Set-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 -SkipReconfigure - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $null = Set-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 -SkipReconfigure + $result = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result.ReconfigurePending | Should -Be $true } @@ -179,8 +179,8 @@ Describe "Set-DbaRgResourcePool" { AfterEach { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External } } } diff --git a/tests/Set-DbaRgWorkloadGroup.Tests.ps1 b/tests/Set-DbaRgWorkloadGroup.Tests.ps1 index 633cc480f2..056ee87049 100644 --- a/tests/Set-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Set-DbaRgWorkloadGroup.Tests.ps1 @@ -43,26 +43,26 @@ Describe "Set-DbaRgWorkloadGroup" { $CommandUnderTest | Should -HaveParameter GroupMaximumRequests -Type Int32 -Not -Mandatory } It "Should have SkipReconfigure parameter" { - $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter SkipReconfigure -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type WorkloadGroup[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $env:instance2 -Enabled } It "Sets a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $resourcePoolType = "Internal" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = $resourcePoolType @@ -75,7 +75,7 @@ Describe "Set-DbaRgWorkloadGroup" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = $resourcePoolType @@ -88,7 +88,7 @@ Describe "Set-DbaRgWorkloadGroup" { } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $env:instance2 $newWorkloadGroup | Should -Not -BeNullOrEmpty $resGov.ReconfigurePending | Should -BeFalse @@ -105,13 +105,13 @@ Describe "Set-DbaRgWorkloadGroup" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -124,7 +124,7 @@ Describe "Set-DbaRgWorkloadGroup" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -138,10 +138,10 @@ Describe "Set-DbaRgWorkloadGroup" { $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $env:instance2 - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName + $null = Remove-DbaRgResourcePool -SqlInstance $env:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup | Should -Not -BeNullOrEmpty $resGov.ReconfigurePending | Should -BeFalse @@ -157,7 +157,7 @@ Describe "Set-DbaRgWorkloadGroup" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) Importance = "MEDIUM" RequestMaximumMemoryGrantPercentage = 25 @@ -168,7 +168,7 @@ Describe "Set-DbaRgWorkloadGroup" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) ResourcePool = "default" Importance = "HIGH" @@ -180,7 +180,7 @@ Describe "Set-DbaRgWorkloadGroup" { } $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $env:instance2 $newWorkloadGroups | Should -Not -BeNullOrEmpty $resGov.ReconfigurePending | Should -BeFalse @@ -197,7 +197,7 @@ Describe "Set-DbaRgWorkloadGroup" { $oldGroupMaximumRequests = 10 $newGroupMaximumRequests = 20 $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" GroupMaximumRequests = $oldGroupMaximumRequests @@ -213,13 +213,13 @@ Describe "Set-DbaRgWorkloadGroup" { It "Skips Resource Governor reconfiguration" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName SkipReconfigure = $false Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = "Internal" @@ -228,18 +228,18 @@ Describe "Set-DbaRgWorkloadGroup" { } $null = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result.ReconfigurePending | Should -BeFalse $null = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $result2 = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result2 = Get-DbaResourceGovernor -SqlInstance $env:instance2 $result2.ReconfigurePending | Should -BeTrue } AfterEach { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $null = Remove-DbaRgWorkloadGroup -SqlInstance $env:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 } } } diff --git a/tests/Set-DbaSpConfigure.Tests.ps1 b/tests/Set-DbaSpConfigure.Tests.ps1 index 1aea043e41..19e83e70df 100644 --- a/tests/Set-DbaSpConfigure.Tests.ps1 +++ b/tests/Set-DbaSpConfigure.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Set-DbaSpConfigure" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,25 +31,25 @@ Describe "Set-DbaSpConfigure" { } BeforeAll { - $remotequerytimeout = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $remotequerytimeout = (Get-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue $newtimeout = $remotequerytimeout + 1 } It "changes the remote query timeout from $remotequerytimeout to $newtimeout" { - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $newtimeout + $results = Set-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteQueryTimeout -Value $newtimeout $results.PreviousValue | Should -Be $remotequerytimeout $results.NewValue | Should -Be $newtimeout } It "changes the remote query timeout from $newtimeout to $remotequerytimeout" { - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout + $results = Set-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout $results.PreviousValue | Should -Be $newtimeout $results.NewValue | Should -Be $remotequerytimeout } It "returns a warning when if the new value is the same as the old" { $warning = $null - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout -WarningVariable warning -WarningAction SilentlyContinue + $results = Set-DbaSpConfigure -SqlInstance $env:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout -WarningVariable warning -WarningAction SilentlyContinue $warning | Should -Match "existing" } } diff --git a/tests/Set-DbaStartupParameter.Tests.ps1 b/tests/Set-DbaStartupParameter.Tests.ps1 index de6bd367b7..feb9be3268 100644 --- a/tests/Set-DbaStartupParameter.Tests.ps1 +++ b/tests/Set-DbaStartupParameter.Tests.ps1 @@ -6,8 +6,8 @@ Describe "Set-DbaStartupParameter" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $defaultInstance = $script:instance1 - $namedInstance = $script:instance2 + $defaultInstance = $env:instance1 + $namedInstance = $env:instance2 $SkipLocalTest = $true # Change to $false to run the tests on a local instance. } diff --git a/tests/Set-DbaTcpPort.Tests.ps1 b/tests/Set-DbaTcpPort.Tests.ps1 index 961d61da30..d2159715b3 100644 --- a/tests/Set-DbaTcpPort.Tests.ps1 +++ b/tests/Set-DbaTcpPort.Tests.ps1 @@ -24,41 +24,41 @@ Describe "Set-DbaTcpPort" { $CommandUnderTest | Should -HaveParameter IpAddress -Type IPAddress[] } It "Should have Force as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $oldPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $oldPort = (Get-DbaTcpPort -SqlInstance $env:instance2).Port $newPort = $oldPort + 1000 - $instance = [DbaInstance]$script:instance2 + $instance = [DbaInstance]$env:instance2 } It "Should change the port" { - $result = Set-DbaTcpPort -SqlInstance $script:instance2 -Port $newPort -Confirm:$false + $result = Set-DbaTcpPort -SqlInstance $env:instance2 -Port $newPort -Confirm:$false $result.Changes | Should -Match 'Changed TcpPort' $result.RestartNeeded | Should -Be $true $result.Restarted | Should -Be $false $null = Restart-DbaService -ComputerName $instance.ComputerName -InstanceName $instance.InstanceName -Type Engine -Force - $setPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $setPort = (Get-DbaTcpPort -SqlInstance $env:instance2).Port $setPort | Should -Be $newPort } It "Should change the port back to the old value" { - $result = Set-DbaTcpPort -SqlInstance $script:instance2 -Port $oldPort -Confirm:$false + $result = Set-DbaTcpPort -SqlInstance $env:instance2 -Port $oldPort -Confirm:$false $result.Changes | Should -Match 'Changed TcpPort' $result.RestartNeeded | Should -Be $true $result.Restarted | Should -Be $false $null = Restart-DbaService -ComputerName $instance.ComputerName -InstanceName $instance.InstanceName -Type Engine -Force - $setPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $setPort = (Get-DbaTcpPort -SqlInstance $env:instance2).Port $setPort | Should -Be $oldPort } } diff --git a/tests/Set-DbaTempDbConfig.Tests.ps1 b/tests/Set-DbaTempDbConfig.Tests.ps1 index fec507e11c..735f09b56b 100644 --- a/tests/Set-DbaTempDbConfig.Tests.ps1 +++ b/tests/Set-DbaTempDbConfig.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Set-DbaTempDbConfig" { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $tempdbDataFilePhysicalName = $server.Databases['tempdb'].Query('SELECT physical_name as PhysicalName FROM sys.database_files WHERE file_id = 1').PhysicalName $tempdbDataFilePath = Split-Path $tempdbDataFilePhysicalName @@ -61,24 +61,24 @@ Describe "Set-DbaTempDbConfig" { $CommandUnderTest | Should -HaveParameter OutFile -Type String } It "Should have OutputScriptOnly as a parameter" { - $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter OutputScriptOnly -Type Switch } It "Should have DisableGrowth as a parameter" { - $CommandUnderTest | Should -HaveParameter DisableGrowth -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter DisableGrowth -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { It "test with an invalid data dir" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileSize 1024 -DataPath "$tempdbDataFilePath\invalidDir_$random" -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $env:instance1 -DataFileSize 1024 -DataPath "$tempdbDataFilePath\invalidDir_$random" -OutputScriptOnly $result | Should -BeNullOrEmpty } It "valid sql is produced with nearly all options set and a single data directory" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 2048 -LogFileSize 512 -DataFileGrowth 1024 -LogFileGrowth 512 -DataPath "$tempdbDataFilePath\DataDir0_$random" -LogPath "$tempdbDataFilePath\Log_$random" -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $env:instance1 -DataFileCount 8 -DataFileSize 2048 -LogFileSize 512 -DataFileGrowth 1024 -LogFileGrowth 512 -DataPath "$tempdbDataFilePath\DataDir0_$random" -LogPath "$tempdbDataFilePath\Log_$random" -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } $sqlStatements.Count | Should -Be 9 @@ -87,7 +87,7 @@ Describe "Set-DbaTempDbConfig" { } It "valid sql is produced with -DisableGrowth" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 1024 -LogFileSize 512 -DisableGrowth -DataPath $tempdbDataFilePath -LogPath $tempdbDataFilePath -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $env:instance1 -DataFileCount 8 -DataFileSize 1024 -LogFileSize 512 -DisableGrowth -DataPath $tempdbDataFilePath -LogPath $tempdbDataFilePath -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } $sqlStatements.Count | Should -Be 9 @@ -97,7 +97,7 @@ Describe "Set-DbaTempDbConfig" { It "multiple data directories are supported" { $dataDirLocations = "$tempdbDataFilePath\DataDir0_$random", "$tempdbDataFilePath\DataDir1_$random", "$tempdbDataFilePath\DataDir2_$random" - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 1024 -DataPath $dataDirLocations -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $env:instance1 -DataFileCount 8 -DataFileSize 1024 -DataPath $dataDirLocations -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } # check the round robin assignment of files to data dir locations diff --git a/tests/Set-DbatoolsConfig.Tests.ps1 b/tests/Set-DbatoolsConfig.Tests.ps1 index 0c7306f335..aa8b5aeb0b 100644 --- a/tests/Set-DbatoolsConfig.Tests.ps1 +++ b/tests/Set-DbatoolsConfig.Tests.ps1 @@ -32,35 +32,35 @@ Describe "Set-DbatoolsConfig" { It "Should have Handler as a non-mandatory ScriptBlock parameter" { $CommandUnderTest | Should -HaveParameter Handler -Type ScriptBlock -Not -Mandatory } - It "Should have Hidden as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Hidden -Type SwitchParameter -Not -Mandatory + It "Should have Hidden as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Hidden -Type Switch -Not -Mandatory } - It "Should have Default as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Default -Type SwitchParameter -Not -Mandatory + It "Should have Default as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Default -Type Switch -Not -Mandatory } - It "Should have Initialize as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Initialize -Type SwitchParameter -Not -Mandatory + It "Should have Initialize as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Initialize -Type Switch -Not -Mandatory } - It "Should have SimpleExport as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter SimpleExport -Type SwitchParameter -Not -Mandatory + It "Should have SimpleExport as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter SimpleExport -Type Switch -Not -Mandatory } - It "Should have ModuleExport as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter ModuleExport -Type SwitchParameter -Not -Mandatory + It "Should have ModuleExport as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter ModuleExport -Type Switch -Not -Mandatory } - It "Should have DisableValidation as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter DisableValidation -Type SwitchParameter -Not -Mandatory + It "Should have DisableValidation as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter DisableValidation -Type Switch -Not -Mandatory } - It "Should have DisableHandler as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter DisableHandler -Type SwitchParameter -Not -Mandatory + It "Should have DisableHandler as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter DisableHandler -Type Switch -Not -Mandatory } - It "Should have PassThru as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter PassThru -Type SwitchParameter -Not -Mandatory + It "Should have PassThru as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter PassThru -Type Switch -Not -Mandatory } - It "Should have Register as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Register -Type SwitchParameter -Not -Mandatory + It "Should have Register as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Register -Type Switch -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 index e2753c57eb..b760da9c07 100644 --- a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 +++ b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 @@ -11,19 +11,19 @@ Describe "Set-DbatoolsInsecureConnection" { BeforeAll { $CommandUnderTest = Get-Command Set-DbatoolsInsecureConnection } - It "Should have SessionOnly as a non-mandatory SwitchParameter" { + It "Should have SessionOnly as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter SessionOnly -Type Switch -Not -Mandatory } It "Should have Scope as a non-mandatory ConfigScope parameter" { $CommandUnderTest | Should -HaveParameter Scope -Type ConfigScope -Not -Mandatory } - It "Should have Register as a non-mandatory SwitchParameter" { + It "Should have Register as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter Register -Type Switch -Not -Mandatory } - It "Should have Verbose as a non-mandatory SwitchParameter" { + It "Should have Verbose as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } - It "Should have Debug as a non-mandatory SwitchParameter" { + It "Should have Debug as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a non-mandatory ActionPreference parameter" { diff --git a/tests/Set-DbatoolsPath.Tests.ps1 b/tests/Set-DbatoolsPath.Tests.ps1 index 4c5cbdddda..ceb0598c2f 100644 --- a/tests/Set-DbatoolsPath.Tests.ps1 +++ b/tests/Set-DbatoolsPath.Tests.ps1 @@ -17,17 +17,17 @@ Describe "Set-DbatoolsPath" { It "Should have Path as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter Path -Type String -Not -Mandatory } - It "Should have Register as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Register -Type SwitchParameter -Not -Mandatory + It "Should have Register as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Register -Type Switch -Not -Mandatory } It "Should have Scope as a non-mandatory ConfigScope parameter" { $CommandUnderTest | Should -HaveParameter Scope -Type ConfigScope -Not -Mandatory } - It "Should have Verbose as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + It "Should have Verbose as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } - It "Should have Debug as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + It "Should have Debug as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction as a non-mandatory ActionPreference parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Show-DbaDbList.Tests.ps1 b/tests/Show-DbaDbList.Tests.ps1 index d1d6777cc2..b1facb9b39 100644 --- a/tests/Show-DbaDbList.Tests.ps1 +++ b/tests/Show-DbaDbList.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Show-DbaDbList" { $CommandUnderTest | Should -HaveParameter DefaultDb -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -31,7 +31,7 @@ Describe "Show-DbaDbList" { . (Join-Path $PSScriptRoot 'constants.ps1') } - Context "Connects and shows database list" -ForEach $script:instance1, $script:instance2 { + Context "Connects and shows database list" -ForEach $env:instance1, $env:instance2 { BeforeAll { $server = Connect-DbaInstance -SqlInstance $_ } diff --git a/tests/Show-DbaInstanceFileSystem.Tests.ps1 b/tests/Show-DbaInstanceFileSystem.Tests.ps1 index 389f2eede1..daa185002a 100644 --- a/tests/Show-DbaInstanceFileSystem.Tests.ps1 +++ b/tests/Show-DbaInstanceFileSystem.Tests.ps1 @@ -12,13 +12,13 @@ Describe "Show-DbaInstanceFileSystem" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have Verbose as a parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch } It "Should have Debug as a parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Debug -Type Switch } It "Should have ErrorAction as a parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference diff --git a/tests/Start-DbaAgentJob.Tests.ps1 b/tests/Start-DbaAgentJob.Tests.ps1 index 9af8fff12c..7484c7d749 100644 --- a/tests/Start-DbaAgentJob.Tests.ps1 +++ b/tests/Start-DbaAgentJob.Tests.ps1 @@ -24,13 +24,13 @@ Describe "Start-DbaAgentJob" { $CommandUnderTest | Should -HaveParameter InputObject -Type Job[] } It "Should have AllJobs parameter" { - $CommandUnderTest | Should -HaveParameter AllJobs -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllJobs -Type Switch } It "Should have Wait parameter" { - $CommandUnderTest | Should -HaveParameter Wait -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Wait -Type Switch } It "Should have Parallel parameter" { - $CommandUnderTest | Should -HaveParameter Parallel -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Parallel -Type Switch } It "Should have WaitPeriod parameter" { $CommandUnderTest | Should -HaveParameter WaitPeriod -Type Int32 @@ -39,7 +39,7 @@ Describe "Start-DbaAgentJob" { $CommandUnderTest | Should -HaveParameter SleepPeriod -Type Int32 } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -49,16 +49,16 @@ Describe "Start-DbaAgentJob" { $jobs = "dbatoolsci_job_$(Get-Random)", "dbatoolsci_job_$(Get-Random)", "dbatoolsci_job_$(Get-Random)" $jobName1, $jobName2, $jobName3 = $jobs foreach ($job in $jobs) { - $null = New-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $job - $null = New-DbaAgentJobStep -SqlInstance $script:instance2, $script:instance3 -Job $job -StepName "step1_$(Get-Random)" -Subsystem TransactSql -Command "WAITFOR DELAY '00:05:00'" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "step2" -StepId 2 -Subsystem TransactSql -Command "WAITFOR DELAY '00:00:01'" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "step3" -StepId 3 -Subsystem TransactSql -Command "SELECT 1" + $null = New-DbaAgentJob -SqlInstance $env:instance2, $env:instance3 -Job $job + $null = New-DbaAgentJobStep -SqlInstance $env:instance2, $env:instance3 -Job $job -StepName "step1_$(Get-Random)" -Subsystem TransactSql -Command "WAITFOR DELAY '00:05:00'" + $null = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $job -StepName "step2" -StepId 2 -Subsystem TransactSql -Command "WAITFOR DELAY '00:00:01'" + $null = New-DbaAgentJobStep -SqlInstance $env:instance2 -Job $job -StepName "step3" -StepId 3 -Subsystem TransactSql -Command "SELECT 1" } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1 | Start-DbaAgentJob + $results = Get-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName1 | Start-DbaAgentJob } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $jobs -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $env:instance2, $env:instance3 -Job $jobs -Confirm:$false } It "returns a CurrentRunStatus of not Idle and supports pipe" { @@ -71,23 +71,23 @@ Describe "Start-DbaAgentJob" { It "does not run all jobs" { $warn = $null - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -WarningAction SilentlyContinue -WarningVariable warn + $null = Start-DbaAgentJob -SqlInstance $env:instance2 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Match 'use one of the job' } It "returns on multiple server inputs" { - $results2 = Start-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $jobName2 + $results2 = Start-DbaAgentJob -SqlInstance $env:instance2, $env:instance3 -Job $jobName2 $results2.SqlInstance.Count | Should -Be 2 } It "starts job at specified step" { - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName3 -StepName 'step3' - $results3 = Get-DbaAgentJobHistory -SqlInstance $script:instance2 -Job $jobName3 + $null = Start-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName3 -StepName 'step3' + $results3 = Get-DbaAgentJobHistory -SqlInstance $env:instance2 -Job $jobName3 $results3.SqlInstance.Count | Should -Be 2 } It "do not start job if the step does not exist" { - $results4 = Start-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName3 -StepName 'stepdoesnoteexist' + $results4 = Start-DbaAgentJob -SqlInstance $env:instance2 -Job $jobName3 -StepName 'stepdoesnoteexist' $results4.SqlInstance.Count | Should -Be 0 } } diff --git a/tests/Start-DbaDbEncryption.Tests.ps1 b/tests/Start-DbaDbEncryption.Tests.ps1 index 2386820dc5..c3ea1a14cb 100644 --- a/tests/Start-DbaDbEncryption.Tests.ps1 +++ b/tests/Start-DbaDbEncryption.Tests.ps1 @@ -8,7 +8,7 @@ Describe "Start-DbaDbEncryption" { $PSDefaultParameterValues["*:Confirm"] = $false $alldbs = @() - 1..5 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $script:instance2 } + 1..5 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $env:instance2 } } AfterAll { @@ -52,7 +52,7 @@ Describe "Start-DbaDbEncryption" { $CommandUnderTest | Should -HaveParameter CertificateExpirationDate -Type DateTime } It "Should have CertificateActiveForServiceBrokerDialog as a parameter" { - $CommandUnderTest | Should -HaveParameter CertificateActiveForServiceBrokerDialog -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CertificateActiveForServiceBrokerDialog -Type Switch } It "Should have BackupSecurePassword as a parameter" { $CommandUnderTest | Should -HaveParameter BackupSecurePassword -Type SecureString @@ -61,13 +61,13 @@ Describe "Start-DbaDbEncryption" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have AllUserDatabases as a parameter" { - $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllUserDatabases -Type Switch } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -75,7 +75,7 @@ Describe "Start-DbaDbEncryption" { It "should mass enable encryption" { $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $env:instance2 Database = $alldbs.Name MasterKeySecurePassword = $passwd BackupSecurePassword = $passwd diff --git a/tests/Start-DbaEndpoint.Tests.ps1 b/tests/Start-DbaEndpoint.Tests.ps1 index 8c8f8298af..01ba9fa065 100644 --- a/tests/Start-DbaEndpoint.Tests.ps1 +++ b/tests/Start-DbaEndpoint.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Start-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Endpoint -Type String[] } It "Should have AllEndpoints as a switch parameter" { - $CommandUnderTest | Should -HaveParameter AllEndpoints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllEndpoints -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Endpoint[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,7 +32,7 @@ Describe "Start-DbaEndpoint" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $endpoint = Get-DbaEndpoint -SqlInstance $server -Endpoint 'TSQL Default TCP' $endpoint | Stop-DbaEndpoint -Confirm:$false } diff --git a/tests/Start-DbaMigration.Tests.ps1 b/tests/Start-DbaMigration.Tests.ps1 index 7e87f18340..a919430e47 100644 --- a/tests/Start-DbaMigration.Tests.ps1 +++ b/tests/Start-DbaMigration.Tests.ps1 @@ -9,20 +9,20 @@ Describe "Start-DbaMigration" { $startmigrationrestoredb = "dbatoolsci_startmigrationrestore$random" $startmigrationrestoredb2 = "dbatoolsci_startmigrationrestoreother$random" $detachattachdb = "dbatoolsci_detachattach$random" - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb, $detachattachdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2, $env:instance3 -Database $startmigrationrestoredb, $detachattachdb - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $env:instance3 Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb2; ALTER DATABASE $startmigrationrestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb; ALTER DATABASE $startmigrationrestoredb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $detachattachdb; ALTER DATABASE $detachattachdb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb2; ALTER DATABASE $startmigrationrestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" - $null = Set-DbaDbOwner -SqlInstance $script:instance2 -Database $startmigrationrestoredb, $detachattachdb -TargetLogin sa + $null = Set-DbaDbOwner -SqlInstance $env:instance2 -Database $startmigrationrestoredb, $detachattachdb -TargetLogin sa } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb, $detachattachdb, $startmigrationrestoredb2 + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2, $env:instance3 -Database $startmigrationrestoredb, $detachattachdb, $startmigrationrestoredb2 } Context "Validate parameters" { @@ -108,7 +108,7 @@ Describe "Start-DbaMigration" { Context "Backup restore" { BeforeAll { - $results = Start-DbaMigration -Force -Source $script:instance2 -Destination $script:instance3 -BackupRestore -SharedPath "C:\temp" -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials + $results = Start-DbaMigration -Force -Source $env:instance2 -Destination $env:instance3 -BackupRestore -SharedPath "C:\temp" -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials } It "returns at least one result" { @@ -122,7 +122,7 @@ Describe "Start-DbaMigration" { } It "retains its name, recovery model, and status" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb2 + $dbs = Get-DbaDatabase -SqlInstance $env:instance2, $env:instance3 -Database $startmigrationrestoredb2 $dbs[0].Name | Should -Not -BeNullOrEmpty $dbs[0].Name | Should -Be $dbs[1].Name $dbs[0].RecoveryModel | Should -Be $dbs[1].RecoveryModel @@ -133,8 +133,8 @@ Describe "Start-DbaMigration" { Context "Backup restore using last backup" { BeforeAll { - $quickbackup = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Backup-DbaDatabase -BackupDirectory C:\temp - $results = Start-DbaMigration -Force -Source $script:instance2 -Destination $script:instance3 -UseLastBackup -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials, StartupProcedures + $quickbackup = Get-DbaDatabase -SqlInstance $env:instance2 -ExcludeSystem | Backup-DbaDatabase -BackupDirectory C:\temp + $results = Start-DbaMigration -Force -Source $env:instance2 -Destination $env:instance3 -UseLastBackup -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials, StartupProcedures } It "returns at least one result" { @@ -148,7 +148,7 @@ Describe "Start-DbaMigration" { } It "retains its name, recovery model, and status" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb2 + $dbs = Get-DbaDatabase -SqlInstance $env:instance2, $env:instance3 -Database $startmigrationrestoredb2 $dbs[0].Name | Should -Not -BeNullOrEmpty $dbs[0].Name | Should -Be $dbs[1].Name $dbs[0].RecoveryModel | Should -Be $dbs[1].RecoveryModel diff --git a/tests/Start-DbaPfDataCollectorSet.Tests.ps1 b/tests/Start-DbaPfDataCollectorSet.Tests.ps1 index 892b4b7e29..6d0e4e855b 100644 --- a/tests/Start-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Start-DbaPfDataCollectorSet.Tests.ps1 @@ -27,16 +27,16 @@ Describe "Start-DbaPfDataCollectorSet" { Context "Command usage" { BeforeAll { - $script:set = Get-DbaPfDataCollectorSet | Select-Object -First 1 - $script:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue + $env:set = Get-DbaPfDataCollectorSet | Select-Object -First 1 + $env:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue Start-Sleep -Seconds 2 } AfterAll { - $script:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue + $env:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue } It "returns a result with the right computername and name is not null" { - $results = $script:set | Select-Object -First 1 | Start-DbaPfDataCollectorSet -WarningAction SilentlyContinue -WarningVariable warn + $results = $env:set | Select-Object -First 1 | Start-DbaPfDataCollectorSet -WarningAction SilentlyContinue -WarningVariable warn if (-not $warn) { $results.ComputerName | Should -Be $env:COMPUTERNAME $results.Name | Should -Not -BeNullOrEmpty diff --git a/tests/Start-DbaService.Tests.ps1 b/tests/Start-DbaService.Tests.ps1 index fe967f208f..ec416a1753 100644 --- a/tests/Start-DbaService.Tests.ps1 +++ b/tests/Start-DbaService.Tests.ps1 @@ -31,13 +31,13 @@ Describe "Start-DbaService" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $instanceName = $server.ServiceName $computerName = $server.NetName @@ -51,7 +51,7 @@ Describe "Start-DbaService" { } It "starts the services back" { - $services = Start-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $services = Start-DbaService -ComputerName $env:instance2 -Type Agent -InstanceName $instanceName $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Running' @@ -68,7 +68,7 @@ Describe "Start-DbaService" { } foreach ($sn in $servicename) { Get-Service -ComputerName $computerName -Name $sn | Stop-Service -WarningAction SilentlyContinue | Out-Null } - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Start-DbaService + $services = Get-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent, Engine | Start-DbaService $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Running' @@ -77,7 +77,7 @@ Describe "Start-DbaService" { } It "errors when passing an invalid InstanceName" { - { Start-DbaService -ComputerName $script:instance2 -Type 'Agent' -InstanceName 'ThisIsInvalid' -EnableException } | Should -Throw 'No SQL Server services found with current parameters.' + { Start-DbaService -ComputerName $env:instance2 -Type 'Agent' -InstanceName 'ThisIsInvalid' -EnableException } | Should -Throw 'No SQL Server services found with current parameters.' } } } diff --git a/tests/Start-DbaTrace.Tests.ps1 b/tests/Start-DbaTrace.Tests.ps1 index 6b0c328c5b..49cf37c01e 100644 --- a/tests/Start-DbaTrace.Tests.ps1 +++ b/tests/Start-DbaTrace.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Start-DbaTrace" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -104,25 +104,25 @@ exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references select TraceID=@TraceID "@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $traceid = ($server.Query($sql)).TraceID - $null = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Stop-DbaTrace + $null = Get-DbaTrace -SqlInstance $env:instance1 -Id $traceid | Stop-DbaTrace } AfterAll { - $null = Remove-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $null = Remove-DbaTrace -SqlInstance $env:instance1 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue } Context "Test Starting Trace" { It "starts in a stopped state" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $results = Get-DbaTrace -SqlInstance $env:instance1 -Id $traceid $results.Id | Should -Be $traceid $results.IsRunning | Should -Be $false } It "is now running" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Start-DbaTrace + $results = Get-DbaTrace -SqlInstance $env:instance1 -Id $traceid | Start-DbaTrace $results.Id | Should -Be $traceid $results.IsRunning | Should -Be $true } diff --git a/tests/Start-DbaXESession.Tests.ps1 b/tests/Start-DbaXESession.Tests.ps1 index 3e5097e892..3960c25ad3 100644 --- a/tests/Start-DbaXESession.Tests.ps1 +++ b/tests/Start-DbaXESession.Tests.ps1 @@ -2,7 +2,7 @@ param($ModuleName = 'dbatools') Describe "Start-DbaXESession" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $conn = $server.ConnectionContext # Get the systemhealth session $systemhealth = Get-DbaXESession -SqlInstance $server -Session system_health @@ -34,7 +34,7 @@ Describe "Start-DbaXESession" { # Drop created objects $conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_invalid') DROP EVENT SESSION [dbatoolsci_session_invalid] ON SERVER;") $conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;") - Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule "XE Session START - dbatoolsci_session_valid", "XE Session STOP - dbatoolsci_session_valid" | Remove-DbaAgentSchedule -Force -Confirm:$false + Get-DbaAgentSchedule -SqlInstance $env:instance2 -Schedule "XE Session START - dbatoolsci_session_valid", "XE Session STOP - dbatoolsci_session_valid" | Remove-DbaAgentSchedule -Force -Confirm:$false } Context "Validate parameters" { @@ -57,13 +57,13 @@ Describe "Start-DbaXESession" { $CommandUnderTest | Should -HaveParameter StopAt -Type DateTime } It "Should have AllSessions as a parameter" { - $CommandUnderTest | Should -HaveParameter AllSessions -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllSessions -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Session[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -119,8 +119,8 @@ Describe "Start-DbaXESession" { Start-Sleep -Seconds 11 $dbatoolsciValid.Refresh() $dbatoolsciValid.IsRunning | Should -Be $false - # Using $script:instance2 because the SMO $server is not updated after the job is removed - (Get-DbaAgentJob -SqlInstance $script:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 + # Using $env:instance2 because the SMO $server is not updated after the job is removed + (Get-DbaAgentJob -SqlInstance $env:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 } It "works when -StartAt is passed" { @@ -136,8 +136,8 @@ Describe "Start-DbaXESession" { Start-Sleep -Seconds 11 $dbatoolsciValid.Refresh() $dbatoolsciValid.IsRunning | Should -Be $true - # Using $script:instance2 because the SMO $server is not updated after the job is removed - (Get-DbaAgentJob -SqlInstance $script:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 + # Using $env:instance2 because the SMO $server is not updated after the job is removed + (Get-DbaAgentJob -SqlInstance $env:instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 } } } diff --git a/tests/Start-DbaXESmartTarget.Tests.ps1 b/tests/Start-DbaXESmartTarget.Tests.ps1 index e0d94edddc..0f5aefea03 100644 --- a/tests/Start-DbaXESmartTarget.Tests.ps1 +++ b/tests/Start-DbaXESmartTarget.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Start-DbaXESmartTarget" { $CommandUnderTest | Should -HaveParameter Session -Type String -Not -Mandatory } It "Should have FailOnProcessingError parameter" { - $CommandUnderTest | Should -HaveParameter FailOnProcessingError -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter FailOnProcessingError -Type Switch -Not -Mandatory } It "Should have Responder parameter" { $CommandUnderTest | Should -HaveParameter Responder -Type Object[] -Not -Mandatory @@ -27,10 +27,10 @@ Describe "Start-DbaXESmartTarget" { $CommandUnderTest | Should -HaveParameter Template -Type String[] -Not -Mandatory } It "Should have NotAsJob parameter" { - $CommandUnderTest | Should -HaveParameter NotAsJob -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NotAsJob -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } diff --git a/tests/Stop-DbaAgentJob.Tests.ps1 b/tests/Stop-DbaAgentJob.Tests.ps1 index 2ef901564c..8807dd4fe1 100644 --- a/tests/Stop-DbaAgentJob.Tests.ps1 +++ b/tests/Stop-DbaAgentJob.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Stop-DbaAgentJob" { $CommandUnderTest | Should -HaveParameter InputObject -Type Job[] } It "Should have Wait as a switch parameter" { - $CommandUnderTest | Should -HaveParameter Wait -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Wait -Type Switch } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -36,7 +36,7 @@ Describe "Stop-DbaAgentJob" { It "Returns a CurrentRunStatus of Idle" -Skip:([Environment]::GetEnvironmentVariable('appveyor')) { BeforeAll { $jobName = 'DatabaseBackup - SYSTEM_DATABASES - FULL' - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $job = Get-DbaAgentJob -SqlInstance $server -Job $jobName } diff --git a/tests/Stop-DbaDbEncryption.Tests.ps1 b/tests/Stop-DbaDbEncryption.Tests.ps1 index f57c176f0e..7c441aa290 100644 --- a/tests/Stop-DbaDbEncryption.Tests.ps1 +++ b/tests/Stop-DbaDbEncryption.Tests.ps1 @@ -12,7 +12,7 @@ Describe "Stop-DbaDbEncryption" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -20,18 +20,18 @@ Describe "Stop-DbaDbEncryption" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $env:instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $env:instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $env:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $env:instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $env:instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -54,7 +54,7 @@ Describe "Stop-DbaDbEncryption" { } It "should disable encryption on a database" { - $results = Stop-DbaDbEncryption -SqlInstance $script:instance2 + $results = Stop-DbaDbEncryption -SqlInstance $env:instance2 $results | ForEach-Object { $_.EncryptionEnabled | Should -Be $false } diff --git a/tests/Stop-DbaEndpoint.Tests.ps1 b/tests/Stop-DbaEndpoint.Tests.ps1 index 7ccc9383d3..4f9ac74457 100644 --- a/tests/Stop-DbaEndpoint.Tests.ps1 +++ b/tests/Stop-DbaEndpoint.Tests.ps1 @@ -15,13 +15,13 @@ Describe "Stop-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter Endpoint -Type String[] } It "Should have AllEndpoints as a switch parameter" { - $CommandUnderTest | Should -HaveParameter AllEndpoints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AllEndpoints -Type Switch } It "Should have InputObject as a parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Endpoint[] } It "Should have EnableException as a switch parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -32,7 +32,7 @@ Describe "Stop-DbaEndpoint" { } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $endpoint = Get-DbaEndpoint -SqlInstance $server -Endpoint 'TSQL Default TCP' $endpoint | Start-DbaEndpoint } diff --git a/tests/Stop-DbaExternalProcess.Tests.ps1 b/tests/Stop-DbaExternalProcess.Tests.ps1 index 7f7c3bcce6..116183620e 100644 --- a/tests/Stop-DbaExternalProcess.Tests.ps1 +++ b/tests/Stop-DbaExternalProcess.Tests.ps1 @@ -14,8 +14,8 @@ Describe "Stop-DbaExternalProcess" { It "Should have ProcessId as a non-mandatory Int32" { $CommandUnderTest | Should -HaveParameter ProcessId -Type Int32 -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -27,7 +27,7 @@ Describe "Stop-DbaExternalProcess Integration Tests" -Tag "IntegrationTests" { Context "Can stop an external process" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Query @" + $null = Invoke-DbaQuery -SqlInstance $env:instance1 -Query @" -- To allow advanced options to be changed. EXECUTE sp_configure 'show advanced options', 1; GO @@ -43,7 +43,7 @@ Describe "Stop-DbaExternalProcess Integration Tests" -Tag "IntegrationTests" { "@ $query = "xp_cmdshell 'powershell -command ""sleep 20""'" - Start-Process -FilePath sqlcmd -ArgumentList "-S $script:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null + Start-Process -FilePath sqlcmd -ArgumentList "-S $env:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null } It "returns results" { diff --git a/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 b/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 index 6688386728..f7d9237da5 100644 --- a/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 @@ -26,15 +26,15 @@ Describe "Stop-DbaPfDataCollectorSet" { Context "Integration Tests" { BeforeAll { - $script:set = Get-DbaPfDataCollectorSet | Select-Object -First 1 - $script:set | Start-DbaPfDataCollectorSet -WarningAction SilentlyContinue + $env:set = Get-DbaPfDataCollectorSet | Select-Object -First 1 + $env:set | Start-DbaPfDataCollectorSet -WarningAction SilentlyContinue Start-Sleep -Seconds 2 } AfterAll { - $script:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue + $env:set | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue } It "returns a result with the right computername and name is not null" { - $results = $script:set | Select-Object -First 1 | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue -WarningVariable warn + $results = $env:set | Select-Object -First 1 | Stop-DbaPfDataCollectorSet -WarningAction SilentlyContinue -WarningVariable warn if (-not $warn) { $results.ComputerName | Should -Be $env:COMPUTERNAME $results.Name | Should -Not -BeNullOrEmpty diff --git a/tests/Stop-DbaProcess.Tests.ps1 b/tests/Stop-DbaProcess.Tests.ps1 index 6300393c22..61bd7b2265 100644 --- a/tests/Stop-DbaProcess.Tests.ps1 +++ b/tests/Stop-DbaProcess.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Stop-DbaProcess" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -43,16 +43,16 @@ Describe "Stop-DbaProcess" { } It "Kills only this specific process" { - $fakeapp = Connect-DbaInstance -SqlInstance $script:instance1 -ClientName 'dbatoolsci test app' - $results = Stop-DbaProcess -SqlInstance $script:instance1 -Program 'dbatoolsci test app' + $fakeapp = Connect-DbaInstance -SqlInstance $env:instance1 -ClientName 'dbatoolsci test app' + $results = Stop-DbaProcess -SqlInstance $env:instance1 -Program 'dbatoolsci test app' $results.Program.Count | Should -Be 1 $results.Program | Should -Be 'dbatoolsci test app' $results.Status | Should -Be 'Killed' } It "Supports piping" { - $fakeapp = Connect-DbaInstance -SqlInstance $script:instance1 -ClientName 'dbatoolsci test app' - $results = Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatoolsci test app' | Stop-DbaProcess + $fakeapp = Connect-DbaInstance -SqlInstance $env:instance1 -ClientName 'dbatoolsci test app' + $results = Get-DbaProcess -SqlInstance $env:instance1 -Program 'dbatoolsci test app' | Stop-DbaProcess $results.Program.Count | Should -Be 1 $results.Program | Should -Be 'dbatoolsci test app' $results.Status | Should -Be 'Killed' diff --git a/tests/Stop-DbaService.Tests.ps1 b/tests/Stop-DbaService.Tests.ps1 index fa416b7124..83c928aab0 100644 --- a/tests/Stop-DbaService.Tests.ps1 +++ b/tests/Stop-DbaService.Tests.ps1 @@ -33,22 +33,22 @@ Describe "Stop-DbaService" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential -Not -Mandatory } It "Should have Force as a parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Force -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $instanceName = $server.ServiceName $computerName = $server.NetName } It "stops some services" { - $services = Stop-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent + $services = Stop-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Stopped' @@ -67,7 +67,7 @@ Describe "Stop-DbaService" { Get-Service -ComputerName $computerName -Name $serviceName | Start-Service -WarningAction SilentlyContinue | Out-Null } - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Stop-DbaService + $services = Get-DbaService -ComputerName $env:instance2 -InstanceName $instanceName -Type Agent, Engine | Stop-DbaService $services | Should -Not -BeNullOrEmpty foreach ($service in $services) { $service.State | Should -Be 'Stopped' @@ -82,8 +82,8 @@ Describe "Stop-DbaService" { } else { $serviceName = "MsSql`$$instanceName", "SqlAgent`$$instanceName" } - foreach ($sn in $servicename) { - Get-Service -ComputerName $computerName -Name $sn | Start-Service -WarningAction SilentlyContinue | Out-Null + foreach ($sn in $servicename) { + Get-Service -ComputerName $computerName -Name $sn | Start-Service -WarningAction SilentlyContinue | Out-Null } } } diff --git a/tests/Stop-DbaTrace.Tests.ps1 b/tests/Stop-DbaTrace.Tests.ps1 index 189c847719..cbb6efa578 100644 --- a/tests/Stop-DbaTrace.Tests.ps1 +++ b/tests/Stop-DbaTrace.Tests.ps1 @@ -23,14 +23,14 @@ Describe "Stop-DbaTrace Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } Describe "Stop-DbaTrace Integration Tests" -Tag "IntegrationTests" { BeforeDiscovery { - $script:instance1 = "localhost" + $env:instance1 = "localhost" } BeforeAll { @@ -113,26 +113,26 @@ exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references select TraceID=@TraceID "@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $script:traceid = ($server.Query($sql)).TraceID - $null = Get-DbaTrace -SqlInstance $script:instance1 -Id $script:traceid | Start-DbaTrace + $server = Connect-DbaInstance -SqlInstance $env:instance1 + $env:traceid = ($server.Query($sql)).TraceID + $null = Get-DbaTrace -SqlInstance $env:instance1 -Id $env:traceid | Start-DbaTrace } AfterAll { - $null = Remove-DbaTrace -SqlInstance $script:instance1 -Id $script:traceid + $null = Remove-DbaTrace -SqlInstance $env:instance1 -Id $env:traceid Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue } Context "Test Stopping Trace" { It "starts in a running state" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $script:traceid - $results.Id | Should -Be $script:traceid + $results = Get-DbaTrace -SqlInstance $env:instance1 -Id $env:traceid + $results.Id | Should -Be $env:traceid $results.IsRunning | Should -BeTrue } It "is now in a stopped state" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $script:traceid | Stop-DbaTrace - $results.Id | Should -Be $script:traceid + $results = Get-DbaTrace -SqlInstance $env:instance1 -Id $env:traceid | Stop-DbaTrace + $results.Id | Should -Be $env:traceid $results.IsRunning | Should -BeFalse } } diff --git a/tests/Stop-DbaXESession.Tests.ps1 b/tests/Stop-DbaXESession.Tests.ps1 index afb9c420db..5c79e4d6b4 100644 --- a/tests/Stop-DbaXESession.Tests.ps1 +++ b/tests/Stop-DbaXESession.Tests.ps1 @@ -15,24 +15,24 @@ Describe "Stop-DbaXESession" { $CommandUnderTest | Should -HaveParameter Session -Type Object[] -Not -Mandatory } It "Should have AllSessions parameter" { - $CommandUnderTest | Should -HaveParameter AllSessions -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter AllSessions -Type Switch -Not -Mandatory } It "Should have InputObject parameter" { $CommandUnderTest | Should -HaveParameter InputObject -Type Session[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE EVENT SESSION [dbatoolsci_session_valid] ON SERVER ADD EVENT sqlserver.lock_acquired;") - $dbatoolsciValid = Get-DbaXESession -SqlInstance $script:instance2 -Session dbatoolsci_session_valid + $dbatoolsciValid = Get-DbaXESession -SqlInstance $env:instance2 -Session dbatoolsci_session_valid $dbatoolsciValid.Start() - $allSessions = Get-DbaXESession -SqlInstance $script:instance2 + $allSessions = Get-DbaXESession -SqlInstance $env:instance2 } BeforeEach { @@ -56,7 +56,7 @@ Describe "Stop-DbaXESession" { } } - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;") } diff --git a/tests/Stop-Function.Tests.ps1 b/tests/Stop-Function.Tests.ps1 index de605baa1d..e534c612ee 100644 --- a/tests/Stop-Function.Tests.ps1 +++ b/tests/Stop-Function.Tests.ps1 @@ -40,14 +40,14 @@ Describe "Stop-Function" { It "Should have Exception as a non-mandatory Exception parameter" { $CommandUnderTest | Should -HaveParameter Exception -Type Exception -Not -Mandatory } - It "Should have OverrideExceptionMessage as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter OverrideExceptionMessage -Type SwitchParameter -Not -Mandatory + It "Should have OverrideExceptionMessage as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter OverrideExceptionMessage -Type Switch -Not -Mandatory } - It "Should have Continue as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter Continue -Type SwitchParameter -Not -Mandatory + It "Should have Continue as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter Continue -Type Switch -Not -Mandatory } - It "Should have SilentlyContinue as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter SilentlyContinue -Type SwitchParameter -Not -Mandatory + It "Should have SilentlyContinue as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter SilentlyContinue -Type Switch -Not -Mandatory } It "Should have ContinueLabel as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter ContinueLabel -Type String -Not -Mandatory diff --git a/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 b/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 index 23d97bf9b9..33b871afee 100644 --- a/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 +++ b/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 @@ -6,15 +6,15 @@ Describe "Suspend-DbaAgDbDataMovement" { Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $env:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $env:instance3 $agname = "dbatoolsci_resumeagdb_agroup" $dbname = "dbatoolsci_resumeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup - $null = Get-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname | Resume-DbaAgDbDataMovement -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $env:instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $env:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaAgDatabase -SqlInstance $env:instance3 -AvailabilityGroup $agname | Resume-DbaAgDbDataMovement -Confirm:$false } AfterAll { @@ -42,16 +42,16 @@ Describe "Suspend-DbaAgDbDataMovement" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityDatabase[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Suspends data movement" { It "returns suspended results" { - $results = Suspend-DbaAgDbDataMovement -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Suspend-DbaAgDbDataMovement -SqlInstance $env:instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.SynchronizationState | Should -Be 'NotSynchronizing' } } -} #$script:instance2 for appveyor +} #$env:instance2 for appveyor diff --git a/tests/Sync-DbaLoginPermission.Tests.ps1 b/tests/Sync-DbaLoginPermission.Tests.ps1 index 6677103880..03983e6fe4 100644 --- a/tests/Sync-DbaLoginPermission.Tests.ps1 +++ b/tests/Sync-DbaLoginPermission.Tests.ps1 @@ -16,7 +16,7 @@ CREATE USER [$DBUserName] FOR LOGIN [$DBUserName] WITH DEFAULT_SCHEMA = dbo; GRANT VIEW ANY DEFINITION to [$DBUserName]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUser -Database master + Invoke-DbaQuery -SqlInstance $env:instance2 -Query $CreateTestUser -Database master #This is used later in the test $CreateTestLogin = @" @@ -27,7 +27,7 @@ CREATE LOGIN [$DBUserName] AfterAll { $DropTestUser = "DROP LOGIN [$DBUserName]" - Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Query $DropTestUser -Database master + Invoke-DbaQuery -SqlInstance $env:instance2, $env:instance3 -Query $DropTestUser -Database master } Context "Validate parameters" { @@ -53,26 +53,26 @@ CREATE LOGIN [$DBUserName] $CommandUnderTest | Should -HaveParameter ExcludeLogin -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Verifying command output" { It "Should not have the user permissions of $DBUserName" { - $permissionsBefore = Get-DbaUserPermission -SqlInstance $script:instance3 -Database master | Where-Object {$_.member -eq $DBUserName} + $permissionsBefore = Get-DbaUserPermission -SqlInstance $env:instance3 -Database master | Where-Object {$_.member -eq $DBUserName} $permissionsBefore | Should -BeNullOrEmpty } It "Should execute against active nodes" { #Creates the user on - Invoke-DbaQuery -SqlInstance $script:instance3 -Query $CreateTestLogin - $results = Sync-DbaLoginPermission -Source $script:instance2 -Destination $script:instance3 -Login $DBUserName -ExcludeLogin 'NotaLogin' -WarningVariable warn + Invoke-DbaQuery -SqlInstance $env:instance3 -Query $CreateTestLogin + $results = Sync-DbaLoginPermission -Source $env:instance2 -Destination $env:instance3 -Login $DBUserName -ExcludeLogin 'NotaLogin' -WarningVariable warn $results.Status | Should -Be 'Successful' $warn | Should -BeNullOrEmpty } It "Should have copied the user permissions of $DBUserName" { - $permissionsAfter = Get-DbaUserPermission -SqlInstance $script:instance3 -Database master | Where-Object {$_.member -eq $DBUserName -and $_.permission -eq 'VIEW ANY DEFINITION' } + $permissionsAfter = Get-DbaUserPermission -SqlInstance $env:instance3 -Database master | Where-Object {$_.member -eq $DBUserName -and $_.permission -eq 'VIEW ANY DEFINITION' } $permissionsAfter.member | Should -Be $DBUserName } } diff --git a/tests/Test-DbaAgSpn.Tests.ps1 b/tests/Test-DbaAgSpn.Tests.ps1 index ce0b3ba6c2..9238f74518 100644 --- a/tests/Test-DbaAgSpn.Tests.ps1 +++ b/tests/Test-DbaAgSpn.Tests.ps1 @@ -28,13 +28,13 @@ Describe "Test-DbaAgSpn" { $CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } It "Should have Verbose parameter" { - $CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Verbose -Type Switch -Not -Mandatory } It "Should have Debug parameter" { - $CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Debug -Type Switch -Not -Mandatory } It "Should have ErrorAction parameter" { $CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference -Not -Mandatory diff --git a/tests/Test-DbaAgentJobOwner.Tests.ps1 b/tests/Test-DbaAgentJobOwner.Tests.ps1 index 09487d36df..8fdaa0a083 100644 --- a/tests/Test-DbaAgentJobOwner.Tests.ps1 +++ b/tests/Test-DbaAgentJobOwner.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Test-DbaAgentJobOwner Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Login -Type String -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -34,24 +34,24 @@ Describe "Test-DbaAgentJobOwner Integration Tests" -Tag "IntegrationTests" { BeforeAll { $saJob = ("dbatoolsci_sa_{0}" -f $(Get-Random)) $notSaJob = ("dbatoolsci_nonsa_{0}" -f $(Get-Random)) - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $saJob -OwnerLogin 'sa' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $notSaJob -OwnerLogin 'NT AUTHORITY\SYSTEM' + $null = New-DbaAgentJob -SqlInstance $env:instance2 -Job $saJob -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $env:instance2 -Job $notSaJob -OwnerLogin 'NT AUTHORITY\SYSTEM' } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $saJob, $notSaJob -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $env:instance2 -Job $saJob, $notSaJob -Confirm:$false } Context "Command actually works" { It "Should return $notSaJob" { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 + $results = Test-DbaAgentJobOwner -SqlInstance $env:instance2 $results | Where-Object {$_.Job -eq $notSaJob} | Should -Not -BeNullOrEmpty } } Context "Command works for specific jobs" { BeforeAll { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 -Job $saJob, $notSaJob + $results = Test-DbaAgentJobOwner -SqlInstance $env:instance2 -Job $saJob, $notSaJob } It "Should find $saJob owner matches default sa" { @@ -65,7 +65,7 @@ Describe "Test-DbaAgentJobOwner Integration Tests" -Tag "IntegrationTests" { Context "Exclusions work" { It "Should exclude $notSaJob job" { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 -ExcludeJob $notSaJob + $results = Test-DbaAgentJobOwner -SqlInstance $env:instance2 -ExcludeJob $notSaJob $results.job | Should -Not -Contain $notSaJob } } diff --git a/tests/Test-DbaAvailabilityGroup.Tests.ps1 b/tests/Test-DbaAvailabilityGroup.Tests.ps1 index 9a6e6391e0..c79deb79a2 100644 --- a/tests/Test-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Test-DbaAvailabilityGroup.Tests.ps1 @@ -30,10 +30,10 @@ Describe "Test-DbaAvailabilityGroup" { $CommandUnderTest | Should -HaveParameter SharedPath -Type String } It "Should have UseLastBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter UseLastBackup -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseLastBackup -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Test-DbaBackupEncrypted.Tests.ps1 b/tests/Test-DbaBackupEncrypted.Tests.ps1 index 148c651e17..26bf4c0179 100644 --- a/tests/Test-DbaBackupEncrypted.Tests.ps1 +++ b/tests/Test-DbaBackupEncrypted.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Test-DbaBackupEncrypted" { $CommandUnderTest | Should -HaveParameter FilePath -Type String[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,7 +29,7 @@ Describe "Test-DbaBackupEncrypted" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $alldbs = @() - 1..2 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $script:instance2 } + 1..2 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $env:instance2 } } AfterAll { @@ -48,27 +48,27 @@ Describe "Test-DbaBackupEncrypted" { } $null = $alldbs | Start-DbaDbEncryption @splat $backups = $alldbs | Select-Object -First 1 | Backup-DbaDatabase -Path C:\temp - $results = $backups | Test-DbaBackupEncrypted -SqlInstance $script:instance2 + $results = $backups | Test-DbaBackupEncrypted -SqlInstance $env:instance2 $results.Encrypted | Should -Be $true } It "should detect encryption from piped file" { $backups = $alldbs | Select-Object -First 1 | Backup-DbaDatabase -Path C:\temp - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backups.BackupPath + $results = Test-DbaBackupEncrypted -SqlInstance $env:instance2 -FilePath $backups.BackupPath $results.Encrypted | Should -Be $true } It "should say a non-encrypted file is not encrypted" { - $backups = New-DbaDatabase -SqlInstance $script:instance2 | Backup-DbaDatabase -Path C:\temp - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backups.BackupPath + $backups = New-DbaDatabase -SqlInstance $env:instance2 | Backup-DbaDatabase -Path C:\temp + $results = Test-DbaBackupEncrypted -SqlInstance $env:instance2 -FilePath $backups.BackupPath $results.Encrypted | Should -Be $false } It "should say an encrypted file is encrypted" { - $encryptor = (Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "#" | Select-Object -First 1).Name - $db = New-DbaDatabase -SqlInstance $script:instance2 - $backup = Backup-DbaDatabase -SqlInstance $script:instance2 -Path C:\temp -EncryptionAlgorithm AES192 -EncryptionCertificate $encryptor -Database $db.Name - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backup.BackupPath + $encryptor = (Get-DbaDbCertificate -SqlInstance $env:instance2 -Database master | Where-Object Name -notmatch "#" | Select-Object -First 1).Name + $db = New-DbaDatabase -SqlInstance $env:instance2 + $backup = Backup-DbaDatabase -SqlInstance $env:instance2 -Path C:\temp -EncryptionAlgorithm AES192 -EncryptionCertificate $encryptor -Database $db.Name + $results = Test-DbaBackupEncrypted -SqlInstance $env:instance2 -FilePath $backup.BackupPath $results.Encrypted | Should -Be $true } } diff --git a/tests/Test-DbaBuild.Tests.ps1 b/tests/Test-DbaBuild.Tests.ps1 index 10163f73ff..ae8e0f9248 100644 --- a/tests/Test-DbaBuild.Tests.ps1 +++ b/tests/Test-DbaBuild.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Test-DbaBuild" { $CommandUnderTest | Should -HaveParameter MaxBehind -Type String -Not -Mandatory } It "Should have Latest parameter" { - $CommandUnderTest | Should -HaveParameter Latest -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Latest -Type Switch -Not -Mandatory } It "Should have SqlInstance parameter" { $CommandUnderTest | Should -HaveParameter SqlInstance -Type DbaInstanceParameter[] -Not -Mandatory @@ -24,13 +24,13 @@ Describe "Test-DbaBuild" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have Update parameter" { - $CommandUnderTest | Should -HaveParameter Update -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Update -Type Switch -Not -Mandatory } It "Should have Quiet parameter" { - $CommandUnderTest | Should -HaveParameter Quiet -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter Quiet -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -66,12 +66,12 @@ Describe "Test-DbaBuild" { . (Join-Path $PSScriptRoot 'constants.ps1') } It "Should return a result" { - $results = Test-DbaBuild -Build "12.00.4502" -MinimumBuild "12.0.4511" -SqlInstance $script:instance2 + $results = Test-DbaBuild -Build "12.00.4502" -MinimumBuild "12.0.4511" -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should return a result" { - $results = Test-DbaBuild -Build "12.0.5540" -MaxBehind "1SP 1CU" -SqlInstance $script:instance2 + $results = Test-DbaBuild -Build "12.0.5540" -MaxBehind "1SP 1CU" -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 b/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 index 9a333986dd..7960d9faa0 100644 --- a/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 +++ b/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Test-DbaComputerCertificateExpiration Integration Tests" -Tag "Integra Context "tests a certificate" { BeforeAll { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path $env:appveyorlabrepo\certificates\localhost.crt -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" } diff --git a/tests/Test-DbaConnection.Tests.ps1 b/tests/Test-DbaConnection.Tests.ps1 index 75f940094e..d0481a3b51 100644 --- a/tests/Test-DbaConnection.Tests.ps1 +++ b/tests/Test-DbaConnection.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Test-DbaConnection" { Context "Testing if command works" { BeforeAll { - $results = Test-DbaConnection -SqlInstance $script:instance1 + $results = Test-DbaConnection -SqlInstance $env:instance1 $whoami = whoami } diff --git a/tests/Test-DbaConnectionAuthScheme.Tests.ps1 b/tests/Test-DbaConnectionAuthScheme.Tests.ps1 index a3e64ab735..faa7b4a248 100644 --- a/tests/Test-DbaConnectionAuthScheme.Tests.ps1 +++ b/tests/Test-DbaConnectionAuthScheme.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Test-DbaConnectionAuthScheme" { Context "returns the proper transport" { BeforeAll { - $results = Test-DbaConnectionAuthScheme -SqlInstance $script:instance1 + $results = Test-DbaConnectionAuthScheme -SqlInstance $env:instance1 } It "returns ntlm auth scheme" { $results.AuthScheme | Should -Be 'ntlm' diff --git a/tests/Test-DbaDbCollation.Tests.ps1 b/tests/Test-DbaDbCollation.Tests.ps1 index 49d468ab4e..d5faf2cc37 100644 --- a/tests/Test-DbaDbCollation.Tests.ps1 +++ b/tests/Test-DbaDbCollation.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Test-DbaDbCollation" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "testing collation of a single database" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $db1 = "dbatoolsci_collation" Get-DbaDatabase -SqlInstance $server -Database $db1 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") @@ -34,7 +34,7 @@ Describe "Test-DbaDbCollation" { } It "confirms the db is the same collation as the server" { - $result = Test-DbaDbCollation -SqlInstance $script:instance1 -Database $db1 + $result = Test-DbaDbCollation -SqlInstance $env:instance1 -Database $db1 $result.IsEqual | Should -BeTrue } } diff --git a/tests/Test-DbaDbCompatibility.Tests.ps1 b/tests/Test-DbaDbCompatibility.Tests.ps1 index 5ad106403d..11bb8dcfb5 100644 --- a/tests/Test-DbaDbCompatibility.Tests.ps1 +++ b/tests/Test-DbaDbCompatibility.Tests.ps1 @@ -18,7 +18,7 @@ Describe "Test-DbaDbCompatibility" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -28,17 +28,17 @@ Describe "Test-DbaDbCompatibility" { } It "Should return a result" { - $results = Test-DbaDbCompatibility -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should return a result for a database" { - $results = Test-DbaDbCompatibility -Database Master -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -Database Master -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should return a result excluding one database" { - $results = Test-DbaDbCompatibility -ExcludeDatabase Master -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -ExcludeDatabase Master -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Test-DbaDbCompression.Tests.ps1 b/tests/Test-DbaDbCompression.Tests.ps1 index 4beef6f892..095058cf75 100644 --- a/tests/Test-DbaDbCompression.Tests.ps1 +++ b/tests/Test-DbaDbCompression.Tests.ps1 @@ -32,8 +32,8 @@ Describe "Test-DbaDbCompression Unit Tests" -Tag 'UnitTests' { It "Should have FilterBy as a non-mandatory parameter of type String" { $CommandUnderTest | Should -HaveParameter FilterBy -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory parameter of type SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory parameter of type Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -45,7 +45,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("Create Schema test", $dbname) $null = $server.Query(@" @@ -59,13 +59,13 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $env:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false } Context "Command gets suggestions" { BeforeAll { - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname } It "Should get results for $dbname" { @@ -84,7 +84,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Command makes right suggestions" { BeforeAll { - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname } It "Should suggest PAGE compression for a table with no updates or scans" { @@ -98,7 +98,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Command excludes results for specified database" { It "Shouldn't get any results for $dbname" { - $result = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname + $result = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -ExcludeDatabase $dbname $result.Database | Should -Not -Contain $dbname } } @@ -106,7 +106,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Command gets Schema suggestions" { BeforeAll { $schema = 'dbo' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Schema $schema + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -Schema $schema } It "Should get results for Schema:$schema" { @@ -117,7 +117,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Command gets Table suggestions" { BeforeAll { $table = 'syscols' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Table $table + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -Table $table } It "Should get results for table:$table" { @@ -128,7 +128,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Command gets limited output" { BeforeAll { $resultCount = 2 - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ResultSize $resultCount -Rank TotalPages -FilterBy Partition + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -ResultSize $resultCount -Rank TotalPages -FilterBy Partition } It "Should get only $resultCount results" { @@ -139,7 +139,7 @@ Describe "Test-DbaDbCompression Integration Tests" -Tag "IntegrationTests" { Context "Returns result for empty table (see #9469)" { BeforeAll { $table = 'testtable' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Table $table + $results = Test-DbaDbCompression -SqlInstance $env:instance2 -Database $dbname -Table $table } It "Should get results for table:$table" { diff --git a/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 b/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 index 6a1500f010..4f37f2c9d5 100644 --- a/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 +++ b/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 @@ -13,7 +13,7 @@ Describe "Test-DbaDbDataGeneratorConfig" { It "Should have FilePath as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter FilePath -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { + It "Should have EnableException as a non-mandatory Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -23,7 +23,7 @@ Describe "Test-DbaDbDataGeneratorConfig" { $dbname = "dbatools_datagentest" $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $env:instance1 -Database master -Query $query $query = @" CREATE TABLE [dbo].[Customer]( @@ -39,13 +39,13 @@ Describe "Test-DbaDbDataGeneratorConfig" { ) ON [PRIMARY] "@ - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $query + Invoke-DbaQuery -SqlInstance $env:instance1 -Database $dbname -Query $query - $file = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance1 -Database $dbname -Table Customer -Path "C:\temp\datageneration" + $file = New-DbaDbDataGeneratorConfig -SqlInstance $env:instance1 -Database $dbname -Table Customer -Path "C:\temp\datageneration" } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "gives no errors with a correct json file" { diff --git a/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 b/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 index f94345fcf0..d74e57d38e 100644 --- a/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 +++ b/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 @@ -64,7 +64,7 @@ Describe "Test-DbaDbDataMaskingConfig Integration Tests" -Tag "IntegrationTests" $dbname = "dbatools_maskingtest" $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $env:instance1 -Database master -Query $query $query = @" CREATE TABLE [dbo].[Customer]( @@ -80,13 +80,13 @@ Describe "Test-DbaDbDataMaskingConfig Integration Tests" -Tag "IntegrationTests" ) ON [PRIMARY] "@ - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $query + Invoke-DbaQuery -SqlInstance $env:instance1 -Database $dbname -Query $query - $file = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Table Customer -Path "C:\temp\datamasking" + $file = New-DbaDbMaskingConfig -SqlInstance $env:instance1 -Database $dbname -Table Customer -Path "C:\temp\datamasking" } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "gives no errors with a correct json file" { diff --git a/tests/Test-DbaDbLogShipStatus.Tests.ps1 b/tests/Test-DbaDbLogShipStatus.Tests.ps1 index ed06297efa..ebd7b68db7 100644 --- a/tests/Test-DbaDbLogShipStatus.Tests.ps1 +++ b/tests/Test-DbaDbLogShipStatus.Tests.ps1 @@ -35,36 +35,36 @@ Describe "Test-DbaDbLogShipStatus Unit Tests" -Tag "UnitTests" { Describe "Test-DbaDbLogShipStatus Integration Tests" -Tag "IntegrationTests" { BeforeDiscovery { - $script:skipIntegrationTests = $false - $script:instance1 = $null - $script:instance2 = $null + $env:skipIntegrationTests = $false + $env:instance1 = $null + $env:instance2 = $null try { . "$PSScriptRoot\constants.ps1" - $script:instance1 = $script:instance1 - $script:instance2 = $script:instance2 + $env:instance1 = $env:instance1 + $env:instance2 = $env:instance2 } catch { - $script:skipIntegrationTests = $true + $env:skipIntegrationTests = $true } } BeforeAll { - if (-not $script:skipIntegrationTests) { - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $script:skipExpressEdition = $server.Edition -notmatch 'Express' + if (-not $env:skipIntegrationTests) { + $server = Connect-DbaInstance -SqlInstance $env:instance1 + $env:skipExpressEdition = $server.Edition -notmatch 'Express' } } Context "When testing SQL Server Express edition" { - It "Warns if SQL instance edition is not supported" -Skip:$script:skipIntegrationTests { - $null = Test-DbaDbLogShipStatus -SqlInstance $script:instance1 -WarningAction SilentlyContinue -WarningVariable editionwarn + It "Warns if SQL instance edition is not supported" -Skip:$env:skipIntegrationTests { + $null = Test-DbaDbLogShipStatus -SqlInstance $env:instance1 -WarningAction SilentlyContinue -WarningVariable editionwarn $editionwarn | Should -Match "Express" } } Context "When no log shipping is found" { - It "Warns if no log shipping found" -Skip:$script:skipIntegrationTests { - $null = Test-DbaDbLogShipStatus -SqlInstance $script:instance2 -Database 'master' -WarningAction SilentlyContinue -WarningVariable doesntexist + It "Warns if no log shipping found" -Skip:$env:skipIntegrationTests { + $null = Test-DbaDbLogShipStatus -SqlInstance $env:instance2 -Database 'master' -WarningAction SilentlyContinue -WarningVariable doesntexist $doesntexist | Should -Match "No information available" } } diff --git a/tests/Test-DbaDbOwner.Tests.ps1 b/tests/Test-DbaDbOwner.Tests.ps1 index a386d61d0c..fed6a13cff 100644 --- a/tests/Test-DbaDbOwner.Tests.ps1 +++ b/tests/Test-DbaDbOwner.Tests.ps1 @@ -28,7 +28,7 @@ Describe "Test-DbaDbOwner Unit Tests" -Tag "UnitTests" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -100,19 +100,19 @@ Describe "Test-DbaDbOwner Unit Tests" -Tag "UnitTests" { Describe "Test-DbaDbOwner Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $script:instance1 = "localhost" + $env:instance1 = "localhost" $dbname = "dbatoolsci_testdbowner" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $null = $server.Query("CREATE DATABASE [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance1 -Database $dbname -Confirm:$false } It "Should return the correct information including database, currentowner and targetowner" { $whoami = whoami - $results = Test-DbaDbOwner -SqlInstance $script:instance1 -Database $dbname + $results = Test-DbaDbOwner -SqlInstance $env:instance1 -Database $dbname $results.Database | Should -Be $dbname $results.CurrentOwner | Should -Be $whoami $results.TargetOwner | Should -Be 'sa' diff --git a/tests/Test-DbaDbQueryStore.Tests.ps1 b/tests/Test-DbaDbQueryStore.Tests.ps1 index 96e044b8d6..f9f8274972 100644 --- a/tests/Test-DbaDbQueryStore.Tests.ps1 +++ b/tests/Test-DbaDbQueryStore.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Test-DbaDbQueryStore" { $CommandUnderTest | Should -HaveParameter InputObject -Type Object[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -29,20 +29,20 @@ Describe "Test-DbaDbQueryStore" { BeforeAll { . "$PSScriptRoot\constants.ps1" $dbname = "JESSdbatoolsci_querystore_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db = New-DbaDatabase -SqlInstance $server -Name $dbname - $null = Set-DbaDbQueryStoreOption -SqlInstance $script:instance2 -Database $dbname -State ReadWrite - $null = Enable-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag 7745 + $null = Set-DbaDbQueryStoreOption -SqlInstance $env:instance2 -Database $dbname -State ReadWrite + $null = Enable-DbaTraceFlag -SqlInstance $env:instance2 -TraceFlag 7745 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Disable-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag 7745 + $null = Remove-DbaDatabase -SqlInstance $env:instance2 -Database $dbname -Confirm:$false + $null = Disable-DbaTraceFlag -SqlInstance $env:instance2 -TraceFlag 7745 } Context 'Function works as expected' { BeforeAll { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 + $svr = Connect-DbaInstance -SqlInstance $env:instance2 $results = Test-DbaDbQueryStore -SqlInstance $svr -Database $dbname } It 'Should return results' { @@ -67,8 +67,8 @@ Describe "Test-DbaDbQueryStore" { Context 'Exclude database works' { BeforeAll { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 - $results = Test-DbaDbQueryStore -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $svr = Connect-DbaInstance -SqlInstance $env:instance2 + $results = Test-DbaDbQueryStore -SqlInstance $env:instance2 -ExcludeDatabase $dbname } It 'Should return results' { $results | Should -Not -BeNullOrEmpty @@ -80,7 +80,7 @@ Describe "Test-DbaDbQueryStore" { Context 'Function works with piping smo server object' { BeforeAll { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 + $svr = Connect-DbaInstance -SqlInstance $env:instance2 $results = $svr | Test-DbaDbQueryStore } It 'Should return results' { diff --git a/tests/Test-DbaDbRecoveryModel.Tests.ps1 b/tests/Test-DbaDbRecoveryModel.Tests.ps1 index 2b5a897f2d..eeba052067 100644 --- a/tests/Test-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Test-DbaDbRecoveryModel.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Test-DbaDbRecoveryModel Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter RecoveryModel -Type Object } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } } @@ -38,30 +38,30 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { $bulkLoggedRecovery = "dbatoolsci_RecoveryModelBulk" $simpleRecovery = "dbatoolsci_RecoveryModelSimple" $psudoSimpleRecovery = "dbatoolsci_RecoveryModelPsudoSimple" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $env:instance2 -Database model $server.Query("CREATE DATABASE $fullRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $env:instance2 -Database model $server.Query("CREATE DATABASE $bulkLoggedRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $env:instance2 -Database model $server.Query("CREATE DATABASE $simpleRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $env:instance2 -Database model $server.Query("CREATE DATABASE $psudoSimpleRecovery") - Set-DbaDbRecoveryModel -sqlInstance $script:instance2 -RecoveryModel BulkLogged -Database $bulkLoggedRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $simpleRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $psudoSimpleRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full -Database $psudoSimpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -sqlInstance $env:instance2 -RecoveryModel BulkLogged -Database $bulkLoggedRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Simple -Database $simpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Simple -Database $psudoSimpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Full -Database $psudoSimpleRecovery -Confirm:$false } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $fullRecovery, $bulkLoggedRecovery, $simpleRecovery, $psudoSimpleRecovery + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance2 -Database $fullRecovery, $bulkLoggedRecovery, $simpleRecovery, $psudoSimpleRecovery } Context "Default Execution" { BeforeAll { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $fullRecovery, $psudoSimpleRecovery, 'Model' + $results = Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -Database $fullRecovery, $psudoSimpleRecovery, 'Model' } It "Should return $fullRecovery, $psudoSimpleRecovery, and Model" { @@ -71,7 +71,7 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { Context "Full Recovery" { BeforeAll { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full -Database $fullRecovery, $psudoSimpleRecovery -ExcludeDatabase 'Model' + $results = Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Full -Database $fullRecovery, $psudoSimpleRecovery -ExcludeDatabase 'Model' } It "Should return $fullRecovery and $psudoSimpleRecovery" { @@ -81,7 +81,7 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { Context "Bulk Logged Recovery" { BeforeAll { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Bulk_Logged -Database $bulkLoggedRecovery + $results = Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Bulk_Logged -Database $bulkLoggedRecovery } It "Should return $bulkLoggedRecovery" { @@ -91,7 +91,7 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { Context "Simple Recovery" { BeforeAll { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $simpleRecovery + $results = Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Simple -Database $simpleRecovery } It "Should return $simpleRecovery" { @@ -101,7 +101,7 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { Context "Psudo Simple Recovery" { BeforeAll { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full | Where-Object {$_.database -eq $psudoSimpleRecovery} + $results = Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Full | Where-Object {$_.database -eq $psudoSimpleRecovery} } It "Should return $psudoSimpleRecovery" { @@ -111,17 +111,17 @@ Describe "Test-DbaDbRecoveryModel Integration Tests" -Tag "IntegrationTests" { Context "Error Check" { It "Should Throw Error for Incorrect Recovery Model" { - { Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Awesome -EnableException -Database 'dontexist' } | Should -Throw + { Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -RecoveryModel Awesome -EnableException -Database 'dontexist' } | Should -Throw } It "Should Throw Error for a DB Connection Error" { Mock Connect-DbaInstance { throw } -ModuleName dbatools - { Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -EnableException } | Should -Throw + { Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -EnableException } | Should -Throw } It "Should Throw Error for Output Error" { Mock Select-DefaultView { throw } -ModuleName dbatools - { Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -EnableException } | Should -Throw + { Test-DbaDbRecoveryModel -SqlInstance $env:instance2 -EnableException } | Should -Throw } } } diff --git a/tests/Test-DbaDeprecatedFeature.Tests.ps1 b/tests/Test-DbaDeprecatedFeature.Tests.ps1 index fbf404113c..cbc0861ec8 100644 --- a/tests/Test-DbaDeprecatedFeature.Tests.ps1 +++ b/tests/Test-DbaDeprecatedFeature.Tests.ps1 @@ -26,18 +26,18 @@ Describe "Test-DbaDeprecatedFeature" { $CommandUnderTest | Should -HaveParameter InputObject -Type Database[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { It "Should return a result" { - $results = Test-DbaDeprecatedFeature -SqlInstance $script:instance2 + $results = Test-DbaDeprecatedFeature -SqlInstance $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should return a result for a database" { - $results = Test-DbaDeprecatedFeature -SqlInstance $script:instance2 -Database Master + $results = Test-DbaDeprecatedFeature -SqlInstance $env:instance2 -Database Master $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Test-DbaDiskAlignment.Tests.ps1 b/tests/Test-DbaDiskAlignment.Tests.ps1 index f948a69cd3..8b2ec67c9c 100644 --- a/tests/Test-DbaDiskAlignment.Tests.ps1 +++ b/tests/Test-DbaDiskAlignment.Tests.ps1 @@ -30,15 +30,15 @@ Describe "Test-DbaDiskAlignment" { Context "Command actually works" { BeforeAll { - $script:dbatoolsci_computer = $env:COMPUTERNAME # This is a placeholder. Replace with actual value if different. + $env:dbatoolsci_computer = $env:COMPUTERNAME # This is a placeholder. Replace with actual value if different. } It "Should return a result" { - $results = Test-DbaDiskAlignment -ComputerName $script:dbatoolsci_computer + $results = Test-DbaDiskAlignment -ComputerName $env:dbatoolsci_computer $results | Should -Not -BeNullOrEmpty } It "Should return a result not using sql" { - $results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $script:dbatoolsci_computer + $results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $env:dbatoolsci_computer $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Test-DbaDiskAllocation.Tests.ps1 b/tests/Test-DbaDiskAllocation.Tests.ps1 index e6fc0318d3..3ef54f7e28 100644 --- a/tests/Test-DbaDiskAllocation.Tests.ps1 +++ b/tests/Test-DbaDiskAllocation.Tests.ps1 @@ -30,15 +30,15 @@ Describe "Test-DbaDiskAllocation" { Context "Command actually works" { BeforeDiscovery { - $script:instance2 = $script:instance2 # Ensure this variable is in scope for discovery + $env:instance2 = $env:instance2 # Ensure this variable is in scope for discovery } It "Should return a result" { - $results = Test-DbaDiskAllocation -ComputerName $script:instance2 + $results = Test-DbaDiskAllocation -ComputerName $env:instance2 $results | Should -Not -BeNullOrEmpty } It "Should return a result not using sql" { - $results = Test-DbaDiskAllocation -NoSqlCheck -ComputerName $script:instance2 + $results = Test-DbaDiskAllocation -NoSqlCheck -ComputerName $env:instance2 $results | Should -Not -BeNullOrEmpty } } diff --git a/tests/Test-DbaDiskSpeed.Tests.ps1 b/tests/Test-DbaDiskSpeed.Tests.ps1 index ce60f67e1c..861b343234 100644 --- a/tests/Test-DbaDiskSpeed.Tests.ps1 +++ b/tests/Test-DbaDiskSpeed.Tests.ps1 @@ -25,8 +25,8 @@ Describe "Test-DbaDiskSpeed Unit Tests" -Tag 'UnitTests' { It "Should have AggregateBy as a non-mandatory String parameter" { $CommandUnderTest | Should -HaveParameter AggregateBy -Type String -Not -Mandatory } - It "Should have EnableException as a non-mandatory SwitchParameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + It "Should have EnableException as a non-mandatory Switch" { + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -38,12 +38,12 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { It "should have info for model" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 $results.FileName | Should -Contain 'modellog.ldf' } It "returns only for master" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -Database master + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -Database master $results | Should -HaveCount 2 $results.FileName | Should -Contain 'master.mdf' $results.FileName | Should -Contain 'mastlog.ldf' @@ -54,13 +54,13 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { } It "sample pipeline" { - $results = @($script:instance1, $script:instance2) | Test-DbaDiskSpeed -Database master + $results = @($env:instance1, $env:instance2) | Test-DbaDiskSpeed -Database master $results | Should -HaveCount 4 } It "multiple databases included" { $databases = @('master', 'model') - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -Database $databases + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -Database $databases $results | Should -HaveCount 4 $results.Database | Should -Contain 'master' $results.Database | Should -Contain 'model' @@ -68,15 +68,15 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { It "multiple databases excluded" { $excludedDatabases = @('master', 'model') - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -ExcludeDatabase $excludedDatabases + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -ExcludeDatabase $excludedDatabases $results | Should -Not -BeNullOrEmpty $results.Database | Should -Not -Contain 'master' $results.Database | Should -Not -Contain 'model' } It "default aggregate by file" { - $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "File" - $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $script:instance1 + $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $env:instance1 -AggregateBy "File" + $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $env:instance1 $resultsWithParam | Should -HaveCount $resultsWithoutParam.Count $resultsWithParam.FileName | Should -Contain 'modellog.ldf' @@ -84,19 +84,19 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { } It "aggregate by database" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Database" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -AggregateBy "Database" $results.Database | Should -Contain 'model' } It "aggregate by disk" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -AggregateBy "Disk" $results | Should -Not -BeNullOrEmpty } It "aggregate by file and check column names returned" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'SizeGB', 'FileName', 'FileID', 'FileType', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name @@ -106,7 +106,7 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { It "aggregate by database and check column names returned" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Database" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -AggregateBy "Database" $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name @@ -116,7 +116,7 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { It "aggregate by disk and check column names returned" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance1 -AggregateBy "Disk" $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name @@ -128,23 +128,23 @@ Describe "Test-DbaDiskSpeed Integration Tests" -Tag "IntegrationTests" { Describe "Test-DbaDiskSpeed Linux Integration Tests" -Tag "LinuxIntegrationTests" { BeforeAll { . "$PSScriptRoot\constants.ps1" - $linuxSecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $linuxSecurePassword + $linuxSecurePassword = ConvertTo-SecureString -String $env:instance2SQLPassword -AsPlainText -Force + $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:instance2SQLUserName, $linuxSecurePassword } Context "Linux instance tests" -Skip:(-not $env:TEST_LINUX_INSTANCE) { It "test commands on a Linux instance" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" - $databases = Get-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential + $results = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" + $databases = Get-DbaDatabase -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential $results.Database | Should -Contain 'model' $results | Should -HaveCount $databases.Count - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" $results | Should -Not -BeNullOrEmpty - $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "File" - $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential + $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "File" + $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential $resultsWithParam | Should -HaveCount $resultsWithoutParam.Count $resultsWithParam.FileName | Should -Contain 'modellog.ldf' @@ -154,7 +154,7 @@ Describe "Test-DbaDiskSpeed Linux Integration Tests" -Tag "LinuxIntegrationTests It "aggregate by file and check column names returned on a Linux instance" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'SizeGB', 'FileName', 'FileID', 'FileType', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential + $results = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name @@ -164,7 +164,7 @@ Describe "Test-DbaDiskSpeed Linux Integration Tests" -Tag "LinuxIntegrationTests It "aggregate by database and check column names returned on a Linux instance" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name @@ -174,7 +174,7 @@ Describe "Test-DbaDiskSpeed Linux Integration Tests" -Tag "LinuxIntegrationTests It "aggregate by disk and check column names returned on a Linux instance" { $expectedColumns = 'ComputerName', 'InstanceName', 'SqlInstance', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $env:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" $results | Should -Not -BeNullOrEmpty $columnNames = $results[0].PSObject.Properties.Name diff --git a/tests/Test-DbaEndpoint.Tests.ps1 b/tests/Test-DbaEndpoint.Tests.ps1 index 78edb2cc0f..f40a3ea41f 100644 --- a/tests/Test-DbaEndpoint.Tests.ps1 +++ b/tests/Test-DbaEndpoint.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Test-DbaEndpoint" { $CommandUnderTest | Should -HaveParameter InputObject -Type Endpoint[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -33,7 +33,7 @@ Describe "Test-DbaEndpoint" { } It "Returns success" -Skip { - $results = Test-DbaEndpoint -SqlInstance $script:instance3 + $results = Test-DbaEndpoint -SqlInstance $env:instance3 $results | Select-Object -First 1 -ExpandProperty Connection | Should -Be 'Success' } } diff --git a/tests/Test-DbaIdentityUsage.Tests.ps1 b/tests/Test-DbaIdentityUsage.Tests.ps1 index 48a54c741c..d4735821a1 100644 --- a/tests/Test-DbaIdentityUsage.Tests.ps1 +++ b/tests/Test-DbaIdentityUsage.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Test-DbaIdentityUsage" { $CommandUnderTest | Should -HaveParameter Threshold -Type Int32 -Not -Mandatory } It "Should have ExcludeSystem parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSystem -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ExcludeSystem -Type Switch -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } @@ -32,37 +32,37 @@ Describe "Test-DbaIdentityUsage" { BeforeAll { $table = "TestTable_$(Get-random)" $tableDDL = "CREATE TABLE $table (testId TINYINT IDENTITY(1,1),testData DATETIME2 DEFAULT getdate() )" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $tableDDL -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $tableDDL -database TempDb $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" 1..128 | ForEach-Object { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $insertSql -database TempDb } } AfterAll { $cleanup = "Drop table $table" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $cleanup -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $cleanup -database TempDb } It "Identity column should have 128 uses" { - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.NumberOfUses | Should -Be 128 } It "TinyInt identity column with 128 rows inserted should be 50.20% full" { - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.PercentUsed | Should -Be 50.20 } It "Identity column should have 255 uses after inserting 127 more rows" { $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" 1..127 | ForEach-Object { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $insertSql -database TempDb } - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.NumberOfUses | Should -Be 255 } It "TinyInt with 255 rows should be 100% full" { - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.PercentUsed | Should -Be 100 } } @@ -71,24 +71,24 @@ Describe "Test-DbaIdentityUsage" { BeforeAll { $table = "TestTable_$(Get-random)" $tableDDL = "CREATE TABLE $table (testId tinyint IDENTITY(0,5),testData DATETIME2 DEFAULT getdate() )" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $tableDDL -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $tableDDL -database TempDb $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" 1..25 | ForEach-Object { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $insertSql -database TempDb } } AfterAll { $cleanup = "Drop table $table" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $cleanup -database TempDb + Invoke-DbaQuery -SqlInstance $env:instance1 -Query $cleanup -database TempDb } It "Identity column should have 24 uses" { - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.NumberOfUses | Should -Be 24 } It "TinyInt identity column with 25 rows using increment of 5 should be 47.06% full" { - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $env:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} $results.PercentUsed | Should -Be 47.06 } } diff --git a/tests/Test-DbaInstanceName.Tests.ps1 b/tests/Test-DbaInstanceName.Tests.ps1 index 35707389fa..bdb3296521 100644 --- a/tests/Test-DbaInstanceName.Tests.ps1 +++ b/tests/Test-DbaInstanceName.Tests.ps1 @@ -18,16 +18,16 @@ Describe "Test-DbaInstanceName" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have ExcludeSsrs as a parameter" { - $CommandUnderTest | Should -HaveParameter ExcludeSsrs -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter ExcludeSsrs -Type Switch } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command tests servername" { BeforeAll { - $results = Test-DbaInstanceName -SqlInstance $script:instance2 + $results = Test-DbaInstanceName -SqlInstance $env:instance2 } It "should say rename is not required" { diff --git a/tests/Test-DbaLastBackup.Tests.ps1 b/tests/Test-DbaLastBackup.Tests.ps1 index c7a2afdbde..9debe62681 100644 --- a/tests/Test-DbaLastBackup.Tests.ps1 +++ b/tests/Test-DbaLastBackup.Tests.ps1 @@ -42,16 +42,16 @@ Describe "Test-DbaLastBackup Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter Prefix -Type String -Not -Mandatory } It "Should have VerifyOnly as a parameter" { - $CommandUnderTest | Should -HaveParameter VerifyOnly -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter VerifyOnly -Type Switch -Not -Mandatory } It "Should have NoCheck as a parameter" { - $CommandUnderTest | Should -HaveParameter NoCheck -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoCheck -Type Switch -Not -Mandatory } It "Should have NoDrop as a parameter" { - $CommandUnderTest | Should -HaveParameter NoDrop -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoDrop -Type Switch -Not -Mandatory } It "Should have CopyFile as a parameter" { - $CommandUnderTest | Should -HaveParameter CopyFile -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter CopyFile -Type Switch -Not -Mandatory } It "Should have CopyPath as a parameter" { $CommandUnderTest | Should -HaveParameter CopyPath -Type String -Not -Mandatory @@ -63,10 +63,10 @@ Describe "Test-DbaLastBackup Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter DeviceType -Type String[] -Not -Mandatory } It "Should have IncludeCopyOnly as a parameter" { - $CommandUnderTest | Should -HaveParameter IncludeCopyOnly -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IncludeCopyOnly -Type Switch -Not -Mandatory } It "Should have IgnoreLogBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreLogBackup -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IgnoreLogBackup -Type Switch -Not -Mandatory } It "Should have AzureCredential as a parameter" { $CommandUnderTest | Should -HaveParameter AzureCredential -Type String -Not -Mandatory @@ -81,16 +81,16 @@ Describe "Test-DbaLastBackup Unit Tests" -Tag 'UnitTests' { $CommandUnderTest | Should -HaveParameter BufferCount -Type Int32 -Not -Mandatory } It "Should have IgnoreDiffBackup as a parameter" { - $CommandUnderTest | Should -HaveParameter IgnoreDiffBackup -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter IgnoreDiffBackup -Type Switch -Not -Mandatory } It "Should have MaxDop as a parameter" { $CommandUnderTest | Should -HaveParameter MaxDop -Type Int32 -Not -Mandatory } It "Should have ReuseSourceFolderStructure as a parameter" { - $CommandUnderTest | Should -HaveParameter ReuseSourceFolderStructure -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter ReuseSourceFolderStructure -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } } @@ -101,7 +101,7 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { $testlastbackup = "dbatoolsci_testlastbackup$random" $dbs = $testlastbackup, "dbatoolsci_lildb", "dbatoolsci_testrestore", "dbatoolsci_singlerestore" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 foreach ($db in $dbs) { $server.Query("CREATE DATABASE $db") $server.Query("ALTER DATABASE $db SET RECOVERY FULL WITH NO_WAIT") @@ -113,31 +113,31 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { AfterAll { # these for sure $dbs += "bigtestrest", "smalltestrest" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false # those just in case test-dbalastbackup didn't cooperate - Get-DbaDatabase -SqlInstance $script:instance1 | Where-Object Name -like 'dbatools-testrestore-dbatoolsci_*' | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance1 | Where-Object Name -like 'dbatools-testrestore-dbatoolsci_*' | Remove-DbaDatabase -Confirm:$false # see "Restores using a specific path" Get-ChildItem -Path C:\Temp\dbatools-testrestore-dbatoolsci_singlerestore* | Remove-Item } Context "Setup restores and backups on the local drive for Test-DbaLastBackup" { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Backup-DbaDatabase -Type Database - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample1')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample2')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample3')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample4')" + Get-DbaDatabase -SqlInstance $env:instance1 -Database $dbs | Backup-DbaDatabase -Type Database + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample')" + Get-DbaDatabase -SqlInstance $env:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample1')" + Get-DbaDatabase -SqlInstance $env:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample2')" + Get-DbaDatabase -SqlInstance $env:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample3')" + Get-DbaDatabase -SqlInstance $env:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample4')" } } Context "Test a single database" { It "Should return success" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database $testlastbackup + $results = Test-DbaLastBackup -SqlInstance $env:instance1 -Database $testlastbackup $results.RestoreResult | Should -Be "Success" $results.DbccResult | Should -Be "Success" $results.BackupDates | ForEach-Object { $_ | Should -BeOfType DbaDateTime } @@ -146,16 +146,16 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Testing the whole instance" { It "Should be more than 3 databases" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -ExcludeDatabase tempdb + $results = Test-DbaLastBackup -SqlInstance $env:instance1 -ExcludeDatabase tempdb $results.count | Should -BeGreaterThan 3 } } Context "Restores using a specific path" { BeforeAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Backup-DbaDatabase - $null = Test-DbaLastBackup -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" -DataDirectory C:\Temp -LogDirectory C:\Temp -NoDrop - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database "dbatools-testrestore-dbatoolsci_singlerestore" + $null = Get-DbaDatabase -SqlInstance $env:instance1 -Database "dbatoolsci_singlerestore" | Backup-DbaDatabase + $null = Test-DbaLastBackup -SqlInstance $env:instance1 -Database "dbatoolsci_singlerestore" -DataDirectory C:\Temp -LogDirectory C:\Temp -NoDrop + $results = Get-DbaDbFile -SqlInstance $env:instance1 -Database "dbatools-testrestore-dbatoolsci_singlerestore" } It "Should match C:\Temp" { @@ -166,7 +166,7 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Test Ignoring Diff Backups" { It "Should return success and not contain a diff backup" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database $testlastbackup -IgnoreDiffBackup + $results = Test-DbaLastBackup -SqlInstance $env:instance1 -Database $testlastbackup -IgnoreDiffBackup $results.RestoreResult | Should -Be "Success" ($results.BackupFiles | Where-Object { $_ -like '*diff*' }).count | Should -Be 0 } @@ -174,12 +174,12 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { Context "Test dbsize skip and cleanup (Issue 3968)" { BeforeAll { - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest -Path $script:appveyorlabrepo\sql2008-backups\db1\FULL -ReplaceDbNameInFile - Backup-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Database smalltestrest -Path $script:appveyorlabrepo\sql2008-backups\db2\FULL\SQL2008_db2_FULL_20170518_041738.bak -ReplaceDbNameInFile - Backup-DbaDatabase -SqlInstance $script:instance1 -Database smalltestrest + $null = Restore-DbaDatabase -SqlInstance $env:instance1 -Database bigtestrest -Path $env:appveyorlabrepo\sql2008-backups\db1\FULL -ReplaceDbNameInFile + Backup-DbaDatabase -SqlInstance $env:instance1 -Database bigtestrest + $null = Restore-DbaDatabase -SqlInstance $env:instance1 -Database smalltestrest -Path $env:appveyorlabrepo\sql2008-backups\db2\FULL\SQL2008_db2_FULL_20170518_041738.bak -ReplaceDbNameInFile + Backup-DbaDatabase -SqlInstance $env:instance1 -Database smalltestrest - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database bigtestrest, smalltestrest -CopyFile -CopyPath c:\temp -MaxSize 3 -Prefix testlast + $results = Test-DbaLastBackup -SqlInstance $env:instance1 -Database bigtestrest, smalltestrest -CopyFile -CopyPath c:\temp -MaxSize 3 -Prefix testlast $fileresult = Get-ChildItem c:\temp | Where-Object { $_.name -like '*bigtestrest' } } @@ -195,7 +195,7 @@ Describe "Test-DbaLastBackup Integration Tests" -Tag "IntegrationTests" { } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest, smalltestrest | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance1 -Database bigtestrest, smalltestrest | Remove-DbaDatabase -Confirm:$false } } } diff --git a/tests/Test-DbaLinkedServerConnection.Tests.ps1 b/tests/Test-DbaLinkedServerConnection.Tests.ps1 index 1d12e52fe6..e9ac60abe3 100644 --- a/tests/Test-DbaLinkedServerConnection.Tests.ps1 +++ b/tests/Test-DbaLinkedServerConnection.Tests.ps1 @@ -17,47 +17,47 @@ Describe "Test-DbaLinkedServerConnection" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + $server = Connect-DbaInstance -SqlInstance $env:instance1 -Database master $server.Query("EXEC master.dbo.sp_addlinkedserver @server = N'localhost', @srvproduct=N'SQL Server'") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + $server = Connect-DbaInstance -SqlInstance $env:instance1 -Database master $server.Query("EXEC master.dbo.sp_dropserver @server=N'localhost', @droplogins='droplogins'") } It "Function returns results" { - $results = Test-DbaLinkedServerConnection -SqlInstance $script:instance1 | Where-Object LinkedServerName -eq 'localhost' + $results = Test-DbaLinkedServerConnection -SqlInstance $env:instance1 | Where-Object LinkedServerName -eq 'localhost' $results | Should -Not -BeNullOrEmpty } It "Linked server name is localhost" { - $results = Test-DbaLinkedServerConnection -SqlInstance $script:instance1 | Where-Object LinkedServerName -eq 'localhost' + $results = Test-DbaLinkedServerConnection -SqlInstance $env:instance1 | Where-Object LinkedServerName -eq 'localhost' $results.LinkedServerName | Should -Be 'localhost' } It "Connectivity is true" { - $results = Test-DbaLinkedServerConnection -SqlInstance $script:instance1 | Where-Object LinkedServerName -eq 'localhost' + $results = Test-DbaLinkedServerConnection -SqlInstance $env:instance1 | Where-Object LinkedServerName -eq 'localhost' $results.Connectivity | Should -BeTrue } It "Piping from Get-DbaLinkedServer returns results" { - $pipeResults = Get-DbaLinkedServer -SqlInstance $script:instance1 | Test-DbaLinkedServerConnection + $pipeResults = Get-DbaLinkedServer -SqlInstance $env:instance1 | Test-DbaLinkedServerConnection $pipeResults | Should -Not -BeNullOrEmpty } It "Piped linked server name is localhost" { - $pipeResults = Get-DbaLinkedServer -SqlInstance $script:instance1 | Test-DbaLinkedServerConnection + $pipeResults = Get-DbaLinkedServer -SqlInstance $env:instance1 | Test-DbaLinkedServerConnection $pipeResults.LinkedServerName | Should -Be 'localhost' } It "Piped connectivity is true" { - $pipeResults = Get-DbaLinkedServer -SqlInstance $script:instance1 | Test-DbaLinkedServerConnection + $pipeResults = Get-DbaLinkedServer -SqlInstance $env:instance1 | Test-DbaLinkedServerConnection $pipeResults.Connectivity | Should -BeTrue } } diff --git a/tests/Test-DbaLoginPassword.Tests.ps1 b/tests/Test-DbaLoginPassword.Tests.ps1 index 4a6649c7ae..59ebd95b80 100644 --- a/tests/Test-DbaLoginPassword.Tests.ps1 +++ b/tests/Test-DbaLoginPassword.Tests.ps1 @@ -26,16 +26,16 @@ Describe "Test-DbaLoginPassword" { $CommandUnderTest | Should -HaveParameter InputObject -Type Login[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Integration Tests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $weaksauce = "dbatoolsci_testweak" $weakpass = ConvertTo-SecureString $weaksauce -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $weaksauce -HashedPassword (Get-PasswordHash $weakpass $server.VersionMajor) -Force + $newlogin = New-DbaLogin -SqlInstance $env:instance1 -Login $weaksauce -HashedPassword (Get-PasswordHash $weakpass $server.VersionMajor) -Force } AfterAll { try { @@ -46,15 +46,15 @@ Describe "Test-DbaLoginPassword" { } It "finds the new weak password and supports piping" { - $results = Get-DbaLogin -SqlInstance $script:instance1 | Test-DbaLoginPassword + $results = Get-DbaLogin -SqlInstance $env:instance1 | Test-DbaLoginPassword $results.SqlLogin | Should -Contain $weaksauce } It "returns just one login" { - $results = Test-DbaLoginPassword -SqlInstance $script:instance1 -Login $weaksauce + $results = Test-DbaLoginPassword -SqlInstance $env:instance1 -Login $weaksauce $results.SqlLogin | Should -Be $weaksauce } It "handles passwords with quotes, see #9095" { - $results = Test-DbaLoginPassword -SqlInstance $script:instance1 -Login $weaksauce -Dictionary "&é`"'(-", "hello" + $results = Test-DbaLoginPassword -SqlInstance $env:instance1 -Login $weaksauce -Dictionary "&é`"'(-", "hello" $results.SqlLogin | Should -Be $weaksauce } } diff --git a/tests/Test-DbaManagementObject.Tests.ps1 b/tests/Test-DbaManagementObject.Tests.ps1 index 3c43be76c0..ab0305ab35 100644 --- a/tests/Test-DbaManagementObject.Tests.ps1 +++ b/tests/Test-DbaManagementObject.Tests.ps1 @@ -27,23 +27,23 @@ Describe "Test-DbaManagementObject" { Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $versionMajor = $server.VersionMajor } It "Should have correct properties" { - $trueResults = Test-DbaManagementObject -ComputerName $script:instance2 -VersionNumber $versionMajor + $trueResults = Test-DbaManagementObject -ComputerName $env:instance2 -VersionNumber $versionMajor $ExpectedProps = 'ComputerName', 'Version', 'Exists' ($trueResults[0].PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } It "Should return true for VersionNumber $versionMajor" { - $trueResults = Test-DbaManagementObject -ComputerName $script:instance2 -VersionNumber $versionMajor + $trueResults = Test-DbaManagementObject -ComputerName $env:instance2 -VersionNumber $versionMajor $trueResults.Exists | Should -Be $true } It "Should return false for VersionNumber -1" { - $falseResults = Test-DbaManagementObject -ComputerName $script:instance2 -VersionNumber -1 + $falseResults = Test-DbaManagementObject -ComputerName $env:instance2 -VersionNumber -1 $falseResults.Exists | Should -Be $false } } diff --git a/tests/Test-DbaMaxDop.Tests.ps1 b/tests/Test-DbaMaxDop.Tests.ps1 index 760be330c4..c9038e4c0a 100644 --- a/tests/Test-DbaMaxDop.Tests.ps1 +++ b/tests/Test-DbaMaxDop.Tests.ps1 @@ -17,29 +17,29 @@ Describe "Test-DbaMaxDop" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command usage" { BeforeDiscovery { - $script:instance2 = $script:instance2 + $env:instance2 = $env:instance2 } BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $db1 = "dbatoolsci_testMaxDop" $server.Query("CREATE DATABASE $db1") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1 $setupright = $null -ne $needed } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $env:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false } It "Command works on SQL Server 2016 or higher instances" -Skip:(-not $setupright) { - $results = Test-DbaMaxDop -SqlInstance $script:instance2 + $results = Test-DbaMaxDop -SqlInstance $env:instance2 $ExpectedProps = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'DatabaseMaxDop', 'CurrentInstanceMaxDop', 'RecommendedMaxDop', 'Notes' $results | ForEach-Object { diff --git a/tests/Test-DbaMaxMemory.Tests.ps1 b/tests/Test-DbaMaxMemory.Tests.ps1 index 0aec016e84..47c0c7c80a 100644 --- a/tests/Test-DbaMaxMemory.Tests.ps1 +++ b/tests/Test-DbaMaxMemory.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Test-DbaMaxMemory" { $CommandUnderTest | Should -HaveParameter Credential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Test-DbaMigrationConstraint.Tests.ps1 b/tests/Test-DbaMigrationConstraint.Tests.ps1 index 95de9e8483..51af54ef66 100644 --- a/tests/Test-DbaMigrationConstraint.Tests.ps1 +++ b/tests/Test-DbaMigrationConstraint.Tests.ps1 @@ -8,9 +8,9 @@ Describe "Test-DbaMigrationConstraint" { $db1 = "dbatoolsci_testMigrationConstraint" $db2 = "dbatoolsci_testMigrationConstraint_2" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "CREATE DATABASE $db1" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "CREATE DATABASE $db2" - $needed = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db1, $db2 + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "CREATE DATABASE $db1" + Invoke-DbaQuery -SqlInstance $env:instance1 -Query "CREATE DATABASE $db2" + $needed = Get-DbaDatabase -SqlInstance $env:instance1 -Database $db1, $db2 $setupright = $true if ($needed.Count -ne 2) { $setupright = $false @@ -19,7 +19,7 @@ Describe "Test-DbaMigrationConstraint" { AfterAll { if (-not $appveyor) { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $env:instance1 -Database $db1, $db2 -ErrorAction SilentlyContinue } } @@ -46,13 +46,13 @@ Describe "Test-DbaMigrationConstraint" { $CommandUnderTest | Should -HaveParameter ExcludeDatabase -Type Object[] } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Validate multiple databases" { BeforeAll { - $results = Test-DbaMigrationConstraint -Source $script:instance1 -Destination $script:instance2 + $results = Test-DbaMigrationConstraint -Source $env:instance1 -Destination $env:instance2 } It 'Both databases are migratable' { foreach ($result in $results) { @@ -63,7 +63,7 @@ Describe "Test-DbaMigrationConstraint" { Context "Validate single database" { It 'Database is migratable' { - $result = Test-DbaMigrationConstraint -Source $script:instance1 -Destination $script:instance2 -Database $db1 + $result = Test-DbaMigrationConstraint -Source $env:instance1 -Destination $env:instance2 -Database $db1 $result.IsMigratable | Should -Be $true } } diff --git a/tests/Test-DbaNetworkLatency.Tests.ps1 b/tests/Test-DbaNetworkLatency.Tests.ps1 index f99d4be164..16bf3a2ba8 100644 --- a/tests/Test-DbaNetworkLatency.Tests.ps1 +++ b/tests/Test-DbaNetworkLatency.Tests.ps1 @@ -23,7 +23,7 @@ Describe "Test-DbaNetworkLatency" { $CommandUnderTest | Should -HaveParameter Count -Type Int32 } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 b/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 index c0a549efc1..2cb28a0c8f 100644 --- a/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 +++ b/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 @@ -18,13 +18,13 @@ Describe "Test-DbaOptimizeForAdHoc" { $CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $results = Test-DbaOptimizeForAdHoc -SqlInstance $script:instance2 + $results = Test-DbaOptimizeForAdHoc -SqlInstance $env:instance2 } It "Should return result for the server" { $results | Should -Not -BeNullOrEmpty diff --git a/tests/Test-DbaPath.Tests.ps1 b/tests/Test-DbaPath.Tests.ps1 index 5af5c7fd1b..76b1f9844e 100644 --- a/tests/Test-DbaPath.Tests.ps1 +++ b/tests/Test-DbaPath.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Test-DbaPath" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $trueTest = (Get-DbaDbFile -SqlInstance $script:instance2 -Database master)[0].PhysicalName + $trueTest = (Get-DbaDbFile -SqlInstance $env:instance2 -Database master)[0].PhysicalName if ($trueTest.Length -eq 0) { Set-ItResult -Inconclusive -Because "Setup failed" } @@ -28,29 +28,29 @@ Describe "Test-DbaPath" { $CommandUnderTest | Should -HaveParameter Path -Type Object } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { It "Should return true if the path IS accessible to the instance" { - $result = Test-DbaPath -SqlInstance $script:instance2 -Path $trueTest + $result = Test-DbaPath -SqlInstance $env:instance2 -Path $trueTest $result | Should -BeTrue } It "Should return false if the path IS NOT accessible to the instance" { - $result = Test-DbaPath -SqlInstance $script:instance2 -Path $falseTest + $result = Test-DbaPath -SqlInstance $env:instance2 -Path $falseTest $result | Should -BeFalse } It "Should return multiple results when passed multiple paths" { - $results = Test-DbaPath -SqlInstance $script:instance2 -Path $trueTest, $falseTest + $results = Test-DbaPath -SqlInstance $env:instance2 -Path $trueTest, $falseTest ($results | Where-Object FilePath -eq $trueTest).FileExists | Should -BeTrue ($results | Where-Object FilePath -eq $falseTest).FileExists | Should -BeFalse } It "Should return multiple results when passed multiple instances" { - $results = Test-DbaPath -SqlInstance $script:instance2, $script:instance1 -Path $falseTest + $results = Test-DbaPath -SqlInstance $env:instance2, $env:instance1 -Path $falseTest foreach ($result in $results) { $result.FileExists | Should -BeFalse } @@ -58,12 +58,12 @@ Describe "Test-DbaPath" { } It "Should return pscustomobject results when passed an array (even with one path)" { - $results = Test-DbaPath -SqlInstance $script:instance2 -Path @($trueTest) + $results = Test-DbaPath -SqlInstance $env:instance2 -Path @($trueTest) ($results | Where-Object FilePath -eq $trueTest).FileExists | Should -BeTrue } It "Should return pscustomobject results indicating if the path is a file or a directory" { - $results = Test-DbaPath -SqlInstance $script:instance2 -Path @($trueTest, $trueTestPath) + $results = Test-DbaPath -SqlInstance $env:instance2 -Path @($trueTest, $trueTestPath) ($results | Where-Object FilePath -eq $trueTest).FileExists | Should -BeTrue ($results | Where-Object FilePath -eq $trueTestPath).FileExists | Should -BeTrue ($results | Where-Object FilePath -eq $trueTest).IsContainer | Should -BeFalse diff --git a/tests/Test-DbaPowerPlan.Tests.ps1 b/tests/Test-DbaPowerPlan.Tests.ps1 index e78d6f83a6..4b955c4fb9 100644 --- a/tests/Test-DbaPowerPlan.Tests.ps1 +++ b/tests/Test-DbaPowerPlan.Tests.ps1 @@ -21,17 +21,17 @@ Describe "Test-DbaPowerPlan" { $CommandUnderTest | Should -HaveParameter PowerPlan -Type String } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command actually works" { BeforeAll { - $null = Set-DbaPowerPlan -ComputerName $script:instance2 -PowerPlan 'Balanced' + $null = Set-DbaPowerPlan -ComputerName $env:instance2 -PowerPlan 'Balanced' } It "Should return result for the server" { - $results = Test-DbaPowerPlan -ComputerName $script:instance2 + $results = Test-DbaPowerPlan -ComputerName $env:instance2 $results | Should -Not -BeNull $results.ActivePowerPlan | Should -Be 'Balanced' $results.RecommendedPowerPlan | Should -Be 'High performance' @@ -40,7 +40,7 @@ Describe "Test-DbaPowerPlan" { } It "Use 'Balanced' plan as best practice" { - $results = Test-DbaPowerPlan -ComputerName $script:instance2 -PowerPlan 'Balanced' + $results = Test-DbaPowerPlan -ComputerName $env:instance2 -PowerPlan 'Balanced' $results.IsBestPractice | Should -BeTrue } } diff --git a/tests/Test-DbaReplLatency.Tests.ps1 b/tests/Test-DbaReplLatency.Tests.ps1 index 10d8fe3ab2..7641411ee7 100644 --- a/tests/Test-DbaReplLatency.Tests.ps1 +++ b/tests/Test-DbaReplLatency.Tests.ps1 @@ -27,13 +27,13 @@ Describe "Test-DbaReplLatency" { $CommandUnderTest | Should -HaveParameter TimeToLive -Type Int32 } It "Should have RetainToken parameter" { - $CommandUnderTest | Should -HaveParameter RetainToken -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter RetainToken -Type Switch } It "Should have DisplayTokenHistory parameter" { - $CommandUnderTest | Should -HaveParameter DisplayTokenHistory -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter DisplayTokenHistory -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } diff --git a/tests/Test-DbaTempDbConfig.Tests.ps1 b/tests/Test-DbaTempDbConfig.Tests.ps1 index fc1f3f7e6f..3805d462e4 100644 --- a/tests/Test-DbaTempDbConfig.Tests.ps1 +++ b/tests/Test-DbaTempDbConfig.Tests.ps1 @@ -22,9 +22,9 @@ Describe "Test-DbaTempDbConfig" { } } - Context "Command actually works on $script:instance2" { + Context "Command actually works on $env:instance2" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $results = Test-DbaTempDbConfig -SqlInstance $server } diff --git a/tests/Test-DbaWindowsLogin.Tests.ps1 b/tests/Test-DbaWindowsLogin.Tests.ps1 index 842ccd5feb..64830e6486 100644 --- a/tests/Test-DbaWindowsLogin.Tests.ps1 +++ b/tests/Test-DbaWindowsLogin.Tests.ps1 @@ -33,28 +33,28 @@ Describe "Test-DbaWindowsLogin" { $CommandUnderTest | Should -HaveParameter InputObject -Type Login[] -Not -Mandatory } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } Context "Command actually works" { BeforeDiscovery { - $script:skipIntegrationTests = [Environment]::GetEnvironmentVariable('DBA_TOOLS_SKIP_INTEGRATION_TESTS') -eq 'true' + $env:skipIntegrationTests = [Environment]::GetEnvironmentVariable('DBA_TOOLS_SKIP_INTEGRATION_TESTS') -eq 'true' } - It "Should return correct properties" -Skip:$script:skipIntegrationTests { - $results = Test-DbaWindowsLogin -SqlInstance $script:instance2 + It "Should return correct properties" -Skip:$env:skipIntegrationTests { + $results = Test-DbaWindowsLogin -SqlInstance $env:instance2 $ExpectedProps = 'AccountNotDelegated', 'AllowReversiblePasswordEncryption', 'CannotChangePassword', 'DisabledInSQLServer', 'Domain', 'Enabled', 'Found', 'LockedOut', 'Login', 'PasswordExpired', 'PasswordNeverExpires', 'PasswordNotRequired', 'Server', 'SmartcardLogonRequired', 'TrustedForDelegation', 'Type', 'UserAccountControl' ($results[0].PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } - It "Should return true if Account type is User" -Skip:$script:skipIntegrationTests { - $results = Test-DbaWindowsLogin -SqlInstance $script:instance2 + It "Should return true if Account type is User" -Skip:$env:skipIntegrationTests { + $results = Test-DbaWindowsLogin -SqlInstance $env:instance2 ($results | Where-Object Type -match 'User').Count | Should -BeGreaterThan 0 } - It "Should return true if Account is Found" -Skip:$script:skipIntegrationTests { - $results = Test-DbaWindowsLogin -SqlInstance $script:instance2 + It "Should return true if Account is Found" -Skip:$env:skipIntegrationTests { + $results = Test-DbaWindowsLogin -SqlInstance $env:instance2 ($results | Where-Object Found).Found | Should -Be $true } } diff --git a/tests/Test-PSRemoting.Tests.ps1 b/tests/Test-PSRemoting.Tests.ps1 index cbf835c1bf..61e1d0b17d 100644 --- a/tests/Test-PSRemoting.Tests.ps1 +++ b/tests/Test-PSRemoting.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Test-PSRemoting" { } It "Handles an instance, using just the computername" { - $result = Test-PSRemoting -ComputerName $script:instance1 + $result = Test-PSRemoting -ComputerName $env:instance1 $result | Should -Be $true } } diff --git a/tests/Uninstall-DbaSqlWatch.Tests.ps1 b/tests/Uninstall-DbaSqlWatch.Tests.ps1 index 998d332865..ac74c325dd 100644 --- a/tests/Uninstall-DbaSqlWatch.Tests.ps1 +++ b/tests/Uninstall-DbaSqlWatch.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Uninstall-DbaSqlWatch" { $CommandUnderTest | Should -HaveParameter Database -Type String } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -26,33 +26,33 @@ Describe "Uninstall-DbaSqlWatch" { BeforeAll { $database = "dbatoolsci_sqlwatch_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $server.Query("CREATE DATABASE $database") - Install-DbaSqlWatch -SqlInstance $script:instance2 -Database $database - Uninstall-DbaSqlWatch -SqlInstance $script:instance2 -Database $database + Install-DbaSqlWatch -SqlInstance $env:instance2 -Database $database + Uninstall-DbaSqlWatch -SqlInstance $env:instance2 -Database $database } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $env:instance2 -Database $database -Confirm:$false } It "Removed all tables" { - $tableCount = (Get-DbaDbTable -SqlInstance $script:instance2 -Database $Database | Where-Object {($_.Name -like "sql_perf_mon_*") -or ($_.Name -like "logger_*")}).Count + $tableCount = (Get-DbaDbTable -SqlInstance $env:instance2 -Database $Database | Where-Object {($_.Name -like "sql_perf_mon_*") -or ($_.Name -like "logger_*")}).Count $tableCount | Should -Be 0 } It "Removed all views" { - $viewCount = (Get-DbaDbView -SqlInstance $script:instance2 -Database $Database | Where-Object {$_.Name -like "vw_sql_perf_mon_*" }).Count + $viewCount = (Get-DbaDbView -SqlInstance $env:instance2 -Database $Database | Where-Object {$_.Name -like "vw_sql_perf_mon_*" }).Count $viewCount | Should -Be 0 } It "Removed all stored procedures" { - $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $Database | Where-Object {($_.Name -like "sp_sql_perf_mon_*") -or ($_.Name -like "usp_logger_*")}).Count + $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $env:instance2 -Database $Database | Where-Object {($_.Name -like "sp_sql_perf_mon_*") -or ($_.Name -like "usp_logger_*")}).Count $sprocCount | Should -Be 0 } It "Removed all SQL Agent jobs" { - $agentCount = (Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object {($_.Name -like "SqlWatch-*") -or ($_.Name -like "DBA-PERF-*")}).Count + $agentCount = (Get-DbaAgentJob -SqlInstance $env:instance2 | Where-Object {($_.Name -like "SqlWatch-*") -or ($_.Name -like "DBA-PERF-*")}).Count $agentCount | Should -Be 0 } } diff --git a/tests/Update-DbaInstance.Tests.ps1 b/tests/Update-DbaInstance.Tests.ps1 index c290c3eac7..2a7cb8ae1b 100644 --- a/tests/Update-DbaInstance.Tests.ps1 +++ b/tests/Update-DbaInstance.Tests.ps1 @@ -841,9 +841,9 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } Context "WhatIf upgrade target instance to latest SPCU" { It "Should whatif-upgrade to latest SPCU" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $instance = $server.ServiceName - $null = Update-DbaInstance -ComputerName $script:instance1 -Path $exeDir -Restart -EnableException -WhatIf -InstanceName $instance 3>$null + $null = Update-DbaInstance -ComputerName $env:instance1 -Path $exeDir -Restart -EnableException -WhatIf -InstanceName $instance 3>$null $testBuild = Test-DbaBuild -SqlInstance $server -MaxBehind 0CU Assert-MockCalled -CommandName Test-PendingReboot -Scope It -ModuleName dbatools Assert-MockCalled -CommandName Test-ElevationRequirement -Scope It -ModuleName dbatools diff --git a/tests/Update-DbaMaintenanceSolution.Tests.ps1 b/tests/Update-DbaMaintenanceSolution.Tests.ps1 index e9f4e77950..e727357cbb 100644 --- a/tests/Update-DbaMaintenanceSolution.Tests.ps1 +++ b/tests/Update-DbaMaintenanceSolution.Tests.ps1 @@ -21,10 +21,10 @@ Describe "Update-DbaMaintenanceSolution" { $CommandUnderTest | Should -HaveParameter LocalFile -Type String } It "Should have Force parameter" { - $CommandUnderTest | Should -HaveParameter Force -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Force -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -36,22 +36,22 @@ Describe "Update-DbaMaintenanceSolution" { BeforeAll { # Setup code for all tests in this context - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 } It "Updates the maintenance solution" { - $result = Update-DbaMaintenanceSolution -SqlInstance $script:instance1 -Database master + $result = Update-DbaMaintenanceSolution -SqlInstance $env:instance1 -Database master $result | Should -Not -BeNullOrEmpty $result.Database | Should -Be 'master' $result.Status | Should -Be 'Updated' } It "Throws an exception when an invalid database is specified" { - { Update-DbaMaintenanceSolution -SqlInstance $script:instance1 -Database 'InvalidDB' -EnableException } | Should -Throw + { Update-DbaMaintenanceSolution -SqlInstance $env:instance1 -Database 'InvalidDB' -EnableException } | Should -Throw } It "Updates only specified solutions" { - $result = Update-DbaMaintenanceSolution -SqlInstance $script:instance1 -Database master -Solution 'IndexOptimize' + $result = Update-DbaMaintenanceSolution -SqlInstance $env:instance1 -Database master -Solution 'IndexOptimize' $result | Should -Not -BeNullOrEmpty $result.Solution | Should -Be 'IndexOptimize' } @@ -59,7 +59,7 @@ Describe "Update-DbaMaintenanceSolution" { It "Uses a local file when specified" { $localFile = "TestDrive:\MaintenanceSolution.sql" Set-Content -Path $localFile -Value "SELECT 1 AS TestColumn" - $result = Update-DbaMaintenanceSolution -SqlInstance $script:instance1 -Database master -LocalFile $localFile + $result = Update-DbaMaintenanceSolution -SqlInstance $env:instance1 -Database master -LocalFile $localFile $result | Should -Not -BeNullOrEmpty $result.Status | Should -Be 'Updated' } diff --git a/tests/Update-DbaServiceAccount.Tests.ps1 b/tests/Update-DbaServiceAccount.Tests.ps1 index d985ecfd51..27aa396fc3 100644 --- a/tests/Update-DbaServiceAccount.Tests.ps1 +++ b/tests/Update-DbaServiceAccount.Tests.ps1 @@ -11,7 +11,7 @@ Describe "Update-DbaServiceAccount" { $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $newPassword = 'Myxtr33mly$ecur3P@ssw0rd' $newSecurePassword = ConvertTo-SecureString $newPassword -AsPlainText -Force - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $env:instance2 $computerName = $server.NetName $instanceName = $server.ServiceName $winLogin = "$computerName\$login" @@ -25,7 +25,7 @@ Describe "Update-DbaServiceAccount" { } } catch { <#User does not exist#> } - if ($l = Get-DbaLogin -SqlInstance $script:instance2 -Login $winLogin) { + if ($l = Get-DbaLogin -SqlInstance $env:instance2 -Login $winLogin) { $results = $server.Query("IF EXISTS (SELECT * FROM sys.server_principals WHERE name = '$winLogin') EXEC sp_who '$winLogin'") foreach ($spid in $results.spid) { $null = $server.Query("kill $spid") @@ -41,7 +41,7 @@ Describe "Update-DbaServiceAccount" { $user.SetInfo() #Get current service users - $services = Get-DbaService -ComputerName $script:instance2 -Type Engine, Agent -Instance $instanceName + $services = Get-DbaService -ComputerName $env:instance2 -Type Engine, Agent -Instance $instanceName $currentAgentUser = ($services | Where-Object { $_.ServiceType -eq 'Agent' }).StartName $currentEngineUser = ($services | Where-Object { $_.ServiceType -eq 'Engine' }).StartName @@ -98,10 +98,10 @@ Describe "Update-DbaServiceAccount" { $CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString -Not -Mandatory } It "Should have NoRestart as a parameter" { - $CommandUnderTest | Should -HaveParameter NoRestart -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter NoRestart -Type Switch -Not -Mandatory } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory } } diff --git a/tests/Update-dbatools.Tests.ps1 b/tests/Update-dbatools.Tests.ps1 index db70bf8c9a..407d0ecaed 100644 --- a/tests/Update-dbatools.Tests.ps1 +++ b/tests/Update-dbatools.Tests.ps1 @@ -11,19 +11,19 @@ Describe "Update-Dbatools" { BeforeAll { $CommandUnderTest = Get-Command Update-Dbatools } - It "Should have Development as a SwitchParameter" { + It "Should have Development as a Switch" { $CommandUnderTest | Should -HaveParameter Development -Type switch } - It "Should have Cleanup as a SwitchParameter" { + It "Should have Cleanup as a Switch" { $CommandUnderTest | Should -HaveParameter Cleanup -Type switch } - It "Should have EnableException as a SwitchParameter" { + It "Should have EnableException as a Switch" { $CommandUnderTest | Should -HaveParameter EnableException -Type switch } - It "Should have Verbose as a SwitchParameter" { + It "Should have Verbose as a Switch" { $CommandUnderTest | Should -HaveParameter Verbose -Type switch } - It "Should have Debug as a SwitchParameter" { + It "Should have Debug as a Switch" { $CommandUnderTest | Should -HaveParameter Debug -Type switch } It "Should have ErrorAction as an ActionPreference" { @@ -56,10 +56,10 @@ Describe "Update-Dbatools" { It "Should have PipelineVariable as a String" { $CommandUnderTest | Should -HaveParameter PipelineVariable -Type string } - It "Should have WhatIf as a SwitchParameter" { + It "Should have WhatIf as a Switch" { $CommandUnderTest | Should -HaveParameter WhatIf -Type switch } - It "Should have Confirm as a SwitchParameter" { + It "Should have Confirm as a Switch" { $CommandUnderTest | Should -HaveParameter Confirm -Type switch } } diff --git a/tests/Watch-DbaDbLogin.Tests.ps1 b/tests/Watch-DbaDbLogin.Tests.ps1 index 7ff201ba7e..b602eddca3 100644 --- a/tests/Watch-DbaDbLogin.Tests.ps1 +++ b/tests/Watch-DbaDbLogin.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Watch-DbaDbLogin" { $CommandUnderTest | Should -HaveParameter InputObject -Type Server[] } It "Should have EnableException as a parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } @@ -39,44 +39,44 @@ Describe "Watch-DbaDbLogin" { $tableName2 = 'dbatoolsciwatchdblogin2' $tableName3 = 'dbatoolsciwatchdblogin3' $databaseName = "dbatoolsci_$random" - $newDb = New-DbaDatabase -SqlInstance $script:instance1 -Name $databaseName + $newDb = New-DbaDatabase -SqlInstance $env:instance1 -Name $databaseName $testFile = 'C:\temp\Servers_$random.txt' if (Test-Path $testFile) { Remove-Item $testFile -Force } - $script:instance1, $script:instance2 | Out-File $testFile + $env:instance1, $env:instance2 | Out-File $testFile - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $env:instance1 + $server2 = Connect-DbaInstance -SqlInstance $env:instance2 - $regServer1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance1 -Name "dbatoolsci_instance1_$random" - $regServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance2 -Name "dbatoolsci_instance2_$random" + $regServer1 = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $env:instance1 -Name "dbatoolsci_instance1_$random" + $regServer2 = Add-DbaRegServer -SqlInstance $env:instance1 -ServerName $env:instance2 -Name "dbatoolsci_instance2_$random" } AfterAll { $null = $newDb | Remove-DbaDatabase -Confirm:$false - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServer -SqlInstance $env:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false } It "ServersFromFile" { - Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName1 -ServersFromFile $testFile -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName1 -IncludeSystemDBs + Watch-DbaDbLogin -SqlInstance $env:instance1 -Database $databaseName -Table $tableName1 -ServersFromFile $testFile -EnableException + $result = Get-DbaDbTable -SqlInstance $env:instance1 -Database $databaseName -Table $tableName1 -IncludeSystemDBs $result.Name | Should -Be $tableName1 $result.Count | Should -BeGreaterThan 0 } It "Pipeline of instances" { - $server1, $server2 | Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -IncludeSystemDBs + $server1, $server2 | Watch-DbaDbLogin -SqlInstance $env:instance1 -Database $databaseName -Table $tableName2 -EnableException + $result = Get-DbaDbTable -SqlInstance $env:instance1 -Database $databaseName -Table $tableName2 -IncludeSystemDBs $result.Name | Should -Be $tableName2 $result.Count | Should -BeGreaterThan 0 } It "ServersFromCMS" { - Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName3 -SqlCms $script:instance1 -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName3 -IncludeSystemDBs + Watch-DbaDbLogin -SqlInstance $env:instance1 -Database $databaseName -Table $tableName3 -SqlCms $env:instance1 -EnableException + $result = Get-DbaDbTable -SqlInstance $env:instance1 -Database $databaseName -Table $tableName3 -IncludeSystemDBs $result.Name | Should -Be $tableName3 $result.Count | Should -BeGreaterThan 0 } diff --git a/tests/Watch-DbaXESession.Tests.ps1 b/tests/Watch-DbaXESession.Tests.ps1 index 70188c819b..ad8629e293 100644 --- a/tests/Watch-DbaXESession.Tests.ps1 +++ b/tests/Watch-DbaXESession.Tests.ps1 @@ -22,16 +22,16 @@ Describe "Watch-DbaXESession" { $CommandUnderTest | Should -HaveParameter InputObject -Type Session[] } It "Should have Raw parameter" { - $CommandUnderTest | Should -HaveParameter Raw -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Raw -Type Switch } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } } Context "Command functions as expected" { BeforeAll { - $script:instanceNotSupported = $true + $env:instanceNotSupported = $true } It "warns if SQL instance version is not supported" { @@ -42,7 +42,7 @@ Describe "Watch-DbaXESession" { } $warningMessage = "" - $null = Watch-DbaXESession -SqlInstance $script:instance1 -Session system_health -WarningAction SilentlyContinue -WarningVariable warningMessage + $null = Watch-DbaXESession -SqlInstance $env:instance1 -Session system_health -WarningAction SilentlyContinue -WarningVariable warningMessage $warningMessage | Should -Match "SQL Server version 11 required" } diff --git a/tests/Write-DbaDbTableData.Tests.ps1 b/tests/Write-DbaDbTableData.Tests.ps1 index a9c387df27..16d9479196 100644 --- a/tests/Write-DbaDbTableData.Tests.ps1 +++ b/tests/Write-DbaDbTableData.Tests.ps1 @@ -6,7 +6,7 @@ Describe "Write-DbaDbTableData" { Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $env:instance1 $random = Get-Random $db = "dbatoolsci_writedbadaatable$random" $server.Query("CREATE DATABASE $db") @@ -45,25 +45,25 @@ Describe "Write-DbaDbTableData" { $CommandUnderTest | Should -HaveParameter NotifyAfter -Type Int32 } It "Should have AutoCreateTable parameter" { - $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter AutoCreateTable -Type Switch } It "Should have NoTableLock parameter" { - $CommandUnderTest | Should -HaveParameter NoTableLock -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter NoTableLock -Type Switch } It "Should have CheckConstraints parameter" { - $CommandUnderTest | Should -HaveParameter CheckConstraints -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter CheckConstraints -Type Switch } It "Should have FireTriggers parameter" { - $CommandUnderTest | Should -HaveParameter FireTriggers -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter FireTriggers -Type Switch } It "Should have KeepIdentity parameter" { - $CommandUnderTest | Should -HaveParameter KeepIdentity -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepIdentity -Type Switch } It "Should have KeepNulls parameter" { - $CommandUnderTest | Should -HaveParameter KeepNulls -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter KeepNulls -Type Switch } It "Should have Truncate parameter" { - $CommandUnderTest | Should -HaveParameter Truncate -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter Truncate -Type Switch } It "Should have BulkCopyTimeOut parameter" { $CommandUnderTest | Should -HaveParameter BulkCopyTimeOut -Type Int32 @@ -72,17 +72,17 @@ Describe "Write-DbaDbTableData" { $CommandUnderTest | Should -HaveParameter ColumnMap -Type Hashtable } It "Should have EnableException parameter" { - $CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter EnableException -Type Switch } It "Should have UseDynamicStringLength parameter" { - $CommandUnderTest | Should -HaveParameter UseDynamicStringLength -Type SwitchParameter + $CommandUnderTest | Should -HaveParameter UseDynamicStringLength -Type Switch } } Context "Command usage" { It "defaults to dbo if no schema is specified" { $results = Get-ChildItem | ConvertTo-DbaDataTable - $results | Write-DbaDbTableData -SqlInstance $script:instance1 -Database $db -Table 'childitem' -AutoCreateTable + $results | Write-DbaDbTableData -SqlInstance $env:instance1 -Database $db -Table 'childitem' -AutoCreateTable ($server.Databases[$db].Tables | Where-Object { $_.Schema -eq 'dbo' -and $_.Name -eq 'childitem' }).Count | Should -Be 1 } diff --git a/tests/constants.ps1 b/tests/constants.ps1 index a6481a03c8..78ebeff9e4 100644 --- a/tests/constants.ps1 +++ b/tests/constants.ps1 @@ -1,51 +1,63 @@ -# constants +# constants.ps1 if (Test-Path "$PSScriptRoot\constants.local.ps1") { Write-Host "Tests will use local constants file: tests\constants.local.ps1." -ForegroundColor Cyan . "$PSScriptRoot\constants.local.ps1" -} elseif ($env:CODESPACES -and ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { - $script:instance1 = "dbatools1" - $script:instance2 = "dbatools2" - $script:instance3 = "dbatools3" - $script:instances = @($script:instance1, $script:instance2) +} elseif ($env:CODESPACES -or ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { + Write-Host "Tests will use codespaces constants." -ForegroundColor Cyan - $script:SqlCred = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) - # We don't want to affect the global PSDefaultParameterValues + # Use global variables instead of $global: for consistency + $global:instance1 = "dbatools1" + $global:instance2 = "dbatools2" + $global:instance3 = "dbatools3" + $global:instances = @($global:instance1, $global:instance2) + + # Global SQL Credential setup + $global:SqlCred = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) + + # Set up default SqlCredential for all commands if (-not $PSDefaultParameterValues.ContainsKey('*:SqlCredential')) { $PSDefaultParameterValues = $PSDefaultParameterValues + @{ - "*:SqlCredential" = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) + "*:SqlCredential" = $global:SqlCred } } } elseif ($env:GITHUB_WORKSPACE) { - $script:dbatoolsci_computer = "localhost" - $script:instance1 = "localhost" - $script:instance2 = "localhost:14333" - $script:instance2SQLUserName = $null # placeholders for -SqlCredential testing - $script:instance2SQLPassword = $null - $script:instance3 = "localhost" - $script:instance2_detailed = "localhost,14333" #Just to make sure things parse a port properly - $script:appveyorlabrepo = "/tmp/appveyor-lab" - $instances = @($script:instance1, $script:instance2) - $script:azureblob = "https://dbatools.blob.core.windows.net/sql" - $script:azureblobaccount = "dbatools" - $script:azureserver = 'psdbatools.database.windows.net' - $script:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" + Write-Host "Tests will use GitHub Actions constants." -ForegroundColor Cyan + + # Use global variables for GitHub Actions constants + $global:dbatoolsci_computer = "localhost" + $global:instance1 = "localhost" + $global:instance2 = "localhost:14333" + $global:instance2SQLUserName = $null + $global:instance2SQLPassword = $null + $global:instance3 = "localhost" + $global:instance2_detailed = "localhost,14333" + $global:appveyorlabrepo = "/tmp/appveyor-lab" + $global:instances = @($global:instance1, $global:instance2) + $global:azureblob = "https://dbatools.blob.core.windows.net/sql" + $global:azureblobaccount = "dbatools" + $global:azureserver = 'psdbatools.database.windows.net' + $global:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" } else { - $script:dbatoolsci_computer = "localhost" - $script:instance1 = "localhost\sql2008r2sp2" - $script:instance2 = "localhost\sql2016" - $script:instance2SQLUserName = $null # placeholders for -SqlCredential testing - $script:instance2SQLPassword = $null - $script:instance3 = "localhost\sql2017" - $script:instance2_detailed = "localhost,14333\sql2016" #Just to make sure things parse a port properly - $script:appveyorlabrepo = "C:\github\appveyor-lab" - $instances = @($script:instance1, $script:instance2) - $ssisserver = "localhost\sql2016" - $script:azureblob = "https://dbatools.blob.core.windows.net/sql" - $script:azureblobaccount = "dbatools" - $script:azureserver = 'psdbatools.database.windows.net' - $script:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" + Write-Host "Tests will use AppVeyor constants." -ForegroundColor Cyan + + # Global variables for AppVeyor constants + $global:dbatoolsci_computer = "localhost" + $global:instance1 = "localhost\sql2008r2sp2" + $global:instance2 = "localhost\sql2016" + $global:instance2SQLUserName = $null + $global:instance2SQLPassword = $null + $global:instance3 = "localhost\sql2017" + $global:instance2_detailed = "localhost,14333\sql2016" + $global:appveyorlabrepo = "C:\github\appveyor-lab" + $global:instances = @($global:instance1, $global:instance2) + $global:ssisserver = "localhost\sql2016" + $global:azureblob = "https://dbatools.blob.core.windows.net/sql" + $global:azureblobaccount = "dbatools" + $global:azureserver = 'psdbatools.database.windows.net' + $global:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" } +# Set global PSDefaultParameterValues if running on AppVeyor if ($env:appveyor) { $PSDefaultParameterValues['*:WarningAction'] = 'SilentlyContinue' -} \ No newline at end of file +} diff --git a/tests/dbatools.Tests.ps1 b/tests/dbatools.Tests.ps1 index b68b6adaff..e991b41a71 100644 --- a/tests/dbatools.Tests.ps1 +++ b/tests/dbatools.Tests.ps1 @@ -233,17 +233,17 @@ Describe "Manifest" { { - $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue + $global:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue } | Should Not Throw } ## Should -Be fixed now - Until the issue with requiring full paths for required assemblies is resolved need to keep this commented out RMS 01112016 -$Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction SilentlyContinue +$global:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction SilentlyContinue It "has a valid name" { - $Script:Manifest.Name | Should -Be $ModuleName + $global:Manifest.Name | Should -Be $ModuleName } @@ -251,7 +251,7 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently It "has a valid root module" { - $Script:Manifest.RootModule | Should -Be "$ModuleName.psm1" + $global:Manifest.RootModule | Should -Be "$ModuleName.psm1" } @@ -259,33 +259,33 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently It "has a valid Description" { - $Script:Manifest.Description | Should -Be 'Provides extra functionality for SQL Server Database admins and enables SQL Server instance migrations.' + $global:Manifest.Description | Should -Be 'Provides extra functionality for SQL Server Database admins and enables SQL Server instance migrations.' } It "has a valid Author" { - $Script:Manifest.Author | Should -Be 'Chrissy LeMaire' + $global:Manifest.Author | Should -Be 'Chrissy LeMaire' } It "has a valid Company Name" { - $Script:Manifest.CompanyName | Should -Be 'dbatools.io' + $global:Manifest.CompanyName | Should -Be 'dbatools.io' } It "has a valid guid" { - $Script:Manifest.Guid | Should -Be '9d139310-ce45-41ce-8e8b-d76335aa1789' + $global:Manifest.Guid | Should -Be '9d139310-ce45-41ce-8e8b-d76335aa1789' } It "has valid PowerShell version" { - $Script:Manifest.PowerShellVersion | Should -Be '3.0' + $global:Manifest.PowerShellVersion | Should -Be '3.0' } It "has valid required assemblies" { - {$Script:Manifest.RequiredAssemblies -eq @()} | Should -Be $true + {$global:Manifest.RequiredAssemblies -eq @()} | Should -Be $true } It "has a valid copyright" { - $Script:Manifest.CopyRight | Should BeLike '* Chrissy LeMaire' + $global:Manifest.CopyRight | Should BeLike '* Chrissy LeMaire' } @@ -299,7 +299,7 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently $FunctionNames = $FunctionFiles - $ExFunctions = $Script:Manifest.ExportedFunctions.Values.Name + $ExFunctions = $global:Manifest.ExportedFunctions.Values.Name $ExFunctions foreach ($FunctionName in $FunctionNames) diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index 5a373e9670..29e334d87f 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -2,11 +2,11 @@ $TestsRunGroups = @{ # run on scenario 2008R2 - "2008R2" = 'autodetect_$script:instance1' + "2008R2" = 'autodetect_$env:instance1' # run on scenario 2016 - "2016" = 'autodetect_$script:instance2' + "2016" = 'autodetect_$env:instance2' # run on scenario 2016_2017 - tests that need developer license - "2016_2017" = 'autodetect_$script:instance2,$script:instance3' + "2016_2017" = 'autodetect_$env:instance2,$env:instance3' #run on scenario service_restarts - SQL Server service tests that might disrupt other tests "service_restarts" = @( 'Start-DbaService',