Skip to content

Commit

Permalink
Resoling UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpitam25 committed Nov 12, 2024
1 parent 45de8a3 commit bb072fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Get-TargetResource
$NotificationEmails,

[Parameter()]
[System.DateTime]
[System.String]
$CompleteAfter,

[Parameter()]
Expand All @@ -37,7 +37,7 @@ function Get-TargetResource
$SkipMerging,

[Parameter()]
[System.DateTime]
[System.String]
$StartAfter,

[Parameter()]
Expand Down Expand Up @@ -125,13 +125,11 @@ function Get-TargetResource
$results = @{
Identity = $Identity
NotificationEmails = [System.String[]]$instance.NotificationEmails
CompleteAfter = $instance.CompleteAfter
AddUsers = [System.Boolean]$instance.AddUsers
BadItemLimit = [System.String]$instance.BadItemLimit
LargeItemLimit = [System.String]$instance.LargeItemLimit
MoveOptions = [System.String[]]$instance.MoveOptions
SkipMerging = [System.String[]]$instance.SkipMerging
StartAfter = $instance.StartAfter
Update = [System.Boolean]$instance.Update
Ensure = 'Present'
Credential = $Credential
Expand All @@ -146,6 +144,16 @@ function Get-TargetResource
TargetDeliveryDomain = $instance.TargetDeliveryDomain
}

if ($instance.CompleteAfter -ne $null)
{
$results.Add('CompleteAfter', $instance.CompleteAfter.ToString("MM/dd/yyyy hh:mm tt"))
}

if ($instance.StartAfter -ne $null)
{
$results.Add('StartAfter', $instance.CompleteAfter.ToString("MM/dd/yyyy hh:mm tt"))
}

return [System.Collections.Hashtable] $results
}
catch
Expand Down Expand Up @@ -173,7 +181,7 @@ function Set-TargetResource
$NotificationEmails,

[Parameter()]
[System.DateTime]
[System.String]
$CompleteAfter,

[Parameter()]
Expand All @@ -197,7 +205,7 @@ function Set-TargetResource
$SkipMerging,

[Parameter()]
[System.DateTime]
[System.String]
$StartAfter,

[Parameter()]
Expand Down Expand Up @@ -265,18 +273,18 @@ function Set-TargetResource

if ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Absent')
{
# Define the path for the CSV file to store the migration users
$csvFilePath = "$env:TEMP\MigrationUsers.csv"
# Convert the list of users to CSV format
$csvContent = @('"EmailAddress"') + ($MigrationUsers | ForEach-Object { "`"$_`"" })

# Convert each item in the array to a custom object with an EmailAddress property
$csvContent = $MigrationUsers | ForEach-Object { [PSCustomObject]@{EmailAddress = $_} }
# Join the results into a single string with new lines
$csvContent = $csvContent -join "`r`n"

# Export to CSV with the header "EmailAddress"
$csvContent | Export-Csv -Path $csvFilePath -NoTypeInformation -Force
# Convert the CSV content to bytes directly without saving to a file
$csvBytes = [System.Text.Encoding]::UTF8.GetBytes($csvContent -join "`r`n")

$BatchParams = @{
Name = $Identity # Use the existing Identity as the new batch name
CSVData = [System.IO.File]::ReadAllBytes($csvFilePath) # Load the CSV as byte array
CSVData = $csvBytes # Directly use the byte array
NotificationEmails = $NotificationEmails # Use the same notification emails if provided
CompleteAfter = $CompleteAfter
StartAfter = $StartAfter
Expand Down Expand Up @@ -376,7 +384,7 @@ function Test-TargetResource
$NotificationEmails,

[Parameter()]
[System.DateTime]
[System.String]
$CompleteAfter,

[Parameter()]
Expand All @@ -400,7 +408,7 @@ function Test-TargetResource
$SkipMerging,

[Parameter()]
[System.DateTime]
[System.String]
$StartAfter,

[Parameter()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ class MSFT_EXOMigration : OMI_BaseResource
{
[Key, Description("The Identity parameter identifies the name of the current migration batch.")] String Identity;
[Write, Description("The NotificationEmails parameter specifies one or more email addresses that migration status reports are sent to.")] String NotificationEmails[];
[Write, Description("The CompleteAfter parameter specifies a delay before the batch is completed.")] DateTime CompleteAfter;
[Write, Description("The CompleteAfter parameter specifies a delay before the batch is completed.")] String CompleteAfter;
[Write, Description("The AddUsers parameter controls whether additional users can be dynamically added to an existing migration batch after it has been created.")] Boolean AddUsers;
[Write, Description("The BadItemLimit parameter specifies the maximum number of bad items that are allowed before the migration request fails.")] String BadItemLimit;
[Write, Description("The LargeItemLimit parameter specifies the maximum number of large items that are allowed before the migration request fails.")] String LargeItemLimit;
[Write, Description("The MoveOptions parameter specifies the stages of the migration that you want to skip for debugging purposes.")] String MoveOptions[];
[Write, Description("The SkipMerging parameter specifies the stages of the migration that you want to skip for debugging purposes.")] String SkipMerging[];
[Write, Description("The StartAfter parameter specifies a delay before the data migration for the users within the batch is started.")] DateTime StartAfter;
[Write, Description("The StartAfter parameter specifies a delay before the data migration for the users within the batch is started.")] String StartAfter;
[Write, Description("The Update switch sets the Update flag on the migration batch.")] Boolean Update;
[Write, Description("The Status parameter returns information about migration users that have the specified status state.")] String Status;
[Write, Description("Migration Users states the list of the users/mailboxes that are part of a migration batch that are to be migrated.")] String MigrationUsers[];
[Write, Description("The SourceEndpoint parameter specifies the migration endpoint to use for the source of the migration batch.")] String SourceEndpoint;
[Write, Description("The TargetDeliveryDomain parameter specifies the FQDN of the external email address created in the source forest for the mail-enabled user when the migration batch is complete.")] String TargetDeliveryDomain;

[Write, Description("Specifies if the migration endpoint should exist or not."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("Credentials of the workload's Admin"), EmbeddedInstance("MSFT_Credential")] string Credential;
Expand Down
31 changes: 24 additions & 7 deletions Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOMigration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ 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 Down Expand Up @@ -126,7 +123,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
return @{
AddUsers = $False;
BadItemLimit = "Unlimited";
CompleteAfter = "07/30/2020 21:00:00";
CompleteAfter = "07/30/2020 9:00:00 PM";
Credential = $Credscredential;
Ensure = "Present";
Identity = "Arpita";
Expand All @@ -136,18 +133,28 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
NotificationEmails = @("[email protected]","[email protected]");
SkipMerging = @("abc");
SourceEndpoint = @{Identity = @{Id = "gmailCalendar"}};
StartAfter = "07/30/2020 21:00:00";
StartAfter = "07/30/2020 9:00:00 PM";
Status = @{Value = "Completing"};
TargetDeliveryDomain = "O365InsightsView.mail.onmicrosoft.com";
Update = $False;
}
}
Mock -CommandName Get-MigrationUser -MockWith {
return @(
@{
Identity = "[email protected]"
},
@{
Identity = "[email protected]"
}
)
}
}
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
Test-TargetResource @testParams -Verbose | Should -Be $false
}

It 'Should remove the instance from the Set method' {
Expand Down Expand Up @@ -197,6 +204,16 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Update = $False;
}
}
Mock -CommandName Get-MigrationUser -MockWith {
return @(
@{
Identity = "[email protected]"
},
@{
Identity = "[email protected]"
}
)
}
}
It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
Expand Down Expand Up @@ -266,7 +283,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {


It 'Should return true from the Test method' {
Test-TargetResource @testParams -Verbose | Should -Be $true
Test-TargetResource @testParams | Should -Be $true
}
}

Expand Down

0 comments on commit bb072fc

Please sign in to comment.