未验证 提交 0e1b3bba 编写于 作者: D Dan Moseley 提交者: GitHub

Improve Stopwatch DebuggerDisplayAttribute test (#70394)

上级 31cd7eb9
......@@ -99,22 +99,15 @@ public static void StartNewAndRestart()
[Fact]
public static void DebuggerAttributesValid()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(new Stopwatch());
Stopwatch watch = new Stopwatch();
Assert.Equal("00:00:00 (IsRunning = False)", GetDebuggerDisplayProperty(watch));
Assert.Equal("00:00:00 (IsRunning = False)", DebuggerAttributes.ValidateDebuggerDisplayReferences(watch));
watch.Start();
Thread.Sleep(10);
Assert.Contains("(IsRunning = True)", GetDebuggerDisplayProperty(watch));
Assert.DoesNotContain("00:00:00 ", GetDebuggerDisplayProperty(watch));
Assert.Contains("(IsRunning = True)", DebuggerAttributes.ValidateDebuggerDisplayReferences(watch));
Assert.DoesNotContain("00:00:00 ", DebuggerAttributes.ValidateDebuggerDisplayReferences(watch));
watch.Stop();
Assert.Contains("(IsRunning = False)", GetDebuggerDisplayProperty(watch));
Assert.DoesNotContain("00:00:00 ", GetDebuggerDisplayProperty(watch));
static string GetDebuggerDisplayProperty(Stopwatch value)
{
return (string)typeof(Stopwatch).GetProperty("DebuggerDisplay", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(value);
}
Assert.Contains("(IsRunning = False)", DebuggerAttributes.ValidateDebuggerDisplayReferences(watch));
Assert.DoesNotContain("00:00:00 ", DebuggerAttributes.ValidateDebuggerDisplayReferences(watch));
}
[OuterLoop("Sleeps for relatively long periods of time")]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册