未验证 提交 d69f341a 编写于 作者: E Egil Hansen 提交者: GitHub

Ensure calling ToString when auto advance is enable does not advance time (#4269)

* Ensure calling ToString when auto advance is enable does not advance time
Co-authored-by: NNikita Balabaev <xakep139@users.noreply.github.com>
上级 cd82a9f4
...@@ -161,7 +161,7 @@ public override long GetTimestamp() ...@@ -161,7 +161,7 @@ public override long GetTimestamp()
/// Returns a string representation this provider's idea of current time. /// Returns a string representation this provider's idea of current time.
/// </summary> /// </summary>
/// <returns>A string representing the provider's current time.</returns> /// <returns>A string representing the provider's current time.</returns>
public override string ToString() => GetUtcNow().ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture); public override string ToString() => _now.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture);
/// <inheritdoc /> /// <inheritdoc />
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period) public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
......
...@@ -320,5 +320,29 @@ public void AutoAdvance() ...@@ -320,5 +320,29 @@ public void AutoAdvance()
Assert.Equal(timeProvider.Start + TimeSpan.FromSeconds(1), second); Assert.Equal(timeProvider.Start + TimeSpan.FromSeconds(1), second);
Assert.Equal(timeProvider.Start + TimeSpan.FromSeconds(2), third); Assert.Equal(timeProvider.Start + TimeSpan.FromSeconds(2), third);
} }
[Fact]
public void ToString_AutoAdvance_off()
{
var timeProvider = new FakeTimeProvider();
_ = timeProvider.ToString();
Assert.Equal(timeProvider.Start, timeProvider.GetUtcNow());
}
[Fact]
public void ToString_AutoAdvance_on()
{
var timeProvider = new FakeTimeProvider
{
AutoAdvanceAmount = TimeSpan.FromSeconds(1)
};
_ = timeProvider.ToString();
timeProvider.AutoAdvanceAmount = TimeSpan.Zero;
Assert.Equal(timeProvider.Start, timeProvider.GetUtcNow());
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册