-
-
Notifications
You must be signed in to change notification settings - Fork 108
Issue85 #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Issue85 #90
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f8acc53
Remove the time interval checking from SheduledMessage.ps1
JasonNoonan ce766b0
Remove StartTimer() and StopTimer() from ScheduledMessage.ps1
JasonNoonan 54f0791
Rename ResetTimer to RecalculateStartAfter
JasonNoonan ab77e20
Rename call to ResetTimer to RecalculateStartAfter
JasonNoonan f19539c
Remove call to ResetTimer in Scheduler.SetSchedule()
JasonNoonan 0c00db3
Modify New-ScheduledCommand so that it always includes StartAfter
JasonNoonan 060c17b
undo last change
JasonNoonan f25d5b6
Revert "undo last change"
JasonNoonan eacca22
Revert "Modify New-ScheduledCommand so that it always includes StartA…
JasonNoonan 2934a55
Update test
JasonNoonan 474abac
Finish first draft of Unit Tests for ScheduledMessage
JasonNoonan 120676e
Remove StopWatch from class
JasonNoonan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,158 @@ | ||
| InModuleScope PoshBot { | ||
|
|
||
| Describe ScheduledMessage { | ||
| # Mock a message | ||
| $msg = [Message]::new() | ||
| $msg.Id = 1 | ||
| $msg.Text = "This is a test message" | ||
|
|
||
| # Call constructor | ||
| $Interval = 'Days' | ||
| $TimeValue = 1 | ||
| $Message = $msg | ||
| $StartAfter = (Get-Date).AddMinutes(1) | ||
|
|
||
| Context "Constructor: String, Int, Message, DateTime" { | ||
|
|
||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, $StartAfter) | ||
|
|
||
| It 'TimeInterval should match argument' { | ||
| $ScheduledMessage.TimeInterval | Should be $Interval | ||
| } | ||
|
|
||
| It 'TimeValue should match argument' { | ||
| $ScheduledMessage.TimeValue | Should be $TimeValue | ||
| } | ||
|
|
||
| It 'Message Id should be 1' { | ||
| $ScheduledMessage.Message.Id | Should be 1 | ||
| } | ||
| It 'Message Text should match argument' { | ||
| $ScheduledMessage.Message.Text | Should match $msg.Text | ||
| } | ||
|
|
||
| It 'StartAfter value should match argument converted to UTC' { | ||
| $ScheduledMessage.StartAfter | Should be $StartAfter.ToUniversalTime() | ||
| } | ||
| } | ||
|
|
||
| Context "Constructor: String, Int, Message" { | ||
|
|
||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message) | ||
|
|
||
| It 'TimeInterval should match argument' { | ||
| $ScheduledMessage.TimeInterval | Should be $Interval | ||
| } | ||
|
|
||
| It 'TimeValue should match argument' { | ||
| $ScheduledMessage.TimeValue | Should be $TimeValue | ||
| } | ||
|
|
||
| It 'Message Id should be 1' { | ||
| $ScheduledMessage.Message.Id | Should be 1 | ||
| } | ||
| It 'Message Text should match argument' { | ||
| $ScheduledMessage.Message.Text | Should match $msg.Text | ||
| } | ||
|
|
||
| It 'Should have a StartAfter value without passing the argument' { | ||
| $ScheduledMessage.StartAfter | Should not BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context "Methods: Init()" { | ||
|
|
||
| $Intervals = @( | ||
| @{ | ||
| Interval = 'Days' | ||
| MS = 86400000 | ||
| }, | ||
| @{ | ||
| Interval = 'Hours' | ||
| MS = 3600000 | ||
| }, | ||
| @{ | ||
| Interval = 'Minutes' | ||
| MS = 60000 | ||
| }, | ||
| @{ | ||
| Interval = 'Seconds' | ||
| MS = 1000 | ||
| } | ||
| ) | ||
|
|
||
| foreach ($Type in $Intervals) { | ||
| It "Should calculate milliseconds for single $($Type.Interval) correctly" { | ||
| $ScheduledMessage = [ScheduledMessage]::new($Type.Interval, 1, $Message) | ||
| $ScheduledMessage.IntervalMS | Should be (1 * $Type.MS) | ||
| } | ||
|
|
||
| It "Should calculate milliseconds for multiple $($Type.Interval) correctly" { | ||
| $ScheduledMessage = [ScheduledMessage]::new($Type.Interval, 5, $Message) | ||
| $ScheduledMessage.IntervalMS | Should be (5 * $Type.MS) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Context "Method: HasElapsed()" { | ||
| $ElapsedMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, (Get-Date).AddHours(-5)) | ||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, (Get-Date).AddHours(5)) | ||
|
|
||
| It 'Should return true when past the StartAfter DateTime' { | ||
| $ElapsedMessage.HasElapsed() | Should BeTrue | ||
| } | ||
|
|
||
| It 'Should return false when before the StartAfter DateTime' { | ||
| $ScheduledMessage.HasElapsed() | Should Not BeTrue | ||
| } | ||
|
|
||
| It 'TimesExecuted should be 1 after executing' { | ||
| $ElapsedMessage.TimesExecuted | Should be 1 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Context "Method: Disable()" { | ||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, (Get-Date)) | ||
|
|
||
| It 'Disables the instance when called' { | ||
| $ScheduledMessage.Disable() | ||
| $SceduleMessage.Enabled | Should Not BeTrue | ||
| } | ||
|
|
||
| It 'Does not throw an error when being called on an already-disabled instance' { | ||
| $ScheduledMessage.Disable() | ||
| $ScheduledMessage.Enabled | Should Not BeTrue | ||
| } | ||
| } | ||
|
|
||
| Context "Method: Enable()" { | ||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, (Get-Date)) | ||
|
|
||
| It 'Enables the instance when called' { | ||
| $ScheduledMessage.Disable() | ||
| $ScheduledMessage.Enable() | ||
| $ScheduledMessage.Enabled | Should BeTrue | ||
| } | ||
|
|
||
| It 'Does not throw an error when being called on an already-enabled instance' { | ||
| $ScheduledMessage.Enable() | ||
| $ScheduledMessage.Enabled | Should BeTrue | ||
| } | ||
| } | ||
|
|
||
| Context "Method: RecalculateStartAfter()" { | ||
| $ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, (Get-Date)) | ||
|
|
||
| It 'Should increase the StartAfter property by IntervalMS' { | ||
| $StartingValue = $ScheduledMessage.StartAfter | ||
| $ScheduledMessage.RecalculateStartAfter() | ||
|
|
||
| (New-TimeSpan $StartingValue $ScheduledMessage.StartAfter).TotalDays | Should Be 1 | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the stopwatch is not longer need. Can you remove it from the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I removed it from the scheduler class. I did a search and the only other areas the stopwatch seems to be referenced were in the actual Bot instance for tracking uptime.
Let me know if you find anything else that requires changing!