-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathIOUtilityTests.cs
More file actions
253 lines (228 loc) · 13.6 KB
/
IOUtilityTests.cs
File metadata and controls
253 lines (228 loc) · 13.6 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using BExIS.IO.Transform.Validation.Exceptions;
using BExIS.IO.Transform.Validation.ValueCheck;
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace BExIS.IO.Tests
{
[TestFixture()]
public class IOUtilityTests
{
private List<DateTimeHelperUTObject> DateTimeCases = new List<DateTimeHelperUTObject>();
[OneTimeSetUp]
public void OneTimeSetUp()
{
DateTimeCases = generateDateTimeCases();
}
[SetUp]
protected void SetUp()
{
}
[TearDown]
public void TearDown()
{
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
}
[TestCase("2024-05-17 16:00:54", "yyyy-MM-dd HH:mm:ss", "5/17/2024 4:00:54 PM", true, "en-US")]
[TestCase("2024-05-17 04:00:54", "yyyy-MM-dd hh:mm:ss", "5/17/2024 4:00:54 AM", true, "en-US")]
[TestCase("12:00 pm", "hh:mm tt", "1/1/0001 12:00:00 PM", true, "en-US")]
[TestCase("12:00:00 pm", "hh:mm:ss tt", "1/1/0001 12:00:00 PM", true, "en-US")]
[TestCase("2023-29-12", "yyyy-d-M", "12/29/2023 12:00:00 AM", true)]
[TestCase("02/29/24", "MM/dd/yy", "2/29/2024 12:00:00 AM", true, "en-US")]
[TestCase("02.12.24", "dd.MM.yy", "12/2/2024 12:00:00 AM", true, "en-US")]
[TestCase("85-11-07", "yy-MM-dd", "11/7/1985 12:00:00 AM", true, "en-US")]
[TestCase("14", "MM", "10/1/0001 12:00:00 AM", false)]
[TestCase("25", "hh", "1/1/0001 10:00:00 AM", false)]
[TestCase("2024", "yyyy", "1/1/2024 12:00:00 AM", true)]
[TestCase("2010", "yyyy", "1/1/2010 12:00:00 AM", true)]
[TestCase("10", "MM", "10/1/0001 12:00:00 AM", true)]
[TestCase("10", "hh", "1/1/0001 10:00:00 AM", true)]
[TestCase("10", "mm", "1/1/0001 12:10:00 AM", true)]
[TestCase("10", "ss", "1/1/0001 12:00:10 AM", true)]
[TestCase("2017-10-24 11:00:00", "yyyy-MM-dd hh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("24.10.2017 11:00:00", "dd.MM.yyyy hh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("5/10/2014 12:00:00 AM", "d/M/yyyy hh:mm:ss tt", "10/5/2014 12:00:00 AM", true)]
[TestCase("7/1/2023 2:00:00 AM", "d/M/yyyy h:mm:ss tt", "1/7/2023 2:00:00 AM", true)]
[TestCase("3/2/2019 7:31", "M/d/yyyy h:m", "3/2/2019 7:31:00 AM", true)]
[TestCase("03/02/2019 7:31", "MM/dd/yyyy h:m", "3/2/2019 7:31:00 AM", true)]
[TestCase("2017-10-24T11:00:00", "yyyy-MM-ddThh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("2017-10-24T13:00:00", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", true)]
[TestCase("2017-10-24T1:00:00", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("5/10/2014", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("2014/12/20", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("2017-10-24", "yyyy-MM-dd", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("24/24/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("10/24/17", "MM/dd/yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("24/24/17", "MM/dd/yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24/10/2017", "dd/MM/yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/2017", "dd/MM/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24/10/17", "dd/MM/yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/17", "dd/MM/yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24.10.2017", "dd.MM.yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10.24.2017", "dd.MM.yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24.10.17", "dd.MM.yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10.24.17", "dd.MM.yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("23:00:00", "HH:mm:ss", "1/1/0001 11:00:00 PM", true)]
[TestCase("11:00:00", "HH:mm:ss", "1/1/0001 11:00:00 PM", false)]
[TestCase("23:00", "HH:mm", "1/1/0001 11:00:00 PM", true)]
[TestCase("11:00", "HH:mm", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00:11", "HH:mm", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00:00 PM", "hh:mm:ss tt", "1/1/0001 11:00:00 PM", true)]
[TestCase("13:00:00 AM", "hh:mm:ss tt", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00 PM", "hh:mm tt", "1/1/0001 11:00:00 PM", true)]
[TestCase("13:00 AM", "hh:mm tt", "1/1/0001 11:00:00 PM", false)]
[TestCase("2017", "yyyy", "1/1/2017 12:00:00 AM", true)]
[TestCase("1", "MM", "1/1/0001 12:00:00 AM", true)]
[TestCase("jan", "MMM", "1/1/2026 12:00:00 AM", true)]
[TestCase("01", "MM", "1/1/0001 12:00:00 AM", true)]
[TestCase("january", "MMMM", "1/1/2026 12:00:00 AM", true)]
[TestCase("Januar", "MMMM", "1/1/2026 12:00:00 AM", true, "de-de")]
[TestCase("24/10/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("2006-2-2", "yyyy-M-d", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-02-02", "yyyy-MM-dd", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-2-2", "yyyy-d-M", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-02-02", "yyyy-dd-MM", "2/2/2006 12:00:00 AM", true)]
[TestCase("5/10/2014 12:00:00 AM", "M/d/yyyy hh:mm:ss tt", "5/10/2014 12:00:00 AM", true)]
public void ConvertStringToDateTimeWithpatternTest(string input, string pattern, string output, bool itMatch, string culture = "")
{
IOUtility iOUtility = new IOUtility();
CultureInfo cultureInfo = null;
if (!string.IsNullOrEmpty(culture))
{
cultureInfo = new CultureInfo(culture, false);
}
DateTime result;
iOUtility.ConvertToDate(input, pattern, out result, cultureInfo);
if (itMatch)
{
result.ToString( new CultureInfo("en-US", false)).Should().NotBeNull("can´t convert : " + input + " with pattern:" + pattern);
result.ToString( new CultureInfo("en-US", false)).Should().Match(output, "not match :" + result + " - " + output);
}
else
{
if (result != null) result.ToString( new CultureInfo("en-US", false)).Should().NotMatch(output, "should not match :" + result + " - " + output);
else result.ToString( new CultureInfo("en-US", false)).Should().BeNullOrEmpty();
}
}
[TestCase("2026-12-24 05:05:50", "yyyy-MM-dd hh:mm:ss", "12/24/2026 5:05:50 AM", true, "en-US")]
[TestCase("12:00 pm", "hh:mm tt", "1/1/0001 12:00:00 PM", true, "en-US")]
[TestCase("12:00:00 pm", "hh:mm:ss tt", "1/1/0001 12:00:00 PM", true, "en-US")]
[TestCase("2023-29-12", "yyyy-d-M", "12/29/2023 12:00:00 AM", true)]
[TestCase("02/29/24", "MM/dd/yy", "2/29/2024 12:00:00 AM", true, "en-US")]
[TestCase("02.12.24", "dd.MM.yy", "12/2/2024 12:00:00 AM", true, "en-US")]
[TestCase("85-11-07", "yy-MM-dd", "11/7/1985 12:00:00 AM", true, "en-US")]
[TestCase("14", "MM", "10/1/0001 12:00:00 AM", false)]
[TestCase("25", "hh", "1/1/0001 10:00:00 AM", false)]
[TestCase("2024", "yyyy", "1/1/2024 12:00:00 AM", true)]
[TestCase("2010", "yyyy", "1/1/2010 12:00:00 AM", true)]
[TestCase("10", "MM", "10/1/0001 12:00:00 AM", true)]
[TestCase("10", "hh", "1/1/0001 10:00:00 AM", true)]
[TestCase("10", "mm", "1/1/0001 12:10:00 AM", true)]
[TestCase("10", "ss", "1/1/0001 12:00:10 AM", true)]
[TestCase("2017-10-24 11:00:00", "yyyy-MM-dd hh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("24.10.2017 11:00:00", "dd.MM.yyyy hh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("5/10/2014 12:00:00 AM", "d/M/yyyy hh:mm:ss tt", "10/5/2014 12:00:00 AM", true)]
[TestCase("7/1/2023 2:00:00 AM", "d/M/yyyy h:mm:ss tt", "1/7/2023 2:00:00 AM", true)]
[TestCase("3/2/2019 7:31", "M/d/yyyy h:m", "3/2/2019 7:31:00 AM", true)]
[TestCase("03/02/2019 7:31", "MM/dd/yyyy h:m", "3/2/2019 7:31:00 AM", true)]
[TestCase("2017-10-24T11:00:00", "yyyy-MM-ddThh:mm:ss", "10/24/2017 11:00:00 AM", true)]
[TestCase("2017-10-24T13:00:00", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", true)]
[TestCase("2017-10-24T1:00:00", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("5/10/2014", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("2014/12/20", "yyyy-MM-ddTHH:mm:ss", "10/24/2017 1:00:00 PM", false)]
[TestCase("2017-10-24", "yyyy-MM-dd", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("24/24/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("10/24/17", "MM/dd/yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("24/24/17", "MM/dd/yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24/10/2017", "dd/MM/yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/2017", "dd/MM/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24/10/17", "dd/MM/yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10/24/17", "dd/MM/yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24.10.2017", "dd.MM.yyyy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10.24.2017", "dd.MM.yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("24.10.17", "dd.MM.yy", "10/24/2017 12:00:00 AM", true)]
[TestCase("10.24.17", "dd.MM.yy", "10/24/2017 12:00:00 AM", false)]
[TestCase("23:00:00", "HH:mm:ss", "1/1/0001 11:00:00 PM", true)]
[TestCase("11:00:00", "HH:mm:ss", "1/1/0001 11:00:00 PM", false)]
[TestCase("23:00", "HH:mm", "1/1/0001 11:00:00 PM", true)]
[TestCase("11:00", "HH:mm", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00:11", "HH:mm", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00:00 PM", "hh:mm:ss tt", "1/1/0001 11:00:00 PM", true)]
[TestCase("13:00:00 AM", "hh:mm:ss tt", "1/1/0001 11:00:00 PM", false)]
[TestCase("11:00 PM", "hh:mm tt", "1/1/0001 11:00:00 PM", true)]
[TestCase("13:00 AM", "hh:mm tt", "1/1/0001 11:00:00 PM", false)]
[TestCase("2017", "yyyy", "1/1/2017 12:00:00 AM", true)]
[TestCase("1", "MM", "1/1/0001 12:00:00 AM", true)]
[TestCase("jan", "MMM", "1/1/2026 12:00:00 AM", true)]
[TestCase("01", "MM", "1/1/0001 12:00:00 AM", true)]
[TestCase("january", "MMMM", "1/1/2026 12:00:00 AM", true)]
[TestCase("Januar", "MMMM", "1/1/2026 12:00:00 AM", true, "de-de")]
[TestCase("24/10/2017", "MM/dd/yyyy", "10/24/2017 12:00:00 AM", false)]
[TestCase("2006-2-2", "yyyy-M-d", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-02-02", "yyyy-MM-dd", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-2-2", "yyyy-d-M", "2/2/2006 12:00:00 AM", true)]
[TestCase("2006-02-02", "yyyy-dd-MM", "2/2/2006 12:00:00 AM", true)]
[TestCase("5/10/2014 12:00:00 AM", "M/d/yyyy hh:mm:ss tt", "5/10/2014 12:00:00 AM", true)]
public void CompareDateTimeValidationAndConvertion(string input, string pattern, string output, bool itMatch, string culture = "")
{
IOUtility iOUtility = new IOUtility();
CultureInfo cultureInfo = null;
if (!string.IsNullOrEmpty(culture))
{
cultureInfo = new CultureInfo(culture, false);
}
DateTime result;
iOUtility.ConvertToDate(input, pattern, out result, cultureInfo);
DataTypeCheck check = new DataTypeCheck("dtCheck", "DateTime", DecimalCharacter.point, pattern, cultureInfo);
var checkresult = check.Execute(input, 1);
if (itMatch)
{
result.ToString(new CultureInfo("en-US", false)).Should().NotBeNull("can´t convert : " + input + " with pattern:" + pattern);
result.ToString(new CultureInfo("en-US", false)).Should().Match(output, "not match :" + result.ToString(new CultureInfo("en-US", false)) + " - " + output);
//checkresult.Should(typeof(DateTime))
//Assert.IsInstanceOf<DateTime>(checkresult, "xyz");
checkresult.Should().BeOfType<DateTime>();
}
else
{
if (result != null) result.ToString(new CultureInfo("en-US", false)).Should().NotMatch(output, "should not match :" + result + " - " + output);
else
{
result.ToString(new CultureInfo("en-US", false)).Should().BeNullOrEmpty();
checkresult.Should().BeOfType<Error>();
}
}
}
#region Helper
private List<DateTimeHelperUTObject> generateDateTimeCases()
{
List<DateTimeHelperUTObject> cases = new List<DateTimeHelperUTObject>();
return cases;
}
#endregion Helper
}
public class DateTimeHelperUTObject
{
public string pattern { get; set; }
public string input { get; set; }
public string output { get; set; }
public bool ItMatch { get; set; }
public CultureInfo CultureInfo { get; set; }
public DateTimeHelperUTObject(string input, string pattern, string output, bool itMatch, CultureInfo cultureInfo = null)
{
pattern = pattern;
input = input;
output = output;
ItMatch = itMatch;
if (cultureInfo == null) CultureInfo = CultureInfo.InvariantCulture;
else CultureInfo = cultureInfo;
}
}
}