コード例 #1
0
        public void TestBaseRepositoryDatesNullCrud()
        {
            // Setup
            var entity = new DatesClass
            {
                SessionId            = Guid.NewGuid(),
                ColumnDate           = null,
                ColumnDateTime       = null,
                ColumnDateTime2      = null,
                ColumnSmallDateTime  = null,
                ColumnDateTimeOffset = null,
                ColumnTime           = null
            };

            using (var repository = new DatesClassRepository(Database.ConnectionStringForRepoDb))
            {
                // Act Insert
                var id = repository.Insert(entity);

                // Act Query
                var data = repository.Query(e => e.SessionId == (Guid)id).FirstOrDefault();

                // Assert
                Assert.IsNotNull(data);
                Assert.IsNull(data.ColumnDate);
                Assert.IsNull(data.ColumnDateTime);
                Assert.IsNull(data.ColumnDateTime2);
                Assert.IsNull(data.ColumnSmallDateTime);
                Assert.IsNull(data.ColumnDateTimeOffset);
                Assert.IsNull(data.ColumnTime);
            }
        }
コード例 #2
0
        public void TestBaseRepositoryDatesCrud()
        {
            // Setup
            var dateTime  = new DateTime(1970, 1, 1, 12, 50, 30, DateTimeKind.Utc);
            var dateTime2 = dateTime.AddMilliseconds(100);
            var entity    = new DatesClass
            {
                SessionId            = Guid.NewGuid(),
                ColumnDate           = dateTime.Date,
                ColumnDateTime       = dateTime,
                ColumnDateTime2      = dateTime2,
                ColumnSmallDateTime  = dateTime,
                ColumnDateTimeOffset = new DateTimeOffset(dateTime.Date).ToOffset(TimeSpan.FromHours(2)),
                ColumnTime           = dateTime.TimeOfDay
            };

            using (var repository = new DatesClassRepository(Database.ConnectionStringForRepoDb))
            {
                // Act Insert
                var id = repository.Insert(entity);

                // Act Query
                var data = repository.Query(e => e.SessionId == (Guid)id).FirstOrDefault();

                // Assert
                Assert.IsNotNull(data);
                Assert.AreEqual(entity.ColumnDate, data.ColumnDate);
                Assert.AreEqual(entity.ColumnDateTime, data.ColumnDateTime);
                Assert.AreEqual(entity.ColumnDateTime2, data.ColumnDateTime2);
                Assert.AreEqual(dateTime.AddSeconds(30), data.ColumnSmallDateTime); // Always in a fraction of minutes, round (off/up)
                Assert.AreEqual(entity.ColumnDateTimeOffset, data.ColumnDateTimeOffset);
                Assert.AreEqual(entity.ColumnTime, data.ColumnTime);
            }
        }