|
1 | | -using Xunit; |
| 1 | +{{ func to_timespan |
| 2 | + if $0 == "00:00:00" |
| 3 | + ret "TimeSpan.Zero" |
| 4 | + end |
| 5 | +
|
| 6 | + parts = string.split $0 ":" |
| 7 | + hours = parts[0] | string.to_int |
| 8 | + minutes = parts[1] | string.to_int |
| 9 | + seconds = parts[2] | string.to_int |
| 10 | + $"new TimeSpan({hours},{minutes},{seconds})" |
| 11 | +end }} |
| 12 | + |
| 13 | +using Microsoft.Extensions.Time.Testing; |
2 | 14 |
|
3 | 15 | public class {{ testClass }} |
4 | 16 | { |
5 | 17 | {{- for test in tests }} |
6 | 18 | [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] |
7 | 19 | public void {{ test.testMethod }}() |
8 | 20 | { |
9 | | - Assert.Equal({{ test.expected }}, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.commands }})); |
| 21 | + {{- for command in test.input.commands }} |
| 22 | + {{- if command.command == "new" }} |
| 23 | + var timeProvider = new FakeTimeProvider(); |
| 24 | + var stopwatch = new {{ testedClass }}(timeProvider); |
| 25 | + {{- else if command.command == "state" }} |
| 26 | + Assert.Equal({{ command.expected | enum "StopwatchState" }}, stopwatch.State); |
| 27 | + {{- else if command.command == "currentLap" }} |
| 28 | + Assert.Equal({{ command.expected | to_timespan }}, stopwatch.CurrentLap); |
| 29 | + {{- else if command.command == "total" }} |
| 30 | + Assert.Equal({{ command.expected | to_timespan }}, stopwatch.Total); |
| 31 | + {{- else if command.command == "previousLaps" }} |
| 32 | + {{- if command.expected.empty? }} |
| 33 | + Assert.Empty(stopwatch.PreviousLaps); |
| 34 | + {{ else }} |
| 35 | + Assert.Equal([{{- for previousLap in command.expected }}{{ previousLap | to_timespan }}{{ if !for.last }}, {{ end }}{{ end -}}], stopwatch.PreviousLaps); |
| 36 | + {{ end -}} |
| 37 | + {{- else if command.command == "advanceTime" }} |
| 38 | + timeProvider.Advance({{ command.by | to_timespan }}); |
| 39 | + {{- else }} |
| 40 | + {{- if command.expected && command.expected.error }} |
| 41 | + Assert.Throws<InvalidOperationException>(() => stopwatch.{{ command.command | pascalize }}()); |
| 42 | + {{ else }} |
| 43 | + stopwatch.{{ command.command | pascalize }}(); |
| 44 | + {{ end -}} |
| 45 | + {{ end -}} |
| 46 | + {{ end -}} |
10 | 47 | } |
11 | 48 | {{ end -}} |
12 | 49 | } |
0 commit comments