Skip to content

Commit 570d4b1

Browse files
committed
test: modernize for mstest v4
1 parent 0856a0f commit 570d4b1

File tree

5 files changed

+66
-102
lines changed

5 files changed

+66
-102
lines changed
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
63
using Microsoft.VisualStudio.TestTools.UnitTesting;
7-
using NCrontab.Advanced.Enumerations;
84

95
namespace NCrontab.Advanced.Tests
106
{
@@ -16,17 +12,17 @@ public class ConstantTests
1612
[TestMethod]
1713
public void VerifyConstants()
1814
{
19-
ValidateExists<CronStringFormat>(Constants.ExpectedFieldCounts);
20-
ValidateExists<CrontabFieldKind>(Constants.MaximumDateTimeValues);
21-
ValidateExists<DayOfWeek>(Constants.CronDays);
15+
ValidateExists(Constants.ExpectedFieldCounts);
16+
ValidateExists(Constants.MaximumDateTimeValues);
17+
ValidateExists(Constants.CronDays);
2218
}
2319

24-
private static void ValidateExists<T>(IDictionary dictionary)
20+
private static void ValidateExists<T>(IDictionary<T, int> dictionary) where T : struct, Enum
2521
{
2622
Assert.IsNotNull(dictionary);
2723

28-
foreach (var value in Enum.GetValues(typeof (T)))
29-
Assert.IsTrue(dictionary.Contains(value), "Contains <{0}>", Enum.GetName(typeof(T), value));
24+
foreach (T value in Enum.GetValues(typeof(T)))
25+
Assert.IsTrue(dictionary.ContainsKey(value), $"Contains <{Enum.GetName(typeof(T), value)}>");
3026
}
3127
}
3228
}

NCrontab.Advanced.Tests/CronInstanceTests.cs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010
using NCrontab.Advanced.Enumerations;
1111
using NCrontab.Advanced.Exceptions;
12-
using NCrontab.Advanced.Tests.Extensions;
1312
using System;
1413
using System.Diagnostics;
1514
using System.Globalization;
@@ -26,13 +25,13 @@ public sealed class CronInstanceTests
2625
[TestMethod]
2726
public void CannotParseNullString()
2827
{
29-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse(null));
28+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse(null));
3029
}
3130

3231
[TestMethod]
3332
public void CannotParseEmptyString()
3433
{
35-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse(string.Empty));
34+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse(string.Empty));
3635
}
3736

3837
[TestMethod]
@@ -52,42 +51,42 @@ public void SixPartAllTimeString()
5251
[TestMethod]
5352
public void InvalidPatternCount()
5453
{
55-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * *", CronStringFormat.Default));
56-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * *", CronStringFormat.Default));
54+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * *", CronStringFormat.Default));
55+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * *", CronStringFormat.Default));
5756

58-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithSeconds));
59-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * *", CronStringFormat.WithSeconds));
57+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithSeconds));
58+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * *", CronStringFormat.WithSeconds));
6059

61-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithYears));
62-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * *", CronStringFormat.WithYears));
60+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithYears));
61+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * *", CronStringFormat.WithYears));
6362

64-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * *", CronStringFormat.WithSecondsAndYears));
65-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * * *", CronStringFormat.WithSecondsAndYears));
63+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * *", CronStringFormat.WithSecondsAndYears));
64+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * * * *", CronStringFormat.WithSecondsAndYears));
6665
}
6766

6867
[TestMethod]
6968
public void OutOfBoundsValues()
7069
{
71-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("-1 * * * * *", CronStringFormat.WithSeconds));
72-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("60 * * * * *", CronStringFormat.WithSeconds));
70+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("-1 * * * * *", CronStringFormat.WithSeconds));
71+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("60 * * * * *", CronStringFormat.WithSeconds));
7372

74-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * 0", CronStringFormat.WithYears));
75-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * 10000", CronStringFormat.WithYears));
73+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * 0", CronStringFormat.WithYears));
74+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * * 10000", CronStringFormat.WithYears));
7675

77-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("-1 * * * *", CronStringFormat.Default));
78-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("60 * * * *", CronStringFormat.Default));
76+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("-1 * * * *", CronStringFormat.Default));
77+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("60 * * * *", CronStringFormat.Default));
7978

80-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* -1 * * *", CronStringFormat.Default));
81-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* 24 * * *", CronStringFormat.Default));
79+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* -1 * * *", CronStringFormat.Default));
80+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* 24 * * *", CronStringFormat.Default));
8281

83-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * 0 * *", CronStringFormat.Default));
84-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * 32 * *", CronStringFormat.Default));
82+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * 0 * *", CronStringFormat.Default));
83+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * 32 * *", CronStringFormat.Default));
8584

86-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * 0 *", CronStringFormat.Default));
87-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * 13 *", CronStringFormat.Default));
85+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * 0 *", CronStringFormat.Default));
86+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * 13 *", CronStringFormat.Default));
8887

89-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * -1", CronStringFormat.Default));
90-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * 8", CronStringFormat.Default));
88+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * -1", CronStringFormat.Default));
89+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * 8", CronStringFormat.Default));
9190
}
9291

9392
[TestMethod]
@@ -123,7 +122,7 @@ public void ThirtyFirstWeekdayForMonthsWithLessThanThirtyDaysProcessesCorrectly(
123122
[TestMethod]
124123
public void CannotParseWhenSecondsRequired()
125124
{
126-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithSeconds));
125+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse("* * * * *", CronStringFormat.WithSeconds));
127126
}
128127

129128
[TestMethod]
@@ -505,7 +504,7 @@ public void IllegalDates()
505504

506505
static void BadField(string expression, CronStringFormat format)
507506
{
508-
Assert2.Throws<CrontabException>(() => CrontabSchedule.Parse(expression, format));
507+
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse(expression, format));
509508
}
510509

511510
[TestMethod]
@@ -615,7 +614,7 @@ public void MultipleInstancesTest()
615614

616615
var parser = CrontabSchedule.Parse(cronString, CronStringFormat.WithYears);
617616
var instances = parser.GetNextOccurrences(input, DateTime.MaxValue).ToList();
618-
Assert.AreEqual(10, instances.Count, "Make sure only 10 instances were generated");
617+
Assert.HasCount(10, instances, "Make sure only 10 instances were generated");
619618

620619
// Now we'll manually iterate through getting values, and check the 11th and 12th
621620
// instance to make sure nothing blows up.
@@ -624,23 +623,23 @@ public void MultipleInstancesTest()
624623
newInput = parser.GetNextOccurrence(newInput);
625624

626625
Assert.IsTrue((newInput = parser.GetNextOccurrence(newInput)) == DateTime.MaxValue, "Make sure 11th instance is the endDate");
627-
Assert.IsTrue((newInput = parser.GetNextOccurrence(newInput)) == DateTime.MaxValue, "Make sure 12th instance is the endDate");
626+
Assert.IsTrue(parser.GetNextOccurrence(newInput) == DateTime.MaxValue, "Make sure 12th instance is the endDate");
628627
}
629628

630629
[TestMethod]
631630
public void NoNextInstanceTest()
632631
{
633632
var stopWatch = new Stopwatch();
634633

635-
var cron = NCrontab.Advanced.CrontabSchedule.Parse("0 0 1 1 * 0001", NCrontab.Advanced.Enumerations.CronStringFormat.WithYears);
634+
var cron = CrontabSchedule.Parse("0 0 1 1 * 0001", CronStringFormat.WithYears);
636635
var date = DateTime.Parse("0001-01-01");
637636

638637
stopWatch.Start();
639638
var result = cron.GetNextOccurrence(date);
640639
stopWatch.Stop();
641640

642641
Assert.AreEqual(DateTime.MaxValue, result, "Next date returned is end date");
643-
Assert.IsFalse(stopWatch.ElapsedMilliseconds > 250, string.Format("Elapsed time should not exceed 250ms (was {0} ms)", stopWatch.ElapsedMilliseconds));
642+
Assert.IsLessThanOrEqualTo(250, stopWatch.ElapsedMilliseconds, $"Elapsed time should not exceed 250ms (was {stopWatch.ElapsedMilliseconds} ms)");
644643
}
645644

646645
[TestMethod]
@@ -765,8 +764,7 @@ static void CronCall(string startTimeString, string cronExpression, string nextT
765764
var schedule = CrontabSchedule.Parse(cronExpression, format);
766765
var next = schedule.GetNextOccurrence(Time(startTimeString));
767766

768-
var message = string.Format("Occurrence of <{0}> after <{1}>, format <{2}>.", cronExpression, startTimeString, Enum.GetName(typeof(CronStringFormat), format));
769-
Assert.AreEqual(nextTimeString, TimeString(next), message);
767+
Assert.AreEqual(nextTimeString, TimeString(next), $"Occurrence of <{cronExpression}> after <{startTimeString}>, format <{Enum.GetName(typeof(CronStringFormat), format)}>.");
770768
}
771769

772770
static void CronFinite(string cronExpression, string startTimeString, string endTimeString, CronStringFormat format)
@@ -775,8 +773,7 @@ static void CronFinite(string cronExpression, string startTimeString, string end
775773
var occurrence = schedule.GetNextOccurrence(Time(startTimeString), Time(endTimeString));
776774

777775
Assert.AreEqual(endTimeString, TimeString(occurrence),
778-
"Occurrence of <{0}> after <{1}> did not terminate with <{2}>.",
779-
cronExpression, startTimeString, endTimeString);
776+
$"Occurrence of <{cronExpression}> after <{startTimeString}> did not terminate with <{endTimeString}>.");
780777
}
781778

782779
static string TimeString(DateTime time) => time.ToString(TimeFormat, CultureInfo.InvariantCulture);

NCrontab.Advanced.Tests/Extensions/AssertExtensions.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)