Skip to content

Commit

Permalink
feat: Add validation to ensure the ExpiryDate comes after the Created…
Browse files Browse the repository at this point in the history
…Date.

feat: Add validation to ensure the Author has been updated from the default template value.
  • Loading branch information
deadlydog committed May 21, 2024
1 parent f64240a commit 37d78a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/CSharpClasses/tiPSClasses/PowerShellTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public void Validate()
throw new ArgumentException("The Urls property value '" + url + "' is not a valid URL.");
}
}

if (ExpiryDate <= CreatedDate)
{
throw new ArgumentException("The ExpiryDate property value must be greater than the CreatedDate property value.");
}

if (!string.IsNullOrWhiteSpace(Author))
{
// Ensure the Author is not the default value from the template often used to create new tips.
if (string.Equals(Author, "Your name and/or username", StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("The Author property value must be set to your name and/or username, or left blank.");
}
}
}
}
}
12 changes: 12 additions & 0 deletions src/tiPS/Classes/PowerShellTip.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ Describe 'Validating a PowerShellTip' {
[tiPS.PowerShellTip] $tip = $ValidTip
{ $tip.Category = 'InvalidCategory' } | Should -Throw
}

It 'Should throw an error when the ExpiryDate is before the CreatedDate' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.ExpiryDate = [DateTime]::Parse('2020-01-15')
{ $tip.Validate() } | Should -Throw
}

It 'Should throw an error when the Author is the default template value' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Author = 'Your name and/or username'
{ $tip.Validate() } | Should -Throw
}
}

Context 'Given the PowerShellTip has all valid properties' {
Expand Down

0 comments on commit 37d78a2

Please sign in to comment.