public void MetadataDateTime_CompareToOtherWhenFullyEqual_ComparesEqual() { var dateTime0 = new MetadataDateTime(DateTimeOffset.UtcNow, UtcDateTime); var dateTime1 = new MetadataDateTime(dateTime0.Date, UtcDateTime); Assert.Equal(0, dateTime0.CompareTo(dateTime1)); Assert.Equal(0, dateTime0.CompareTo((object)dateTime1)); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: false)); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: false)); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: true)); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: true, compareOnlyCommonValidFields: false)); Assert.True(dateTime1.Equals(dateTime0)); Assert.True(dateTime1.Equals((object)dateTime0)); }
public void MetadataDateTime_CompareToOtherNonStrictWithDifferentFlagsAndDifferenceInCommonField_CommonFieldsCompareAsNotEqual() { var dateTime0 = new MetadataDateTime(DateTimeOffset.Now, Date | MetadataDateTimeFlags.LeapSecond); var dateTime1 = new MetadataDateTime(dateTime0.Date.AddDays(1), DateTime | MetadataDateTimeFlags.LeapSecond); Assert.True(dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: true) != 0); Assert.False(dateTime1.Equals(dateTime0)); Assert.True(dateTime1 != dateTime0); }
public void MetadataDateTime_CompareToOtherNonStrictWithDifferentFlags_CommonFieldsCompareAsEqual() { var dateTime0 = new MetadataDateTime(DateTimeOffset.Now, DateTime | MetadataDateTimeFlags.LeapSecond); var rawDateTime = dateTime0.Date.DateTime; var dateTime1 = new MetadataDateTime(new DateTimeOffset(new DateTime(rawDateTime.Year, rawDateTime.Month, rawDateTime.Day)), Date); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: true)); Assert.True(dateTime1.Equals(dateTime0)); Assert.False(dateTime0.GetHashCode() == dateTime1.GetHashCode()); }
public void MetadataDateTime_EqualsNull_ThrowsArgumentException() { var dateTime = new MetadataDateTime(DateTimeOffset.UtcNow, UtcDateTime); Assert.Throws <ArgumentException>(() => dateTime.Equals(null)); }