Exemple #1
0
        public void GetParsers_Returns_Collection_Of_All_Registered_Parsers()
        {
            var parser1  = new DateTime_Invariant_Parser();
            var parser2  = new DateTimeOffset_Local_Parser();
            var resolver = new TypeParserResolver(parser1, parser2);

            var parsers = resolver.GetParsers();

            Assert.AreEqual(2, parsers.Length);
            Assert.IsTrue(parsers.Contains(parser1));
            Assert.IsTrue(parsers.Contains(parser2));
        }
        [DataRow("en-GB", "2019-07-01T17:42:32.123+0800", true, "2019-07-01 09:42:32.123 Utc")]             // Local timezone specified, output is UTC
        public void TryParse_Behaves_Correctly(string culture, string text, bool expectedResult, string expectedValueText)
        {
            using (new CultureSwap(culture)) {
                var parser = new DateTime_Invariant_Parser();

                var actualResult = parser.TryParse(text, out var actualValue);

                var expectedValue = DataRowParser.DateTime(expectedValueText);
                Assert.AreEqual(expectedResult, actualResult);
                Assert.AreEqual(expectedValue, actualValue);
                Assert.AreEqual(expectedValue?.Kind, actualValue.Kind);
            }
        }