|
| 1 | +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} |
| 2 | +param( |
| 3 | + $ModuleName = "FabricTools", |
| 4 | + $expectedParams = @( |
| 5 | + "SubscriptionId" |
| 6 | + "ResourceGroupName" |
| 7 | + "CapacityName" |
| 8 | + "SkuName" |
| 9 | + "AdministrationMembers" |
| 10 | + "Tags" |
| 11 | + "NoWait" |
| 12 | + "WhatIf" |
| 13 | + "Confirm" |
| 14 | + "Verbose" |
| 15 | + "Debug" |
| 16 | + "ErrorAction" |
| 17 | + "WarningAction" |
| 18 | + "InformationAction" |
| 19 | + "ProgressAction" |
| 20 | + "ErrorVariable" |
| 21 | + "WarningVariable" |
| 22 | + "InformationVariable" |
| 23 | + "OutVariable" |
| 24 | + "OutBuffer" |
| 25 | + "PipelineVariable" |
| 26 | + ) |
| 27 | +) |
| 28 | + |
| 29 | +Describe "Update-FabricCapacity" -Tag "UnitTests" { |
| 30 | + |
| 31 | + BeforeDiscovery { |
| 32 | + $command = Get-Command -Name Update-FabricCapacity |
| 33 | + $expected = $expectedParams |
| 34 | + } |
| 35 | + |
| 36 | + Context "Parameter validation" { |
| 37 | + BeforeAll { |
| 38 | + $command = Get-Command -Name Update-FabricCapacity |
| 39 | + $expected = $expectedParams |
| 40 | + } |
| 41 | + |
| 42 | + It "Has parameter: <_>" -ForEach $expected { |
| 43 | + $command | Should -HaveParameter $PSItem |
| 44 | + } |
| 45 | + |
| 46 | + It "Should have exactly the number of expected parameters $($expected.Count)" { |
| 47 | + $hasparms = $command.Parameters.Values.Name |
| 48 | + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + Context "Parameter validation rules" { |
| 53 | + BeforeAll { |
| 54 | + $command = Get-Command -Name Update-FabricCapacity |
| 55 | + } |
| 56 | + |
| 57 | + It "SubscriptionId should be mandatory" { |
| 58 | + $command.Parameters['SubscriptionId'].Attributes.Mandatory | Should -Be $true |
| 59 | + } |
| 60 | + |
| 61 | + It "ResourceGroupName should be mandatory" { |
| 62 | + $command.Parameters['ResourceGroupName'].Attributes.Mandatory | Should -Be $true |
| 63 | + } |
| 64 | + |
| 65 | + It "CapacityName should be mandatory" { |
| 66 | + $command.Parameters['CapacityName'].Attributes.Mandatory | Should -Be $true |
| 67 | + } |
| 68 | + |
| 69 | + It "SkuName should be mandatory" { |
| 70 | + $command.Parameters['SkuName'].Attributes.Mandatory | Should -Be $true |
| 71 | + } |
| 72 | + |
| 73 | + It "AdministrationMembers should be mandatory" { |
| 74 | + $command.Parameters['AdministrationMembers'].Attributes.Mandatory | Should -Be $true |
| 75 | + } |
| 76 | + |
| 77 | + It "Tags should not be mandatory" { |
| 78 | + $command.Parameters['Tags'].Attributes.Mandatory | Should -Be $false |
| 79 | + } |
| 80 | + |
| 81 | + It "NoWait should not be mandatory" { |
| 82 | + $command.Parameters['NoWait'].Attributes.Mandatory | Should -Be $false |
| 83 | + } |
| 84 | + |
| 85 | + It "SubscriptionId should be of type Guid" { |
| 86 | + $command.Parameters['SubscriptionId'].ParameterType.Name | Should -Be "Guid" |
| 87 | + } |
| 88 | + |
| 89 | + It "ResourceGroupName should be of type String" { |
| 90 | + $command.Parameters['ResourceGroupName'].ParameterType.Name | Should -Be "String" |
| 91 | + } |
| 92 | + |
| 93 | + It "CapacityName should be of type String" { |
| 94 | + $command.Parameters['CapacityName'].ParameterType.Name | Should -Be "String" |
| 95 | + } |
| 96 | + |
| 97 | + It "SkuName should be of type String" { |
| 98 | + $command.Parameters['SkuName'].ParameterType.Name | Should -Be "String" |
| 99 | + } |
| 100 | + |
| 101 | + It "AdministrationMembers should be of type String array" { |
| 102 | + $command.Parameters['AdministrationMembers'].ParameterType.Name | Should -Be "String[]" |
| 103 | + } |
| 104 | + |
| 105 | + It "Tags should be of type Hashtable" { |
| 106 | + $command.Parameters['Tags'].ParameterType.Name | Should -Be "Hashtable" |
| 107 | + } |
| 108 | + |
| 109 | + It "NoWait should be of type SwitchParameter" { |
| 110 | + $command.Parameters['NoWait'].ParameterType.Name | Should -Be "SwitchParameter" |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + Context "Parameter validation attributes" { |
| 115 | + BeforeAll { |
| 116 | + $command = Get-Command -Name Update-FabricCapacity |
| 117 | + } |
| 118 | + |
| 119 | + It "ResourceGroupName should have ValidateLength attribute with max length 90" { |
| 120 | + $validateLengthAttr = $command.Parameters['ResourceGroupName'].Attributes | Where-Object { $_.GetType().Name -eq "ValidateLengthAttribute" } |
| 121 | + $validateLengthAttr | Should -Not -BeNullOrEmpty |
| 122 | + $validateLengthAttr.MaxLength | Should -Be 90 |
| 123 | + } |
| 124 | + |
| 125 | + It "CapacityName should have ValidateLength attribute with min length 3 and max length 63" { |
| 126 | + $validateLengthAttr = $command.Parameters['CapacityName'].Attributes | Where-Object { $_.GetType().Name -eq "ValidateLengthAttribute" } |
| 127 | + $validateLengthAttr | Should -Not -BeNullOrEmpty |
| 128 | + $validateLengthAttr.MinLength | Should -Be 3 |
| 129 | + $validateLengthAttr.MaxLength | Should -Be 63 |
| 130 | + } |
| 131 | + |
| 132 | + It "CapacityName should have ValidatePattern attribute" { |
| 133 | + $validatePatternAttr = $command.Parameters['CapacityName'].Attributes | Where-Object { $_.GetType().Name -eq "ValidatePatternAttribute" } |
| 134 | + $validatePatternAttr | Should -Not -BeNullOrEmpty |
| 135 | + } |
| 136 | + } |
| 137 | +} |
0 commit comments