Skip to content

Commit

Permalink
Add mocked command to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienTschanz committed Dec 11, 2024
1 parent 28ee71b commit 05fc142
Show file tree
Hide file tree
Showing 49 changed files with 161 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ResourceGenerator/UnitTest.Template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Reset-MSCloudLoginConnectionProfileContext -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Add-M365DSCTelemetryEvent -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-MgBetaPolicyAuthenticationMethodPolicyAuthenticationMethodConfiguration -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
$Credential = New-Object System.Management.Automation.PSCredential ('tenantadmin@mydomain.com', $secpasswd)

Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Update-MgBetaDirectoryAttributeSet -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down Expand Up @@ -85,7 +88,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential;
}
}

It 'Should return false from the Test method' {
Test-TargetResource @testParams | Should -Be $false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Update-MgBetaEntitlementManagementConnectedOrganization -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Microsoft365DSC/Microsoft365DSC.AADGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-MgBetaNetworkAccessConnectivityRemoteNetwork -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
$secpasswd = ConvertTo-SecureString (New-Guid | Out-String) -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ('tenantadmin@contoso.com', $secpasswd)


Mock -CommandName Get-PSSession -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Remove-PSSession -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down Expand Up @@ -75,7 +78,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Test-TargetResource @testParams | Should -Be $false
}
It 'Should Create the id from the Set method' {
Set-TargetResource @testParams
Set-TargetResource @testParams
Should -Invoke -CommandName Invoke-M365DSCVerifiedIdWebRequest -Exactly 2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Get-PSSession -MockWith {
}

Expand Down Expand Up @@ -62,7 +65,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
} -ClientOnly)
attestations = (New-CimInstance -ClassName MSFT_AADVerifiedIdAuthorityContractAttestations -Property @{
required = $True
} -ClientOnly)
} -ClientOnly)

} -ClientOnly)
Ensure = 'Present'
Expand Down Expand Up @@ -92,7 +95,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
)
}
}
default {
default {
return @{
value = @()
}
Expand All @@ -108,7 +111,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Test-TargetResource @testParams | Should -Be $false
}
It 'Should Create the id from the Set method' {
Set-TargetResource @testParams
Set-TargetResource @testParams
Should -Invoke -CommandName Invoke-M365DSCVerifiedIdWebRequest -Exactly 4
}
}
Expand Down Expand Up @@ -195,7 +198,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
)
}
}
default {
default {
return @{
value = @(
@{
Expand Down Expand Up @@ -416,7 +419,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
)
}
}
default {
default {
return @{
value = @(
@{
Expand Down Expand Up @@ -628,7 +631,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
)
}
}
default {
default {
return @{
value = @(
@{
Expand Down Expand Up @@ -799,7 +802,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
)
}
}
default {
default {
return @{
value = @(
@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Save-M365DSCPartialExport -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Reset-MSCloudLoginConnectionProfileContext -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return 'Credentials'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "ServicePrincipalWithThumbprint"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName Save-M365DSCPartialExport -MockWith {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return 'Credentials'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return 'Credentials'
}
Expand Down Expand Up @@ -55,7 +58,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
@{
id = '3eacc231-d77b-4efb-bb5f-310f68bd6198'
DisplayName = 'MyExcludedGroup'
},
},
@{
id = '6ee86c9f-2b3c-471d-ad38-ff4673ed723e'
DisplayName = 'MyAssignedGroup'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Confirm-M365DSCDependencies -MockWith {
}

Mock -CommandName Get-MSCloudLoginConnectionProfile -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}
Expand Down
Loading

0 comments on commit 05fc142

Please sign in to comment.