提交 a6c3192c 编写于 作者: H Heejae Chang 提交者: Tomas Matousek

add unit test for progress reporter

上级 d88adacf
......@@ -688,6 +688,38 @@ public void SemanticChange_Propagation()
}
}
[Fact]
public void ProgressReporterTest()
{
var solution = GetInitialSolutionInfoWithP2P();
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
WaitWaiter(workspace.ExportProvider);
var service = workspace.Services.GetService<ISolutionCrawlerService>();
var reporter = service.GetProgressReporter(workspace);
Assert.False(reporter.InProgress);
bool started = false;
reporter.Started += (o, a) => { started = true; };
bool stopped = false;
reporter.Stopped += (o, a) => { stopped = true; };
var registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
registrationService.Register(workspace);
workspace.OnSolutionAdded(solution);
Wait((SolutionCrawlerRegistrationService)registrationService, workspace);
registrationService.Unregister(workspace);
Assert.True(started);
Assert.True(stopped);
}
}
private void InsertText(string code, string text, bool expectDocumentAnalysis, string language = LanguageNames.CSharp)
{
using (var workspace = TestWorkspaceFactory.CreateWorkspaceFromLines(
......
......@@ -59,20 +59,24 @@ public bool InProgress
}
}
public void Start()
public Task Start()
{
if (Interlocked.Increment(ref _count) == 1)
{
RaiseStarted();
return RaiseStarted();
}
return SpecializedTasks.EmptyTask;
}
public void Stop()
public Task Stop()
{
if (Interlocked.Decrement(ref _count) == 0)
{
RaiseStopped();
return RaiseStopped();
}
return SpecializedTasks.EmptyTask;
}
private Task RaiseStarted()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册