/// <summary> /// Initializes a new instance of the <see cref="MostRecentlyUsed"/> class. /// </summary> /// <param name="filePath">The full file path for the file.</param> /// <param name="lastOpened">The last time the file was opened by the application.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="filePath"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="filePath"/> is an empty string. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="lastOpened"/> is <see langword="DateTimeOffset.MinValue" /> or <see cref="DateTimeOffset.MaxValue"/>. /// </exception> public MostRecentlyUsed(string filePath, DateTimeOffset lastOpened) { { Lokad.Enforce.Argument(() => filePath); Lokad.Enforce.Argument(() => filePath, Lokad.Rules.StringIs.NotEmpty); Lokad.Enforce.With<ArgumentException>( !lastOpened.Equals(DateTimeOffset.MinValue), Resources.Exceptions_Messages_ArgumentException); Lokad.Enforce.With<ArgumentException>( !lastOpened.Equals(DateTimeOffset.MaxValue), Resources.Exceptions_Messages_ArgumentException); } m_FilePath = filePath; m_LastOpened = lastOpened; }
public void CompareTwoDateInDiffTZ () { DateTimeOffset dt1 = new DateTimeOffset (2007, 12, 16, 15, 06, 00, new TimeSpan (1, 0, 0)); DateTimeOffset dt2 = new DateTimeOffset (2007, 12, 16, 9, 06, 00, new TimeSpan (-5, 0, 0)); DateTimeOffset dt3 = new DateTimeOffset (2007, 12, 16, 14, 06, 00, new TimeSpan (1, 0, 0)); object o = dt1; Assert.IsTrue (dt1.CompareTo (dt2) == 0); Assert.IsTrue (DateTimeOffset.Compare (dt1, dt2) == 0); Assert.IsTrue (dt1 == dt2); Assert.IsTrue (dt1.Equals (dt2)); Assert.IsFalse (dt1 == dt3); Assert.IsTrue (dt1 != dt3); Assert.IsFalse (dt1.EqualsExact (dt2)); Assert.IsTrue (dt1.CompareTo (dt3) > 0); Assert.IsTrue (((IComparable)dt1).CompareTo (o) == 0); }
public void EqualsObject () { DateTimeOffset offset1 = new DateTimeOffset (); Assert.IsFalse (offset1.Equals (null), "null"); // found using Gendarme :) Assert.IsTrue (offset1.Equals (offset1), "self"); DateTimeOffset offset2 = new DateTimeOffset (DateTime.Today); Assert.IsFalse (offset1.Equals (offset2), "1!=2"); Assert.IsFalse (offset2.Equals (offset1), "2!=1"); }
public static void Equals(DateTimeOffset dateTimeOffset1, object obj, bool expectedEquals, bool expectedEqualsExact) { Assert.Equal(expectedEquals, dateTimeOffset1.Equals(obj)); if (obj is DateTimeOffset) { DateTimeOffset dateTimeOffset2 = (DateTimeOffset)obj; Assert.Equal(expectedEquals, dateTimeOffset1.Equals(dateTimeOffset2)); Assert.Equal(expectedEquals, DateTimeOffset.Equals(dateTimeOffset1, dateTimeOffset2)); Assert.Equal(expectedEquals, dateTimeOffset1.GetHashCode().Equals(dateTimeOffset2.GetHashCode())); Assert.Equal(expectedEqualsExact, dateTimeOffset1.EqualsExact(dateTimeOffset2)); Assert.Equal(expectedEquals, dateTimeOffset1 == dateTimeOffset2); Assert.Equal(!expectedEquals, dateTimeOffset1 != dateTimeOffset2); } }
/// <summary> /// Initializes the builder. This resets all the /// internal data structures and prepares them for /// the reception of data for a new <see cref="TestSection"/>. /// </summary> /// <param name="name">The name of the test section.</param> /// <param name="startTime">The start time.</param> /// <exception cref="ArgumentNullException"> /// Thrown when <paramref name="name"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when <paramref name="name"/> is an empty string. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when <paramref name="startTime"/> is equal to <see cref="DateTimeOffset.MinValue"/>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when <paramref name="startTime"/> is equal to <see cref="DateTimeOffset.MaxValue"/>. /// </exception> public void Initialize(string name, DateTimeOffset startTime) { { Lokad.Enforce.Argument(() => name); Lokad.Enforce.Argument(() => name, Lokad.Rules.StringIs.NotEmpty); Lokad.Enforce.With<ArgumentOutOfRangeException>( !startTime.Equals(DateTimeOffset.MinValue), Resources.Exceptions_Messages_ArgumentOutOfRange, startTime); Lokad.Enforce.With<ArgumentOutOfRangeException>( !startTime.Equals(DateTimeOffset.MaxValue), Resources.Exceptions_Messages_ArgumentOutOfRange, startTime); } Clear(); m_Name = name; m_StartTime = startTime; }
/// <summary> /// Adds the warning message. /// </summary> /// <param name="time">The time on which the message was logged.</param> /// <param name="warningMessage">The warning message.</param> /// <exception cref="ArgumentNullException"> /// Thrown when <paramref name="warningMessage"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when <paramref name="warningMessage"/> is an empty string. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when <paramref name="time"/> is equal to <see cref="DateTimeOffset.MinValue"/>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when <paramref name="time"/> is equal to <see cref="DateTimeOffset.MaxValue"/>. /// </exception> /// <exception cref="CannotAddMessageToUninitializedTestSectionException"> /// Thrown when the <c>Initialize</c> method has not been called. /// </exception> public void AddWarningMessage(DateTimeOffset time, string warningMessage) { { Lokad.Enforce.Argument(() => warningMessage); Lokad.Enforce.Argument(() => warningMessage, Lokad.Rules.StringIs.NotEmpty); Lokad.Enforce.With<ArgumentOutOfRangeException>( !time.Equals(DateTimeOffset.MinValue), Resources.Exceptions_Messages_ArgumentOutOfRange, time); Lokad.Enforce.With<ArgumentOutOfRangeException>( !time.Equals(DateTimeOffset.MaxValue), Resources.Exceptions_Messages_ArgumentOutOfRange, time); } if (!WasInitialized) { throw new CannotAddMessageToUninitializedTestSectionException(); } m_WarningMessages.Add(new DateBasedTestInformation(time, warningMessage)); }
public static void ValidateDateNotDefault(DateTimeOffset date, string fieldName) { if(date.Equals(DateTimeOffset.MinValue) || date.Equals(DateTimeOffset.MaxValue)) throw new OrderFieldBadFormatException(string.Format("{0} date value must have a valid logical date (not default value).", fieldName)); }