Пример #1
0
        public void DateTimeUtcConverter_TestCleaningData()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", "Eastern Standard Time" }, { "DateTimeFormat", "MM/dd/yyyy hh:mm:ss" }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", " 05/04/2017      11:02:33+01:00 ");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual("2017-05-04T10:02:33.000Z", convertedPoint["DateTime"].ToString());
        }
Пример #2
0
        public void DateTimeUtcConverter_HandleMoreIso8601()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", "Eastern Standard Time" }, { "DateTimeFormat", "yyyy-MM-dd HH:mm:ss" }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", "2018-08-20T13:44:55.6000000-07:00");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual("2018-08-20T20:44:55.600Z", convertedPoint["DateTime"].ToString());
        }
Пример #3
0
        public void DateTimeUtcConverter_ConvertFails_ReturnsOrgString()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", "50" }, { "DateTimeFormat", "HH:mm" }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", "This is crap text");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual("This is crap text", convertedPoint["DateTime"].ToString()); // UTC
        }
Пример #4
0
        public void DateTimeUtcConverter_ConvertWithInvalidFormat_Success()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", "Mountain Standard Time" }, { "DateTimeFormat", "HH:mm" }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", "2017-01-01 22:11:00.000");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual("2017-01-02T05:11:00.000Z", convertedPoint["DateTime"].ToString()); // UTC
        }
Пример #5
0
        public void DateTimeUtcConverter_ConvertTimeOnly_Success()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", "Mountain Standard Time" }, { "DateTimeFormat", "HH:mm" }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", "09:01");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            var udts = (string)convertedPoint["DateTime"];

            Assert.AreEqual("16:01:00.000Z", udts.Split('T')[1]); // UTC
        }
Пример #6
0
        public void DateTimeUtcConverter_ExactFormatCases()
        {
            const string timeZoneId     = "50";
            const string dateTimeFormat = "HH:mm zzz";
            const string time           = "09:01+01:00";

            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", timeZoneId }, { "DateTimeFormat", dateTimeFormat }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", time);
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);
            var dateTime       = DateTime.ParseExact(time, dateTimeFormat, null, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.NoCurrentDateDefault);

            dateTime = dateTime.ToUniversalTime();
            var expectedValue = dateTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK");

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual(expectedValue, convertedPoint["DateTime"].ToString());
        }