public void TestBaseRepositoryDatesNullCrudAsync() { // 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 insertResult = repository.InsertAsync(entity); var id = insertResult.Result; // Act Query var queryResult = repository.QueryAsync(e => e.SessionId == (Guid)id); var data = queryResult.Result.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); } }
public void TestBaseRepositoryDatesCrudAsync() { // 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 insertResult = repository.InsertAsync(entity); var id = insertResult.Result; // Act Query var queryResult = repository.QueryAsync(e => e.SessionId == (Guid)id); var data = queryResult.Result.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); } }