public void TimestampParser_GivenTimestampOutOfRangeMessage_ReturnsTrue() { var parser = new TimestampParser(); long timestamp; bool result = parser.TryParseTimestamp( TEST_TIMESTAMP_MESSAGE, out timestamp ); Assert.IsTrue( result ); }
public void TimestampParser_GivenUnparsableMessage_ReturnsFalse() { var parser = new TimestampParser(); long timestamp; bool result = parser.TryParseTimestamp( "timestamp", out timestamp ); Assert.IsFalse( result ); }
public void TimestampParser_GivenTimestampOutOfRangeMessage_ParsesTimestampOutOfIt() { var parser = new TimestampParser(); long timestamp; parser.TryParseTimestamp( TEST_TIMESTAMP_MESSAGE, out timestamp ); Assert.AreEqual( TEST_TIMESTAMP, timestamp ); }
/// <summary> /// Adjusts the server skew if necessary based on the body of the response /// </summary> /// <param name="responseBody">The body of the response</param> /// <returns>Whether the timestamp was changed or not</returns> private bool TryCalculateServerSkewFromResponse( string responseBody ) { var timestampParser = new TimestampParser(); long serverTimestampSeconds; if( timestampParser.TryParseTimestamp( responseBody, out serverTimestampSeconds ) ) { long clientTimestampMilliseconds = m_timestampProvider.GetCurrentTimestampInMilliseconds(); m_serverSkewMillis = serverTimestampSeconds * 1000 - clientTimestampMilliseconds; return true; } return false; }
/// <summary> /// Adjusts the server skew if necessary based on the body of the response /// </summary> /// <param name="responseBody">The body of the response</param> /// <returns>Whether the timestamp was changed or not</returns> private bool TryCalculateServerSkewFromResponse(string responseBody) { var timestampParser = new TimestampParser(); long serverTimestampSeconds; if (timestampParser.TryParseTimestamp(responseBody, out serverTimestampSeconds)) { long clientTimestampMilliseconds = m_timestampProvider.GetCurrentTimestampInMilliseconds(); m_serverSkewMillis = serverTimestampSeconds * 1000 - clientTimestampMilliseconds; return(true); } return(false); }