Zuletzt geändert von Jannis Klein am 2025/02/13 13:15

Von Version 8.2
bearbeitet von Jannis Klein
am 2025/01/28 15:20
Änderungskommentar: Es gibt keinen Kommentar für diese Version
Auf Version 9.1
bearbeitet von Jannis Klein
am 2025/01/28 16:03
Änderungskommentar: Es gibt keinen Kommentar für diese Version

Zusammenfassung

Details

Seiteneigenschaften
Inhalt
... ... @@ -279,6 +279,77 @@
279 279  
280 280  === Testen der PowerShell-Module ===
281 281  
282 +Die Funktionalität des erstellten Moduls können Sie mithilfe von Pester (dem Standard-Framework für Unit-Testing in PowerShell) oder eines dedizierten PowerShell Scripts verifizieren. So stellen Sie sicher, dass die Logik fehlerfrei und robust ist. Das Modul //ISSRestConnector.psm1// können Sie mit Pester (5.5.0) beispielsweise folgendermaßen testen:
283 +
284 +1. Erstellen Sie eine neue Datei mit dem Namen //ISSRestConnectorTests.ps1//.
285 +1. Fügen Sie den nachfolgenden Code in die Datei ein.
286 +1. Drücken Sie Strg + S, um die Datei zu speichern.
287 +1. Führen Sie das Script
288 +
289 +{{code language="PowerShell" layout="LINENUMBERS" title="**ISSRestConnectorTest.ps1**"}}
290 +Import-Module -Name Pester -MinimumVersion 5.5.0
291 +Remove-Module ".\Modules\ISSRestConnector.psm1" -Force -ErrorAction SilentlyContinue
292 +Import-Module -Name ".\Modules\ISSRestConnector.psm1" -Force
293 +
294 +Describe "Get-ISSData Function Tests" {
295 + BeforeAll {
296 + # Mock the API response
297 + $global:MockApiResponse = @{
298 + Name = "iss"
299 + Id = 25544
300 + Latitude = 12.34
301 + Longitude = 56.78
302 + Altitude = 408.5
303 + Velocity = 27600.0
304 + Visibility = "daylight"
305 + Timestamp = [datetime]::Now.ToUniversalTime().Subtract([datetime]::UnixEpoch).TotalSeconds
306 + }
307 + }
308 +
309 + Context "When the API responds successfully" {
310 + BeforeEach {
311 + # Mock the API call
312 + Mock -CommandName Invoke-RestMethod -ParameterFilter { $Method -eq 'GET' } -MockWith {
313 + return $global:MockApiResponse
314 + } -ModuleName "ISSRestConnector"
315 + }
316 +
317 + It "Should return a PSCustomObject with expected properties" {
318 + $result = Get-ISSData
319 + $result | Should -BeOfType PSCustomObject
320 + $result.Name | Should -Not -BeNullOrEmpty
321 + $result.Latitude | Should -Not -BeNullOrEmpty
322 + $result.Longitude | Should -Not -BeNullOrEmpty
323 + $result.Altitude | Should -Not -BeNullOrEmpty
324 + $result.Velocity | Should -Not -BeNullOrEmpty
325 + }
326 +
327 + It "Should correctly map the API response to the output object" {
328 + $result = Get-ISSData
329 + $result.Name | Should -Be "iss"
330 + $result.Latitude | Should -Be 12.34
331 + $result.Longitude | Should -Be 56.78
332 + $result.Altitude | Should -Be 408.5
333 + $result.Velocity | Should -Be 27600.0
334 + }
335 + }
336 +
337 + Context "When the API fails" {
338 +
339 + It "Should log an error when the API fails" {
340 + # Mock a failure in the API call
341 + Mock -CommandName Invoke-RestMethod -ParameterFilter { $Method -eq 'GET' } -MockWith {
342 + throw "API error"
343 + } -ModuleName "ISSRestConnector"
344 +
345 + $error.Clear() # Clear any pre-existing errors
346 + Get-ISSData
347 + $error[1].Exception.Message | Should -Contain "API error"
348 + }
349 + }
350 +}
351 +{{/code}}
352 +
282 282  === Erstellen der PowerShell-Microservices in AESB ===
283 283  
284 284  === Integrieren der PowerShell-Module in die PowerShell-Microservices ===
© Aagon GmbH 2025
Besuchen Sie unsere neue Aagon-Community