Esempio n. 1
0
        public void ReadTimeTz()
        {
            // TODO: Decide on the DateTime kind (#346)
            var expectedNpgsqlTimeTz = new NpgsqlTimeTZ(13, 3, 45, 001000, new NpgsqlTimeZone(-5, 0));
            var expectedDateTime     = new DateTime(expectedNpgsqlTimeTz.AtTimeZone(NpgsqlTimeZone.UTC).Ticks, DateTimeKind.Utc).ToLocalTime();

            using (var cmd = new NpgsqlCommand("SELECT '13:03:45.001-05'::TIMETZ", Conn))
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();

                    // Regular type (DateTime)
                    Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime)));
                    Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime));
                    Assert.That(reader.GetFieldValue <DateTime>(0), Is.EqualTo(expectedDateTime));
                    Assert.That(reader[0], Is.EqualTo(expectedDateTime));
                    Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime));

                    // Provider-specific type (NpgsqlTimeTZ)
                    Assert.That(reader.GetTimeTZ(0), Is.EqualTo(expectedNpgsqlTimeTz));
                    Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTimeTZ)));
                    Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTimeTz));
                    Assert.That(reader.GetFieldValue <NpgsqlTimeTZ>(0), Is.EqualTo(expectedNpgsqlTimeTz));
                }
        }
Esempio n. 2
0
        public void ReadTimeTz()
        {
            // TODO: Decide on the DateTime kind (#346)
            var expectedNpgsqlTimeTz = new NpgsqlTimeTZ(13, 3, 45, 001000, new NpgsqlTimeZone(-5, 0));
            var expectedDateTime = new DateTime(expectedNpgsqlTimeTz.AtTimeZone(NpgsqlTimeZone.UTC).Ticks, DateTimeKind.Utc).ToLocalTime();
            using (var cmd = new NpgsqlCommand("SELECT '13:03:45.001-05'::TIMETZ", Conn))
            using (var reader = cmd.ExecuteReader())
            {
                reader.Read();

                // Regular type (DateTime)
                Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime)));
                Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime));
                Assert.That(reader.GetFieldValue<DateTime>(0), Is.EqualTo(expectedDateTime));
                Assert.That(reader[0], Is.EqualTo(expectedDateTime));
                Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime));

                // Provider-specific type (NpgsqlTimeTZ)
                Assert.That(reader.GetTimeTZ(0), Is.EqualTo(expectedNpgsqlTimeTz));
                Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTimeTZ)));
                Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTimeTz));
                Assert.That(reader.GetFieldValue<NpgsqlTimeTZ>(0), Is.EqualTo(expectedNpgsqlTimeTz));
            }
        }