Skip to content

Commit

Permalink
Added UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpitam25 committed Nov 11, 2024
1 parent dc86433 commit b5bfd3e
Show file tree
Hide file tree
Showing 3 changed files with 8,112 additions and 95,439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ function Set-TargetResource
# Retrieve the migration batch
$migrationBatch = Get-MigrationBatch -Identity $currentInstance.Identity -ErrorAction Stop

if ($migrationBatch.Status.Value -in @('Completed', 'CompletedWithErrors', 'Stopped', 'Failed', 'SyncedWithErrors'))
if ($migrationBatch.Status -in @('Completed', 'CompletedWithErrors', 'Stopped', 'Failed', 'SyncedWithErrors'))
{
# If the migration batch is in a final state, remove it directly
Remove-MigrationBatch -Identity $currentInstance.Identity -Confirm:$false
Write-Host "Migration batch '$($currentInstance.Identity)' has been removed as it was in a completed or stopped state."
}
elseif ($migrationBatch.Status.Value -in @('InProgress', 'Syncing', 'Queued', 'Completing'))
elseif ($migrationBatch.Status -in @('InProgress', 'Syncing', 'Queued', 'Completing'))
{
# If the migration batch is in progress, stop it first
Stop-MigrationBatch -Identity $currentInstance.Identity -Confirm:$false
Expand Down
129 changes: 113 additions & 16 deletions Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOMigration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Get-MigrationUser -MockWith {
}

Mock -CommandName Get-MigrationUser -MockWith {
}

# Mock Write-Host to hide output during the tests
Mock -CommandName Write-Host -MockWith {
}
Expand All @@ -70,9 +73,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand Down Expand Up @@ -108,9 +111,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Ensure = "Absent";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand All @@ -128,9 +131,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand Down Expand Up @@ -164,9 +167,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Ensure = "Absent";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand All @@ -184,9 +187,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand Down Expand Up @@ -216,12 +219,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
BadItemLimit = "Unlimited";
CompleteAfter = "7/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Absent";
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand All @@ -236,12 +239,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
BadItemLimit = "Unlimited";
CompleteAfter = "7/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Absent";
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("peixintest1@$OrganizationName","akstest39@$OrganizationName");
MigrationUsers = @("peixintest1@bellred.org","akstest39@bellred.org");
MoveOptions = @();
NotificationEmails = @("eac_admin@$OrganizationName","abc@$OrganizationName");
NotificationEmails = @("eac_admin@bellred.org","abc@bellred.org");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Expand All @@ -256,5 +259,99 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Test-TargetResource @testParams | Should -Be $true
}
}

Context -Name "The instance exists and values are NOT in the desired state" -Fixture {
BeforeAll {
$testParams = @{
AddUsers = $False;
BadItemLimit = "Unlimited";
CompleteAfter = "7/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("[email protected]","[email protected]");
MoveOptions = @();
NotificationEmails = @("[email protected]","[email protected]");
SkipMerging = @("abc");
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Status = "Completing";
TargetDeliveryDomain = "O365InsightsView.mail.onmicrosoft.com";
Update = $False;
}

Mock -CommandName Get-MigrationBatch -MockWith {
return @{
AddUsers = $False;
BadItemLimit = "Unlimited";
CompleteAfter = "7/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("[email protected]","[email protected]");
MoveOptions = @();
NotificationEmails = @("[email protected]","[email protected]");
SkipMerging = @();
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Status = "Completing";
TargetDeliveryDomain = "O365InsightsView.mail.onmicrosoft.com";
Update = $False;
}
}
}

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
Should -Invoke -CommandName Set-MigrationBatch -Exactly 1
}
}

Context -Name 'ReverseDSC Tests' -Fixture {
BeforeAll {
$Global:CurrentModeIsExport = $true
$Global:PartialExportFileName = "$(New-Guid).partial.ps1"
$testParams = @{
Credential = $Credential;
}

Mock -CommandName Get-MigrationBatch -MockWith {
return @{
AddUsers = $False;
BadItemLimit = "Unlimited";
CompleteAfter = "7/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Present";
Identity = "Arpita";
LargeItemLimit = "Unlimited";
MigrationUsers = @("[email protected]","[email protected]");
MoveOptions = @();
NotificationEmails = @("[email protected]","[email protected]");
SkipMerging = @();
SourceEndpoint = "gmailCalendar";
StartAfter = "7/30/2020 9:00:00 PM";
Status = "Completing";
TargetDeliveryDomain = "O365InsightsView.mail.onmicrosoft.com";
Update = $False;
}
}
}
It 'Should Reverse Engineer resource from the Export method' {
$result = Export-TargetResource @testParams
$result | Should -Not -BeNullOrEmpty
}
}
}
}

Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope
Loading

0 comments on commit b5bfd3e

Please sign in to comment.