|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Tests exporting MS SQL database objects from the given server and database as files, into a consistent folder structure. |
| 4 | +#> |
| 5 | + |
| 6 | +$basename = "$(($MyInvocation.MyCommand.Name -split '\.',2)[0])." |
| 7 | +$skip = !(Test-Path .changes -Type Leaf) ? $false : |
| 8 | + !@(Get-Content .changes |Get-Item |Select-Object -ExpandProperty Name |Where-Object {$_.StartsWith($basename)}) |
| 9 | +if($skip) {Write-Information "No changes to $basename" -infa Continue} |
| 10 | +Describe 'Export-DatabaseScripts' -Tag Export-DatabaseScripts -Skip:$skip { |
| 11 | + BeforeAll { |
| 12 | + $scriptsdir,$sep = (Split-Path $PSScriptRoot),[io.path]::PathSeparator |
| 13 | + if($scriptsdir -notin ($env:Path -split $sep)) {$env:Path += "$sep$scriptsdir"} |
| 14 | + Mock Export-DbaScript {} |
| 15 | + try {[void][MockObject]} |
| 16 | + catch {Add-Type -TypeDefinition @' |
| 17 | +public class ScriptNameObjectBase {} |
| 18 | +public class MockObject : ScriptNameObjectBase |
| 19 | +{ |
| 20 | + public string Name { get; } = $"ObjectName{System.DateTime.Now.Microsecond}"; |
| 21 | + public string Schema { get; } = "dbo"; |
| 22 | + public bool IsSystemObject { get; } |
| 23 | +} |
| 24 | +public class Database : MockObject |
| 25 | +{ |
| 26 | + public bool ServiceBroker { get; } |
| 27 | + public MockObject[] Assemblies { get; } = new MockObject[] {}; |
| 28 | + public MockObject[] Triggers { get; } = new MockObject[] {}; |
| 29 | + public MockObject[] Defaults { get; } = new MockObject[] {}; |
| 30 | + public MockObject[] ExtendedProperties { get; } = new MockObject[] {}; |
| 31 | + public MockObject[] UserDefinedFunctions { get; } = new MockObject[] {}; |
| 32 | + public MockObject[] Rules { get; } = new MockObject[] {}; |
| 33 | + public MockObject[] AsymmetricKeys { get; } = new MockObject[] {}; |
| 34 | + public MockObject[] Certificates { get; } = new MockObject[] {}; |
| 35 | + public MockObject[] Roles { get; } = new MockObject[] {}; |
| 36 | + public MockObject[] Schemas { get; } = new MockObject[] {}; |
| 37 | + public MockObject[] SymmetricKeys { get; } = new MockObject[] {}; |
| 38 | + public MockObject[] Users { get; } = new MockObject[] {}; |
| 39 | + public MockObject[] Sequences { get; } = new MockObject[] {}; |
| 40 | + public MockObject[] FullTextCatalogs { get; } = new MockObject[] {}; |
| 41 | + public MockObject[] FullTextStopLists { get; } = new MockObject[] {}; |
| 42 | + public MockObject[] PartitionFunctions { get; } = new MockObject[] {}; |
| 43 | + public MockObject[] PartitionSchemes { get; } = new MockObject[] {}; |
| 44 | + public MockObject[] StoredProcedures { get; } = new MockObject[] { new MockObject() }; |
| 45 | + public MockObject[] Synonyms { get; } = new MockObject[] {}; |
| 46 | + public MockObject[] Tables { get; } = new MockObject[] { new MockObject() }; |
| 47 | + public MockObject[] UserDefinedDataTypes { get; } = new MockObject[] {}; |
| 48 | + public MockObject[] XmlSchemaCollections { get; } = new MockObject[] {}; |
| 49 | + public MockObject[] Views { get; } = new MockObject[] { new MockObject() }; |
| 50 | +} |
| 51 | +'@} |
| 52 | + } |
| 53 | + Context 'Exports MS SQL database objects from the given server and database as files, into a consistent folder structure' ` |
| 54 | + -Tag ExportDatabaseScripts,Export,DatabaseScripts,Database,SQL { |
| 55 | + It "Export scripts" { |
| 56 | + New-Object Database |Export-DatabaseScripts.ps1 |
| 57 | + Assert-MockCalled -CommandName Export-DbaScript -Times 3 |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments