Skip to content

Commit 6af325d

Browse files
committed
Added OutOfOrder and Empty tests in At functions.
1 parent e99408b commit 6af325d

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

FluentScheduler.UnitTests/Fluent/3.Duration/EverydayUnitTests.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void AtMultipleTimeSpan()
9090

9191
// Assert
9292
Equal(expected, calculated.Value);
93-
93+
9494
// Arrange
9595
now = now.AddHours(5.1);
9696
expected = expected.Date.Add(timeSpans[1]);
@@ -121,7 +121,7 @@ public void AtMultipleTimeSpan()
121121
// Assert
122122
Equal(expected, calculated.Value);
123123
}
124-
124+
125125
[Fact]
126126
public void AtMultipleTimeSpan2()
127127
{
@@ -142,7 +142,7 @@ public void AtMultipleTimeSpan2()
142142

143143
// Assert
144144
Equal(expected, calculated.Value);
145-
145+
146146
// Arrange
147147
now = now.AddHours(1.1);
148148
expected = expected.Date.Add(timeSpans[2]);
@@ -227,7 +227,7 @@ public void EverydayAt15()
227227
// Assert
228228
Equal(expectedDate, calculated.Value);
229229
}
230-
230+
231231
[Fact]
232232
public void EverydayAt16()
233233
{
@@ -400,4 +400,26 @@ public void Between19and22()
400400
// Assert
401401
Equal(expectedDate, calculated.Value);
402402
}
403+
404+
[Fact]
405+
public void ThrowIfAtOutOfOrder()
406+
{
407+
// Arrange
408+
var fluentCalculator = new FluentTimeCalculator();
409+
var run = new EverydayUnit(fluentCalculator);
410+
411+
// Act
412+
Throws<ArgumentException>(() => run.At(new TimeSpan(10, 0, 0), new TimeSpan(9, 0, 0)));
413+
}
414+
415+
[Fact]
416+
public void ThrowIfAtEmpty()
417+
{
418+
// Arrange
419+
var fluentCalculator = new FluentTimeCalculator();
420+
var run = new EverydayUnit(fluentCalculator);
421+
422+
// Act
423+
Throws<ArgumentException>(() => run.At());
424+
}
403425
}

FluentScheduler.UnitTests/Fluent/3.Duration/PeriodOnceSetTests.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void At()
2121

2222
// Act
2323
run.At(8, 40);
24-
var calculated = calculator.Calculate(now);
24+
var calculated = calculator.Calculate(now)!;
2525

2626
// Assert
2727
Equal(expected, calculated.Value);
@@ -31,7 +31,7 @@ public void At()
3131
public void AtTimeSpan()
3232
{
3333
// Arrange
34-
var now = new DateTime(2018, 3, 3, 10, 0 ,0);
34+
var now = new DateTime(2018, 3, 3, 10, 0, 0);
3535
var expected = new DateTime(2018, 3, 3, 12, 30, 0);
3636

3737
var timeSpan = new TimeSpan(12, 30, 0);
@@ -44,12 +44,34 @@ public void AtTimeSpan()
4444

4545
// Act
4646
run.At(timeSpan);
47-
var calculated = calculator.Calculate(now);
47+
var calculated = calculator.Calculate(now)!;
4848

4949
// Assert
5050
Equal(expected, calculated.Value);
5151
}
5252

53+
[Fact]
54+
public void ThrowIfAtEmpty()
55+
{
56+
// Arrange
57+
var fluentCalculator = new FluentTimeCalculator();
58+
var run = new PeriodOnceSet(fluentCalculator);
59+
60+
// Act
61+
Throws<ArgumentException>(() => run.At());
62+
}
63+
64+
[Fact]
65+
public void ThrowIfAtOutOfOrder()
66+
{
67+
// Arrange
68+
var fluentCalculator = new FluentTimeCalculator();
69+
var run = new PeriodOnceSet(fluentCalculator);
70+
71+
// Act
72+
Throws<ArgumentException>(() => run.At(new TimeSpan(10, 0, 0), new TimeSpan(9, 0, 0)));
73+
}
74+
5375
[Fact]
5476
public void InTheNextMonth()
5577
{
@@ -65,9 +87,9 @@ public void InTheNextMonth()
6587

6688
// Act
6789
run.Every(1).Months().On(10).At(11, 30);
68-
var calculated = calculator.Calculate(now);
90+
var calculated = calculator.Calculate(now)!;
6991

7092
// Assert
7193
Equal(expectedDate, calculated.Value);
7294
}
73-
}
95+
}

FluentScheduler/Fluent/3.Duration/PeriodOnceSet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void At(int hour, int minute)
3232
public void At(params TimeSpan[] timeCollection)
3333
{
3434
ThrowHelper.ThrowIfEmpty(timeCollection);
35+
ThrowHelper.ThrowIfOutOfOrder(timeCollection);
3536
ThrowHelper.ThrowIfOutOfMilitaryTimeRange(timeCollection);
3637

3738
foreach (var time in timeCollection)

0 commit comments

Comments
 (0)