public virtual void GenerateSqlLiteral_returns_DateTimeOffset_literal() { var value = new DateTimeOffset(2015, 3, 12, 13, 36, 37, 371, new TimeSpan(-7, 0, 0)); var literal = new DateTimeOffsetTypeMapping("DateTimeOffset").GenerateSqlLiteral(value); Assert.Equal("TIMESTAMP '2015-03-12 13:36:37.3710000-07:00'", literal); }
public virtual void DateTimeOffset_value_comparer_behaves_correctly() { var typeMapping = new DateTimeOffsetTypeMapping("datetimeoffset", DbType.DateTimeOffset); var same1 = new DateTimeOffset(2000, 1, 1, 12, 0, 0, TimeSpan.FromHours(0)); var same2 = new DateTimeOffset(2000, 1, 1, 12, 0, 0, TimeSpan.FromHours(0)); var different = new DateTimeOffset(2000, 1, 1, 13, 0, 0, TimeSpan.FromHours(1)); // Note that a difference in offset results in inequality, unlike the .NET default comparison behavior Assert.False(typeMapping.Comparer.Equals(same1, different)); Assert.True(typeMapping.Comparer.Equals(same1, same2)); var parameters = new[] { Expression.Parameter(typeof(DateTimeOffset)), Expression.Parameter(typeof(DateTimeOffset)) }; var equalsBody = typeMapping.Comparer.ExtractEqualsBody(parameters[0], parameters[1]); var equalsComparer = Expression.Lambda <Func <DateTimeOffset, DateTimeOffset, bool> >(equalsBody, parameters).Compile(); Assert.False(equalsComparer(same1, different)); Assert.True(equalsComparer(same1, same2)); }