forked from microsoft/Microsoft365DSC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
730 additions
and
0 deletions.
There are no files selected for viewing
425 changes: 425 additions & 0 deletions
425
Modules/Microsoft365DSC/DSCResources/MSFT_EXOMigrationEnpoint/MSFT_EXOMigrationEnpoint.psm1
Large diffs are not rendered by default.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...Microsoft365DSC/DSCResources/MSFT_EXOMigrationEnpoint/MSFT_EXOMigrationEnpoint.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("ResourceName")] | ||
class MSFT_ResourceName : OMI_BaseResource | ||
{ | ||
[Key, Description("")] String PrimaryKey; | ||
[Write, Description("")] String OtherProperties; | ||
|
||
[Write, Description("Credentials of the workload's Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; | ||
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; | ||
[Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; | ||
[Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; | ||
[Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; | ||
[Write, Description("Access token used for authentication.")] String AccessTokens[]; | ||
}; |
6 changes: 6 additions & 0 deletions
6
Modules/Microsoft365DSC/DSCResources/MSFT_EXOMigrationEnpoint/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
# ResourceName | ||
|
||
## Description | ||
|
||
##TODO - Provide a short description of what the resource is set to configure. |
32 changes: 32 additions & 0 deletions
32
Modules/Microsoft365DSC/DSCResources/MSFT_EXOMigrationEnpoint/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"resourceName": "ResourceName", | ||
"description": "Description of what the resource is about.", | ||
"roles": { | ||
"read": [ | ||
"Role" | ||
], | ||
"update": [ | ||
"Role" | ||
] | ||
}, | ||
"permissions": { | ||
"graph": { | ||
"delegated": { | ||
"read": [], | ||
"update": [] | ||
}, | ||
"application": { | ||
"read": [ | ||
{ | ||
"name": "Permission for Monitoring and Export" | ||
} | ||
], | ||
"update": [ | ||
{ | ||
"name": "Permission for deploying" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Modules/Microsoft365DSC/Examples/Resources/ResourceName/1-Create.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint | ||
) | ||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Modules/Microsoft365DSC/Examples/Resources/ResourceName/2-Update.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint | ||
) | ||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Modules/Microsoft365DSC/Examples/Resources/ResourceName/3-Remove.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint | ||
) | ||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
|
||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
Tests/Unit/Microsoft365DSC/Microsoft365DSC.ResourceName.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
[CmdletBinding()] | ||
param( | ||
) | ||
$M365DSCTestFolder = Join-Path -Path $PSScriptRoot ` | ||
-ChildPath '..\..\Unit' ` | ||
-Resolve | ||
$CmdletModule = (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\Stubs\Microsoft365.psm1' ` | ||
-Resolve) | ||
$GenericStubPath = (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\Stubs\Generic.psm1' ` | ||
-Resolve) | ||
Import-Module -Name (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\UnitTestHelper.psm1' ` | ||
-Resolve) | ||
|
||
$CurrentScriptPath = $PSCommandPath.Split('\') | ||
$CurrentScriptName = $CurrentScriptPath[$CurrentScriptPath.Length -1] | ||
$ResourceName = $CurrentScriptName.Split('.')[1] | ||
$Global:DscHelper = New-M365DscUnitTestHelper -StubModule $CmdletModule ` | ||
-DscResource $ResourceName -GenericStubModule $GenericStubPath | ||
|
||
Describe -Name $Global:DscHelper.DescribeHeader -Fixture { | ||
InModuleScope -ModuleName $Global:DscHelper.ModuleName -ScriptBlock { | ||
Invoke-Command -ScriptBlock $Global:DscHelper.InitializeScript -NoNewScope | ||
BeforeAll { | ||
|
||
$secpasswd = ConvertTo-SecureString (New-Guid | Out-String) -AsPlainText -Force | ||
$Credential = New-Object System.Management.Automation.PSCredential ('[email protected]', $secpasswd) | ||
|
||
Mock -CommandName Confirm-M365DSCDependencies -MockWith { | ||
} | ||
|
||
Mock -CommandName New-M365DSCConnection -MockWith { | ||
return "Credentials" | ||
} | ||
|
||
##TODO - Mock any Remove/Set/New cmdlets | ||
|
||
# Mock Write-Host to hide output during the tests | ||
Mock -CommandName Write-Host -MockWith { | ||
} | ||
$Script:exportedInstances =$null | ||
$Script:ExportMode = $false | ||
} | ||
# Test contexts | ||
Context -Name "The instance should exist but it DOES NOT" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
##TODO - Add Parameters | ||
Ensure = 'Present' | ||
Credential = $Credential; | ||
} | ||
|
||
##TODO - Mock the Get-Cmdlet to return $null | ||
Mock -CommandName Get-Cmdlet -MockWith { | ||
return $null | ||
} | ||
} | ||
It 'Should return Values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Absent' | ||
} | ||
It 'Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
|
||
It 'Should create a new instance from the Set method' { | ||
##TODO - Replace the New-Cmdlet by the appropriate one | ||
Should -Invoke -CommandName New-Cmdlet -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name "The instance exists but it SHOULD NOT" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
##TODO - Add Parameters | ||
Ensure = 'Absent' | ||
Credential = $Credential; | ||
} | ||
|
||
##TODO - Mock the Get-Cmdlet to return an instance | ||
Mock -CommandName Get-Cmdlet -MockWith { | ||
return @{ | ||
|
||
} | ||
} | ||
} | ||
It 'Should return Values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Present' | ||
} | ||
It 'Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
|
||
It 'Should remove the instance from the Set method' { | ||
##TODO - Replace the Remove-Cmdlet by the appropriate one | ||
Should -Invoke -CommandName Remove-Cmdlet -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name "The instance exists and values are already in the desired state" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
##TODO - Add Parameters | ||
Ensure = 'Present' | ||
Credential = $Credential; | ||
} | ||
|
||
##TODO - Mock the Get-Cmdlet to return the desired values | ||
Mock -CommandName Get-Cmdlet -MockWith { | ||
return @{ | ||
|
||
} | ||
} | ||
} | ||
|
||
It 'Should return true from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $true | ||
} | ||
} | ||
|
||
Context -Name "The instance exists and values are NOT in the desired state" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
##TODO - Add Parameters | ||
Ensure = 'Present' | ||
Credential = $Credential; | ||
} | ||
|
||
##TODO - Mock the Get-Cmdlet to return a drift | ||
Mock -CommandName Get-Cmdlet -MockWith { | ||
return @{ | ||
|
||
} | ||
} | ||
} | ||
|
||
It 'Should return Values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Present' | ||
} | ||
|
||
It 'Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
|
||
It 'Should call the Set method' { | ||
Set-TargetResource @testParams | ||
##TODO - Replace the Update-Cmdlet by the appropriate one | ||
Should -Invoke -CommandName Update-Cmdlet -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name 'ReverseDSC Tests' -Fixture { | ||
BeforeAll { | ||
$Global:CurrentModeIsExport = $true | ||
$Global:PartialExportFileName = "$(New-Guid).partial.ps1" | ||
$testParams = @{ | ||
Credential = $Credential; | ||
} | ||
|
||
##TODO - Mock the Get-Cmdlet to return an instance | ||
Mock -CommandName Get-Cmdlet -MockWith { | ||
return @{ | ||
|
||
} | ||
} | ||
} | ||
It 'Should Reverse Engineer resource from the Export method' { | ||
$result = Export-TargetResource @testParams | ||
$result | Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
} | ||
|
||
Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope |