tests/examples/Export-AxModelV2.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
$commandName = "Export-AxModelV2"
################################### New Example test ###################################

$exampleRaw = "Get-AxAosInstance | Export-AxModelV2"
#Remember to escape any variables names in the line above.
#Remember to you need to output $true to the pester test, otherwise is fails.
#; `$var -eq `$true

#Here you declare any variable(s) you need to complete the test.

$example = $exampleRaw -replace "`n.*" -replace "PS C:\\>"

Describe "Specific example testing for $commandName" {

    It "Example - $example" {
        # mock the tested command so we don't actually do anything
        # because it can be unsafe and we don't have the environment setup
        # (so the only thing we are testing is that the code is semantically
        # correct and provides all the needed params)
        Mock Get-AxAosInstance { 
            $InstanceDetail = [Ordered]@{}
    
            $InstanceDetail.InstanceName = ""
            $InstanceDetail.ConfigurationName = ""
            $InstanceDetail.BinDirectory = ""
            $InstanceDetail.ExecutablePath = ""
    
            $InstanceDetail.FileVersion = ""
            $InstanceDetail.ProductVersion = ""
            $InstanceDetail.FileVersionUpdated = ""
            $InstanceDetail.ProductVersionUpdated = ""
    
            $InstanceDetail.DatabaseServer = ""
            $InstanceDetail.DatabaseName = ""
            $InstanceDetail.ModelstoreDatabase = ""
    
            $InstanceDetail.AosPort = ""
            $InstanceDetail.WsdlPort = ""
            $InstanceDetail.NetTcpPort = ""
        
            $InstanceDetail.RegistryKeyPath = ""
            $InstanceDetail.InstanceNumber = ""
            $InstanceDetail.ComputerName = ""
    
            [PSCustomObject] $InstanceDetail
        }

        Mock $commandName {
            # I am returning true here,
            # but some of the examples drill down to the returned object
            # so in strict mode we would fail
            $true
        }
        # here simply invoke the example
        $result = Invoke-Expression $example
        # and check that we got result from the mock
        $result | Should -BeTrue
    }
}
################################### New Example test ###################################

$exampleRaw = "`$Test = `"1`"" + [environment]::NewLine
$exampleRaw = "Export-AxModelV2 -DatabaseServer localhost -ModelstoreDatabase MicrosoftDynamicsAx_model -Name *CUS*"
#Remember to escape any variables names in the line above.
#Remember to you need to output $true to the pester test, otherwise is fails.
#; `$var -eq `$true

#Here you declare any variable(s) you need to complete the test.

$example = $exampleRaw -replace "`n.*" -replace "PS C:\\>"

Describe "Specific example testing for $commandName" {

    It "Example - $example" {
        # mock the tested command so we don't actually do anything
        # because it can be unsafe and we don't have the environment setup
        # (so the only thing we are testing is that the code is semantically
        # correct and provides all the needed params)
        Mock $commandName {
            # I am returning true here,
            # but some of the examples drill down to the returned object
            # so in strict mode we would fail
            $true
        }
        # here simply invoke the example
        $result = Invoke-Expression $example
        # and check that we got result from the mock
        $result | Should -BeTrue
    }
}
################################### Entire help loaded ###################################

<#
 
 
NAME
    Export-AxModelV2
     
SYNOPSIS
    Export AX 2012 model
     
     
SYNTAX
    Export-AxModelV2 [[-DatabaseServer] <String>] [[-ModelstoreDatabase] <String>] [[-Path] <String>] [[-Name] <String>
    ] [[-Id] <String>] [[-Layer] <String>] [-GenerateScript] [<CommonParameters>]
     
     
DESCRIPTION
    Export AX 2012 model from the AX 2012 model store
     
 
PARAMETERS
    -DatabaseServer <String>
        Server name of the database server
         
        Default value is: "localhost"
         
        Required? false
        Position? 2
        Default value localhost
        Accept pipeline input? true (ByPropertyName)
        Accept wildcard characters? false
         
    -ModelstoreDatabase <String>
        Name of the modelstore database
         
        Default value is: "MicrosoftDynamicsAx_model"
         
        Note: From AX 2012 R2 and upwards you need to provide the full name for the modelstore database. E.g. "AX2012R3
        _PROD_model"
         
        Required? false
        Position? 3
        Default value MicrosoftDynamicsAx_model
        Accept pipeline input? true (ByPropertyName)
        Accept wildcard characters? false
         
    -Path <String>
        Path to the location where you want the file to be exported
         
        Default value is: "c:\temp\ax2012.tools"
         
        Required? false
        Position? 4
        Default value c:\temp\ax2012.tools
        Accept pipeline input? false
        Accept wildcard characters? false
         
    -Name <String>
        Name of the AX 2012 model that you are looking for
         
        Accepts wildcards for searching. E.g. -Name "ISV*MODULE*"
         
        Default value is "*" which will search for all models
         
        Required? false
        Position? 5
        Default value *
        Accept pipeline input? false
        Accept wildcard characters? false
         
    -Id <String>
        Id of the AX 2012 model that you are looking for
         
        Accepts wildcards for searching. E.g. -Id "2*"
         
        Default value is "*" which will search for all models
         
        Required? false
        Position? 6
        Default value *
        Accept pipeline input? false
        Accept wildcard characters? false
         
    -Layer <String>
        Layer where the AX 2012 model that you are looking for should reside
         
        Accepts wildcards for searching. E.g. -Layer "IS*"
         
        Default value is "*" which will search for models in all layers
         
        Required? false
        Position? 7
        Default value *
        Accept pipeline input? false
        Accept wildcard characters? false
         
    -GenerateScript [<SwitchParameter>]
        Switch to instruct the cmdlet to output the script to execute the command in hand
         
        Required? false
        Position? named
        Default value False
        Accept pipeline input? false
        Accept wildcard characters? false
         
    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
     
INPUTS
     
OUTPUTS
    System.String
     
     
NOTES
     
     
        Author: Mötz Jensen (@Splaxi)
     
    -------------------------- EXAMPLE 1 --------------------------
     
    PS C:\>Get-AxAosInstance | Export-AxModelV2
     
    This will fetch all the AX 2012 AOS instances that are configured on the machine.
    Foreach of the instances it will export all AX 2012 Models into a sub folder to "c:\temp\ax2012.tools".
     
     
     
     
    -------------------------- EXAMPLE 2 --------------------------
     
    PS C:\>$Test = "1"
     
    PS C:\> Export-AxModelV2 -DatabaseServer "localhost" -ModelstoreDatabase "MicrosoftDynamicsAx_model" -Names "*CUS*"
     
    This will fetch all the AX 2012 AOS instances that are configured on the machine.
    Foreach of the instances it will export all AX 2012 Models into a sub folder to "c:\temp\ax2012.tools".
     
     
     
     
     
RELATED LINKS
 
 
 
#>