public async Task LowerDigitsAreIgnoredAsync()
        {
            if (!Dialect.SupportsDateTimeScale)
            {
                Assert.Ignore("Lower digits cannot be ignored when dialect does not support scale");
            }

            var baseDate = new DateTimeOffset(2017, 10, 01, 17, 55, 24, 548, TimeSpan.FromHours(2));
            var entity   = new DateTimeOffsetClass
            {
                Id    = AdditionalDateId,
                Value = baseDate.AddTicks(TimeSpan.TicksPerMillisecond / 3)
            };

            Assert.That(entity.Value, Is.Not.EqualTo(baseDate));

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    await(s.SaveAsync(entity));
                    await(t.CommitAsync());
                }

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    var retrieved = await(s.LoadAsync <DateTimeOffsetClass>(AdditionalDateId));
                    Assert.That(retrieved.Value, Is.EqualTo(baseDate));
                    await(t.CommitAsync());
                }
        }
        protected override void OnSetUp()
        {
            base.OnSetUp();

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    var d = new DateTimeOffsetClass
                    {
                        Id    = DateId,
                        Value = Now
                    };
                    s.Save(d);
                    t.Commit();
                }
        }
        public virtual async Task SaveUseExpectedSqlTypeAsync()
        {
            var driver = (ClientDriverWithParamsStats)Sfi.ConnectionProvider.Driver;

            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    var d = new DateTimeOffsetClass
                    {
                        Id            = 2,
                        Value         = Now,
                        NullableValue = Now
                    };
                    driver.ClearStats();
                    await(s.SaveAsync(d));
                    await(t.CommitAsync());
                }

            // 2 properties + revision
            AssertSqlType(driver, 3, true);
        }
        public async Task ReadWriteAsync()
        {
            var entity = new DateTimeOffsetClass
            {
                Id    = AdditionalDateId,
                Value = GetTestDate()
            };

            // Now must be acquired before transaction because some db freezes current_timestamp at transaction start,
            // like PostgreSQL. https://www.postgresql.org/docs/7.2/static/functions-datetime.html#AEN6700
            // This then wrecks tests with DbTimestampType if the always out of tran Now is called for fetching
            // beforeNow only after transaction start.
            // And account db accuracy
            var beforeNow = Now.AddTicks(-DateAccuracyInTicks);

            // Save
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    await(s.SaveAsync(entity));
                    await(t.CommitAsync());
                }
            var afterNow = Now.AddTicks(DateAccuracyInTicks);

            if (RevisionCheck)
            {
                Assert.That(entity.Revision, Is.GreaterThan(beforeNow).And.LessThan(afterNow), "Revision not correctly seeded.");
                Assert.That(entity.NullableValue, Is.Null, "NullableValue unexpectedly seeded.");
            }

            // Retrieve, compare then update
            DateTimeOffsetClass retrieved;

            using (var s = OpenSession())
            {
                using (var t = s.BeginTransaction())
                {
                    retrieved = await(s.GetAsync <DateTimeOffsetClass>(AdditionalDateId));

                    Assert.That(retrieved, Is.Not.Null, "Entity not saved or cannot be retrieved by its key.");
                    Assert.That(retrieved.Value, Is.EqualTo(entity.Value), "Unexpected value.");
                    if (RevisionCheck)
                    {
                        Assert.That(retrieved.Revision, Is.EqualTo(entity.Revision), "Revision should be the same.");
                    }
                    Assert.That(retrieved.NullableValue, Is.EqualTo(entity.NullableValue), "NullableValue should be the same.");
                    await(t.CommitAsync());
                }
                beforeNow = Now.AddTicks(-DateAccuracyInTicks);
                using (var t = s.BeginTransaction())
                {
                    retrieved.NullableValue = GetTestDate();
                    retrieved.Value         = GetTestDate().AddMonths(-1);
                    await(t.CommitAsync());
                }
                afterNow = Now.AddTicks(DateAccuracyInTicks);
            }

            if (RevisionCheck)
            {
                Assert.That(
                    retrieved.Revision,
                    Is.GreaterThan(beforeNow).And.LessThan(afterNow).And.GreaterThanOrEqualTo(entity.Revision),
                    "Revision not correctly incremented.");
            }

            // Retrieve and compare again
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    var retrievedAgain = await(s.GetAsync <DateTimeOffsetClass>(AdditionalDateId));

                    Assert.That(retrievedAgain, Is.Not.Null, "Entity deleted or cannot be retrieved again by its key.");
                    Assert.That(
                        retrievedAgain.Value,
                        Is.EqualTo(retrieved.Value),
                        "Unexpected value at second compare.");
                    if (RevisionCheck)
                    {
                        Assert.That(retrievedAgain.Revision, Is.EqualTo(retrieved.Revision), "Revision should be the same again.");
                    }
                    Assert.That(
                        retrievedAgain.NullableValue,
                        Is.EqualTo(retrieved.NullableValue.Value),
                        "Unexpected NullableValue at second compare.");
                    await(t.CommitAsync());
                }
        }