提交 6e1cd85d 编写于 作者: D David Kean

Merge pull request #7518 from davkean/test_delay

Cleanup of ForegroundNotificationServiceTests
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
......@@ -15,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Threading
{
public class ForegroundNotificationServiceTests
{
private readonly IForegroundNotificationService _service;
private readonly ForegroundNotificationService _service;
private bool _done;
public ForegroundNotificationServiceTests()
......@@ -38,7 +39,7 @@ public async Task Test_Enqueue()
Assert.True(_done);
Assert.True(ran);
Assert.True(Empty(_service));
Assert.True(_service.IsEmpty_TestOnly);
}
[WpfFact]
......@@ -60,7 +61,7 @@ public async Task Test_Cancellation()
await PumpWait();
Assert.False(ran);
Assert.True(Empty(_service));
Assert.True(_service.IsEmpty_TestOnly);
}
}
......@@ -69,19 +70,19 @@ public async Task Test_Delay()
{
var asyncToken = EmptyAsyncToken.Instance;
DateTime now = DateTime.UtcNow;
DateTime set = DateTime.UtcNow;
Stopwatch watch = Stopwatch.StartNew();
_service.RegisterNotification(() =>
{
set = DateTime.UtcNow;
watch.Stop();
_done = true;
}, 50, asyncToken, CancellationToken.None);
await PumpWait();
Assert.True(set.Subtract(now).TotalMilliseconds > 50);
Assert.True(Empty(_service));
Assert.False(watch.IsRunning);
Assert.True(watch.ElapsedMilliseconds >= 50);
Assert.True(_service.IsEmpty_TestOnly);
}
[WpfFact]
......@@ -134,7 +135,7 @@ public async Task Test_HeavyMultipleCall()
await PumpWait().ConfigureAwait(false);
Assert.True(_done);
Assert.Equal(count, 9000000);
Assert.True(Empty(_service));
Assert.True(_service.IsEmpty_TestOnly);
}
private async Task PumpWait()
......@@ -144,11 +145,5 @@ private async Task PumpWait()
await Task.Delay(TimeSpan.FromMilliseconds(1));
}
}
private static bool Empty(IForegroundNotificationService service)
{
var temp = (ForegroundNotificationService)service;
return temp.IsEmpty_TestOnly;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册