Exemplo n.º 1
0
        public void Resolve_DefaultTicksConverterForNoFormat()
        {
            var resolver = new TimestampStringConverterResolver();

            var converter = resolver.Resolve(null);

            Assert.IsInstanceOfType(converter, typeof(TimestampFromTicksConverter));
            Assert.IsTrue(converter.IsUsingDefaultFormat);
        }
Exemplo n.º 2
0
        public void Resolve_TicksFormatAliases()
        {
            var resolver = new TimestampStringConverterResolver();

            foreach (var alias in TicksFormatAliases)
            {
                var converter = resolver.Resolve(alias);

                Assert.IsInstanceOfType(converter, typeof(TimestampFromTicksConverter), $"Incorrect type of the converter for the format: {alias}");
                Assert.IsTrue(converter.IsUsingDefaultFormat);
            }
        }
Exemplo n.º 3
0
        public void Resolve_OnlyFormatForDefaultTicksConverter()
        {
            var resolver = new TimestampStringConverterResolver();

            var converter = resolver.Resolve("ms");

            Assert.IsInstanceOfType(converter, typeof(TimestampFromTicksConverter));
            Assert.IsFalse(converter.IsUsingDefaultFormat);

            string stringValue = "345";
            var    testValue   = DateTimeOffset.MinValue.AddMilliseconds(345);

            Assert.AreEqual(testValue, converter.Convert(stringValue));
            Assert.AreEqual(stringValue, converter.ConvertBack(testValue));
        }
Exemplo n.º 4
0
        public void Resolve_TimeWithCustomFormat()
        {
            var resolver = new TimestampStringConverterResolver();

            string stringValue = "3.14:30:20.040555";
            var    testValue   = DateTimeOffset.MinValue.Add(new TimeSpan(3, 14, 30, 20, 040)).AddTicks(5550);

            foreach (var alias in TimeFormatAliases)
            {
                var converter = resolver.Resolve($"{alias}:d\\.hh\\:mm\\:ss\\.ffffff");

                Assert.IsFalse(converter.IsUsingDefaultFormat);

                Assert.AreEqual(testValue, converter.Convert(stringValue));
                Assert.AreEqual(stringValue, converter.ConvertBack(testValue));
            }
        }
Exemplo n.º 5
0
        public void Resolve_TicksWithCustomFormat()
        {
            var resolver = new TimestampStringConverterResolver();

            long   microsecondTicksValue = 311420040555L;
            var    testValue             = DateTimeOffset.MinValue.AddTicks(microsecondTicksValue * 10);
            string stringValue           = microsecondTicksValue.ToString();

            foreach (var alias in TicksFormatAliases)
            {
                var converter = resolver.Resolve($"{alias}:us");

                Assert.IsFalse(converter.IsUsingDefaultFormat);

                Assert.AreEqual(testValue, converter.Convert(stringValue));
                Assert.AreEqual(stringValue, converter.ConvertBack(testValue));
            }
        }