public void MetadataDateTime_CompareToOtherStrictWithDifferentFlags_IsNonzero() { var dateTime0 = new MetadataDateTime(DateTimeOffset.UtcNow, UtcDateTime); var dateTime1 = new MetadataDateTime(dateTime0.Date, DateTime); Assert.True(dateTime0.CompareTo(dateTime1, strict: true) > 0); Assert.True(dateTime1.CompareTo(dateTime0, strict: true) < 0); }
public void MetadataDateTime_CompareToOtherNonStrictWithDifferentFlagsAndDifferenceInNotCommonField_CommonFieldsCompareAsEqual() { // NOTE: It is possible for this test to fail if, by adding one second, it causes the date to roll over to a new year. // So don't run this test on New Year's Eve at 23:59:59+. var dateTime0 = new MetadataDateTime(DateTimeOffset.Now, MetadataDateTimeFlags.Year); var dateTime1 = new MetadataDateTime(dateTime0.Date.AddSeconds(1), DateTime); Assert.Equal(0, dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: true)); }
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_CompareToOtherNonStrictWithNoCommonFlags_ComparesUnderlyingDateTimeOnly() { var dateTime0 = new MetadataDateTime(DateTimeOffset.Now, Date); var dateTime1 = new MetadataDateTime(dateTime0.Date.AddSeconds(1.2), UtcTime); Assert.True((dateTime0.Flags & dateTime1.Flags) == MetadataDateTimeFlags.None); var dateTimeOffsetCompareToResult = dateTime0.Date.CompareTo(dateTime1.Date); var metadataDateTimeCompareToResult = dateTime0.CompareTo(dateTime1, strict: false, compareOnlyCommonValidFields: true); Assert.Equal(dateTimeOffsetCompareToResult, metadataDateTimeCompareToResult); }
public void MetadataDateTimeBuilder_WithLeapSecond_CreatesExpectedMetadataDateTime() { var year = 1999; var second = 60; var flags = MetadataDateTimeFlags.Year | MetadataDateTimeFlags.Second | MetadataDateTimeFlags.LeapSecond; var date = new System.DateTimeOffset(year, 1, 1, 0, 0, 59, TimeSpan.Zero); var expectedMetadataDateTime = new MetadataDateTime(date, flags); var builder = new MetadataDateTimeBuilder(year).WithSecond(second); var actualMetadataDateTime = builder.Build(); Assert.Equal(0, expectedMetadataDateTime.CompareTo(actualMetadataDateTime, strict: true, compareOnlyCommonValidFields: false)); }
public void MetadataDateTimeBuilder_WithUtcOffsetHoursOutOfRange_CreatesExpectedMetadataDateTime() { var year = 1991; var offsetHours = 123; var offsetMinutes = 22; var flags = MetadataDateTimeFlags.Year; var dateTime = new DateTime(year, 1, 1); var date = new System.DateTimeOffset(dateTime, TimeSpan.Zero); var expectedMetadataDateTime = new MetadataDateTime(date, flags); var builder = new MetadataDateTimeBuilder(year).WithOffset(offsetHours, offsetMinutes); var actualMetadataDateTime = builder.Build(); Assert.Equal(0, expectedMetadataDateTime.CompareTo(actualMetadataDateTime, strict: true, compareOnlyCommonValidFields: false)); }
public void CfgVarMetadata_InflateMetadataDateTime_GetsExpectedMetadataDateTimeValue(string cfgFileValue, MetadataDateTime expectedCfgVarMetadataDateValue) { var cfgBooleanEntry = "build_date =" + cfgFileValue; using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgBooleanEntry))) { var cfgVarMetadataBoolean = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataDate; var compareResult = expectedCfgVarMetadataDateValue.CompareTo(cfgVarMetadataBoolean.Date, strict: true, compareOnlyCommonValidFields: false); if (compareResult != 0) { Output.WriteLine("Input: [" + cfgFileValue + "]\nExpected: " + expectedCfgVarMetadataDateValue + "\nActual: " + cfgVarMetadataBoolean.Date); } Assert.Equal(0, compareResult); } }
public void MetadataDateTimeBuilder_WithLocalUtcOffset_CreatesExpectedMetadataDateTime() { var year = 1984; var offsetHours = -3; var offsetMinutes = -3; var flags = MetadataDateTimeFlags.Year | MetadataDateTimeFlags.UtcOffset; var dateTime = new DateTime(year, 1, 1); var offset = TimeZoneInfo.Local.GetUtcOffset(dateTime); var date = new System.DateTimeOffset(dateTime, offset); var expectedMetadataDateTime = new MetadataDateTime(date, flags); var builder = new MetadataDateTimeBuilder(year).WithOffset(offsetHours, offsetMinutes).WithLocalUtcOffset(); var actualMetadataDateTime = builder.Build(); Assert.Equal(0, expectedMetadataDateTime.CompareTo(actualMetadataDateTime, strict: true, compareOnlyCommonValidFields: false)); }
public void MetadataDateTimeBuilder_WithInvalidValues_CreatesExpectedMetadataDateTime() { var year = 1979; var month = 69; var day = 32; var hour = 44; var minute = 88; var second = -2; var flags = MetadataDateTimeFlags.Year; var dateTime = new DateTime(year, 1, 1); var date = new System.DateTimeOffset(dateTime, TimeSpan.Zero); var expectedMetadataDateTime = new MetadataDateTime(date, flags); var builder = new MetadataDateTimeBuilder(year).WithMonth(month).WithDay(day).WithHour(hour).WithMinute(minute).WithSecond(second); var actualMetadataDateTime = builder.Build(); Assert.Equal(0, expectedMetadataDateTime.CompareTo(actualMetadataDateTime, strict: true, compareOnlyCommonValidFields: false)); }
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 MetadataDateTimeBuilder_WithAllValidValues_CreatesExpectedMetadataDateTime() { var year = 2018; var month = 10; var day = 15; var hour = 17; var minute = 34; var second = 48; var offsetHours = 1; var offsetMinutes = 23; var flags = Enum.GetValues(typeof(MetadataDateTimeFlags)).Cast <MetadataDateTimeFlags>().Aggregate((all, flag) => all | flag) & ~MetadataDateTimeFlags.LeapSecond; var offset = new TimeSpan(offsetHours, offsetMinutes, 0); var date = new System.DateTimeOffset(year, month, day, hour, minute, second, offset); var expectedMetadataDateTime = new MetadataDateTime(date, flags); var builder = new MetadataDateTimeBuilder(year); builder.WithMonth(month).WithDay(day).WithHour(hour).WithMinute(minute).WithSecond(second).WithOffset(offsetHours, offsetMinutes); var actualMetadataDateTime = builder.Build(); Assert.Equal(0, expectedMetadataDateTime.CompareTo(actualMetadataDateTime, strict: true, compareOnlyCommonValidFields: false)); }
public void MetadataDateTime_CompareToIncompatibleType_ThrowsArgumentException() { var dateTime = new MetadataDateTime(DateTimeOffset.UtcNow, UtcDateTime); Assert.Throws <ArgumentException>(() => dateTime.CompareTo(DateTimeOffset.UtcNow)); }
public void MetadataDateTime_CompareToNull_ThrowsArgumentException() { var dateTime = new MetadataDateTime(DateTimeOffset.UtcNow, UtcDateTime); Assert.Throws <ArgumentException>(() => dateTime.CompareTo(null)); }