using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace ScrewTurn.Wiki.Tests {
///
/// Implement some useful testing tool.s
///
public static class Tools {
private const string DateTimeFormat = "yyyy-MM-dd-HH-mm-ss";
///
/// Prints a date/time in the "yyyy/MM/dd HH:mm:ss" format.
///
/// The date/time to print.
/// The string value.
private static string PrintDateTime(DateTime dt) {
return dt.ToString(DateTimeFormat);
}
///
/// Asserts that two date/time values are equal.
///
/// The expected date/time value.
/// The actual date/time value.
/// A value indicating whether to ignore a difference up to 10 seconds.
public static void AssertDateTimesAreEqual(DateTime expected, DateTime actual, bool ignoreUpToTenSecondsDifference) {
if(ignoreUpToTenSecondsDifference) {
TimeSpan span = expected - actual;
Assert.IsTrue(Math.Abs(span.TotalSeconds) <= 10, "Wrong date/time value");
/*Assert.AreEqual(
PrintDateTime(expected).Substring(0, DateTimeFormat.Length - 1),
PrintDateTime(actual).Substring(0, DateTimeFormat.Length - 1),
"Wrong date/time value");*/
}
else {
Assert.AreEqual(PrintDateTime(expected), PrintDateTime(actual), "Wrong date/time value");
}
}
///
/// Asserts that two date/time values are equal.
///
/// The expected date/time value.
/// The actual date/time value.
public static void AssertDateTimesAreEqual(DateTime expected, DateTime actual) {
AssertDateTimesAreEqual(expected, actual, false);
}
}
}