44namespace RelogicLabs . JsonSchema . Tests . Negative ;
55
66[ TestClass ]
7- public class DateTests
7+ public class DateTimeTests
88{
99 [ TestMethod ]
1010 public void When_JsonNotDate_ExceptionThrown ( )
1111 {
1212 var schema = "#date" ;
13- var json = "\" This is a string \" " ;
13+ var json = "\" This is not a valid date \" " ;
1414
1515 JsonSchema . IsValid ( schema , json ) ;
1616 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -20,7 +20,20 @@ public void When_JsonNotDate_ExceptionThrown()
2020 }
2121
2222 [ TestMethod ]
23- public void When_DateFormatIncorrect_ExceptionThrown ( )
23+ public void When_JsonNotTime_ExceptionThrown ( )
24+ {
25+ var schema = "#time" ;
26+ var json = "\" This is not a valid time\" " ;
27+
28+ JsonSchema . IsValid ( schema , json ) ;
29+ var exception = Assert . ThrowsException < JsonSchemaException > (
30+ ( ) => JsonAssert . IsValid ( schema , json ) ) ;
31+ Assert . AreEqual ( DTYP02 , exception . ErrorCode ) ;
32+ Console . WriteLine ( exception ) ;
33+ }
34+
35+ [ TestMethod ]
36+ public void When_DateInputWrong_ExceptionThrown ( )
2437 {
2538 var schema = """ @date("DD-MM-YY") """ ;
2639 var json = """ "99-09-01" """ ;
@@ -32,7 +45,19 @@ public void When_DateFormatIncorrect_ExceptionThrown()
3245 }
3346
3447 [ TestMethod ]
35- public void When_DayOutOfRange_ExceptionThrown ( )
48+ public void When_TimeInputWrong_ExceptionThrown ( )
49+ {
50+ var schema = """ @time("hh:mm:ss t") """ ;
51+ var json = """ "13:10:10 PM" """ ;
52+ JsonSchema . IsValid ( schema , json ) ;
53+ var exception = Assert . ThrowsException < JsonSchemaException > (
54+ ( ) => JsonAssert . IsValid ( schema , json ) ) ;
55+ Assert . AreEqual ( DHUR03 , exception . ErrorCode ) ;
56+ Console . WriteLine ( exception ) ;
57+ }
58+
59+ [ TestMethod ]
60+ public void When_DateDayOutOfRange_ExceptionThrown ( )
3661 {
3762 var schema = """ @date("DD-MM-YYYY") """ ;
3863 var json = """ "29-02-1939" """ ;
@@ -44,7 +69,7 @@ public void When_DayOutOfRange_ExceptionThrown()
4469 }
4570
4671 [ TestMethod ]
47- public void When_DayOutOfRange2_ExceptionThrown ( )
72+ public void When_DateDayOutOfRange2_ExceptionThrown ( )
4873 {
4974 var schema = """ @date("DD-MM-YYYY") """ ;
5075 var json = """ "32-12-1939" """ ;
@@ -56,7 +81,7 @@ public void When_DayOutOfRange2_ExceptionThrown()
5681 }
5782
5883 [ TestMethod ]
59- public void When_InvalidMonthFullNameFormat_ExceptionThrown ( )
84+ public void When_InvalidDateMonthFullName_ExceptionThrown ( )
6085 {
6186 var schema = """ @date("MMMM DD, YYYY G") """ ;
6287 var json = """ "Septembar 01, 1939 AD" """ ;
@@ -68,7 +93,7 @@ public void When_InvalidMonthFullNameFormat_ExceptionThrown()
6893 }
6994
7095 [ TestMethod ]
71- public void When_InvalidMonthShortNameFormat_ExceptionThrown ( )
96+ public void When_InvalidDateMonthShortName_ExceptionThrown ( )
7297 {
7398 var schema = """ @date("MMM DD, YYYY G") """ ;
7499 var json = """ "Sap 01, 1939 AD" """ ;
@@ -80,7 +105,7 @@ public void When_InvalidMonthShortNameFormat_ExceptionThrown()
80105 }
81106
82107 [ TestMethod ]
83- public void When_InvalidMonthNumberFormat_ExceptionThrown ( )
108+ public void When_InvalidDateMonthNumber_ExceptionThrown ( )
84109 {
85110 var schema = """ @date("MM-DD, YYYY G") """ ;
86111 var json = """ "Sep-01, 1939 AD" """ ;
@@ -92,7 +117,7 @@ public void When_InvalidMonthNumberFormat_ExceptionThrown()
92117 }
93118
94119 [ TestMethod ]
95- public void When_InvalidMonthNumberRange_ExceptionThrown ( )
120+ public void When_InvalidDateMonthNumberRange_ExceptionThrown ( )
96121 {
97122 var schema = """ @date("MM-DD, YYYY G") """ ;
98123 var json = """ "13-01, 1939 AD" """ ;
@@ -104,7 +129,7 @@ public void When_InvalidMonthNumberRange_ExceptionThrown()
104129 }
105130
106131 [ TestMethod ]
107- public void When_InvalidWeekdayFormat_ExceptionThrown ( )
132+ public void When_InvalidDateWeekdayInput_ExceptionThrown ( )
108133 {
109134 var schema = """ @date("DDD, MMM DD, YYYY G") """ ;
110135 var json = """ "Fry, Sep 01, 1939 AD" """ ;
@@ -116,7 +141,7 @@ public void When_InvalidWeekdayFormat_ExceptionThrown()
116141 }
117142
118143 [ TestMethod ]
119- public void When_ConflictingInfoInInput_ExceptionThrown ( )
144+ public void When_ConflictingDateInfoInInput_ExceptionThrown ( )
120145 {
121146 var schema = """ @date("MMMM, DD-MM-YYYY") """ ;
122147 var json = """ "January, 01-12-1939" """ ;
@@ -128,7 +153,19 @@ public void When_ConflictingInfoInInput_ExceptionThrown()
128153 }
129154
130155 [ TestMethod ]
131- public void When_InvalidWeekday_ExceptionThrown ( )
156+ public void When_ConflictingTimeInfoInInput_ExceptionThrown ( )
157+ {
158+ var schema = """ @time("hh, hh:mm:ss") """ ;
159+ var json = """ "12, 11:10:12" """ ;
160+ JsonSchema . IsValid ( schema , json ) ;
161+ var exception = Assert . ThrowsException < JsonSchemaException > (
162+ ( ) => JsonAssert . IsValid ( schema , json ) ) ;
163+ Assert . AreEqual ( DCNF01 , exception . ErrorCode ) ;
164+ Console . WriteLine ( exception ) ;
165+ }
166+
167+ [ TestMethod ]
168+ public void When_InvalidDateWeekday_ExceptionThrown ( )
132169 {
133170 var schema = """ @date("DDD, MMM DD, YYYY G") """ ;
134171 var json = """ "Sat, Sep 01, 1939 AD" """ ;
@@ -140,7 +177,7 @@ public void When_InvalidWeekday_ExceptionThrown()
140177 }
141178
142179 [ TestMethod ]
143- public void When_InvalidYearFormat_ExceptionThrown ( )
180+ public void When_InvalidDateYearInput_ExceptionThrown ( )
144181 {
145182 var schema = """ @date("DD-MM-YY") """ ;
146183 var json = """ "01-09-Twenty" """ ;
@@ -152,7 +189,7 @@ public void When_InvalidYearFormat_ExceptionThrown()
152189 }
153190
154191 [ TestMethod ]
155- public void When_InvalidYearFormat2_ExceptionThrown ( )
192+ public void When_InvalidDateYearInput2_ExceptionThrown ( )
156193 {
157194 var schema = """ @date("DD-MM-YYYY") """ ;
158195 var json = """ "01-09-0000" """ ;
@@ -164,7 +201,7 @@ public void When_InvalidYearFormat2_ExceptionThrown()
164201 }
165202
166203 [ TestMethod ]
167- public void When_InvalidYearFormat3_ExceptionThrown ( )
204+ public void When_InvalidDateYearInput3_ExceptionThrown ( )
168205 {
169206 var schema = """ @date("DD-MM-YY") """ ;
170207 var json = """ "01-09-1939" """ ;
@@ -176,7 +213,7 @@ public void When_InvalidYearFormat3_ExceptionThrown()
176213 }
177214
178215 [ TestMethod ]
179- public void When_InvalidEraFormat_ExceptionThrown ( )
216+ public void When_InvalidDateEraInput_ExceptionThrown ( )
180217 {
181218 var schema = """ @date("DD-MM-YYYY G") """ ;
182219 var json = """ "02-12-1939 AA" """ ;
@@ -188,9 +225,9 @@ public void When_InvalidEraFormat_ExceptionThrown()
188225 }
189226
190227 [ TestMethod ]
191- public void When_InvalidDateTextMissing_ExceptionThrown ( )
228+ public void When_InvalidTimeTextMissing_ExceptionThrown ( )
192229 {
193- var schema = """ @date ("DD-MM-YYYY 'Time' hh:mm:ss") """ ;
230+ var schema = """ @time ("DD-MM-YYYY 'Time' hh:mm:ss") """ ;
194231 var json = """ "01-11-1939 10:00:00" """ ;
195232 JsonSchema . IsValid ( schema , json ) ;
196233 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -200,9 +237,9 @@ public void When_InvalidDateTextMissing_ExceptionThrown()
200237 }
201238
202239 [ TestMethod ]
203- public void When_InvalidHourFormat_ExceptionThrown ( )
240+ public void When_InvalidTimeHourInput_ExceptionThrown ( )
204241 {
205- var schema = """ @date ("hh:mm:ss") """ ;
242+ var schema = """ @time ("hh:mm:ss") """ ;
206243 var json = """ "Twelve:00:00" """ ;
207244 JsonSchema . IsValid ( schema , json ) ;
208245 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -212,9 +249,9 @@ public void When_InvalidHourFormat_ExceptionThrown()
212249 }
213250
214251 [ TestMethod ]
215- public void When_InvalidHourRange_ExceptionThrown ( )
252+ public void When_InvalidTimeHourRange_ExceptionThrown ( )
216253 {
217- var schema = """ @date ("hh:mm:ss") """ ;
254+ var schema = """ @time ("hh:mm:ss") """ ;
218255 var json = """ "24:00:00" """ ;
219256 JsonSchema . IsValid ( schema , json ) ;
220257 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -224,9 +261,9 @@ public void When_InvalidHourRange_ExceptionThrown()
224261 }
225262
226263 [ TestMethod ]
227- public void When_InvalidMinuteFormat_ExceptionThrown ( )
264+ public void When_InvalidTimeMinuteInput_ExceptionThrown ( )
228265 {
229- var schema = """ @date ("hh:mm:ss") """ ;
266+ var schema = """ @time ("hh:mm:ss") """ ;
230267 var json = """ "23:one:00" """ ;
231268 JsonSchema . IsValid ( schema , json ) ;
232269 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -236,9 +273,9 @@ public void When_InvalidMinuteFormat_ExceptionThrown()
236273 }
237274
238275 [ TestMethod ]
239- public void When_InvalidMinuteRange_ExceptionThrown ( )
276+ public void When_InvalidTimeMinuteRange_ExceptionThrown ( )
240277 {
241- var schema = """ @date ("hh:mm:ss") """ ;
278+ var schema = """ @time ("hh:mm:ss") """ ;
242279 var json = """ "23:60:00" """ ;
243280 JsonSchema . IsValid ( schema , json ) ;
244281 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -248,9 +285,9 @@ public void When_InvalidMinuteRange_ExceptionThrown()
248285 }
249286
250287 [ TestMethod ]
251- public void When_InvalidSecondFormat_ExceptionThrown ( )
288+ public void When_InvalidTimeSecondInput_ExceptionThrown ( )
252289 {
253- var schema = """ @date ("hh:mm:ss") """ ;
290+ var schema = """ @time ("hh:mm:ss") """ ;
254291 var json = """ "23:59:Three" """ ;
255292 JsonSchema . IsValid ( schema , json ) ;
256293 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -260,9 +297,9 @@ public void When_InvalidSecondFormat_ExceptionThrown()
260297 }
261298
262299 [ TestMethod ]
263- public void When_InvalidSecondRange_ExceptionThrown ( )
300+ public void When_InvalidTimeSecondRange_ExceptionThrown ( )
264301 {
265- var schema = """ @date ("hh:mm:ss") """ ;
302+ var schema = """ @time ("hh:mm:ss") """ ;
266303 var json = """ "23:59:60" """ ;
267304 JsonSchema . IsValid ( schema , json ) ;
268305 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -272,9 +309,9 @@ public void When_InvalidSecondRange_ExceptionThrown()
272309 }
273310
274311 [ TestMethod ]
275- public void When_InvalidSecondFractionFormat_ExceptionThrown ( )
312+ public void When_InvalidTimeSecondFraction_ExceptionThrown ( )
276313 {
277- var schema = """ @date ("hh:mm:ss.fff") """ ;
314+ var schema = """ @time ("hh:mm:ss.fff") """ ;
278315 var json = """ "23:59:00.11" """ ;
279316 JsonSchema . IsValid ( schema , json ) ;
280317 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -284,19 +321,19 @@ public void When_InvalidSecondFractionFormat_ExceptionThrown()
284321 }
285322
286323 [ TestMethod ]
287- public void When_InvalidHourFormatWithExtra0_ExceptionThrown ( )
324+ public void When_InvalidTimeNoHourInput_ExceptionThrown ( )
288325 {
289- var schema = """ @date ("h:m:s") """ ;
290- var json = """ "01 :3:8" """ ;
326+ var schema = """ @time ("h:m:s") """ ;
327+ var json = """ ":3:8" """ ;
291328 JsonSchema . IsValid ( schema , json ) ;
292329 var exception = Assert . ThrowsException < JsonSchemaException > (
293330 ( ) => JsonAssert . IsValid ( schema , json ) ) ;
294- Assert . AreEqual ( DSYM01 , exception . ErrorCode ) ;
331+ Assert . AreEqual ( DHUR02 , exception . ErrorCode ) ;
295332 Console . WriteLine ( exception ) ;
296333 }
297334
298335 [ TestMethod ]
299- public void When_InvalidTimeFormat_ExceptionThrown ( )
336+ public void When_InvalidTimeInput_ExceptionThrown ( )
300337 {
301338 var schema = """ @date("hh mm ss") """ ;
302339 var json = """ "01:10:08" """ ;
@@ -308,9 +345,9 @@ public void When_InvalidTimeFormat_ExceptionThrown()
308345 }
309346
310347 [ TestMethod ]
311- public void When_InvalidAmPmFormat_ExceptionThrown ( )
348+ public void When_InvalidTimeAmPmInput_ExceptionThrown ( )
312349 {
313- var schema = """ @date ("hh:mm:ss t") """ ;
350+ var schema = """ @time ("hh:mm:ss t") """ ;
314351 var json = """ "12:00:00 AD" """ ;
315352 JsonSchema . IsValid ( schema , json ) ;
316353 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -320,9 +357,9 @@ public void When_InvalidAmPmFormat_ExceptionThrown()
320357 }
321358
322359 [ TestMethod ]
323- public void When_Invalid12HourFormat_ExceptionThrown ( )
360+ public void When_InvalidTime12HourInput_ExceptionThrown ( )
324361 {
325- var schema = """ @date ("hh:mm:ss t") """ ;
362+ var schema = """ @time ("hh:mm:ss t") """ ;
326363 var json = """ "13:00:00 AM" """ ;
327364 JsonSchema . IsValid ( schema , json ) ;
328365 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -332,9 +369,21 @@ public void When_Invalid12HourFormat_ExceptionThrown()
332369 }
333370
334371 [ TestMethod ]
335- public void When_InvalidUTCOffsetFormat_ExceptionThrown ( )
372+ public void When_InvalidTimeAmPmMissing_ExceptionThrown ( )
373+ {
374+ var schema = """ @time("hh:mm:sst") """ ;
375+ var json = """ "11:11:11" """ ;
376+ JsonSchema . IsValid ( schema , json ) ;
377+ var exception = Assert . ThrowsException < JsonSchemaException > (
378+ ( ) => JsonAssert . IsValid ( schema , json ) ) ;
379+ Assert . AreEqual ( DTAP01 , exception . ErrorCode ) ;
380+ Console . WriteLine ( exception ) ;
381+ }
382+
383+ [ TestMethod ]
384+ public void When_InvalidTimeUTCOffsetInput_ExceptionThrown ( )
336385 {
337- var schema = """ @date ("hh:mm:ss Z") """ ;
386+ var schema = """ @time ("hh:mm:ss Z") """ ;
338387 var json = """ "11:00:00 Six" """ ;
339388 JsonSchema . IsValid ( schema , json ) ;
340389 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -344,9 +393,9 @@ public void When_InvalidUTCOffsetFormat_ExceptionThrown()
344393 }
345394
346395 [ TestMethod ]
347- public void When_InvalidUTCOffsetHourRange_ExceptionThrown ( )
396+ public void When_InvalidTimeUTCOffsetHourRange_ExceptionThrown ( )
348397 {
349- var schema = """ @date ("hh:mm:ss Z") """ ;
398+ var schema = """ @time ("hh:mm:ss Z") """ ;
350399 var json = """ "11:00:00 +14" """ ;
351400 JsonSchema . IsValid ( schema , json ) ;
352401 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -356,9 +405,9 @@ public void When_InvalidUTCOffsetHourRange_ExceptionThrown()
356405 }
357406
358407 [ TestMethod ]
359- public void When_InvalidUTCOffsetMinuteRange_ExceptionThrown ( )
408+ public void When_InvalidTimeUTCOffsetMinuteRange_ExceptionThrown ( )
360409 {
361- var schema = """ @date ("hh:mm:ss ZZ") """ ;
410+ var schema = """ @time ("hh:mm:ss ZZ") """ ;
362411 var json = """ "11:00:00 +10:60" """ ;
363412 JsonSchema . IsValid ( schema , json ) ;
364413 var exception = Assert . ThrowsException < JsonSchemaException > (
@@ -368,7 +417,7 @@ public void When_InvalidUTCOffsetMinuteRange_ExceptionThrown()
368417 }
369418
370419 [ TestMethod ]
371- public void When_InvalidPatternCauseLexerError_ExceptionThrown ( )
420+ public void When_InvalidDatePatternCauseLexerError_ExceptionThrown ( )
372421 {
373422 var schema = """ @date("ABCD") """ ;
374423 var json = "\" 23-09-01T14:35:10.555\" " ;
@@ -379,4 +428,17 @@ public void When_InvalidPatternCauseLexerError_ExceptionThrown()
379428 Assert . AreEqual ( DLEX01 , exception . ErrorCode ) ;
380429 Console . WriteLine ( exception ) ;
381430 }
431+
432+ [ TestMethod ]
433+ public void When_InvalidTimePatternCauseLexerError_ExceptionThrown ( )
434+ {
435+ var schema = """ @time("ABCD") """ ;
436+ var json = "\" 23-09-01T14:35:10.555\" " ;
437+
438+ JsonSchema . IsValid ( schema , json ) ;
439+ var exception = Assert . ThrowsException < JsonSchemaException > (
440+ ( ) => JsonAssert . IsValid ( schema , json ) ) ;
441+ Assert . AreEqual ( DLEX01 , exception . ErrorCode ) ;
442+ Console . WriteLine ( exception ) ;
443+ }
382444}
0 commit comments