-
Notifications
You must be signed in to change notification settings - Fork 315
/
TimeSpanParserTests.cs
87 lines (79 loc) · 2.22 KB
/
TimeSpanParserTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestPlatform.CoreUtilities.UnitTests;
[TestClass]
public class TimeSpanParserTests
{
[TestMethod]
// core use cases
[DataRow("5400000")]
[DataRow("5400000ms")]
[DataRow("5400s")]
[DataRow("90m")]
[DataRow("1.5h")]
[DataRow("0.0625d")]
// with space for parsing from xml
[DataRow("5400000 ms")]
[DataRow("5400 s")]
[DataRow("90 m")]
[DataRow("1.5 h")]
[DataRow("0.0625 d")]
// nice to haves
[DataRow("5400000MS")]
[DataRow("5400000millisecond")]
[DataRow("5400000milliseconds")]
[DataRow("5400000mil")]
[DataRow("5400000milisecond")]
[DataRow("5400000miliseconds")]
[DataRow("5400000mils")]
[DataRow("5400000millis")]
[DataRow("5400000millisecs")]
[DataRow("5400000milisecs")]
[DataRow("5400S")]
[DataRow("5400second")]
[DataRow("5400seconds")]
[DataRow("5400sec")]
[DataRow("5400secs")]
[DataRow("90M")]
[DataRow("90minute")]
[DataRow("90minutes")]
[DataRow("90min")]
[DataRow("90mins")]
[DataRow("1.5H")]
[DataRow("1.5hour")]
[DataRow("1.5hours")]
[DataRow("1.5hrs")]
[DataRow("1.5hr")]
[DataRow("0.0625D")]
[DataRow("0.0625day")]
[DataRow("0.0625days")]
public void Parses90Minutes(string time)
{
Assert.IsTrue(TimeSpanParser.TryParse(time, out var t));
Assert.AreEqual(TimeSpan.FromMinutes(90), t);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
[DataRow("\n")]
[DataRow("\t")]
public void ReturnsEmptyTimeSpanOnNullOrWhiteSpace(string time)
{
Assert.IsTrue(TimeSpanParser.TryParse(time, out var t));
Assert.AreEqual(TimeSpan.Zero, t);
}
[TestMethod]
[DataRow("09808asf")]
[DataRow("asfsadf")]
[DataRow("min")]
[DataRow("ms")]
[DataRow("1.1.1")]
public void ReturnsFalseForInvalidInput(string time)
{
Assert.IsFalse(TimeSpanParser.TryParse(time, out var _));
}
}