/// <summary> /// Ensure that the date provided to be injected into a GUID is the same date we get back from it. /// Allowed for an optional resolution loss in the time. Calculates the delta using ticks to /// avoid floating point drift in using TotalMilliseconds. /// </summary> private void IsReversible(ICombProvider Comb, int ClockDriftAllowedMs) { var dt = DateTime.UtcNow; var comb = Comb.Create(dt); var dtDecoded = Comb.GetTimestamp(comb); var delta = (dtDecoded.Ticks - dt.Ticks) / 10000; Assert.InRange(delta, -ClockDriftAllowedMs, ClockDriftAllowedMs); }
public void TestUtcNoRepeatTimestampProvider() { var g1 = SqlNoRepeatCombs.Create(); var dt1 = SqlNoRepeatCombs.GetTimestamp(g1); var inSequenceCount = 0; for (var i = 0; i < 1000; i++) { var g2 = SqlNoRepeatCombs.Create(); var dt2 = SqlNoRepeatCombs.GetTimestamp(g2); if (dt2 > dt1) { inSequenceCount++; } else { Console.WriteLine($"{dt1:MM/dd/yyyy hh:mm:ss.fff} > {dt2:MM/dd/yyyy hh:mm:ss.fff}"); } dt1 = dt2; } Assert.Equal(1000, inSequenceCount); }