| | | 1 | | using ValidateLib.ErrorsAndWarnings.Errors.Specific; |
| | | 2 | | using ValidateLib.Metadata.Descriptors; |
| | | 3 | | using ValidateLib.TabularData.Datatypes; |
| | | 4 | | using ValidateLib.TabularData.Datatypes.DurationDatatypes; |
| | | 5 | | |
| | | 6 | | namespace DatatypeTests |
| | | 7 | | { |
| | | 8 | | public class DurationTests |
| | | 9 | | { |
| | | 10 | | |
| | | 11 | | [Theory] |
| | | 12 | | [InlineData("P1Y", @"^P\d+Y$")] |
| | | 13 | | [InlineData("P1M", @"^P\d+M$")] |
| | | 14 | | [InlineData("P1D", @"^P\d+D$")] |
| | | 15 | | |
| | | 16 | | public void DurationSupportedPatternsTests(string stringValue, string formatPattern) |
| | 1 | 17 | | { |
| | 1 | 18 | | FormatDescriptor format = new FormatDescriptor { pattern = formatPattern }; |
| | 1 | 19 | | DurationDT duration = new DurationDT(stringValue, format); |
| | 1 | 20 | | DatatypeFactory.GetDatatype(stringValue, "duration", format); |
| | | 21 | | |
| | 1 | 22 | | } |
| | | 23 | | |
| | | 24 | | [Theory] |
| | | 25 | | [InlineData("P2Y6M5DT12H35M30S")] |
| | | 26 | | [InlineData("P1DT2H")] |
| | | 27 | | [InlineData("P20M ")] |
| | | 28 | | [InlineData("PT20M")] |
| | | 29 | | [InlineData("P0Y20M0D")] |
| | | 30 | | [InlineData("P0Y")] |
| | | 31 | | [InlineData("-P60D")] |
| | | 32 | | [InlineData("PT1M30.5S")] |
| | | 33 | | |
| | | 34 | | public void ValidDurationWithoutPatternTest(string stringValue) |
| | 1 | 35 | | { |
| | 1 | 36 | | DurationDT duration = new DurationDT(stringValue); |
| | 1 | 37 | | DatatypeFactory.GetDatatype(stringValue, "duration", null); |
| | 1 | 38 | | } |
| | | 39 | | |
| | | 40 | | [Theory] |
| | | 41 | | [InlineData("notaduration")] |
| | | 42 | | [InlineData("P1YKlm")] |
| | | 43 | | |
| | | 44 | | public void DurationWithoutPatternInvalidValues(string stringValue) |
| | 1 | 45 | | { |
| | 1 | 46 | | FormatDescriptor format = new FormatDescriptor { }; |
| | 1 | 47 | | Assert.Throws<DatatypeValidationError>(() => DatatypeFactory.GetDatatype(stringValue, "duration", null)); |
| | 1 | 48 | | } |
| | | 49 | | |
| | | 50 | | [Theory] |
| | | 51 | | [InlineData("P1Y2M3DT4H5M6S", @"^P\d+Y$")] |
| | | 52 | | [InlineData("PT12H", @"^P\d+M$")] |
| | | 53 | | [InlineData("PT45M", @"^P\d+D$")] |
| | | 54 | | public void DurationInvalidValuesWithPatternTest(string stringValue, string formatPattern) |
| | 1 | 55 | | { |
| | 1 | 56 | | FormatDescriptor format = new FormatDescriptor { pattern = formatPattern }; |
| | 1 | 57 | | Assert.Throws<DatatypeValidationError>(() => DatatypeFactory.GetDatatype(stringValue, "duration", format)); |
| | 1 | 58 | | } |
| | | 59 | | |
| | | 60 | | [Theory] |
| | | 61 | | [InlineData("PT130S", @"^-?P.*$")] |
| | | 62 | | [InlineData("-P60D", @"^-?P\d+D$")] |
| | | 63 | | public void DurationValuesWithPatternTest(string stringValue, string formatPattern) |
| | 1 | 64 | | { |
| | 1 | 65 | | FormatDescriptor format = new FormatDescriptor { pattern = formatPattern }; |
| | 1 | 66 | | DatatypeFactory.GetDatatype(stringValue, "duration", format); |
| | 1 | 67 | | } |
| | | 68 | | |
| | | 69 | | } |
| | | 70 | | } |