From 1067405d9e30e4aa952a9ffc6024caedf56f4dd2 Mon Sep 17 00:00:00 2001 From: ece-jacob-scott Date: Sat, 23 Feb 2019 14:52:49 -0600 Subject: [PATCH 1/4] [feature] Made subject no longer mandatory and added test --- .../commands/utility/Send-MailMessage.cs | 3 +-- .../Send-MailMessage.Tests.ps1 | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs index 506715eb5bf..96689806ba6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs @@ -117,9 +117,8 @@ public sealed class SendMailMessage : PSCmdlet /// /// Gets or sets the subject of the email message. /// - [Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)] + [Parameter(Mandatory = false, Position = 1, ValueFromPipelineByPropertyName = true)] [Alias("sub")] - [ValidateNotNullOrEmpty] public string Subject { get; set; } /// diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index f9962008966..220223b76f4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -106,4 +106,23 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { $mail.MessageParts.Count | Should -BeExactly 1 $mail.MessageParts[0].BodyData | Should -BeExactly $InputObject.Body } + + $ItArgs = $PesterArgs.Clone() + $ItArgs['Name'] = "Can send mail message from user to self without subject " + $ItArgs['Name'] + + It @ItArgs { + $body = "Greetings from me." + $subject = "Test message" + Send-MailMessage -To $address -From $address -ReplyTo $address -Body $body -SmtpServer 127.0.0.1 + Test-Path -Path $mailBox | Should -BeTrue + $mail = read-mail $mailBox + $mail.From | Should -BeExactly $address + $mail.To.Count | Should -BeExactly 1 + $mail.To[0] | Should -BeExactly $address + $mail.ReplyTo.Count | Should -BeExactly 1 + $mail.ReplyTo[0] | Should -BeExactly $address + $mail.Subject | Should -BeNullorEmpty + $mail.Body.Count | Should -BeExactly 1 + $mail.Body[0] | Should -BeExactly $body + } } From 2d1482d485bb7b1c3d673bf3f3cc7de2c445a603 Mon Sep 17 00:00:00 2001 From: ece-jacob-scott Date: Sun, 24 Feb 2019 13:27:21 -0600 Subject: [PATCH 2/4] [feature] Removed Subject line from no subject line test --- .../Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index 220223b76f4..4c928b83c97 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -112,12 +112,12 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { It @ItArgs { $body = "Greetings from me." - $subject = "Test message" Send-MailMessage -To $address -From $address -ReplyTo $address -Body $body -SmtpServer 127.0.0.1 Test-Path -Path $mailBox | Should -BeTrue $mail = read-mail $mailBox $mail.From | Should -BeExactly $address - $mail.To.Count | Should -BeExactly 1 + $mail.To.Count | Should -BeExactly 1It + $body = "Greetings from me." $mail.To[0] | Should -BeExactly $address $mail.ReplyTo.Count | Should -BeExactly 1 $mail.ReplyTo[0] | Should -BeExactly $address From 7d64d2062175a8aceb28956b8f12c7b3bbe8fc6d Mon Sep 17 00:00:00 2001 From: ece-jacob-scott Date: Sat, 16 Mar 2019 18:00:00 -0500 Subject: [PATCH 3/4] [feature] Fixed a test typo --- .../Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index 4c928b83c97..efc0998518b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -116,7 +116,7 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { Test-Path -Path $mailBox | Should -BeTrue $mail = read-mail $mailBox $mail.From | Should -BeExactly $address - $mail.To.Count | Should -BeExactly 1It + $mail.To.Count | Should -BeExactly 1 $body = "Greetings from me." $mail.To[0] | Should -BeExactly $address $mail.ReplyTo.Count | Should -BeExactly 1 From 0929c1f9c09dc3f390fe00f29527c871b0464ead Mon Sep 17 00:00:00 2001 From: ece-jacob-scott Date: Sat, 16 Mar 2019 18:38:51 -0500 Subject: [PATCH 4/4] [feature] added a no subject test case --- .../Send-MailMessage.Tests.ps1 | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 index efc0998518b..ef851fab56d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 @@ -61,6 +61,16 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { SmtpServer = "127.0.0.1" } } + @{ + Name = "with No Subject" + InputObject = @{ + From = "user01@example.com" + To = "user02@example.com" + ReplyTo = "noreply@example.com" + Body = "Body $(Get-Date)" + SmtpServer = "127.0.0.1" + } + } ) It "Can send mail message using named parameters " -TestCases $testCases { @@ -78,7 +88,9 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { $mail.Headers["From"] | Should -BeExactly $InputObject.From $mail.Headers["To"] | Should -BeExactly $InputObject.To $mail.Headers["Reply-To"] | Should -BeExactly $InputObject.ReplyTo - $mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject + If ($InputObject.Subject -ne $null) { + $mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject + } $mail.MessageParts.Count | Should -BeExactly 1 $mail.MessageParts[0].BodyData | Should -BeExactly $InputObject.Body @@ -101,28 +113,11 @@ Describe "Send-MailMessage" -Tags CI, RequireSudoOnUnix { $mail.Headers["From"] | Should -BeExactly $InputObject.From $mail.Headers["To"] | Should -BeExactly $InputObject.To $mail.Headers["Reply-To"] | Should -BeExactly $InputObject.ReplyTo - $mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject + If ($InputObject.Subject -ne $null) { + $mail.Headers["Subject"] | Should -BeExactly $InputObject.Subject + } $mail.MessageParts.Count | Should -BeExactly 1 $mail.MessageParts[0].BodyData | Should -BeExactly $InputObject.Body } - - $ItArgs = $PesterArgs.Clone() - $ItArgs['Name'] = "Can send mail message from user to self without subject " + $ItArgs['Name'] - - It @ItArgs { - $body = "Greetings from me." - Send-MailMessage -To $address -From $address -ReplyTo $address -Body $body -SmtpServer 127.0.0.1 - Test-Path -Path $mailBox | Should -BeTrue - $mail = read-mail $mailBox - $mail.From | Should -BeExactly $address - $mail.To.Count | Should -BeExactly 1 - $body = "Greetings from me." - $mail.To[0] | Should -BeExactly $address - $mail.ReplyTo.Count | Should -BeExactly 1 - $mail.ReplyTo[0] | Should -BeExactly $address - $mail.Subject | Should -BeNullorEmpty - $mail.Body.Count | Should -BeExactly 1 - $mail.Body[0] | Should -BeExactly $body - } }