Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen committed Apr 27, 2023
2 parents cce9762 + 462091c commit 892e2a9
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 83 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.6.0] - 2023-03-07

### Added

- Added Version filter parameter for `Get-LocalInstance`.
- Parameter to create a SqlClientConnection in `New-LocalInstance`.
- Parameter to create a SqlClientConnection in `New-Database`.

## [1.5.0] - 2022-09-30

### Added
Expand Down
19 changes: 17 additions & 2 deletions docs/Get-SqlTestLocalInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Returns connection parameters to a available localDb.
## SYNTAX

```
Get-SqlTestLocalInstance [[-First] <Int32>] [<CommonParameters>]
Get-SqlTestLocalInstance [[-First] <Int32>] [[-Version] <Version>] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -37,7 +37,7 @@ Version v11.0
## PARAMETERS

### -First
Specifies maximum number of returned instances.
Specifies maximum number of returned sql server instances.

```yaml
Type: Int32
Expand All @@ -51,6 +51,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Version
Filters the version of the returned sql server instance.
```yaml
Type: Version
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
23 changes: 19 additions & 4 deletions docs/New-SqlTestDatabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Creates a new database and returns the connection parameters.

```
New-SqlTestDatabase [-Instance] <PSObject> [-InstanceConnection] <SqlConnection> [[-Name] <String>]
[<CommonParameters>]
[-Connected] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -50,7 +50,7 @@ Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
Expand All @@ -60,12 +60,12 @@ Specifies a open sql connection to the instance.
```yaml
Type: SqlConnection
Parameter Sets: (All)
Aliases:
Aliases: Connection

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
Expand All @@ -84,6 +84,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Connected
Speficies if a SqlClient connection should be created.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
17 changes: 16 additions & 1 deletion docs/New-SqlTestLocalInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Returns connection parameters to new localDb.
## SYNTAX

```
New-SqlTestLocalInstance [[-Name] <String>] [[-Version] <Version>] [<CommonParameters>]
New-SqlTestLocalInstance [[-Name] <String>] [[-Version] <Version>] [-Connected] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -66,6 +66,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Connected
Speficies if a SqlClient connection should be created.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
4 changes: 2 additions & 2 deletions src/PsSqlTestServer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PsSqlTestServer.psm1'

# Version number of this module.
ModuleVersion = '1.5.0'
ModuleVersion = '1.6.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -51,7 +51,7 @@ Description = 'Cmdlets to provide and manage SQL servers for tests.'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @('PsSqlClient')
RequiredModules = @(@{ ModuleName = 'PsSqlClient'; ModuleVersion = '1.5.0' })

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand Down
2 changes: 1 addition & 1 deletion src/Public/Clear-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Clear-LocalInstance {
[switch] $WhatIf
)

Import-Module PsSqlLocalDb -MinimumVersion 0.3 -ErrorAction Stop
Import-Module PsSqlLocalDb -MinimumVersion 0.4 -ErrorAction Stop

Get-LocalInstance -First $null | Where-Object Name -Like test-* | Remove-LocalInstance -WhatIf:$WhatIf
}
12 changes: 8 additions & 4 deletions src/Public/Get-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ function Get-LocalInstance {

[CmdletBinding()]
param (
# Specifies maximum number of returned instances.
# Specifies maximum number of returned sql server instances.
[Parameter()]
[int] $First = 1
[int] $First = 1,

# Filters the version of the returned sql server instance.
[Parameter()]
[System.Version] $Version
)

Import-Module PsSqlLocalDb -MinimumVersion 0.3 -ErrorAction Stop
Import-Module PsSqlLocalDb -MinimumVersion 0.4 -ErrorAction Stop

$selectParam = @{}
if ( $First ) {
$selectParam.First = $First
}

Get-LocalDbInstance | Select-Object @selectParam | ForEach-Object {
Get-LocalDbInstance -Version:$Version | Select-Object @selectParam | ForEach-Object {
$instance = $PSItem

# add metadata
Expand Down
39 changes: 28 additions & 11 deletions src/Public/New-Database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,47 @@ function New-Database {
[CmdletBinding()]
param (
# Specifies the instance, to create the database in.
[Parameter( Mandatory )]
[Parameter( Mandatory, ValueFromPipeline )]
[ValidateNotNullOrEmpty()]
[PsObject] $Instance,

# Specifies a open sql connection to the instance.
[Parameter( Mandatory )]
[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[ValidateNotNullOrEmpty()]
[Alias('Connection')]
[Microsoft.Data.SqlClient.SqlConnection] $InstanceConnection,

# Specifies the name of the database to create.
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $Name = ( New-DatabaseName )
[string] $Name = ( New-DatabaseName ),

# Speficies if a SqlClient connection should be created.
[Parameter()]
[switch] $Connected
)

$Database = $Instance.PsObject.Copy()
$Database | Add-Member InstanceName $Database.Name
$Database.Name = $Name
process {
$Database = $Instance.PsObject.Copy()
$Database | Add-Member InstanceName $Database.Name
$Database.Name = $Name

Invoke-TSqlCommand "CREATE DATABASE [$Name]" -Connection $InstanceConnection

Invoke-TSqlCommand "CREATE DATABASE [$Name]" -Connection $InstanceConnection
$Database | Add-Member InitialCatalog $Name
$Database.ConnectionString += ";Initial Catalog=$( $Database.InitialCatalog )"
$Database | Add-Member InstanceConnection $InstanceConnection

$Database | Add-Member InitialCatalog $Name
$Database.ConnectionString += ";Initial Catalog=$( $Database.InitialCatalog )"
$Database | Add-Member InstanceConnection $InstanceConnection
# connect instance if needed
if ( $Connected.IsPresent ) {
$DatabaseConnection = $Database | Connect-TSqlInstance
if ( $DatabaseConnection | Test-TSqlConnection ) {
$Database.Connection = $DatabaseConnection
} else {
Write-Error "Failed to connect database."
}
}

Write-Output $Database
Write-Output $Database
}
}
35 changes: 23 additions & 12 deletions src/Public/New-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,35 @@ function New-LocalInstance {

# Specifies the version of the sql server.
[Parameter()]
[System.Version] $Version
[System.Version] $Version,

# Speficies if a SqlClient connection should be created.
[Parameter()]
[switch] $Connected
)

Import-Module PsSqlLocalDb -MinimumVersion 0.3 -ErrorAction Stop
Import-Module PsSqlLocalDb -MinimumVersion 0.4 -ErrorAction Stop

# create instance
if ( $Version ) {
$instance = New-LocalDbInstance -Name $Name -Version $Version
} else {
$instance = New-LocalDbInstance -Name $Name
}
$Instance = New-LocalDbInstance -Name $Name -Version:$Version

# add metadata
$instance | Add-Member 'DataSource' "(LocalDb)\$( $instance.Name )"
$instance | Add-Member 'ConnectTimeout' 30
$instance | Add-Member 'ConnectionString' "Data Source=$( $instance.DataSource );Connect Timeout=$( $instance.ConnectTimeout );Integrated Security=True"
$instance | Add-Member 'IsLocalDb' $true
$Instance | Add-Member DataSource "(LocalDb)\$( $Instance.Name )"
$Instance | Add-Member ConnectTimeout 30
$Instance | Add-Member ConnectionString "Data Source=$( $Instance.DataSource );Connect Timeout=$( $Instance.ConnectTimeout );Integrated Security=True"
$Instance | Add-Member IsLocalDb $true

# connect instance if needed
if ( $Connected.IsPresent ) {
$InstanceConnection = $Instance | Connect-TSqlInstance
if ( $InstanceConnection | Test-TSqlConnection ) {
$Instance | Add-Member Connection $InstanceConnection
} else {
Write-Error "Failed to connect instance."
}

}

# return
$instance | Write-Output
$Instance | Write-Output
}
2 changes: 1 addition & 1 deletion src/Public/Remove-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Remove-LocalInstance {
)

begin {
Import-Module PsSqlLocalDb -MinimumVersion 0.3 -ErrorAction Stop
Import-Module PsSqlLocalDb -MinimumVersion 0.4 -ErrorAction Stop
}

process {
Expand Down
2 changes: 1 addition & 1 deletion src/Public/Test-LocalDb.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Test-LocalDb {
[CmdletBinding()]
param ()

if ( -Not ( Import-Module PsSqlLocalDb -MinimumVersion 0.3 -PassThru -ErrorAction SilentlyContinue )) {
if ( -Not ( Import-Module PsSqlLocalDb -MinimumVersion 0.4 -PassThru -ErrorAction SilentlyContinue )) {
Write-Warning 'PsSqlLocalDb is not installed in required version.'
return $false
}
Expand Down
10 changes: 5 additions & 5 deletions tasks/Dependencies.Tasks.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
task InstallBuildDependencies -Jobs {
Install-Module platyPs -Scope CurrentUser -ErrorAction Stop -Verbose
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease -AllowClobber
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease:$AllowPrerelease -AllowClobber
}

task InstallTestDependencies -Jobs {
Install-Module psdocker -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease
Install-Module PsSqlLocalDb -Scope CurrentUser -MinimumVersion 0.3 -ErrorAction Stop -Verbose -AllowPrerelease
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease -AllowClobber
Install-Module psdocker -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease:$AllowPrerelease
Install-Module PsSqlLocalDb -Scope CurrentUser -MinimumVersion 0.3 -ErrorAction Stop -Verbose -AllowPrerelease:$AllowPrerelease
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease:$AllowPrerelease -AllowClobber
}

task InstallReleaseDependencies -Jobs {
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease -AllowClobber
Install-Module PsSqlClient -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease:$AllowPrerelease -AllowClobber
}
11 changes: 8 additions & 3 deletions test/Get-LocalInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ Describe Get-LocalInstance -Tag SqlLocalDB {
$result.ConnectionString | Should -Not -BeNullOrEmpty
}

BeforeDiscovery {
$PsSqlClient = Import-Module PsSqlClient -PassThru -ErrorAction SilentlyContinue
It 'Returns values by version' {
$result = Get-SqlTestLocalInstance -Version 15.0

$result | Should -Not -BeNullOrEmpty
$result.Count | Should -Be 1
$result.DataSource | Should -Not -BeNullOrEmpty
$result.ConnectionString | Should -Not -BeNullOrEmpty
}

Context PsSqlClient -Skip:( -Not $PsSqlClient ) {
Context PsSqlClient {

BeforeAll {
$LocalDb = Get-SqlTestLocalInstance
Expand Down
Loading

0 comments on commit 892e2a9

Please sign in to comment.