Prevent tests from failing due to dates rounding

This commit is contained in:
Stephan
2016-10-10 19:18:49 +02:00
parent fba4b91bec
commit f1e5b3fcfa

View File

@@ -142,7 +142,13 @@ namespace Umbraco.Tests.TestHelpers
}
else if (dateTimeFormat.IsNullOrWhiteSpace() == false && actualValue is DateTime)
{
Assert.AreEqual(((DateTime) expectedValue).ToString(dateTimeFormat), ((DateTime)actualValue).ToString(dateTimeFormat), "Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expectedValue, actualValue);
// round to second else in some cases tests can fail ;-(
var expectedDateTime = (DateTime) expectedValue;
expectedDateTime = expectedDateTime.AddTicks(-(expectedDateTime.Ticks%TimeSpan.TicksPerSecond));
var actualDateTime = (DateTime) actualValue;
actualDateTime = actualDateTime.AddTicks(-(actualDateTime.Ticks % TimeSpan.TicksPerSecond));
Assert.AreEqual(expectedDateTime.ToString(dateTimeFormat), actualDateTime.ToString(dateTimeFormat), "Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expectedValue, actualValue);
}
else
{